Block-Structured AMR Software Framework
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 
14 namespace amrex
15 {
16 
17 class Hypre
18 {
19 public:
20 
21  enum class Interface : int { structed, semi_structed, ij };
22 
23  Hypre (const BoxArray& grids,
24  const DistributionMapping& dmap,
25  const Geometry& geom,
26  MPI_Comm comm_);
27 
28  virtual ~Hypre ();
29  Hypre (Hypre &&) noexcept = default;
30  Hypre& operator= (Hypre &&) noexcept = default;
31 
32  Hypre (Hypre const&) = delete;
33  Hypre& operator= (Hypre const&) = delete;
34 
35  void setScalars (Real sa, Real sb);
36  void setACoeffs (const MultiFab& alpha);
37  void setBCoeffs (const Array<const MultiFab*,BL_SPACEDIM>& beta);
38  void setVerbose (int _verbose);
39  void setIsMatrixSingular(bool flag) { is_matrix_singular = flag; }
40  virtual void solve (MultiFab& soln, const MultiFab& rhs, Real rel_tol, Real abs_tol,
41  int max_iter, const BndryData& bndry, int max_bndry_order) = 0;
42 
43  static HYPRE_Int ispow2 (HYPRE_Int i)
44  {
45  return (i == 1) ? 1 : (((i <= 0) || (i & 1)) ? 0 : ispow2(i / 2));
46  }
47 
49  const auto& v = b.loVect();
50  return {AMREX_D_DECL(static_cast<HYPRE_Int>(v[0]),
51  static_cast<HYPRE_Int>(v[1]),
52  static_cast<HYPRE_Int>(v[2]))};
53  }
54 
56  const auto& v = b.hiVect();
57  return {AMREX_D_DECL(static_cast<HYPRE_Int>(v[0]),
58  static_cast<HYPRE_Int>(v[1]),
59  static_cast<HYPRE_Int>(v[2]))};
60  }
61 
62 
63  void setHypreOptionsNamespace (const std::string& ns) noexcept
64  { options_namespace = ns; }
65  void setHypreOldDefault (bool l) noexcept {old_default = l;}
66  void setHypreRelaxType (int n) noexcept {relax_type = n;}
67  void setHypreRelaxOrder (int n) noexcept {relax_order = n;}
68  void setHypreNumSweeps (int n) noexcept {num_sweeps = n;}
69  void setHypreStrongThreshold (Real t) noexcept {strong_threshold = t;}
70 
71  static constexpr HYPRE_Int regular_stencil_size = 2*AMREX_SPACEDIM + 1;
72  static constexpr HYPRE_Int eb_stencil_size = AMREX_D_TERM(3, *3, *3);
73 
74 protected:
75 
78 
79  int verbose = 0;
80  bool old_default = true; // Falgout coarsening with modified classical interpolation
81  int relax_type = 6; // G-S/Jacobi hybrid relaxation
82  int relax_order = 1; // uses C/F relaxation
83  int num_sweeps = 2; // Sweeeps on each level
84  Real strong_threshold = Real(0.25); // Hypre default is 0.25
85 
86  std::string options_namespace{"hypre"};
87 
91 
93 
94  FabFactory<FArrayBox> const* m_factory = nullptr;
95  BndryData const* m_bndry = nullptr;
96  int m_maxorder = -1;
97 
98  bool is_matrix_singular { false };
99 };
100 
101 [[nodiscard]] std::unique_ptr<Hypre>
102 makeHypre (const BoxArray& grids, const DistributionMapping& dmap,
103  const Geometry& geom, MPI_Comm comm_, Hypre::Interface interface,
104  const iMultiFab* overset_mask = nullptr);
105 
106 }
107 
108 #endif
#define AMREX_D_TERM(a, b, c)
Definition: AMReX_SPACE.H:129
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
#define BL_SPACEDIM
Definition: AMReX_SPACE.H:15
int MPI_Comm
Definition: AMReX_ccse-mpi.H:47
static constexpr int MPI_COMM_NULL
Definition: AMReX_ccse-mpi.H:55
A BndryData stores and manipulates boundary data information on each side of each box in a BoxArray.
Definition: AMReX_BndryData.H:41
A collection of Boxes stored in an Array.
Definition: AMReX_BoxArray.H:550
Calculates the distribution of FABs to MPI processes.
Definition: AMReX_DistributionMapping.H:41
Rectangular problem domain geometry.
Definition: AMReX_Geometry.H:73
Definition: AMReX_Hypre.H:18
Array< MultiFab, AMREX_SPACEDIM > bcoefs
Definition: AMReX_Hypre.H:89
bool is_matrix_singular
Definition: AMReX_Hypre.H:98
void setHypreOldDefault(bool l) noexcept
Definition: AMReX_Hypre.H:65
void setVerbose(int _verbose)
Definition: AMReX_Hypre.cpp:89
MultiFab acoefs
Definition: AMReX_Hypre.H:88
int verbose
Definition: AMReX_Hypre.H:79
void setHypreStrongThreshold(Real t) noexcept
Definition: AMReX_Hypre.H:69
Hypre(Hypre &&) noexcept=default
void setHypreRelaxType(int n) noexcept
Definition: AMReX_Hypre.H:66
static HYPRE_Int ispow2(HYPRE_Int i)
Definition: AMReX_Hypre.H:43
static constexpr HYPRE_Int eb_stencil_size
Definition: AMReX_Hypre.H:72
MPI_Comm comm
Definition: AMReX_Hypre.H:76
Real scalar_a
Definition: AMReX_Hypre.H:90
BndryData const * m_bndry
Definition: AMReX_Hypre.H:95
void setHypreOptionsNamespace(const std::string &ns) noexcept
Definition: AMReX_Hypre.H:63
MultiFab diaginv
Definition: AMReX_Hypre.H:92
int m_maxorder
Definition: AMReX_Hypre.H:96
FabFactory< FArrayBox > const * m_factory
Definition: AMReX_Hypre.H:94
Real scalar_b
Definition: AMReX_Hypre.H:90
Geometry geom
Definition: AMReX_Hypre.H:77
void setBCoeffs(const Array< const MultiFab *, BL_SPACEDIM > &beta)
Definition: AMReX_Hypre.cpp:80
std::string options_namespace
Definition: AMReX_Hypre.H:86
void setHypreNumSweeps(int n) noexcept
Definition: AMReX_Hypre.H:68
int relax_order
Definition: AMReX_Hypre.H:82
int relax_type
Definition: AMReX_Hypre.H:81
static Array< HYPRE_Int, AMREX_SPACEDIM > hiV(const Box &b)
Definition: AMReX_Hypre.H:55
int num_sweeps
Definition: AMReX_Hypre.H:83
static constexpr HYPRE_Int regular_stencil_size
Definition: AMReX_Hypre.H:71
void setScalars(Real sa, Real sb)
Definition: AMReX_Hypre.cpp:67
Real strong_threshold
Definition: AMReX_Hypre.H:84
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
void setIsMatrixSingular(bool flag)
Definition: AMReX_Hypre.H:39
static Array< HYPRE_Int, AMREX_SPACEDIM > loV(const Box &b)
Definition: AMReX_Hypre.H:48
void setACoeffs(const MultiFab &alpha)
Definition: AMReX_Hypre.cpp:74
void setHypreRelaxOrder(int n) noexcept
Definition: AMReX_Hypre.H:67
Interface
Definition: AMReX_Hypre.H:21
bool old_default
Definition: AMReX_Hypre.H:80
virtual ~Hypre()
Hypre(const BoxArray &grids, const DistributionMapping &dmap, const Geometry &geom, MPI_Comm comm_)
Definition: AMReX_Hypre.cpp:27
A collection (stored as an array) of FArrayBox objects.
Definition: AMReX_MultiFab.H:38
Definition: AMReX_Amr.cpp:49
const int[]
Definition: AMReX_BLProfiler.cpp:1664
std::unique_ptr< Hypre > makeHypre(const BoxArray &grids, const DistributionMapping &dmap, const Geometry &geom, MPI_Comm comm_, Hypre::Interface interface, const iMultiFab *overset_mask)
Definition: AMReX_Hypre.cpp:12
std::array< T, N > Array
Definition: AMReX_Array.H:24