Block-Structured AMR Software Framework
AMReX_HypreNodeLap.H
Go to the documentation of this file.
1 #ifndef AMREX_HYPRE_NODE_LAP_H_
2 #define AMREX_HYPRE_NODE_LAP_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_Geometry.H>
6 #include <AMReX_MultiFab.H>
7 #include <AMReX_iMultiFab.H>
8 #include <AMReX_LayoutData.H>
9 #include <AMReX_BndryData.H>
10 #include <AMReX_MultiFabUtil.H>
11 #include <AMReX_HypreIJIface.H>
12 
13 #include <algorithm>
14 #include <memory>
15 #include <type_traits>
16 
17 namespace amrex {
18 
19 class MLNodeLinOp;
20 
22 {
23 public:
24  HypreNodeLap (const BoxArray& grids_, const DistributionMapping& dmap_,
25  const Geometry& geom_, const FabFactory<FArrayBox>& factory_,
26  const iMultiFab& owner_mask_, const iMultiFab& dirichlet_mask_,
27  MPI_Comm comm_, MLNodeLinOp const* linop_, int verbose_,
28  std::string options_namespace_);
30 
31  HypreNodeLap (HypreNodeLap const&) = delete;
32  HypreNodeLap (HypreNodeLap &&) = delete;
35 
36  using Int = HYPRE_Int;
37  // To generate global ids for Hypre, we need to remove duplicates on
38  // nodes shared by multiple Boxes. So we need to use a type that
39  // supports atomicAdd. HYPRE_Int is either int or long long. The
40  // latter does not have native atomicAdd support in CUDA/HIP.
41  using AtomicInt = std::conditional_t<sizeof(Int) == 4, unsigned int, unsigned long long>;
42 
43  void solve (MultiFab& soln, const MultiFab& rhs,
44  Real rel_tol, Real abs_tol, int max_iter);
45 
46  void setHypreOptionsNamespace(const std::string& ns)
47  { options_namespace = ns; }
48 
49 private:
50 
54  FabFactory<FArrayBox> const* factory = nullptr;
55  iMultiFab const* owner_mask = nullptr;
56  iMultiFab const* dirichlet_mask = nullptr;
58  MLNodeLinOp const* linop = nullptr;
59  int verbose = 0;
60 
61  std::unique_ptr<HypreIJIface> hypre_ij;
62 
63  // Non-owning references to Hypre matrix, rhs, and solution data
64  HYPRE_IJMatrix A = nullptr;
65  HYPRE_IJVector b = nullptr;
66  HYPRE_IJVector x = nullptr;
67 
74 
75  std::string options_namespace{"hypre"};
76 
77 public: // for CUDA
79 #ifdef AMREX_USE_GPU
81 #endif
83  void fill_global_node_id ();
84  static void adjust_singular_matrix (Int const* ncols, Int const* cols, Int const* rows, Real* mat);
85  void loadVectors (MultiFab& soln, const MultiFab& rhs);
86  void getSolution (MultiFab& soln);
87 };
88 
89 }
90 
91 #endif
int MPI_Comm
Definition: AMReX_ccse-mpi.H:47
static constexpr int MPI_COMM_NULL
Definition: AMReX_ccse-mpi.H:55
A collection of Boxes stored in an Array.
Definition: AMReX_BoxArray.H:549
Calculates the distribution of FABs to MPI processes.
Definition: AMReX_DistributionMapping.H:41
An Array of FortranArrayBox(FAB)-like Objects.
Definition: AMReX_FabArray.H:344
Rectangular problem domain geometry.
Definition: AMReX_Geometry.H:73
Definition: AMReX_HypreNodeLap.H:22
std::conditional_t< sizeof(Int)==4, unsigned int, unsigned long long > AtomicInt
Definition: AMReX_HypreNodeLap.H:41
Int fill_local_node_id()
Definition: AMReX_HypreNodeLap.cpp:156
MultiFab tmpsoln
Definition: AMReX_HypreNodeLap.H:73
void fill_global_node_id()
Definition: AMReX_HypreNodeLap.cpp:253
HypreNodeLap(HypreNodeLap &&)=delete
LayoutData< Gpu::DeviceVector< Int > > node_id_vec
Definition: AMReX_HypreNodeLap.H:69
iMultiFab local_node_id
Definition: AMReX_HypreNodeLap.H:71
FabFactory< FArrayBox > const * factory
Definition: AMReX_HypreNodeLap.H:54
Geometry geom
Definition: AMReX_HypreNodeLap.H:53
HypreNodeLap & operator=(HypreNodeLap const &)=delete
int verbose
Definition: AMReX_HypreNodeLap.H:59
HypreNodeLap(const BoxArray &grids_, const DistributionMapping &dmap_, const Geometry &geom_, const FabFactory< FArrayBox > &factory_, const iMultiFab &owner_mask_, const iMultiFab &dirichlet_mask_, MPI_Comm comm_, MLNodeLinOp const *linop_, int verbose_, std::string options_namespace_)
Definition: AMReX_HypreNodeLap.cpp:12
Int fill_local_node_id_cpu()
Definition: AMReX_HypreNodeLap.cpp:215
HYPRE_Int Int
Definition: AMReX_HypreNodeLap.H:36
LayoutData< Int > id_offset
Definition: AMReX_HypreNodeLap.H:72
void getSolution(MultiFab &soln)
Definition: AMReX_HypreNodeLap.cpp:335
std::string options_namespace
Definition: AMReX_HypreNodeLap.H:75
BoxArray grids
Definition: AMReX_HypreNodeLap.H:51
HYPRE_IJMatrix A
Definition: AMReX_HypreNodeLap.H:64
void solve(MultiFab &soln, const MultiFab &rhs, Real rel_tol, Real abs_tol, int max_iter)
Definition: AMReX_HypreNodeLap.cpp:137
HYPRE_IJVector b
Definition: AMReX_HypreNodeLap.H:65
void loadVectors(MultiFab &soln, const MultiFab &rhs)
Definition: AMReX_HypreNodeLap.cpp:294
DistributionMapping dmap
Definition: AMReX_HypreNodeLap.H:52
std::unique_ptr< HypreIJIface > hypre_ij
Definition: AMReX_HypreNodeLap.H:61
void setHypreOptionsNamespace(const std::string &ns)
Definition: AMReX_HypreNodeLap.H:46
Int fill_local_node_id_gpu()
Definition: AMReX_HypreNodeLap.cpp:171
LayoutData< Int > nnodes_grid
Definition: AMReX_HypreNodeLap.H:68
iMultiFab const * owner_mask
Definition: AMReX_HypreNodeLap.H:55
MLNodeLinOp const * linop
Definition: AMReX_HypreNodeLap.H:58
HypreNodeLap(HypreNodeLap const &)=delete
MPI_Comm comm
Definition: AMReX_HypreNodeLap.H:57
iMultiFab const * dirichlet_mask
Definition: AMReX_HypreNodeLap.H:56
FabArray< BaseFab< AtomicInt > > node_id
Definition: AMReX_HypreNodeLap.H:70
static void adjust_singular_matrix(Int const *ncols, Int const *cols, Int const *rows, Real *mat)
Definition: AMReX_HypreNodeLap.cpp:281
HYPRE_IJVector x
Definition: AMReX_HypreNodeLap.H:66
Definition: AMReX_MLNodeLinOp.H:16
A collection (stored as an array) of FArrayBox objects.
Definition: AMReX_MultiFab.H:38
Definition: AMReX_iMultiFab.H:32
Definition: AMReX_Amr.cpp:49