Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_Hypre.H
Go to the documentation of this file.
1#ifndef AMREX_HYPRE_H_
2#define AMREX_HYPRE_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Geometry.H>
6#include <AMReX_MultiFab.H>
7#include <AMReX_BndryData.H>
8
9#include "HYPRE.h"
10#include "_hypre_utilities.h"
11#include "HYPRE_parcsr_ls.h"
12
13#include <memory>
14
22namespace amrex
23{
24
32namespace HypreDefaults {
33#ifdef HYPRE_USING_GPU
34 inline constexpr bool gpu = true;
35#else
36 inline constexpr bool gpu = false;
37#endif
39 inline constexpr bool old_default = !gpu;
40 inline constexpr int coarsen_type = gpu ? 8 : 6;
41 inline constexpr int interp_type = gpu ? 6 : 0;
42 inline constexpr int pmax_elmts = 4;
43 inline constexpr int keep_transpose = gpu ? 1 : 0;
44 inline constexpr int relax_type = gpu ? 18 : 6;
45 inline constexpr int relax_order = gpu ? 0 : 1;
46
48 inline void setGpuOptions (HYPRE_Solver solver)
49 {
50 HYPRE_BoomerAMGSetCoarsenType(solver, coarsen_type);
51 HYPRE_BoomerAMGSetInterpType(solver, interp_type);
52 HYPRE_BoomerAMGSetPMaxElmts(solver, pmax_elmts);
53 HYPRE_BoomerAMGSetKeepTranspose(solver, keep_transpose);
54 }
55}
56
65class Hypre
66{
67public:
68
70 enum class Interface : int { structed, semi_structed, ij };
71
80 Hypre (const BoxArray& grids,
81 const DistributionMapping& dmap,
82 const Geometry& geom,
83 MPI_Comm comm_);
84
85 virtual ~Hypre ();
86 Hypre (Hypre &&) noexcept = default;
87 Hypre& operator= (Hypre &&) noexcept = default;
88
89 Hypre (Hypre const&) = delete;
90 Hypre& operator= (Hypre const&) = delete;
91
95 void setScalars (Real sa, Real sb);
99 void setACoeffs (const MultiFab& alpha);
103 void setBCoeffs (const Array<const MultiFab*,BL_SPACEDIM>& beta);
105 void setVerbose (int _verbose);
107 void setIsMatrixSingular(bool flag) { is_matrix_singular = flag; }
119 virtual void solve (MultiFab& soln, const MultiFab& rhs, Real rel_tol, Real abs_tol,
120 int max_iter, const BndryData& bndry, int max_bndry_order) = 0;
121
125 static HYPRE_Int ispow2 (HYPRE_Int i)
126 {
127 if (i == 1) {
128 return 1;
129 } else if ((i <= 0) || (i & 1)) {
130 return 0;
131 } else {
132 return ispow2(i/2);
133 }
134 }
135
138 const auto& v = b.loVect();
139 return {AMREX_D_DECL(static_cast<HYPRE_Int>(v[0]),
140 static_cast<HYPRE_Int>(v[1]),
141 static_cast<HYPRE_Int>(v[2]))};
142 }
143
146 const auto& v = b.hiVect();
147 return {AMREX_D_DECL(static_cast<HYPRE_Int>(v[0]),
148 static_cast<HYPRE_Int>(v[1]),
149 static_cast<HYPRE_Int>(v[2]))};
150 }
151
152
154 void setHypreOptionsNamespace (const std::string& ns) noexcept
155 { options_namespace = ns; }
157 void setHypreOldDefault (bool l) noexcept {old_default = l;}
159 void setHypreRelaxType (int n) noexcept {relax_type = n;}
161 void setHypreRelaxOrder (int n) noexcept {relax_order = n;}
163 void setHypreNumSweeps (int n) noexcept {num_sweeps = n;}
166
168 static constexpr HYPRE_Int regular_stencil_size = 2*AMREX_SPACEDIM + 1;
170 static constexpr HYPRE_Int eb_stencil_size = AMREX_D_TERM(3, *3, *3);
171
172protected:
173
176
177 int verbose = 0;
181 int num_sweeps = 2; // Sweeeps on each level
182 Real strong_threshold = Real(0.25); // HYPRE default is 0.25
183
184 std::string options_namespace{"hypre"};
185
189
191 BndryData const* m_bndry = nullptr;
192 int m_maxorder = -1;
193
194 bool is_matrix_singular { false };
195};
196
208[[nodiscard]] std::unique_ptr<Hypre>
209makeHypre (const BoxArray& grids, const DistributionMapping& dmap,
210 const Geometry& geom, MPI_Comm comm_, Hypre::Interface interface,
211 const iMultiFab* overset_mask = nullptr);
212
213}
214
215#endif
Boundary data container that owns masks, boundary values, and metadata.
Problem-domain geometry: maps between index space and physical space.
HYPRE_Solver solver
HYPRE solver/preconditioner whose options are being set.
Definition AMReX_HypreIJIface.cpp:21
GpuArray< Real, 3 > beta
Definition AMReX_MLEBNodeFDLaplacian.cpp:1834
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
#define BL_SPACEDIM
Definition AMReX_SPACE.H:15
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
__host__ __device__ const int * hiVect() const &noexcept
Return a pointer to the high-end coordinates (useful for Fortran calls).
Definition AMReX_Box.H:210
__host__ __device__ const int * loVect() const &noexcept
Return a pointer to the low-end coordinates (useful for Fortran calls).
Definition AMReX_Box.H:205
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:51
Abstract factory interface for creating, aliasing, and destroying FAB objects.
Definition AMReX_FabFactory.H:73
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:85
Lightweight base class shared by HYPRE-backed linear solvers, HypreABecLap, HypreABecLap2,...
Definition AMReX_Hypre.H:66
static Array< HYPRE_Int, 3 > hiV(const Box &b)
Convenience helper that casts a box's high corner to HYPRE_Int.
Definition AMReX_Hypre.H:145
bool is_matrix_singular
Definition AMReX_Hypre.H:194
void setBCoeffs(const Array< const MultiFab *, 3 > &beta)
Install per-face b coefficients for each spatial direction.
Definition AMReX_Hypre.cpp:76
Array< MultiFab, 3 > bcoefs
Definition AMReX_Hypre.H:187
void setHypreOldDefault(bool l) noexcept
Toggle HYPRE's "old default" AMG setup (Falgout + modified classical interpolation) via l.
Definition AMReX_Hypre.H:157
void setVerbose(int _verbose)
Set HYPRE verbosity level (_verbose).
Definition AMReX_Hypre.cpp:85
MultiFab acoefs
Definition AMReX_Hypre.H:186
int verbose
Definition AMReX_Hypre.H:177
void setHypreStrongThreshold(Real t) noexcept
Adjust HYPRE's AMG strong-connection threshold used during coarsening via t.
Definition AMReX_Hypre.H:165
Hypre(Hypre &&) noexcept=default
void setHypreRelaxType(int n) noexcept
Choose the relaxation type handed to HYPRE (see HYPRE docs for valid codes) via n.
Definition AMReX_Hypre.H:159
static HYPRE_Int ispow2(HYPRE_Int i)
Return 1 if i is a power of two, otherwise 0.
Definition AMReX_Hypre.H:125
static constexpr HYPRE_Int eb_stencil_size
Stencil size used on EB cells (3^D).
Definition AMReX_Hypre.H:170
MPI_Comm comm
Definition AMReX_Hypre.H:174
Real scalar_a
Definition AMReX_Hypre.H:188
BndryData const * m_bndry
Definition AMReX_Hypre.H:191
void setHypreOptionsNamespace(const std::string &ns) noexcept
Override the ParmParse namespace consulted for HYPRE runtime options (ns).
Definition AMReX_Hypre.H:154
int m_maxorder
Definition AMReX_Hypre.H:192
FabFactory< FArrayBox > const * m_factory
Definition AMReX_Hypre.H:190
Real scalar_b
Definition AMReX_Hypre.H:188
Geometry geom
Definition AMReX_Hypre.H:175
std::string options_namespace
Definition AMReX_Hypre.H:184
void setHypreNumSweeps(int n) noexcept
Set the number of pre/post smoothing sweeps HYPRE executes on each level via n.
Definition AMReX_Hypre.H:163
int relax_order
Definition AMReX_Hypre.H:180
static Array< HYPRE_Int, 3 > loV(const Box &b)
Convenience helper that casts a box's low corner to HYPRE_Int.
Definition AMReX_Hypre.H:137
int relax_type
Definition AMReX_Hypre.H:179
int num_sweeps
Definition AMReX_Hypre.H:181
static constexpr HYPRE_Int regular_stencil_size
Stencil size used on regular cells.
Definition AMReX_Hypre.H:168
void setScalars(Real sa, Real sb)
Store constant scalars applied to the a (diagonal) and b (Laplacian) terms.
Definition AMReX_Hypre.cpp:63
Real strong_threshold
Definition AMReX_Hypre.H:182
virtual void solve(MultiFab &soln, const MultiFab &rhs, Real rel_tol, Real abs_tol, int max_iter, const BndryData &bndry, int max_bndry_order)=0
Solve the linear system using the concrete interface implementation.
void setIsMatrixSingular(bool flag)
Flag a singular operator (enables null-space handling in derived classes).
Definition AMReX_Hypre.H:107
void setACoeffs(const MultiFab &alpha)
Install per-cell a coefficients.
Definition AMReX_Hypre.cpp:70
void setHypreRelaxOrder(int n) noexcept
Choose the relaxation ordering (C/F, lexicographic, etc.) via n.
Definition AMReX_Hypre.H:161
Interface
HYPRE interface modes supported.
Definition AMReX_Hypre.H:70
bool old_default
Definition AMReX_Hypre.H:178
virtual ~Hypre()
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
std::array< T, N > Array
Definition AMReX_Array.H:31
constexpr int interp_type
Definition AMReX_Hypre.H:41
constexpr int coarsen_type
Definition AMReX_Hypre.H:40
constexpr bool gpu
Definition AMReX_Hypre.H:36
constexpr int relax_order
Definition AMReX_Hypre.H:45
constexpr int relax_type
Definition AMReX_Hypre.H:44
constexpr bool old_default
Falgout coarsening with modified classical interpolation.
Definition AMReX_Hypre.H:39
constexpr int pmax_elmts
Definition AMReX_Hypre.H:42
void setGpuOptions(HYPRE_Solver solver)
Coarsening, interpolation and transpose options for GPU builds.
Definition AMReX_Hypre.H:48
constexpr int keep_transpose
Definition AMReX_Hypre.H:43
int MPI_Comm
Definition AMReX_ccse-mpi.H:51
static constexpr int MPI_COMM_NULL
Definition AMReX_ccse-mpi.H:59
Definition AMReX_Amr.cpp:50
std::unique_ptr< Hypre > makeHypre(const BoxArray &grids, const DistributionMapping &dmap, const Geometry &geom, MPI_Comm comm_, Hypre::Interface interface, const iMultiFab *overset_mask)
Factory that instantiates the requested HYPRE interface.
Definition AMReX_Hypre.cpp:12