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
22template <typename MF> class MLNodeLaplacianT;
24
73{
74public:
75 using BigInt = HYPRE_BigInt;
76
85 HypreMLNodeLap (MLNodeLaplacian const& a_linop,
86 std::string a_prefix = "hypre_mlnodelap",
87 int a_verbose = 0);
88
90
91 HypreMLNodeLap (HypreMLNodeLap const&) = delete;
95
109 void solve (Vector<MultiFab*> const& a_sol, Vector<MultiFab const*> const& a_rhs,
110 Real a_reltol, Real a_abstol, int a_maxiter);
111
114 void setThrowException (bool t) noexcept { m_throw_exception = t; }
115
117 [[nodiscard]] int getNumIters () const { return m_num_iters; }
118 [[nodiscard]] Real getFinalResidualNorm () const { return m_final_res; }
119
121 [[nodiscard]] BigInt numUnknowns () const { return m_nglobal; }
122
133 void updateMatrix ();
147 void setReuseSolverSetup (bool v);
151 [[nodiscard]] Real getMatrixScale () const noexcept { return m_reuse.scale; }
155 void setReuseSetupMaxIter (int n) noexcept { m_reuse_max_iter = n; }
164 void setReuseSetupMaxChange (Real f) { m_reuse.setMaxChange(f); }
167 if (m_ij) { m_ij->setNeedSetup(); }
168 m_algmg_reset = true;
169 }
170
173 void buildMatrix ();
178
179private:
180 using IdFab = BaseFab<Long>;
181 using IdFabArray = FabArray<IdFab>;
182
183 void numberUnknowns ();
184 void loadRHS (Vector<MultiFab const*> const& a_rhs, Vector<MultiFab*> const& a_sol);
185 void getSolution (Vector<MultiFab*> const& a_sol);
186 void dumpSystem (int k, bool solution);
188 void fail (std::string const& msg) const;
189
191 [[nodiscard]] int neumannScale (int lev, IntVect const& iv) const;
193 [[nodiscard]] bool onDirichletFace (int lev, IntVect const& iv) const;
194
195 [[nodiscard]] FabFactory<FArrayBox> const* factory (int lev) const;
196
197 MLNodeLaplacian const* m_linop;
198 std::string m_prefix;
199 int m_verbose = 0;
200 int m_nlevels = 0;
201 MPI_Comm m_comm = MPI_COMM_NULL;
202 int m_nprocs = 1;
203 int m_myproc = 0;
204
205 Vector<Geometry> m_geom;
206 Vector<BoxArray> m_nd_grids; // nodal BoxArrays
208 Vector<int> m_ref_ratio; // m_ref_ratio[lev]: ratio between lev and lev+1
209
210 // Host-accessible (pinned in GPU builds) per-level data
211 Vector<std::unique_ptr<IdFabArray>> m_gid; // global id or -1
212 Vector<std::unique_ptr<iMultiFab>> m_owner; // node ownership
213 Vector<std::unique_ptr<iMultiFab>> m_dmsk; // Dirichlet (incl. c/f on fine levels)
214 Vector<std::unique_ptr<iMultiFab>> m_ndfine; // nodal fine mask (numbering only)
215 Vector<std::unique_ptr<IdFabArray>> m_cgid_on_f; // level lev-1 gid on coarsened level lev nodes
216 Vector<std::unique_ptr<iMultiFab>> m_cndfine_on_f; // level lev-1 nodal fine mask, same layout
217 Vector<std::unique_ptr<MultiFab>> m_ndvol; // EB: nodal fluid volume fraction (or null)
218 Vector<std::unique_ptr<MultiFab>> m_scale; // EB: unknown scaling 1/sqrt(ndvol) (or null)
219 Vector<std::unique_ptr<MultiFab>> m_cscale_on_f; // level lev-1 scaling on coarsened level lev nodes
220 bool m_eb_scaling = true; // <prefix>.eb_scaling
221 bool m_has_dirichlet = false; // any non-periodic Dirichlet domain face
222 bool m_throw_exception = false;
223
225 struct DirichletCoupling { Long row; Real coef; int lev; int li; IntVect node; };
226 Vector<DirichletCoupling> m_dbc;
227
228 Vector<Long> m_rank_offset; // first gid of each rank, plus total at the end
229 BigInt m_ilower = 0;
230 BigInt m_iupper = -1;
231 BigInt m_nglobal = 0;
232 Long m_pin_gid = -1; // pinned unknown for singular problems
233
234 enum class Backend { hypre, algmg };
235 Backend m_backend = Backend::hypre;
236
237 // Matrix Market dumps
238 int m_dump_max = 0;
239 std::string m_dump_prefix;
240 Long m_dump_gather_max = 50000000;
241
242 // The hypre matrix assembled (again) from triplets: zeroed
243 // if assembled before, the triplets added, assembled
244 void ijBeginAssembly ();
245 void ijAddTriplets (Gpu::DeviceVector<BigInt> const& rows,
246 Gpu::DeviceVector<BigInt> const& cols,
247 Gpu::DeviceVector<Real> const& vals);
248 void ijEndAssembly ();
249
250 // Owned rows of the assembled matrix (AlgMG backend and dumps)
251 composite::OwnedCSR m_csr;
252 std::unique_ptr<SpMatrix<Real>> m_spA;
253 std::unique_ptr<AlgMG<Real>> m_algmg;
254
255 // Right-hand side and solution of this rank's rows
256 Vector<Real> m_bvec;
257 Vector<Real> m_xvec;
258
259 std::unique_ptr<HypreIJIface> m_ij;
260 HYPRE_IJMatrix m_A = nullptr;
261 HYPRE_IJVector m_b = nullptr;
262 HYPRE_IJVector m_x = nullptr;
263
264 int m_num_iters = 0;
265 Real m_final_res = 0.0;
266 Real m_bnorm = 0.0; // 2-norm of the assembled right-hand side
267
268 // Setup reuse (see HypreMLABecLap): in-place updates of the assembled
269 // matrix through the entry slots of the triplets, and whether the
270 // hypre matrix has been assembled once (then zeroed and assembled again)
271 bool m_reuse_setup = false;
272 int m_reuse_max_iter = 0;
275 composite::SetupReuse m_reuse;
280 bool m_recompute_pp = false;
281 bool m_matrix_assembled = false;
282 bool m_ij_gather_failed = false; // hypre dropped an entry: no in-place updates
285 Long m_ntrip = -1;
286 composite::EntryGather m_ij_gather;
290 Gpu::DeviceVector<Long> m_alg_row_offset;
291 Gpu::DeviceVector<Long> m_alg_col_index;
292 composite::EntryGather m_alg_gather;
293 bool m_algmg_reset = false;
294 bool m_algmg_kept = false;
295};
296
297}
298
299#endif
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:243
An Array of FortranArrayBox(FAB)-like Objects.
Definition AMReX_FabArray.H:383
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:118
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:242
void resetSolverSetup()
Redo the solver setup (hypre) or the AlgMG hierarchy at the next solve.
Definition AMReX_HypreMLNodeLap.H:166
void updateMatrix()
Assemble the matrix again from the operator's current coefficients, for the following solves: the MLN...
Definition AMReX_HypreMLNodeLap.cpp:1180
HypreMLNodeLap(HypreMLNodeLap const &)=delete
void setThrowException(bool t) noexcept
Definition AMReX_HypreMLNodeLap.H:114
void setReuseSetupMaxIter(int n) noexcept
Definition AMReX_HypreMLNodeLap.H:155
int getNumIters() const
Iterations and final relative residual of the last solve.
Definition AMReX_HypreMLNodeLap.H:117
void buildMatrix()
Definition AMReX_HypreMLNodeLap.cpp:529
HYPRE_BigInt BigInt
Definition AMReX_HypreMLNodeLap.H:75
BigInt numUnknowns() const
Number of composite unknowns.
Definition AMReX_HypreMLNodeLap.H:121
void populateMatrix(Gpu::DeviceVector< BigInt > &rows, Gpu::DeviceVector< BigInt > &cols, Gpu::DeviceVector< Real > &vals)
Definition AMReX_HypreMLNodeLap.cpp:1055
HypreMLNodeLap(HypreMLNodeLap &&)=delete
void setReuseSetupMaxChange(Real f)
Definition AMReX_HypreMLNodeLap.H:164
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:1398
void setReuseSolverSetup(bool v)
Keep the solver setup across updateMatrix() calls, as HypreMLABecLap::setReuseSolverSetup: the kept s...
Definition AMReX_HypreMLNodeLap.cpp:1037
Real getMatrixScale() const noexcept
Definition AMReX_HypreMLNodeLap.H:151
Definition AMReX_MLNodeLaplacian.H:34
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
PODVector< T, ArenaAllocator< T > > DeviceVector
A PODVector that uses the standard memory Arena. Note that the memory might or might not be managed d...
Definition AMReX_GpuContainers.H:24
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
MLNodeLaplacianT< MultiFab > MLNodeLaplacian
Double precision nodal Laplacian.
Definition AMReX_HypreMLNodeLap.H:23
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38