|
|
|
@ -0,0 +1,44 @@ |
|
|
|
|
|
|
|
<!DOCTYPE html> |
|
|
|
|
|
|
|
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Solvers and preconditioners · HYPRE.jl</title><script data-outdated-warner src="../assets/warner.js"></script><link rel="canonical" href="https://fredrikekre.github.io/HYPRE.jl/stable/solvers-preconditioners/"/><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../">HYPRE.jl</a></span></div><form class="docs-search" action="../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../">Home</a></li><li><a class="tocitem" href="../matrix-vector/">Matrix/vector representation</a></li><li class="is-active"><a class="tocitem" href>Solvers and preconditioners</a></li><li><a class="tocitem" href="../libhypre/">LibHYPRE C API</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Solvers and preconditioners</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Solvers and preconditioners</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/fredrikekre/HYPRE.jl" title="View the repository on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">GitHub</span></a><a class="docs-navbar-link" href="https://github.com/fredrikekre/HYPRE.jl/blob/master/docs/src/solvers-preconditioners.md" title="Edit source on GitHub"><span class="docs-icon fas"></span></a><a class="docs-settings-button docs-navbar-link fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button docs-navbar-link fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="Solvers-and-preconditioners"><a class="docs-heading-anchor" href="#Solvers-and-preconditioners">Solvers and preconditioners</a><a id="Solvers-and-preconditioners-1"></a><a class="docs-heading-anchor-permalink" href="#Solvers-and-preconditioners" title="Permalink"></a></h1><p>HYPRE.jl wraps most of HYPREs <a href="https://hypre.readthedocs.io/en/latest/api-sol-parcsr.html">ParCSR solvers and preconditioners</a>.</p><p>The synopsis for HYPRE.jl's wrappers is the same for all solvers:</p><pre><code class="language-julia hljs"># Setup up linear system (see previous section) |
|
|
|
|
|
|
|
A = HYPREMatrix(...) |
|
|
|
|
|
|
|
b = HYPREVector(...) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create a solver |
|
|
|
|
|
|
|
solver = HYPRESolver(; settings...) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Solve A x = b |
|
|
|
|
|
|
|
x = HYPRE.solve(solver, A, b)</code></pre><p>Settings are passed as keyword arguments, with the names matching directly to <code>HYPRE_SolverSetXXX</code> calls from the HYPRE C API (see example below). Most settings are passed directly to HYPRE, for example <code>Tol = 1e-9</code> would be passed directly to <code>HYPRE_SolverSetTol</code> for the correponding solver.</p><p>Setting a preconditioner can be done by passing a <code>HYPRESolver</code> directly with the <code>Precond</code> keyword argument, without any need to also pass the corresponding <code>HYPRE_SolverSetup</code> and <code>HYPRE_SolverSolve</code> as must be done in the C API. In addition, solvers that have required settings when used as a preconditioner will have those applied automatically.</p><p>HYPRE.jl adds finalizers to the solvers, which takes care of calling the their respective <code>HYPRE_SolverDestroy</code> function when the solver is garbage collected.</p><h4 id="Example:-Conjugate-gradient-with-algebraic-multigrid-preconditioner"><a class="docs-heading-anchor" href="#Example:-Conjugate-gradient-with-algebraic-multigrid-preconditioner">Example: Conjugate gradient with algebraic multigrid preconditioner</a><a id="Example:-Conjugate-gradient-with-algebraic-multigrid-preconditioner-1"></a><a class="docs-heading-anchor-permalink" href="#Example:-Conjugate-gradient-with-algebraic-multigrid-preconditioner" title="Permalink"></a></h4><p>Here is an example of creating a <code>PCG</code> (conjugate gradient) solver with <code>BoomerAMG</code> (algebraic multigrid) as preconditioner:</p><pre><code class="language-julia hljs"># Setup up linear system |
|
|
|
|
|
|
|
A = HYPREMatrix(...) |
|
|
|
|
|
|
|
b = HYPREVector(...) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Preconditioner |
|
|
|
|
|
|
|
precond = HYPRE.BoomerAMG(; RelaxType = 6, CoarsenType = 6) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Solver |
|
|
|
|
|
|
|
solver = HYPRE.PCG(; MaxIter = 1000, Tol = 1e-9, Precond = precond) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Solve |
|
|
|
|
|
|
|
x = HYPRE.solve(solver, A, b)</code></pre><p>Note that <code>Tol = 0.0</code> and <code>MaxIter = 1</code> are required settings when using <code>BoomerAMG</code> as a preconditioner. These settings are added automatically since it is passed as a preconditioner to the <code>PCG</code> solver.</p><div class="admonition is-category-not"><header class="admonition-header">Corresponding C code</header><div class="admonition-body"><p>For comparison, here is the corresponding C code for setting up the solver above:</p><pre><code class="language-c hljs">/* Setup linear system */ |
|
|
|
|
|
|
|
HYPRE_IJMatrix A; |
|
|
|
|
|
|
|
HYPRE_IJVector b, x; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Preconditioner */ |
|
|
|
|
|
|
|
HYPRE_Solver precond; |
|
|
|
|
|
|
|
HYPRE_BoomerAMGCreate(&precond); |
|
|
|
|
|
|
|
HYPRE_BoomerAMGSetCoarsenType(precond, 6); |
|
|
|
|
|
|
|
HYPRE_BoomerAMGSetRelaxType(precond, 6); |
|
|
|
|
|
|
|
HYPRE_BoomerAMGSetTol(precond, 0.0); |
|
|
|
|
|
|
|
HYPRE_BoomerAMGSetMaxIter(precond, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Solver */ |
|
|
|
|
|
|
|
HYPRE_Solver solver; |
|
|
|
|
|
|
|
HYPRE_ParCSRPCGCreate(MPI_COMM_WORLD, &solver); |
|
|
|
|
|
|
|
HYPRE_PCGSetMaxIter(solver, 1000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Add preconditioner */ |
|
|
|
|
|
|
|
HYPRE_PCGSetPrecond(solver, (HYPRE_PtrToSolverFcn) HYPRE_BoomerAMGSolve, |
|
|
|
|
|
|
|
(HYPRE_PtrToSolverFcn) HYPRE_BoomerAMGSetup, precond); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Solve */ |
|
|
|
|
|
|
|
HYPRE_ParCSRPCGSetup(solver, A, b, x); |
|
|
|
|
|
|
|
HYPRE_ParCSRPCGSolve(solver, A, b, x);</code></pre></div></div></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../matrix-vector/">« Matrix/vector representation</a><a class="docs-footer-nextpage" href="../libhypre/">LibHYPRE C API »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.28.0-DEV on <span class="colophon-date" title="Thursday 28 July 2022 15:33">Thursday 28 July 2022</span>. Using Julia version 1.7.3.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |