|
chombo-discharge
|
Stateful owner of the outer-Krylov solver path. More...
#include <CD_EllipticSolverChain.H>

Public Types | |
| using | Vec = Vector< LevelData< T > * > |
| Multilevel data type. | |
Public Member Functions | |
| KrylovSolver () noexcept=default | |
| Default constructor. Must call define() before use. | |
| ~KrylovSolver () noexcept | |
| Destructor. Frees the persistent work vectors and custom solvers. | |
| 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. | |
| 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. | |
| int | lastKrylovIterations () const |
| Iteration count of the most recent Krylov solve (GMRES/BiCGStab). | |
| void | snapshotGuess (Vec &a_phi, const Vec &a_rhs) |
| Snapshot the chain's starting guess and its residual for the fallback warm-start rule. | |
| bool | keepOrRestore (Vec &a_phi, const Vec &a_rhs) |
| Warm-start rule applied between fallback attempts. | |
Protected Member Functions | |
| void | allocateWork (const Vec &a_template) |
| Lazily allocate the persistent residual-correction vectors r0/dphi from a template hierarchy. | |
| void | freeWork () |
| Free the persistent work vectors and undefine the custom solvers. | |
Protected Attributes | |
| AMRMultiGrid< LevelData< T > > * | m_mg = nullptr |
| Multigrid solver (not owned). | |
| AMRMultigridKrylovOp< T > | m_op |
| Multigrid-cycle-as-preconditioner adapter. | |
| KrylovBiCGStab< T > | m_bicg |
| Custom BiCGStab solver (lazily defined on first BiCGStab solve). | |
| KrylovGMRES< T > | m_gmres |
| Custom GMRES solver (lazily defined on first GMRES solve). | |
| int | m_lastKrylovIters = -1 |
| Iteration count of the most recent Krylov solve, or -1 if none has run. | |
| int | m_lbase = 0 |
| Coarsest level. | |
| int | m_lmax = 0 |
| Finest level. | |
| bool | m_isDefined = false |
| Whether define() has been called. | |
| bool | m_workAllocated = false |
| Whether r0/dphi are allocated for the current grid. | |
| Vec | m_r0 |
| Persistent initial residual. | |
| Vec | m_dphi |
| Persistent correction. | |
| Vec | m_phiInit |
| Snapshot of the chain's starting guess (the initial-residual solution) for the warm-start rule. | |
| Real | m_initResidual = 0.0 |
| Residual of the snapshot (the initial residual of the fallback chain). | |
Stateful owner of the outer-Krylov solver path.
Holds the multigrid-cycle adapter (AMRMultigridKrylovOp), the chombo-discharge BiCGStab/GMRES solvers, and the persistent residual-correction work vectors. define() is called once per regrid; solve() reuses the adapter, the (lazily defined) custom solvers and the work vectors across all subsequent solves, so there is no per-solve work-vector allocation. solve() runs in residual-correction form so the inhomogeneous boundary/jump contribution enters only through the initial residual r0 = rhs - L(phi); the matvec and preconditioner are applied with homogeneous boundary conditions, and warm starts are honoured.
|
protected |
Lazily allocate the persistent residual-correction vectors r0/dphi from a template hierarchy.
| [in] | a_template | A hierarchy whose layout the work vectors mirror (e.g. the rhs). |
| void EllipticSolverChain::KrylovSolver< T >::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.
| [in] | a_mg | Fully set-up multigrid solver (reused for matvec and preconditioning) |
| [in] | a_validCells | Per-level valid-cell mask (true where not covered by a finer level), e.g. from AmrMesh::getValidCells |
| [in] | a_dx | Grid spacing on each level (index 0..a_lmax) |
| [in] | a_lbase | Coarsest level in the solve |
| [in] | a_lmax | Finest level in the solve |
| [in] | a_numVCycles | Number of multigrid cycles per preconditioner invocation (cycle type from gmg_cycle; normally a V-cycle) |
| bool EllipticSolverChain::KrylovSolver< T >::keepOrRestore | ( | Vec & | a_phi, |
| const Vec & | a_rhs | ||
| ) |
Warm-start rule applied between fallback attempts.
If the just-failed attempt left a residual smaller than the snapshot's initial residual, a_phi is kept (the failed solve is a better warm start); otherwise a_phi is restored to the snapshot (the initial-residual solution). snapshotGuess() must have been called first.
| [in,out] | a_phi | Current solution; restored to the snapshot if it did not improve on the initial residual. |
| [in] | a_rhs | Right-hand side, used to evaluate the current residual. |
|
inline |
Iteration count of the most recent Krylov solve (GMRES/BiCGStab).
| void EllipticSolverChain::KrylovSolver< T >::snapshotGuess | ( | Vec & | a_phi, |
| const Vec & | a_rhs | ||
| ) |
Snapshot the chain's starting guess and its residual for the fallback warm-start rule.
Call once, before the first attempt in a fallback chain. Stores a copy of the starting solution (the "initial-residual solution") so keepOrRestore() can fall back to it.
| [in,out] | a_phi | The starting guess (after any zeroing the host has applied); its ghost cells may be filled. |
| [in] | a_rhs | Right-hand side, used to evaluate the initial residual. |
| bool EllipticSolverChain::KrylovSolver< T >::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.
| [in,out] | a_phi | Solution (in: initial guess unless a_zeroPhi; out: solution) |
| [in] | a_rhs | Right-hand side |
| [in] | a_zeroPhi | If true, start from phi = 0 |
| [in] | a_type | Which Krylov method to run (GMRES or BiCGStab) |
| [in] | a_settings | Outer-Krylov settings (tolerance, iterations, restart, verbosity) |