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

Adapter presenting an already-defined AMRMultiGrid as a LinearOp over the AMR hierarchy. More...

#include <CD_AMRMultigridKrylovOp.H>

Inheritance diagram for AMRMultigridKrylovOp< T >:
Inheritance graph
[legend]
Collaboration diagram for AMRMultigridKrylovOp< T >:
Collaboration graph
[legend]

Public Member Functions

 AMRMultigridKrylovOp ()=default
 Default constructor. Call define() before use.
 
virtual ~AMRMultigridKrylovOp ()
 Destructor. Frees the preconditioner scratch storage.
 
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 adapter. Call once per regrid (after the AMRMultiGrid has been defined and init'd).
 
void applyOp (Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_phi, bool a_homogeneous=false) override
 Matrix-vector product L(phi) over the AMR hierarchy (always homogeneous for the Krylov path).
 
void residual (Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_phi, const Vector< LevelData< T > * > &a_rhs, bool a_homogeneous=false) override
 AMR residual a_lhs = L(a_phi) - a_rhs.
 
void preCond (Vector< LevelData< T > * > &a_cor, const Vector< LevelData< T > * > &a_residual) override
 Apply the preconditioner: a_cor approx L^{-1} a_residual via m_numVCycles multigrid cycles (cycle type from the AMRMultiGrid configuration; normally V-cycles).
 
void create (Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_rhs) override
 Allocate a_lhs to mirror a_rhs.
 
void clear (Vector< LevelData< T > * > &a_lhs) override
 Free a holder created by create().
 
void assign (Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_rhs) override
 Copy a_rhs into a_lhs.
 
Real dotProduct (const Vector< LevelData< T > * > &a_1, const Vector< LevelData< T > * > &a_2) override
 AMR-composite inner product (allocation-free, fine-covered cells masked out).
 
void mDotProduct (const Vector< LevelData< T > * > &a_1, const int a_sz, const Vector< LevelData< T > * > a_2[], Real a_mdots[]) override
 Batched inner products a_mdots[k] = dotProduct(a_1, a_2[k]) for k=0..a_sz-1.
 
void incr (Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_x, Real a_scale) override
 Increment a_lhs += a_scale*a_x.
 
void axby (Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_x, const Vector< LevelData< T > * > &a_y, Real a_a, Real a_b) override
 Set a_lhs = a_a*a_x + a_b*a_y.
 
void scale (Vector< LevelData< T > * > &a_lhs, const Real &a_scale) override
 Scale a_lhs *= a_scale.
 
Real norm (const Vector< LevelData< T > * > &a_rhs, int a_ord) override
 Norm of a_rhs. For a_ord==2 this is the inner-product-induced norm sqrt(dotProduct(x,x)) so that it is consistent with dotProduct (a requirement of GMRES); other orders use the per-level max norm.
 
void setToZero (Vector< LevelData< T > * > &a_lhs) override
 Set a_lhs = 0.
 

Protected Attributes

AMRMultiGrid< LevelData< T > > * m_mg = nullptr
 Reused multigrid solver (not owned).
 
Vector< AMRLevelOp< LevelData< T > > * > m_amrOps
 Per-level AMR operators borrowed from m_mg (not owned).
 
Vector< Real > m_dxScale
 Per-level dx^SpaceDim, the AMR inner-product weight.
 
Vector< RefCountedPtr< LevelData< BaseFab< bool > > > > m_validMask
 Per-level valid-cell mask: false where the level is covered by a finer level (excluded from the inner product). Shared (refcounted) with AmrMesh's valid-cell mask rather than built here.
 
Vector< Real > m_volume
 Per-level reduced total volume (geometry-only, vector-independent); cached on first dotProduct.
 
bool m_volumeCached = false
 Whether m_volume has been computed and reduced. Reset to false in define() (regrid invalidates it).
 
int m_lbase = 0
 Coarsest level in the solve.
 
int m_lmax = 0
 Finest level in the solve.
 
int m_numVCycles = 1
 Number of multigrid cycles per preconditioner application (cycle type from the AMRMultiGrid configuration; normally V-cycles).
 
bool m_precondInit = false
 Whether the preconditioner scratch has been allocated.
 
Vector< LevelData< T > * > m_precondTmp
 Preconditioner scratch (residual), lazily allocated on first preCond.
 
Vector< LevelData< T > * > m_precondDcor
 Preconditioner scratch (cycle correction), lazily allocated on first preCond.
 

Detailed Description

template<class T>
class AMRMultigridKrylovOp< T >

Adapter presenting an already-defined AMRMultiGrid as a LinearOp over the AMR hierarchy.

This lets an outer Krylov solver (GMRES/BiCGStab, operating on Vector<LevelData<T>*>) use the multigrid cycle as a preconditioner. The matrix-vector product and the preconditioner delegate to the supplied, fully set-up AMRMultiGrid (its AMR operators and multigrid cycle; the cycle type follows the AMRMultiGrid configuration / cycle, normally a V-cycle for efficiency). The vector operations delegate to the per-level AMR operators, and the AMR inner product is computed allocation-free using a per-level fine-covered mask precomputed in define().

Note
T is the FAB type (EBCellFAB or MFCellFAB); the LinearOp acts on Vector<LevelData<T>*>.

Member Function Documentation

◆ applyOp()

template<class T >
void AMRMultigridKrylovOp< T >::applyOp ( Vector< LevelData< T > * > &  a_lhs,
const Vector< LevelData< T > * > &  a_phi,
bool  a_homogeneous = false 
)
override

Matrix-vector product L(phi) over the AMR hierarchy (always homogeneous for the Krylov path).

Parameters
[out]a_lhsResult L(phi)
[in]a_phiInput vector
[in]a_homogeneousUse homogeneous boundary conditions

◆ assign()

template<class T >
void AMRMultigridKrylovOp< T >::assign ( Vector< LevelData< T > * > &  a_lhs,
const Vector< LevelData< T > * > &  a_rhs 
)
override

Copy a_rhs into a_lhs.

Parameters
[out]a_lhsDestination
[in]a_rhsSource

◆ axby()

template<class T >
void AMRMultigridKrylovOp< T >::axby ( Vector< LevelData< T > * > &  a_lhs,
const Vector< LevelData< T > * > &  a_x,
const Vector< LevelData< T > * > &  a_y,
Real  a_a,
Real  a_b 
)
override

Set a_lhs = a_a*a_x + a_b*a_y.

Parameters
[out]a_lhsResult
[in]a_xFirst operand
[in]a_ySecond operand
[in]a_aScale of a_x
[in]a_bScale of a_y

◆ clear()

template<class T >
void AMRMultigridKrylovOp< T >::clear ( Vector< LevelData< T > * > &  a_lhs)
override

Free a holder created by create().

Parameters
[in,out]a_lhsHolder to free

◆ create()

template<class T >
void AMRMultigridKrylovOp< T >::create ( Vector< LevelData< T > * > &  a_lhs,
const Vector< LevelData< T > * > &  a_rhs 
)
override

Allocate a_lhs to mirror a_rhs.

Parameters
[out]a_lhsNew holder
[in]a_rhsTemplate holder

◆ define()

template<class T >
void AMRMultigridKrylovOp< 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 adapter. Call once per regrid (after the AMRMultiGrid has been defined and init'd).

Parameters
[in]a_mgThe fully set-up multigrid solver to reuse for matvec and preconditioning
[in]a_validCellsPer-level valid-cell mask (true where not covered by a finer level). Reused from AmrMesh::getValidCells rather than rebuilt here.
[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 applied per preconditioner invocation (cycle type from the AMRMultiGrid configuration; normally a V-cycle)

◆ dotProduct()

template<class T >
Real AMRMultigridKrylovOp< T >::dotProduct ( const Vector< LevelData< T > * > &  a_1,
const Vector< LevelData< T > * > &  a_2 
)
override

AMR-composite inner product (allocation-free, fine-covered cells masked out).

Parameters
[in]a_1First operand
[in]a_2Second operand
Returns
Inner product

◆ incr()

template<class T >
void AMRMultigridKrylovOp< T >::incr ( Vector< LevelData< T > * > &  a_lhs,
const Vector< LevelData< T > * > &  a_x,
Real  a_scale 
)
override

Increment a_lhs += a_scale*a_x.

Parameters
[in,out]a_lhsAccumulator
[in]a_xIncrement
[in]a_scaleScale factor

◆ mDotProduct()

template<class T >
void AMRMultigridKrylovOp< T >::mDotProduct ( const Vector< LevelData< T > * > &  a_1,
const int  a_sz,
const Vector< LevelData< T > * >  a_2[],
Real  a_mdots[] 
)
override

Batched inner products a_mdots[k] = dotProduct(a_1, a_2[k]) for k=0..a_sz-1.

Overrides the LinearOp default (which loops dotProduct, one MPI reduction each). Here all a_sz*nLevel rank-local partials are reduced in a single MPI_Allreduce. This is the per-iteration cost of Krylov orthogonalization (Gram-Schmidt), so the single fused reduction is the dominant scaling win.

Parameters
[in]a_1Fixed operand
[in]a_szNumber of right operands
[in]a_2Array of a_sz right operands
[out]a_mdotsArray of a_sz inner products

◆ norm()

template<class T >
Real AMRMultigridKrylovOp< T >::norm ( const Vector< LevelData< T > * > &  a_rhs,
int  a_ord 
)
override

Norm of a_rhs. For a_ord==2 this is the inner-product-induced norm sqrt(dotProduct(x,x)) so that it is consistent with dotProduct (a requirement of GMRES); other orders use the per-level max norm.

Parameters
[in]a_rhsVector
[in]a_ordNorm order
Returns
Norm

◆ preCond()

template<class T >
void AMRMultigridKrylovOp< T >::preCond ( Vector< LevelData< T > * > &  a_cor,
const Vector< LevelData< T > * > &  a_residual 
)
override

Apply the preconditioner: a_cor approx L^{-1} a_residual via m_numVCycles multigrid cycles (cycle type from the AMRMultiGrid configuration; normally V-cycles).

Parameters
[out]a_corPreconditioned correction
[in]a_residualResidual to precondition

◆ residual()

template<class T >
void AMRMultigridKrylovOp< T >::residual ( Vector< LevelData< T > * > &  a_lhs,
const Vector< LevelData< T > * > &  a_phi,
const Vector< LevelData< T > * > &  a_rhs,
bool  a_homogeneous = false 
)
override

AMR residual a_lhs = L(a_phi) - a_rhs.

Parameters
[out]a_lhsResidual
[in]a_phiSolution estimate
[in]a_rhsRight-hand side
[in]a_homogeneousUse homogeneous boundary conditions

◆ scale()

template<class T >
void AMRMultigridKrylovOp< T >::scale ( Vector< LevelData< T > * > &  a_lhs,
const Real &  a_scale 
)
override

Scale a_lhs *= a_scale.

Parameters
[in,out]a_lhsVector
[in]a_scaleScale factor

◆ setToZero()

template<class T >
void AMRMultigridKrylovOp< T >::setToZero ( Vector< LevelData< T > * > &  a_lhs)
override

Set a_lhs = 0.

Parameters
[out]a_lhsVector

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