chombo-discharge
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EllipticSolverChain::KrylovSolver< T > Class Template Reference

Stateful owner of the outer-Krylov solver path. More...

#include <CD_EllipticSolverChain.H>

Inheritance diagram for EllipticSolverChain::KrylovSolver< T >:
Inheritance graph
[legend]

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).
 

Detailed Description

template<class T>
class EllipticSolverChain::KrylovSolver< T >

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.

Note
T is the FAB type (EBCellFAB or MFCellFAB).

Member Function Documentation

◆ allocateWork()

template<class T >
void EllipticSolverChain::KrylovSolver< T >::allocateWork ( const Vec a_template)
protected

Lazily allocate the persistent residual-correction vectors r0/dphi from a template hierarchy.

Parameters
[in]a_templateA hierarchy whose layout the work vectors mirror (e.g. the rhs).

◆ define()

template<class T >
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.

Parameters
[in]a_mgFully set-up multigrid solver (reused for matvec and preconditioning)
[in]a_validCellsPer-level valid-cell mask (true where not covered by a finer level), e.g. from AmrMesh::getValidCells
[in]a_dxGrid spacing on each level (index 0..a_lmax)
[in]a_lbaseCoarsest level in the solve
[in]a_lmaxFinest level in the solve
[in]a_numVCyclesNumber of multigrid cycles per preconditioner invocation (cycle type from gmg_cycle; normally a V-cycle)

◆ keepOrRestore()

template<class T >
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.

Parameters
[in,out]a_phiCurrent solution; restored to the snapshot if it did not improve on the initial residual.
[in]a_rhsRight-hand side, used to evaluate the current residual.
Returns
True if the current solution was kept, false if it was restored.

◆ lastKrylovIterations()

template<class T >
int EllipticSolverChain::KrylovSolver< T >::lastKrylovIterations ( ) const
inline

Iteration count of the most recent Krylov solve (GMRES/BiCGStab).

Returns
Number of iterations, or -1 if no Krylov solve has run.

◆ snapshotGuess()

template<class T >
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.

Parameters
[in,out]a_phiThe starting guess (after any zeroing the host has applied); its ghost cells may be filled.
[in]a_rhsRight-hand side, used to evaluate the initial residual.

◆ solve()

template<class T >
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.

Parameters
[in,out]a_phiSolution (in: initial guess unless a_zeroPhi; out: solution)
[in]a_rhsRight-hand side
[in]a_zeroPhiIf true, start from phi = 0
[in]a_typeWhich Krylov method to run (GMRES or BiCGStab)
[in]a_settingsOuter-Krylov settings (tolerance, iterations, restart, verbosity)
Returns
True if the Krylov solver reported convergence.

The documentation for this class was generated from the following files: