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
12#include <memory>
13
21namespace amrex
22{
23
32class Hypre
33{
34public:
35
37 enum class Interface : int { structed, semi_structed, ij };
38
47 Hypre (const BoxArray& grids,
48 const DistributionMapping& dmap,
49 const Geometry& geom,
50 MPI_Comm comm_);
51
52 virtual ~Hypre ();
53 Hypre (Hypre &&) noexcept = default;
54 Hypre& operator= (Hypre &&) noexcept = default;
55
56 Hypre (Hypre const&) = delete;
57 Hypre& operator= (Hypre const&) = delete;
58
62 void setScalars (Real sa, Real sb);
66 void setACoeffs (const MultiFab& alpha);
70 void setBCoeffs (const Array<const MultiFab*,BL_SPACEDIM>& beta);
72 void setVerbose (int _verbose);
74 void setIsMatrixSingular(bool flag) { is_matrix_singular = flag; }
86 virtual void solve (MultiFab& soln, const MultiFab& rhs, Real rel_tol, Real abs_tol,
87 int max_iter, const BndryData& bndry, int max_bndry_order) = 0;
88
92 static HYPRE_Int ispow2 (HYPRE_Int i)
93 {
94 if (i == 1) {
95 return 1;
96 } else if ((i <= 0) || (i & 1)) {
97 return 0;
98 } else {
99 return ispow2(i/2);
100 }
101 }
102
105 const auto& v = b.loVect();
106 return {AMREX_D_DECL(static_cast<HYPRE_Int>(v[0]),
107 static_cast<HYPRE_Int>(v[1]),
108 static_cast<HYPRE_Int>(v[2]))};
109 }
110
113 const auto& v = b.hiVect();
114 return {AMREX_D_DECL(static_cast<HYPRE_Int>(v[0]),
115 static_cast<HYPRE_Int>(v[1]),
116 static_cast<HYPRE_Int>(v[2]))};
117 }
118
119
121 void setHypreOptionsNamespace (const std::string& ns) noexcept
122 { options_namespace = ns; }
124 void setHypreOldDefault (bool l) noexcept {old_default = l;}
126 void setHypreRelaxType (int n) noexcept {relax_type = n;}
128 void setHypreRelaxOrder (int n) noexcept {relax_order = n;}
130 void setHypreNumSweeps (int n) noexcept {num_sweeps = n;}
133
135 static constexpr HYPRE_Int regular_stencil_size = 2*AMREX_SPACEDIM + 1;
137 static constexpr HYPRE_Int eb_stencil_size = AMREX_D_TERM(3, *3, *3);
138
139protected:
140
143
144 int verbose = 0;
145 bool old_default = true; // Falgout coarsening with modified classical interpolation
146 int relax_type = 6; // G-S/Jacobi hybrid relaxation
147 int relax_order = 1; // uses C/F relaxation
148 int num_sweeps = 2; // Sweeeps on each level
149 Real strong_threshold = Real(0.25); // HYPRE default is 0.25
150
151 std::string options_namespace{"hypre"};
152
156
158
160 BndryData const* m_bndry = nullptr;
161 int m_maxorder = -1;
162
163 bool is_matrix_singular { false };
164};
165
177[[nodiscard]] std::unique_ptr<Hypre>
178makeHypre (const BoxArray& grids, const DistributionMapping& dmap,
179 const Geometry& geom, MPI_Comm comm_, Hypre::Interface interface,
180 const iMultiFab* overset_mask = nullptr);
181
182}
183
184#endif
Boundary data container that owns masks, boundary values, and metadata.
#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
A BndryData stores and manipulates boundary data information on each side of each box in a BoxArray.
Definition AMReX_BndryData.H:46
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:568
__host__ __device__ const int * hiVect() const &noexcept
Return a constant pointer the array of high end coordinates. Useful for calls to FORTRAN.
Definition AMReX_Box.H:191
__host__ __device__ const int * loVect() const &noexcept
Return a constant pointer the array of low end coordinates. Useful for calls to FORTRAN.
Definition AMReX_Box.H:186
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:43
Definition AMReX_FabFactory.H:50
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
Lightweight base class shared by HYPRE-backed linear solvers, HypreABecLap, HypreABecLap2,...
Definition AMReX_Hypre.H:33
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:112
bool is_matrix_singular
Definition AMReX_Hypre.H:163
void setBCoeffs(const Array< const MultiFab *, 3 > &beta)
Install per-face b coefficients for each spatial direction.
Definition AMReX_Hypre.cpp:78
Array< MultiFab, 3 > bcoefs
Definition AMReX_Hypre.H:154
void setHypreOldDefault(bool l) noexcept
Toggle HYPRE's "old default" AMG setup (Falgout + modified classical interpolation) via l.
Definition AMReX_Hypre.H:124
void setVerbose(int _verbose)
Set HYPRE verbosity level (_verbose).
Definition AMReX_Hypre.cpp:87
MultiFab acoefs
Definition AMReX_Hypre.H:153
int verbose
Definition AMReX_Hypre.H:144
void setHypreStrongThreshold(Real t) noexcept
Adjust HYPRE's AMG strong-connection threshold used during coarsening via t.
Definition AMReX_Hypre.H:132
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:126
static HYPRE_Int ispow2(HYPRE_Int i)
Return 1 if i is a power of two, otherwise 0.
Definition AMReX_Hypre.H:92
static constexpr HYPRE_Int eb_stencil_size
Stencil size used on EB cells (3^D).
Definition AMReX_Hypre.H:137
MPI_Comm comm
Definition AMReX_Hypre.H:141
Real scalar_a
Definition AMReX_Hypre.H:155
BndryData const * m_bndry
Definition AMReX_Hypre.H:160
void setHypreOptionsNamespace(const std::string &ns) noexcept
Override the ParmParse namespace consulted for HYPRE runtime options (ns).
Definition AMReX_Hypre.H:121
MultiFab diaginv
Definition AMReX_Hypre.H:157
int m_maxorder
Definition AMReX_Hypre.H:161
FabFactory< FArrayBox > const * m_factory
Definition AMReX_Hypre.H:159
Real scalar_b
Definition AMReX_Hypre.H:155
Geometry geom
Definition AMReX_Hypre.H:142
std::string options_namespace
Definition AMReX_Hypre.H:151
void setHypreNumSweeps(int n) noexcept
Set the number of pre/post smoothing sweeps HYPRE executes on each level via n.
Definition AMReX_Hypre.H:130
int relax_order
Definition AMReX_Hypre.H:147
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:104
int relax_type
Definition AMReX_Hypre.H:146
int num_sweeps
Definition AMReX_Hypre.H:148
static constexpr HYPRE_Int regular_stencil_size
Stencil size used on regular cells.
Definition AMReX_Hypre.H:135
void setScalars(Real sa, Real sb)
Store constant scalars applied to the a (diagonal) and b (Laplacian) terms.
Definition AMReX_Hypre.cpp:65
Real strong_threshold
Definition AMReX_Hypre.H:149
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:74
void setACoeffs(const MultiFab &alpha)
Install per-cell a coefficients.
Definition AMReX_Hypre.cpp:72
void setHypreRelaxOrder(int n) noexcept
Choose the relaxation ordering (C/F, lexicographic, etc.) via n.
Definition AMReX_Hypre.H:128
Interface
HYPRE interface modes supported.
Definition AMReX_Hypre.H:37
bool old_default
Definition AMReX_Hypre.H:145
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:79
std::array< T, N > Array
Definition AMReX_Array.H:26
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:49
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