13#ifndef CD_ELLIPTICSOLVERCHAIN_H
14#define CD_ELLIPTICSOLVERCHAIN_H
21#include <AMRMultiGrid.H>
30#include <CD_NamespaceHeader.H>
104 for (
int i = 0; i <
solvers.size(); i++) {
184 const bool a_gmgConverged,
185 const int a_krylovIters = -1,
186 const int a_verbosity = -1,
187 const std::string& a_name =
"")
189 if (a_gmgAttempted) {
197 if (a_verbosity >= 1 && wasLatched && !
m_latched) {
198 pout() << a_name <<
" - multigrid re-probe succeeded; releasing the Krylov fallback latch" << endl;
241 for (
int i = 0; i < a_solvers.size(); i++) {
261 if (a_str ==
"gmg") {
264 else if (a_str ==
"gmres") {
267 else if (a_str ==
"bicgstab") {
271 MayDay::Error(
"EllipticSolverChain::toSolverType - solver must be 'gmg', 'gmres', or 'bicgstab'");
317 using Vec = Vector<LevelData<T>*>;
341 define(AMRMultiGrid<LevelData<T>>* a_mg,
342 const Vector<RefCountedPtr<LevelData<BaseFab<
bool>>>>& a_validCells,
343 const Vector<Real>& a_dx,
346 const
int a_numVCycles);
409 AMRMultiGrid<LevelData<T>>*
m_mg =
nullptr;
474#include <CD_NamespaceFooter.H>
Linear-operator adapter that exposes an AMR-multigrid cycle as a Krylov preconditioner.
Implementation of CD_EllipticSolverChain.H.
Preconditioned BiCGStab over an AMR hierarchy, with persistent work vectors and fused reductions.
Restarted, right-preconditioned GMRES over an AMR hierarchy, with persistent basis and fused reductio...
Adapter presenting an already-defined AMRMultiGrid as a LinearOp over the AMR hierarchy.
Definition CD_AMRMultigridKrylovOp.H:78
Stateful owner of the outer-Krylov solver path.
Definition CD_EllipticSolverChain.H:312
Vec m_dphi
Persistent correction.
Definition CD_EllipticSolverChain.H:459
Vec m_phiInit
Snapshot of the chain's starting guess (the initial-residual solution) for the warm-start rule.
Definition CD_EllipticSolverChain.H:464
bool keepOrRestore(Vec &a_phi, const Vec &a_rhs)
Warm-start rule applied between fallback attempts.
Definition CD_EllipticSolverChainImplem.H:76
bool m_workAllocated
Whether r0/dphi are allocated for the current grid.
Definition CD_EllipticSolverChain.H:449
int lastKrylovIterations() const
Iteration count of the most recent Krylov solve (GMRES/BiCGStab).
Definition CD_EllipticSolverChain.H:365
int m_lastKrylovIters
Iteration count of the most recent Krylov solve, or -1 if none has run.
Definition CD_EllipticSolverChain.H:429
bool solve(Vec &a_phi, const Vec &a_rhs, const bool a_zeroPhi, const SolverType a_type, const Settings &a_settings)
Solve L(phi) = rhs with the chosen outer Krylov method preconditioned by the multigrid cycle.
Definition CD_EllipticSolverChainImplem.H:119
int m_lmax
Finest level.
Definition CD_EllipticSolverChain.H:439
void snapshotGuess(Vec &a_phi, const Vec &a_rhs)
Snapshot the chain's starting guess and its residual for the fallback warm-start rule.
Definition CD_EllipticSolverChainImplem.H:62
Real m_initResidual
Residual of the snapshot (the initial residual of the fallback chain).
Definition CD_EllipticSolverChain.H:469
bool m_isDefined
Whether define() has been called.
Definition CD_EllipticSolverChain.H:444
Vec m_r0
Persistent initial residual.
Definition CD_EllipticSolverChain.H:454
AMRMultiGrid< LevelData< T > > * m_mg
Multigrid solver (not owned).
Definition CD_EllipticSolverChain.H:409
KrylovGMRES< T > m_gmres
Custom GMRES solver (lazily defined on first GMRES solve).
Definition CD_EllipticSolverChain.H:424
KrylovSolver() noexcept=default
Default constructor. Must call define() before use.
int m_lbase
Coarsest level.
Definition CD_EllipticSolverChain.H:434
Vector< LevelData< T > * > Vec
Multilevel data type.
Definition CD_EllipticSolverChain.H:317
void define(AMRMultiGrid< LevelData< T > > *a_mg, const Vector< RefCountedPtr< LevelData< BaseFab< bool > > > > &a_validCells, const Vector< Real > &a_dx, const int a_lbase, const int a_lmax, const int a_numVCycles)
Define the multigrid-preconditioner adapter and reset the persistent work. Call once per regrid.
Definition CD_EllipticSolverChainImplem.H:95
AMRMultigridKrylovOp< T > m_op
Multigrid-cycle-as-preconditioner adapter.
Definition CD_EllipticSolverChain.H:414
KrylovBiCGStab< T > m_bicg
Custom BiCGStab solver (lazily defined on first BiCGStab solve).
Definition CD_EllipticSolverChain.H:419
void allocateWork(const Vec &a_template)
Lazily allocate the persistent residual-correction vectors r0/dphi from a template hierarchy.
Definition CD_EllipticSolverChainImplem.H:52
void freeWork()
Free the persistent work vectors and undefine the custom solvers.
Definition CD_EllipticSolverChainImplem.H:37
Preconditioned BiCGStab solver acting on an AMR hierarchy through AMRMultigridKrylovOp.
Definition CD_KrylovBiCGStab.H:36
Restarted GMRES(m) acting on an AMR hierarchy through AMRMultigridKrylovOp.
Definition CD_KrylovGMRES.H:38
Support code for using an AMR-multigrid cycle as a preconditioner for an outer Krylov solver.
Definition CD_EllipticSolverChain.H:37
std::string solverTypeName(const SolverType a_type)
Human-readable name for a solver type, for diagnostic output.
Definition CD_EllipticSolverChain.H:283
SolverType toSolverType(const std::string &a_str)
Map a solver-type string to the corresponding enum.
Definition CD_EllipticSolverChain.H:259
SolverType
Top-level solve method.
Definition CD_EllipticSolverChain.H:43
@ BiCGStab
BiCGStab preconditioned by the multigrid cycle.
@ GMG
Stand-alone multigrid V-cycling (no outer Krylov).
@ GMRES
GMRES preconditioned by the multigrid cycle.
Stateful policy for the solver fallback chain.
Definition CD_EllipticSolverChain.H:130
int retryInterval
Re-probe GMG every this many solves while latched. Clamped to >= 1; 1 reproduces always-retry behavio...
Definition CD_EllipticSolverChain.H:134
bool isLatched() const
Whether the policy is currently latched onto the Krylov fallback.
Definition CD_EllipticSolverChain.H:212
int startIndex(const Vector< SolverType > &a_solvers)
Start index into a_solvers for this solve, advancing the re-probe counter. Call exactly once per solv...
Definition CD_EllipticSolverChain.H:152
void recordOutcome(const bool a_gmgAttempted, const bool a_gmgConverged, const int a_krylovIters=-1, const int a_verbosity=-1, const std::string &a_name="")
Record the outcome of this solve and update the latch.
Definition CD_EllipticSolverChain.H:183
bool m_reprobeNext
Whether a cheap Krylov solve has armed an adaptive early re-probe of GMG on the next solve.
Definition CD_EllipticSolverChain.H:231
bool m_latched
Whether a failed GMG attempt has latched us onto the Krylov fallback.
Definition CD_EllipticSolverChain.H:221
int firstNonGmg(const Vector< SolverType > &a_solvers) const
Index of the first non-GMG solver in the chain, or 0 if there is none.
Definition CD_EllipticSolverChain.H:239
int m_sinceProbe
Solves since the last GMG attempt while latched.
Definition CD_EllipticSolverChain.H:226
int reprobeIters
Adaptive early re-probe: re-probe GMG on the next solve whenever the Krylov fallback converged in thi...
Definition CD_EllipticSolverChain.H:141
Outer-Krylov configuration. Defaults reproduce stand-alone multigrid (solvers == {GMG}).
Definition CD_EllipticSolverChain.H:64
Real eps
Relative residual tolerance.
Definition CD_EllipticSolverChain.H:74
int restart
GMRES restart length (unused for BiCGStab).
Definition CD_EllipticSolverChain.H:84
Vector< SolverType > solvers
Solvers attempted in order; the first that converges wins. E.g. {GMG, GMRES} means "try stand-alone ...
Definition CD_EllipticSolverChain.H:69
int maxIter
Maximum outer iterations.
Definition CD_EllipticSolverChain.H:79
bool usesKrylov() const
Whether any solver in the chain is a Krylov method (and hence needs the preconditioner adapter).
Definition CD_EllipticSolverChain.H:102
int numVCycles
Number of multigrid cycles applied per preconditioner invocation. The cycle type (V/W) is deferred to...
Definition CD_EllipticSolverChain.H:90
int verbosity
Outer Krylov verbosity.
Definition CD_EllipticSolverChain.H:95