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
21
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; }
110 void setThrowException (bool t) noexcept { throw_exception = t; }
122 virtual void solve (MultiFab& soln, const MultiFab& rhs, Real rel_tol, Real abs_tol,
123 int max_iter, const BndryData& bndry, int max_bndry_order) = 0;
124
128 static HYPRE_Int ispow2 (HYPRE_Int i)
129 {
130 if (i == 1) {
131 return 1;
132 } else if ((i <= 0) || (i & 1)) {
133 return 0;
134 } else {
135 return ispow2(i/2);
136 }
137 }
138
141 const auto& v = b.loVect();
142 return {AMREX_D_DECL(static_cast<HYPRE_Int>(v[0]),
143 static_cast<HYPRE_Int>(v[1]),
144 static_cast<HYPRE_Int>(v[2]))};
145 }
146
149 const auto& v = b.hiVect();
150 return {AMREX_D_DECL(static_cast<HYPRE_Int>(v[0]),
151 static_cast<HYPRE_Int>(v[1]),
152 static_cast<HYPRE_Int>(v[2]))};
153 }
154
155
157 void setHypreOptionsNamespace (const std::string& ns) noexcept
158 { options_namespace = ns; }
159
160 void setHypreOldDefault (bool l) noexcept {old_default = l;}
162 void setHypreRelaxType (int n) noexcept {relax_type = n;}
164 void setHypreRelaxOrder (int n) noexcept {relax_order = n;}
166 void setHypreNumSweeps (int n) noexcept {num_sweeps = n;}
169
171 static constexpr HYPRE_Int regular_stencil_size = 2*AMREX_SPACEDIM + 1;
173 static constexpr HYPRE_Int eb_stencil_size = AMREX_D_TERM(3, *3, *3);
174
175protected:
176
179
180 int verbose = 0;
184 int num_sweeps = 2; // Sweeeps on each level
185 Real strong_threshold = Real(0.25); // HYPRE default is 0.25
186
187 std::string options_namespace{"hypre"};
188
192
194 BndryData const* m_bndry = nullptr;
195 int m_maxorder = -1;
196
197 bool is_matrix_singular { false };
198 bool throw_exception { false };
199};
200
212[[nodiscard]] std::unique_ptr<Hypre>
213makeHypre (const BoxArray& grids, const DistributionMapping& dmap,
214 const Geometry& geom, MPI_Comm comm_, Hypre::Interface interface,
215 const iMultiFab* overset_mask = nullptr);
216
217}
218
219#endif
Boundary data container that owns masks, boundary values, and metadata.
Problem-domain geometry: maps between index space and physical space.
#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:87
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:148
bool is_matrix_singular
Definition AMReX_Hypre.H:197
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:190
void setHypreOldDefault(bool l) noexcept
Toggle HYPRE's "old default" AMG setup (Falgout + modified classical interpolation) via l.
Definition AMReX_Hypre.H:160
void setVerbose(int _verbose)
Set HYPRE verbosity level (_verbose).
Definition AMReX_Hypre.cpp:85
MultiFab acoefs
Definition AMReX_Hypre.H:189
void setThrowException(bool t) noexcept
Definition AMReX_Hypre.H:110
int verbose
Definition AMReX_Hypre.H:180
void setHypreStrongThreshold(Real t) noexcept
Adjust HYPRE's AMG strong-connection threshold used during coarsening via t.
Definition AMReX_Hypre.H:168
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:162
static HYPRE_Int ispow2(HYPRE_Int i)
Return 1 if i is a power of two, otherwise 0.
Definition AMReX_Hypre.H:128
static constexpr HYPRE_Int eb_stencil_size
Stencil size used on EB cells (3^D).
Definition AMReX_Hypre.H:173
MPI_Comm comm
Definition AMReX_Hypre.H:177
Real scalar_a
Definition AMReX_Hypre.H:191
BndryData const * m_bndry
Definition AMReX_Hypre.H:194
void setHypreOptionsNamespace(const std::string &ns) noexcept
Override the ParmParse namespace consulted for HYPRE runtime options (ns).
Definition AMReX_Hypre.H:157
int m_maxorder
Definition AMReX_Hypre.H:195
bool throw_exception
Definition AMReX_Hypre.H:198
FabFactory< FArrayBox > const * m_factory
Definition AMReX_Hypre.H:193
Real scalar_b
Definition AMReX_Hypre.H:191
Geometry geom
Definition AMReX_Hypre.H:178
std::string options_namespace
Definition AMReX_Hypre.H:187
void setHypreNumSweeps(int n) noexcept
Set the number of pre/post smoothing sweeps HYPRE executes on each level via n.
Definition AMReX_Hypre.H:166
int relax_order
Definition AMReX_Hypre.H:183
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:140
int relax_type
Definition AMReX_Hypre.H:182
int num_sweeps
Definition AMReX_Hypre.H:184
static constexpr HYPRE_Int regular_stencil_size
Stencil size used on regular cells.
Definition AMReX_Hypre.H:171
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:185
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:164
Interface
HYPRE interface modes supported.
Definition AMReX_Hypre.H:70
@ structed
Definition AMReX_Hypre.H:70
@ ij
Definition AMReX_Hypre.H:70
@ semi_structed
Definition AMReX_Hypre.H:70
bool old_default
Definition AMReX_Hypre.H:181
virtual ~Hypre()
Hypre(const BoxArray &grids, const DistributionMapping &dmap, const Geometry &geom, MPI_Comm comm_)
Construct a HYPRE wrapper bound to the supplied grids.
Definition AMReX_Hypre.cpp:27
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
BoomerAMG defaults.
Definition AMReX_Hypre.H:32
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
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
BndryDataT< MultiFab > BndryData
Definition AMReX_BndryData.H:336
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