Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_HypreMLNodeLap.H
Go to the documentation of this file.
1#ifndef AMREX_HYPRE_ML_NODELAP_H_
2#define AMREX_HYPRE_ML_NODELAP_H_
3#include <AMReX_Config.H>
4
7#include <AMReX_MultiFab.H>
8
9#include <memory>
10#include <string>
11
19
20namespace amrex {
21
22class MLNodeLaplacian;
23
68{
69public:
70 using BigInt = HYPRE_BigInt;
71
80 HypreMLNodeLap (MLNodeLaplacian const& a_linop,
81 std::string a_prefix = "hypre_mlnodelap",
82 int a_verbose = 0);
83
85
86 HypreMLNodeLap (HypreMLNodeLap const&) = delete;
90
104 void solve (Vector<MultiFab*> const& a_sol, Vector<MultiFab const*> const& a_rhs,
105 Real a_reltol, Real a_abstol, int a_maxiter);
106
109 void setThrowException (bool t) noexcept { m_throw_exception = t; }
110
112 [[nodiscard]] int getNumIters () const { return m_num_iters; }
113 [[nodiscard]] Real getFinalResidualNorm () const { return m_final_res; }
114
116 [[nodiscard]] BigInt numUnknowns () const { return m_nglobal; }
117
119 void buildMatrix ();
120
121private:
122 using IdFab = BaseFab<Long>;
123 using IdFabArray = FabArray<IdFab>;
124
125 void numberUnknowns ();
126 void loadRHS (Vector<MultiFab const*> const& a_rhs, Vector<MultiFab*> const& a_sol);
127 void getSolution (Vector<MultiFab*> const& a_sol);
128 void dumpSystem (int k, bool solution);
130 void fail (std::string const& msg) const;
131
133 [[nodiscard]] int neumannScale (int lev, IntVect const& iv) const;
135 [[nodiscard]] bool onDirichletFace (int lev, IntVect const& iv) const;
136
137 [[nodiscard]] FabFactory<FArrayBox> const* factory (int lev) const;
138
139 MLNodeLaplacian const* m_linop;
140 std::string m_prefix;
141 int m_verbose = 0;
142 int m_nlevels = 0;
143 MPI_Comm m_comm = MPI_COMM_NULL;
144 int m_nprocs = 1;
145 int m_myproc = 0;
146
147 Vector<Geometry> m_geom;
148 Vector<BoxArray> m_nd_grids; // nodal BoxArrays
150 Vector<int> m_ref_ratio; // m_ref_ratio[lev]: ratio between lev and lev+1
151
152 // Host-accessible (pinned in GPU builds) per-level data
153 Vector<std::unique_ptr<IdFabArray>> m_gid; // global id or -1
154 Vector<std::unique_ptr<iMultiFab>> m_owner; // node ownership
155 Vector<std::unique_ptr<iMultiFab>> m_dmsk; // Dirichlet (incl. c/f on fine levels)
156 Vector<std::unique_ptr<iMultiFab>> m_ndfine; // nodal fine mask (numbering only)
157 Vector<std::unique_ptr<IdFabArray>> m_cgid_on_f; // level lev-1 gid on coarsened level lev nodes
158 Vector<std::unique_ptr<iMultiFab>> m_cndfine_on_f; // level lev-1 nodal fine mask, same layout
159 Vector<std::unique_ptr<MultiFab>> m_ndvol; // EB: nodal fluid volume fraction (or null)
160 Vector<std::unique_ptr<MultiFab>> m_scale; // EB: unknown scaling 1/sqrt(ndvol) (or null)
161 Vector<std::unique_ptr<MultiFab>> m_cscale_on_f; // level lev-1 scaling on coarsened level lev nodes
162 bool m_eb_scaling = true; // <prefix>.eb_scaling
163 bool m_has_dirichlet = false; // any non-periodic Dirichlet domain face
164 bool m_throw_exception = false;
165
167 struct DirichletCoupling { Long row; Real coef; int lev; int li; IntVect node; };
168 Vector<DirichletCoupling> m_dbc;
169
170 Vector<Long> m_rank_offset; // first gid of each rank, plus total at the end
171 BigInt m_ilower = 0;
172 BigInt m_iupper = -1;
173 BigInt m_nglobal = 0;
174 Long m_pin_gid = -1; // pinned unknown for singular problems
175
176 enum class Backend { hypre, algmg };
177 Backend m_backend = Backend::hypre;
178
179 // Matrix Market dumps
180 int m_dump_max = 0;
181 std::string m_dump_prefix;
182 Long m_dump_gather_max = 50000000;
183
184 // Owned rows of the assembled matrix (AlgMG backend and dumps)
185 composite::OwnedCSR m_csr;
186 std::unique_ptr<SpMatrix<Real>> m_spA;
187 std::unique_ptr<AlgMG<Real>> m_algmg;
188
189 // Right-hand side and solution of this rank's rows
190 Vector<Real> m_bvec;
191 Vector<Real> m_xvec;
192
193 std::unique_ptr<HypreIJIface> m_ij;
194 HYPRE_IJMatrix m_A = nullptr;
195 HYPRE_IJVector m_b = nullptr;
196 HYPRE_IJVector m_x = nullptr;
197
198 int m_num_iters = 0;
199 Real m_final_res = 0.0;
200 Real m_bnorm = 0.0; // 2-norm of the assembled right-hand side
201};
202
203}
204
205#endif
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:222
An Array of FortranArrayBox(FAB)-like Objects.
Definition AMReX_FabArray.H:356
Abstract factory interface for creating, aliasing, and destroying FAB objects.
Definition AMReX_FabFactory.H:73
HypreMLNodeLap & operator=(HypreMLNodeLap const &)=delete
Real getFinalResidualNorm() const
Definition AMReX_HypreMLNodeLap.H:113
HypreMLNodeLap(MLNodeLaplacian const &a_linop, std::string a_prefix="hypre_mlnodelap", int a_verbose=0)
Assemble the composite matrix from a prepared linear operator.
Definition AMReX_HypreMLNodeLap.cpp:240
HypreMLNodeLap(HypreMLNodeLap const &)=delete
void setThrowException(bool t) noexcept
Definition AMReX_HypreMLNodeLap.H:109
int getNumIters() const
Iterations and final relative residual of the last solve.
Definition AMReX_HypreMLNodeLap.H:112
void buildMatrix()
Internal: called by the constructor (public only for CUDA extended lambdas).
Definition AMReX_HypreMLNodeLap.cpp:514
HYPRE_BigInt BigInt
Definition AMReX_HypreMLNodeLap.H:70
BigInt numUnknowns() const
Number of composite unknowns.
Definition AMReX_HypreMLNodeLap.H:116
HypreMLNodeLap(HypreMLNodeLap &&)=delete
void solve(Vector< MultiFab * > const &a_sol, Vector< MultiFab const * > const &a_rhs, Real a_reltol, Real a_abstol, int a_maxiter)
Solve the composite system.
Definition AMReX_HypreMLNodeLap.cpp:1192
Definition AMReX_MLNodeLaplacian.H:33
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
amrex_long Long
Definition AMReX_INT.H:30
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
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38