1#ifndef AMREX_GMRES_MLMG_H_
2#define AMREX_GMRES_MLMG_H_
3#include <AMReX_Config.H>
53 void solve (MF& a_sol, MF
const& a_rhs,
RT a_tol_rel,
RT a_tol_abs);
156 bool usePrecond (
bool new_flag) {
return std::exchange(m_use_precond, new_flag); }
171 bool m_use_precond =
true;
172 int m_precond_niters = 1;
175template <
typename MF>
177 : m_mlmg(&mlmg), m_linop(&mlmg.getLinOp()), m_nlevels(m_linop->NAMRLevels())
183template <
typename MF>
187 for (
int ilev = 0; ilev < m_nlevels; ++ilev) {
188 vmf[ilev] = m_linop->make(ilev, 0,
IntVect(0));
193template <
typename MF>
197 for (
int ilev = 0; ilev < m_nlevels; ++ilev) {
198 vmf[ilev] = m_linop->make(ilev, 0,
IntVect(1));
204template <
typename MF>
210template <
typename MF>
213 for (
auto& xmf : mf) {
218template <
typename MF>
224template <
typename MF>
227 for (
auto& xmf : lhs) {
232template <
typename MF>
235 auto nlevels =
int(lhs.
size());
236 for (
int ilev = 0; ilev < nlevels; ++ilev) {
241template <
typename MF>
244 auto nlevels =
int(lhs.
size());
245 for (
int ilev = 0; ilev < nlevels; ++ilev) {
250template <
typename MF>
253 auto nlevels =
int(lhs.
size());
254 for (
int ilev = 0; ilev < nlevels; ++ilev) {
259template <
typename MF>
265template <
typename MF>
269 m_mlmg->setPrecondIter(m_precond_niters);
273 for (
int ilev = 0; ilev < m_nlevels; ++ilev) {
279template <
typename MF>
283 this->solve({&a_sol}, {&a_rhs}, a_tol_rel, a_tol_abs);
286template <
typename MF>
289 m_mlmg->incPrintIdentation();
290 auto mlmg_verbose = m_mlmg->getVerbose();
291 auto mlmg_bottom_verbose = m_mlmg->getBottomVerbose();
292 m_mlmg->setVerbose(m_verbose);
293 auto mlmg_bottom_solver = m_mlmg->getBottomSolver();
303 auto res = makeVecLHS();
304 auto cor = makeVecLHS();
308 bool need_to_scale_rhs = m_linop->scaleRHS(0,
nullptr);
309 for (
int ilev = 0; ilev < m_nlevels; ++ilev) {
311 if (need_to_scale_rhs) {
313 auto r = m_linop->scaleRHS(ilev, &(cor[ilev]));
321 for (
int ilev = 0; ilev < m_nlevels; ++ilev) {
322 m_linop->setDirichletNodesToZero(ilev,0,res[ilev]);
324 m_gmres.setInitialGuessNonzero(
false);
325 m_gmres.solve(cor, res, a_tol_rel, a_tol_abs);
327 for (
int ilev = 0; ilev < m_nlevels; ++ilev) {
331 m_mlmg->setBottomSolver(mlmg_bottom_solver);
332 m_mlmg->setVerbose(mlmg_verbose);
333 m_mlmg->setBottomVerbose(mlmg_bottom_verbose);
334 m_mlmg->decPrintIdentation();
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
Solve using GMRES with multigrid as preconditioner.
Definition AMReX_GMRES_MLMG.H:28
void solve(MF &a_sol, MF const &a_rhs, RT a_tol_rel, RT a_tol_abs)
Solve the linear system.
Definition AMReX_GMRES_MLMG.H:280
static void assign(VEC &lhs, VEC const &rhs)
Copy rhs into lhs level by level.
Definition AMReX_GMRES_MLMG.H:233
VEC makeVecRHS() const
Return a MultiFab vector without ghost cells for RHS storage.
Definition AMReX_GMRES_MLMG.H:184
GMRESMLMGT(MG &mlmg)
Wrap an existing MLMG hierarchy as a GMRES operator/preconditioner.
Definition AMReX_GMRES_MLMG.H:176
int getNumIters() const
Number of iterations executed by the last solve().
Definition AMReX_GMRES_MLMG.H:75
void setPrecondNumIters(int precond_niters)
Adjust how many MLMG smoothing iterations run inside each GMRES iteration.
Definition AMReX_GMRES_MLMG.H:163
Vector< MF > VEC
Definition AMReX_GMRES_MLMG.H:30
static void setToZero(VEC &lhs)
Reset lhs to zero on every AMR level.
Definition AMReX_GMRES_MLMG.H:225
GM & getGMRES()
Direct access to the underlying GMRES driver for fine-grained tuning.
Definition AMReX_GMRES_MLMG.H:81
void setVerbose(int v)
Set verbosity level v for both GMRES and MLMG components.
Definition AMReX_GMRES_MLMG.H:66
typename MG::RT RT
Definition AMReX_GMRES_MLMG.H:32
RT dotProduct(VEC const &mf1, VEC const &mf2) const
Return the preconditioner-aware dot product between mf1 and mf2.
Definition AMReX_GMRES_MLMG.H:219
GMRES< Vector< MF >, GMRESMLMGT< MF > > GM
Definition AMReX_GMRES_MLMG.H:33
VEC makeVecLHS() const
Definition AMReX_GMRES_MLMG.H:194
RT norm2(VEC const &mf) const
Return the 2-norm of mf using the multigrid operator's weighting.
Definition AMReX_GMRES_MLMG.H:205
static void scale(VEC &mf, RT scale_factor)
Scale each component of mf by scale_factor.
Definition AMReX_GMRES_MLMG.H:211
MLMGT< MF > MG
Definition AMReX_GMRES_MLMG.H:31
static void linComb(VEC &lhs, RT a, VEC const &rhs_a, RT b, VEC const &rhs_b)
Form a linear combination: lhs = a * rhs_a + b * rhs_b.
Definition AMReX_GMRES_MLMG.H:251
static void increment(VEC &lhs, VEC const &rhs, RT a)
Add a scaled vector: lhs += a * rhs.
Definition AMReX_GMRES_MLMG.H:242
RT getResidualNorm() const
Final residual 2-norm produced by the last solve().
Definition AMReX_GMRES_MLMG.H:78
bool usePrecond(bool new_flag)
Enable or disable MLMG as a preconditioner.
Definition AMReX_GMRES_MLMG.H:156
void apply(VEC &lhs, VEC const &rhs) const
Apply the operator supplied to the constructor.
Definition AMReX_GMRES_MLMG.H:260
void setMaxIters(int niters)
Cap the number of GMRES iterations executed per solve to niters.
Definition AMReX_GMRES_MLMG.H:72
void precond(VEC &lhs, VEC const &rhs) const
Apply the MLMG-based preconditioner: lhs = P^{-1}(rhs).
Definition AMReX_GMRES_MLMG.H:266
int getNumIters() const
Number of iterations executed by the last solve().
Definition AMReX_GMRES.H:142
void define(M &linop)
Bind the solver to a linear operator.
Definition AMReX_GMRES.H:221
void setVerbose(int v)
Set verbosity level v (0 = silent).
Definition AMReX_GMRES.H:125
void setMaxIters(int niters)
Cap the number of iterations performed by solve().
Definition AMReX_GMRES.H:139
RT getResidualNorm() const
Final residual 2-norm from the last solve().
Definition AMReX_GMRES.H:148
Abstract base class for multilevel linear operators used by MLMG and the bottom solvers.
Definition AMReX_MLLinOp.H:139
Definition AMReX_MLMG.H:39
void preparePrecond()
Prepare preconditioner-specific caches (e.g., boundary data).
Definition AMReX_MLMG.H:1857
typename MLLinOpT< MF >::RT RT
Definition AMReX_MLMG.H:54
Long size() const noexcept
Definition AMReX_Vector.H:54
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:273
void Scale(MF &dst, typename MF::value_type val, int scomp, int ncomp, int nghost)
dst *= val
Definition AMReX_FabArrayUtility.H:2175
Vector< const T * > GetVecOfConstPtrs(const Vector< T > &a)
Definition AMReX_Vector.H:94
int nComp(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nComp().
Definition AMReX_FabArrayBase.cpp:2939
void LinComb(MF &dst, typename MF::value_type a, MF const &src_a, int acomp, typename MF::value_type b, MF const &src_b, int bcomp, int dcomp, int ncomp, IntVect const &nghost)
dst = a*src_a + b*src_b
Definition AMReX_FabArrayUtility.H:2241
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
Vector< T * > GetVecOfPtrs(Vector< T > &a)
Definition AMReX_Vector.H:65
void LocalCopy(DMF &dst, SMF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst = src
Definition AMReX_FabArrayUtility.H:2182
void setBndry(MF &dst, typename MF::value_type val, int scomp, int ncomp)
dst = val in ghost cells.
Definition AMReX_FabArrayUtility.H:2168
const int[]
Definition AMReX_BLProfiler.cpp:1665
void Saxpy(MF &dst, typename MF::value_type a, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst += a * src
Definition AMReX_FabArrayUtility.H:2198
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition AMReX_FabArrayUtility.H:2161