chombo-discharge
Loading...
Searching...
No Matches
CD_FieldSolverAMG.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
12
13#ifdef CH_USE_PETSC
14
15#ifndef CD_FIELDSOLVERAMG_H
16#define CD_FIELDSOLVERAMG_H
17
18// Std includes
19#include <string>
20
21// Petsc includes
22#include <petsc.h>
23
24// Our includes
25#include <CD_FieldSolver.H>
26#include <CD_PetscHelmholtzOp.H>
29#include <CD_NamespaceHeader.H>
30
40{
45 friend class FieldSolverMG;
46
47public:
52
57 FieldSolverAMG(const FieldSolverAMG& a_other) = delete;
58
63 FieldSolverAMG(const FieldSolverAMG&& a_other) = delete;
64
71 operator=(const FieldSolverAMG& a_other) = delete;
72
79 operator=(const FieldSolverAMG&& a_other) = delete;
80
84 virtual ~FieldSolverAMG();
85
94 virtual bool
95 solve(MFAMRCellData& a_potential,
96 const MFAMRCellData& a_rho,
97 const EBAMRIVData& a_sigma,
98 const bool a_zeroPhi = false) override;
99
103 virtual void
104 parseOptions() override;
105
109 virtual void
110 parseRuntimeOptions() override;
111
117 virtual void
118 computeElectricField(MFAMRCellData& a_E, const MFAMRCellData& a_potential) const override;
119
125 virtual void
126 computeElectricField(MFAMRFluxData& a_E, const MFAMRCellData& a_potential) const override;
127
134 virtual void
135 computeElectricField(EBAMRCellData& a_E,
136 const phase::which_phase a_phase,
137 const MFAMRCellData& a_potential) const override;
138
145 virtual void
146 computeElectricField(EBAMRFluxData& a_E,
147 const phase::which_phase a_phase,
148 const MFAMRCellData& a_potential) const override;
149
156 virtual void
157 regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) override;
158
162 virtual void
163 registerOperators() override;
164
168 virtual void
169 setupSolver() override;
170
180 virtual void
181 setSolverPermittivities(const MFAMRCellData& a_permittivityCell,
182 const MFAMRFluxData& a_permittivityFace,
183 const MFAMRIVData& a_permittivityEB) override;
184
188 virtual void
189 invalidateSolver() override;
190
191protected:
195 static constexpr Real m_alpha = 0.0;
196
200 static constexpr Real m_beta = -1.0;
201
206
210 std::string m_kspType;
211
216
220 std::string m_amgSmootherKsp;
221
225 std::string m_amgSmootherPc;
226
231
236
241
245 std::string m_pcType;
246
251
256
261
265 enum class JumpBCType
266 {
267 Natural,
268 SaturationCharge
269 };
270
275
280
285
290
294 RefCountedPtr<PetscHelmholtzEBBC> m_petscEbBc;
295
299 RefCountedPtr<PetscHelmholtzJumpBC> m_petscJumpBc;
300
304 RefCountedPtr<PetscHelmholtzOp> m_petscOp;
305
309 KSP m_ksp;
310
317
323
328
333
337 virtual void
339
343 virtual void
345
358 static PetscErrorCode
359 monitorResidual(KSP a_ksp, PetscInt a_iteration, PetscReal a_residualNorm, void* a_context);
360
364 virtual void
366};
367
368#include <CD_NamespaceFooter.H>
369
370#endif
371
372#endif
Contains declaration of a base electrostatics solver class.
Declaration of a base class for electrode (EB) boundary conditions of PetscHelmholtzOp.
Declaration of a base class for the interface (jump) conditions of PetscHelmholtzOp.
Declaration of a Helmholtz operator assembled as a PETSc matrix.
Real m_kspAtol
Absolute residual tolerance.
Definition CD_FieldSolverAMG.H:255
JumpBCType
Conditions on the interface between the gas and the dielectrics.
Definition CD_FieldSolverAMG.H:266
virtual void parseStencilSettings()
Parse the order and the least-squares weight of the EB face stencils (eb_order, eb_weight).
Definition CD_FieldSolverAMG.cpp:143
virtual void parseOptions() override
Parse class options.
Definition CD_FieldSolverAMG.cpp:62
int m_kspMaxIter
Maximum number of Krylov iterations.
Definition CD_FieldSolverAMG.H:260
virtual void parseRuntimeOptions() override
Parse class options that can change at run time.
Definition CD_FieldSolverAMG.cpp:78
FieldSolverAMG & operator=(const FieldSolverAMG &a_other)=delete
Disallowed copy assignment operator.
Real m_monitorZeroResidNorm
The 2-norm of the zero-residual b - A*0 = b of the current solve, which the true residual is printed ...
Definition CD_FieldSolverAMG.H:322
FieldSolverAMG(const FieldSolverAMG &&a_other)=delete
Disallowed move constructor.
Real m_monitorFirstNorm
Residual norm of the KSP at its first iteration of the current solve.
Definition CD_FieldSolverAMG.H:327
Real m_kspRtol
Relative residual tolerance.
Definition CD_FieldSolverAMG.H:250
std::string m_amgSmootherKsp
KSP type of the smoother on each level of a multigrid preconditioner, e.g. 'chebyshev' or 'richardson...
Definition CD_FieldSolverAMG.H:220
virtual void registerOperators() override
Register the AMR operators this class needs.
Definition CD_FieldSolverAMG.cpp:635
int m_gamgAggressiveCoarsening
Number of levels that GAMG coarsens aggressively (square graph).
Definition CD_FieldSolverAMG.H:240
JumpBCType m_jumpBcType
Interface condition.
Definition CD_FieldSolverAMG.H:274
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) override
Regrid. The operator is rebuilt on the next solve.
Definition CD_FieldSolverAMG.cpp:611
bool m_kappaSource
Weight the space charge density by the volume fraction in solve, or not, as in FieldSolverGMG.
Definition CD_FieldSolverAMG.H:289
virtual ~FieldSolverAMG()
Destructor. Destroys the PETSc solver, unless PETSc has already been finalized.
Definition CD_FieldSolverAMG.cpp:50
FieldSolverAMG()
Default constructor.
Definition CD_FieldSolverAMG.cpp:37
int m_kspGmresRestart
Restart length of GMRES and FGMRES.
Definition CD_FieldSolverAMG.H:215
RefCountedPtr< PetscHelmholtzOp > m_petscOp
The operator.
Definition CD_FieldSolverAMG.H:304
virtual void invalidateSolver() override
Destroy the PETSc solver and the operator. They are set up again before the next solve.
Definition CD_FieldSolverAMG.cpp:624
int m_amgSmootherIts
Number of smoothing steps on each level of a multigrid preconditioner.
Definition CD_FieldSolverAMG.H:230
std::string m_pcType
PETSc preconditioner type, e.g. 'gamg' or 'hypre'.
Definition CD_FieldSolverAMG.H:245
virtual void setupSolver() override
Assemble the operator and set up the PETSc solver.
Definition CD_FieldSolverAMG.cpp:307
std::string m_kspType
PETSc Krylov solver type, e.g. 'gmres', 'fgmres', 'bcgs' (also given as 'bicgstab') or 'cg'.
Definition CD_FieldSolverAMG.H:210
int m_petscVerbosity
Verbosity of the PETSc solve.
Definition CD_FieldSolverAMG.H:316
static constexpr Real m_alpha
Operator alpha. There is no diagonal term.
Definition CD_FieldSolverAMG.H:195
Real m_gamgThreshold
GAMG graph threshold: connections weaker than this are dropped when aggregating. Negative keeps them ...
Definition CD_FieldSolverAMG.H:235
virtual void setSolverPermittivities(const MFAMRCellData &a_permittivityCell, const MFAMRFluxData &a_permittivityFace, const MFAMRIVData &a_permittivityEB) override
Change the permittivities used by the solver, e.g. for a semi-implicit scheme.
Definition CD_FieldSolverAMG.cpp:588
RefCountedPtr< PetscHelmholtzJumpBC > m_petscJumpBc
Conditions on the interface between the gas and the dielectrics.
Definition CD_FieldSolverAMG.H:299
static PetscErrorCode monitorResidual(KSP a_ksp, PetscInt a_iteration, PetscReal a_residualNorm, void *a_context)
KSP monitor that prints the residual at every iteration, as the Krylov solvers of FieldSolverGMG do.
Definition CD_FieldSolverAMG.cpp:524
KSP m_ksp
The PETSc solver.
Definition CD_FieldSolverAMG.H:309
Real m_monitorPreviousNorm
Residual norm of the KSP at the previous iteration of the current solve.
Definition CD_FieldSolverAMG.H:332
RefCountedPtr< PetscHelmholtzEBBC > m_petscEbBc
Boundary conditions on the electrode faces.
Definition CD_FieldSolverAMG.H:294
std::string m_amgSmootherPc
PC type of the smoother on each level of a multigrid preconditioner, e.g. 'sor' or 'jacobi'.
Definition CD_FieldSolverAMG.H:225
int m_ebWeight
Least-squares weighting of the EB face stencils.
Definition CD_FieldSolverAMG.H:284
virtual bool solve(MFAMRCellData &a_potential, const MFAMRCellData &a_rho, const EBAMRIVData &a_sigma, const bool a_zeroPhi=false) override
Solve the Poisson equation.
Definition CD_FieldSolverAMG.cpp:158
friend class FieldSolverMG
FieldSolverMG owns a FieldSolverAMG as its algebraic multigrid stage, and parses its settings and sha...
Definition CD_FieldSolverAMG.H:45
static constexpr Real m_beta
Operator beta. The operator is -div(eps * grad(phi)).
Definition CD_FieldSolverAMG.H:200
bool m_isSolverSetup
Is the solver set up or not.
Definition CD_FieldSolverAMG.H:205
int m_ebOrder
Highest order of the EB face stencils, for the electrode and the interface faces.
Definition CD_FieldSolverAMG.H:279
FieldSolverAMG & operator=(const FieldSolverAMG &&a_other)=delete
Disallowed move assignment operator.
virtual void parseSolverSettings()
Parse the PETSc solver settings.
Definition CD_FieldSolverAMG.cpp:91
virtual void destroySolver()
Destroy the PETSc solver and the operator.
Definition CD_FieldSolverAMG.cpp:566
FieldSolverAMG(const FieldSolverAMG &a_other)=delete
Disallowed copy constructor.
FieldSolver()
Constructor.
Definition CD_FieldSolver.cpp:34
virtual void computeElectricField()
Compute the cell-centered electric field.
Definition CD_FieldSolver.cpp:131
which_phase
Enumeration of supported phases.
Definition CD_MultiFluidIndexSpace.H:38