chombo-discharge
Loading...
Searching...
No Matches
CD_AMRMultigridKrylovOp.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13#ifndef CD_AMRMULTIGRIDKRYLOVOP_H
14#define CD_AMRMULTIGRIDKRYLOVOP_H
15
16// Std includes
17#include <cmath>
18
19// Chombo includes
20#include <LinearSolver.H>
21#include <AMRMultiGrid.H>
22#include <LevelData.H>
23#include <BaseFab.H>
24#include <RefCountedPtr.H>
25#include <Vector.H>
26#include <EBCellFAB.H>
27#include <MFCellFAB.H>
28
29// Our includes
30#include <CD_EBHelmholtzOp.H>
31#include <CD_MFHelmholtzOp.H>
32#include <CD_NamespaceHeader.H>
33
39template <class T>
41
45template <>
47{
52};
53
57template <>
59{
64};
65
76template <class T>
77class AMRMultigridKrylovOp : public LinearOp<Vector<LevelData<T>*>>
78{
79public:
84
88 virtual ~AMRMultigridKrylovOp();
89
101 void
102 define(AMRMultiGrid<LevelData<T>>* a_mg,
103 const Vector<RefCountedPtr<LevelData<BaseFab<bool>>>>& a_validCells,
104 const Vector<Real>& a_dx,
105 const int a_lbase,
106 const int a_lmax,
107 const int a_numVCycles);
108
115 void
116 applyOp(Vector<LevelData<T>*>& a_lhs, const Vector<LevelData<T>*>& a_phi, bool a_homogeneous = false) override;
117
125 void
126 residual(Vector<LevelData<T>*>& a_lhs,
127 const Vector<LevelData<T>*>& a_phi,
128 const Vector<LevelData<T>*>& a_rhs,
129 bool a_homogeneous = false) override;
130
137 void
138 preCond(Vector<LevelData<T>*>& a_cor, const Vector<LevelData<T>*>& a_residual) override;
139
145 void
146 create(Vector<LevelData<T>*>& a_lhs, const Vector<LevelData<T>*>& a_rhs) override;
147
152 void
153 clear(Vector<LevelData<T>*>& a_lhs) override;
154
160 void
161 assign(Vector<LevelData<T>*>& a_lhs, const Vector<LevelData<T>*>& a_rhs) override;
162
169 Real
170 dotProduct(const Vector<LevelData<T>*>& a_1, const Vector<LevelData<T>*>& a_2) override;
171
182 void
183 mDotProduct(const Vector<LevelData<T>*>& a_1,
184 const int a_sz,
185 const Vector<LevelData<T>*> a_2[],
186 Real a_mdots[]) override;
187
194 void
195 incr(Vector<LevelData<T>*>& a_lhs, const Vector<LevelData<T>*>& a_x, Real a_scale) override;
196
205 void
206 axby(Vector<LevelData<T>*>& a_lhs,
207 const Vector<LevelData<T>*>& a_x,
208 const Vector<LevelData<T>*>& a_y,
209 Real a_a,
210 Real a_b) override;
211
217 void
218 scale(Vector<LevelData<T>*>& a_lhs, const Real& a_scale) override;
219
227 Real
228 norm(const Vector<LevelData<T>*>& a_rhs, int a_ord) override;
229
234 void
235 setToZero(Vector<LevelData<T>*>& a_lhs) override;
236
237protected:
241 AMRMultiGrid<LevelData<T>>* m_mg = nullptr;
242
246 Vector<AMRLevelOp<LevelData<T>>*> m_amrOps;
247
251 Vector<Real> m_dxScale;
252
257 Vector<RefCountedPtr<LevelData<BaseFab<bool>>>> m_validMask;
258
262 mutable Vector<Real> m_volume;
263
267 mutable bool m_volumeCached = false;
268
272 int m_lbase = 0;
273
277 int m_lmax = 0;
278
284
288 bool m_precondInit = false;
289
293 mutable Vector<LevelData<T>*> m_precondTmp;
294
298 mutable Vector<LevelData<T>*> m_precondDcor;
299};
300
301#include <CD_NamespaceFooter.H>
302
304
305#endif
Implementation of CD_AMRMultigridKrylovOp.H.
Declaration of Helmholtz multigrid operators.
Declaration of a class for solving multiphase Helmholtz equations.
Adapter presenting an already-defined AMRMultiGrid as a LinearOp over the AMR hierarchy.
Definition CD_AMRMultigridKrylovOp.H:78
int m_lbase
Coarsest level in the solve.
Definition CD_AMRMultigridKrylovOp.H:272
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.
Definition CD_AMRMultigridKrylovOpImplem.H:81
void incr(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_x, Real a_scale) override
Increment a_lhs += a_scale*a_x.
Definition CD_AMRMultigridKrylovOpImplem.H:275
void assign(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_rhs) override
Copy a_rhs into a_lhs.
Definition CD_AMRMultigridKrylovOpImplem.H:154
Vector< LevelData< T > * > m_precondTmp
Preconditioner scratch (residual), lazily allocated on first preCond.
Definition CD_AMRMultigridKrylovOp.H:293
int m_numVCycles
Number of multigrid cycles per preconditioner application (cycle type from the AMRMultiGrid configura...
Definition CD_AMRMultigridKrylovOp.H:283
Vector< Real > m_dxScale
Per-level dx^SpaceDim, the AMR inner-product weight.
Definition CD_AMRMultigridKrylovOp.H:251
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).
Definition CD_AMRMultigridKrylovOpImplem.H:35
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 typ...
Definition CD_AMRMultigridKrylovOpImplem.H:97
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.
Definition CD_AMRMultigridKrylovOpImplem.H:214
AMRMultiGrid< LevelData< T > > * m_mg
Reused multigrid solver (not owned).
Definition CD_AMRMultigridKrylovOp.H:241
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.
Definition CD_AMRMultigridKrylovOpImplem.H:284
Vector< Real > m_volume
Per-level reduced total volume (geometry-only, vector-independent); cached on first dotProduct.
Definition CD_AMRMultigridKrylovOp.H:262
int m_lmax
Finest level in the solve.
Definition CD_AMRMultigridKrylovOp.H:277
AMRMultigridKrylovOp()=default
Default constructor. Call define() before use.
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...
Definition CD_AMRMultigridKrylovOp.H:257
Vector< AMRLevelOp< LevelData< T > > * > m_amrOps
Per-level AMR operators borrowed from m_mg (not owned).
Definition CD_AMRMultigridKrylovOp.H:246
void create(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_rhs) override
Allocate a_lhs to mirror a_rhs.
Definition CD_AMRMultigridKrylovOpImplem.H:131
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).
Definition CD_AMRMultigridKrylovOpImplem.H:74
bool m_volumeCached
Whether m_volume has been computed and reduced. Reset to false in define() (regrid invalidates it).
Definition CD_AMRMultigridKrylovOp.H:267
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,...
Definition CD_AMRMultigridKrylovOpImplem.H:306
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).
Definition CD_AMRMultigridKrylovOpImplem.H:163
bool m_precondInit
Whether the preconditioner scratch has been allocated.
Definition CD_AMRMultigridKrylovOp.H:288
Vector< LevelData< T > * > m_precondDcor
Preconditioner scratch (cycle correction), lazily allocated on first preCond.
Definition CD_AMRMultigridKrylovOp.H:298
virtual ~AMRMultigridKrylovOp()
Destructor. Frees the preconditioner scratch storage.
Definition CD_AMRMultigridKrylovOpImplem.H:25
void clear(Vector< LevelData< T > * > &a_lhs) override
Free a holder created by create().
Definition CD_AMRMultigridKrylovOpImplem.H:142
void setToZero(Vector< LevelData< T > * > &a_lhs) override
Set a_lhs = 0.
Definition CD_AMRMultigridKrylovOpImplem.H:322
void scale(Vector< LevelData< T > * > &a_lhs, const Real &a_scale) override
Scale a_lhs *= a_scale.
Definition CD_AMRMultigridKrylovOpImplem.H:297
Helmholtz operator for equations like alpha*a(x)*phi(x) + beta*div(b(x)*grad(phi(x))) = rho.
Definition CD_EBHelmholtzOp.H:42
Operator for solving multifluid Helmholtz on a grid level.
Definition CD_MFHelmholtzOp.H:44
Trait mapping a FAB type to the concrete chombo-discharge Helmholtz operator that owns it.
Definition CD_AMRMultigridKrylovOp.H:40