chombo-discharge
Loading...
Searching...
No Matches
FieldSolverAMG Class Reference

Electrostatic field solver that assembles the operator as a PETSc matrix and solves it with a PETSc Krylov method, preconditioned by algebraic multigrid. More...

#include <CD_FieldSolverAMG.H>

Inheritance diagram for FieldSolverAMG:
Collaboration diagram for FieldSolverAMG:

Public Member Functions

 FieldSolverAMG ()
 Default constructor.
 FieldSolverAMG (const FieldSolverAMG &a_other)=delete
 Disallowed copy constructor.
 FieldSolverAMG (const FieldSolverAMG &&a_other)=delete
 Disallowed move constructor.
FieldSolverAMG & operator= (const FieldSolverAMG &a_other)=delete
 Disallowed copy assignment operator.
FieldSolverAMG & operator= (const FieldSolverAMG &&a_other)=delete
 Disallowed move assignment operator.
virtual ~FieldSolverAMG ()
 Destructor. Destroys the PETSc solver, unless PETSc has already been finalized.
virtual bool solve (MFAMRCellData &a_potential, const MFAMRCellData &a_rho, const EBAMRIVData &a_sigma, const bool a_zeroPhi=false) override
 Solve the Poisson equation.
virtual void parseOptions () override
 Parse class options.
virtual void parseRuntimeOptions () override
 Parse class options that can change at run time.
virtual void computeElectricField (MFAMRCellData &a_E, const MFAMRCellData &a_potential) const override
 Compute the cell-centered electric field.
virtual void computeElectricField (MFAMRFluxData &a_E, const MFAMRCellData &a_potential) const override
 Compute the face-centered electric field.
virtual void computeElectricField (EBAMRCellData &a_E, const phase::which_phase a_phase, const MFAMRCellData &a_potential) const override
 Compute the cell-centered electric field on a phase.
virtual void computeElectricField (EBAMRFluxData &a_E, const phase::which_phase a_phase, const MFAMRCellData &a_potential) const override
 Compute the face-centered electric field on a phase.
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.
virtual void registerOperators () override
 Register the AMR operators this class needs.
virtual void setupSolver () override
 Assemble the operator and set up the PETSc solver.
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.
virtual void invalidateSolver () override
 Destroy the PETSc solver and the operator. They are set up again before the next solve.
Public Member Functions inherited from FieldSolver
 FieldSolver ()
 Constructor.
 FieldSolver (const FieldSolver &a_other)=delete
 Disallowed copy constructor.
 FieldSolver (const FieldSolver &&a_other)=delete
 Disallowed move constructor.
FieldSolver & operator= (const FieldSolver &a_other)=delete
 Disallowed copy assignment operator.
FieldSolver & operator= (const FieldSolver &&a_other)=delete
 Disallowed move assignment operator.
virtual ~FieldSolver ()
 Constructor.
virtual bool solve (const bool a_zeroPhi=false)
 Solve Poisson equation using m_potential, m_rho, and m_sigma.
virtual bool solve (MFAMRCellData &a_potential, const bool a_zerophi=false)
 Solve Poisson equation onto a_phi using m_rho, and m_sigma as right-hand sides.
virtual void computeElectricField ()
 Compute the cell-centered electric field.
virtual void allocate ()
 Allocates internal storage for FieldSolver. Derived classes may want to overwrite.
virtual void preRegrid (const int a_lbase, const int a_oldFinestLevel)
 Cache state before regridding.
virtual void computeDisplacementField (MFAMRCellData &a_displacementField, const MFAMRCellData &a_electricField)
 Compute displacement field from the electric field.
virtual void deallocate ()
 Deallocate internal storage.
void setRho (const Real a_rho)
 Set space charge to constant value everywhere.
void setRho (const std::function< Real(const RealVect)> &a_rho)
 Set space charge to spatially dependent function.
void setSigma (const Real a_sigma)
 Set surface charge to specified value.
void setSigma (const std::function< Real(const RealVect)> &a_sigma)
 Set surface charge density to spatially dependent function.
void setComputationalGeometry (const RefCountedPtr< ComputationalGeometry > &a_computationalGeometry)
 Set the computational geometry.
void setAmr (const RefCountedPtr< AmrMesh > &a_amr)
 Set the amr object.
virtual void setPermittivities ()
 Set the permittivities.
virtual void writePlotFile ()
 Write plot file.
virtual void postCheckpoint ()
 Post checkpoint method.
virtual void writePlotData (LevelData< EBCellFAB > &a_output, int &a_comp, const std::string &a_outputRealm, const int a_level, const bool a_forceNoInterp=false) const noexcept
 Write output data to a_output.
virtual void writeMultifluidData (LevelData< EBCellFAB > &a_output, int &a_comp, const MFAMRCellData &a_data, const phase::which_phase a_phase, const std::string &a_outputRealm, const int a_level, const bool a_interp) const noexcept
 Write multifluid data to single-fluid data holders.
virtual void writeSurfaceData (LevelData< EBCellFAB > &a_output, int &a_comp, const LevelData< BaseIVFAB< Real > > &a_data, const std::string &a_outputRealm, const int a_level) const noexcept
 Write surface data to volume data holder.
void setRealm (const std::string &a_realm)
 Set Realm.
void setTime (const int a_timeStep, const Real a_time, const Real a_dt)
 Set time for this solver.
void setVerbosity (const int a_verbosity)
 Set verbosity.
virtual void setVoltage (std::function< Real(const Real a_time)> a_voltage)
 Set potential dependence in time.
virtual void setDomainSideBcFunction (const int a_dir, const Side::LoHiSide a_side, const ElectrostaticDomainBc::BcFunction &a_function)
 Boundary condition function on a domain side.
virtual void setElectrodeDirichletFunction (const int a_electrode, const ElectrostaticEbBc::BcFunction &a_function)
 Set embedded boundary Dirichlet function on a specific electrode.
virtual int getNumberOfPlotVariables () const
 Get number of output fields.
const std::function< Real(const Real a_time)> & getVoltage () const
 Get voltage function.
Real getCurrentVoltage () const
 Get current voltage.
Real getTime () const
 Get time.
Real computeCapacitance ()
 Compute the capacitance.
Real computeEnergy (const MFAMRCellData &a_electricField)
 Compute energy density U = 0.5*int(E.dot.D dV).
virtual Vector< std::string > getPlotVariableNames () const
 Get output plot names.
virtual Vector< long long > computeLoads (const DisjointBoxLayout &a_dbl, const int a_level)
 Get computational loads for a level.
void setDataLocation (const Location::Cell a_dataLocation)
 Set the data location for the solver.
std::string getRealm () const
 Get the Realm where this solver is registered.
MFAMRCellData & getPotential ()
 Get potential on both phases.
MFAMRCellData & getElectricField ()
 Get electric field on both phases.
MFAMRCellData & getRho ()
 Get storage for the space charge density.
MFAMRCellData & getResidue ()
 Get the residue.
MFAMRCellData & getPermittivityCell ()
 Get cell-centered permittivity.
MFAMRFluxData & getPermittivityFace ()
 Get face-centered permittivity.
MFAMRIVData & getPermittivityEB ()
 Get irregular b coefficient.
EBAMRIVData & getSigma ()
 Get m_sigma.
Location::Cell getDataLocation () const
 Get data location.

Protected Types

enum class  JumpBCType { Natural , SaturationCharge }
 Conditions on the interface between the gas and the dielectrics.

Protected Member Functions

virtual void parseSolverSettings ()
 Parse the PETSc solver settings.
virtual void parseStencilSettings ()
 Parse the order and the least-squares weight of the EB face stencils (eb_order, eb_weight).
virtual void destroySolver ()
 Destroy the PETSc solver and the operator.
Protected Member Functions inherited from FieldSolver
virtual void parseVerbosity ()
 Parse solver class verbosity.
virtual void parsePlotVariables ()
 Function which parses which plot variables to write to plot files.
virtual void parseDomainBc ()
 Parse domain boundary conditions.
virtual void parseRegridSlopes ()
 Parse slope regrid.
virtual void setDefaultDomainBcFunctions ()
 Set default BC functions. This sets all the m_domainBcFunction objects to s_defaultDomainBcFunction, which return 1 everywhere.
virtual void setDefaultEbBcFunctions ()
 Set default Dirichlet boundary conditions on the embedded boundaries.
Real getDielectricPermittivity (const RealVect &a_pos) const
 Get relative permittivity at some point in space.
virtual void setCellPermittivities (EBCellFAB &a_relPerm, const Box &a_cellBox, const EBISBox &a_ebisbox, const RealVect &a_probLo, const Real &a_dx, VoFIterator &a_vofit)
 Set cell-centered permittivities.
virtual void setFacePermittivities (EBFluxFAB &a_relPerm, const Box &a_cellBox, const EBISBox &a_ebisbox, const RealVect &a_probLo, const Real &a_dx, std::array< FaceIterator, SpaceDim > &a_faceIter)
 Set face-centered permittivities.
virtual void setEbPermittivities (BaseIVFAB< Real > &a_relPerm, const Box &a_cellBox, const EBISBox &a_ebisbox, const RealVect &a_origin, const Real &a_dx, VoFIterator &a_vofit)
 Set EB-centered permittivities.
virtual ElectrostaticDomainBc::BcType parseBcString (const std::string &a_str) const
 Returns BC type based on string.
virtual std::string makeBcString (const int a_dir, const Side::LoHiSide a_side) const
 Shortcut for making a boundary condition string.
virtual void fillCoveredPotential (MFAMRCellData &a_phi) const noexcept
 Utility routine that fills the gas-side covered cells by the potential from the closest electrode.
void aliasState (const FieldSolver &a_owner)
 Share the data and the configuration of another solver.

Static Protected Member Functions

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.

Protected Attributes

bool m_isSolverSetup
 Is the solver set up or not.
std::string m_kspType
 PETSc Krylov solver type, e.g. 'gmres', 'fgmres', 'bcgs' (also given as 'bicgstab') or 'cg'.
int m_kspGmresRestart
 Restart length of GMRES and FGMRES.
std::string m_amgSmootherKsp
 KSP type of the smoother on each level of a multigrid preconditioner, e.g. 'chebyshev' or 'richardson'.
std::string m_amgSmootherPc
 PC type of the smoother on each level of a multigrid preconditioner, e.g. 'sor' or 'jacobi'.
int m_amgSmootherIts
 Number of smoothing steps on each level of a multigrid preconditioner.
Real m_gamgThreshold
 GAMG graph threshold: connections weaker than this are dropped when aggregating. Negative keeps them all.
int m_gamgAggressiveCoarsening
 Number of levels that GAMG coarsens aggressively (square graph).
std::string m_pcType
 PETSc preconditioner type, e.g. 'gamg' or 'hypre'.
Real m_kspRtol
 Relative residual tolerance.
Real m_kspAtol
 Absolute residual tolerance.
int m_kspMaxIter
 Maximum number of Krylov iterations.
JumpBCType m_jumpBcType
 Interface condition.
int m_ebOrder
 Highest order of the EB face stencils, for the electrode and the interface faces.
int m_ebWeight
 Least-squares weighting of the EB face stencils.
bool m_kappaSource
 Weight the space charge density by the volume fraction in solve, or not, as in FieldSolverGMG.
RefCountedPtr< PetscHelmholtzEBBC > m_petscEbBc
 Boundary conditions on the electrode faces.
RefCountedPtr< PetscHelmholtzJumpBC > m_petscJumpBc
 Conditions on the interface between the gas and the dielectrics.
RefCountedPtr< PetscHelmholtzOp > m_petscOp
 The operator.
KSP m_ksp
 The PETSc solver.
int m_petscVerbosity
 Verbosity of the PETSc solve.
Real m_monitorZeroResidNorm
 The 2-norm of the zero-residual b - A*0 = b of the current solve, which the true residual is printed relative to.
Real m_monitorFirstNorm
 Residual norm of the KSP at its first iteration of the current solve.
Real m_monitorPreviousNorm
 Residual norm of the KSP at the previous iteration of the current solve.
Protected Attributes inherited from FieldSolver
Location::Cell m_dataLocation
 Flag which specifies that data location.
Location::Face m_faceLocation
 Flag which specifies where the permittivities are stored.
std::string m_realm
 Realm where this solver is registered.
std::string m_className
 Class name (i.e., "FieldSolver" for the base class).
RefCountedPtr< MultiFluidIndexSpace > m_multifluidIndexSpace
 Multifluid index space.
RefCountedPtr< ComputationalGeometry > m_computationalGeometry
 Computational geometry.
RefCountedPtr< AmrMesh > m_amr
 AMR - needed for pretty much everything.
MFAMRCellData m_cache
 Cached state used for regridding.
Vector< RefCountedPtr< LayoutData< VoFIterator > > > m_grownCellVofIter
 Pre-built VoFIterators for grown-box irregular cells (solid phase, grow=1).
MFAMRCellData m_potential
 State data, i.e. the potential. The centering of this is the same as m_dataLocation.
MFAMRCellData m_electricField
 Electric field. The centering of this is the same as m_dataLocation.
MFAMRCellData m_rho
 Storage for space charge density.
EBAMRIVData m_sigma
 Storage for surface charge density.
MFAMRCellData m_residue
 Residue, e.g. used after solving Poisson equation.
MFAMRCellData m_permittivityCell
 Cell permittivity.
MFAMRFluxData m_permittivityFace
 Face permittivity.
MFAMRIVData m_permittivityEB
 EB permittivity.
bool m_isVoltageSet
 Flag for checking if voltage has been set.
bool m_plotPotential
 If true, potential will be added to plot files.
bool m_plotRho
 If true, space charge will be added to plot files.
bool m_plotElectricField
 If true, the electric field will be added to plot files.
bool m_plotElectricFieldSolid
 If true, the electric field on the inside of dielectrics will be added to plot files.
bool m_plotResidue
 If true, the residue will be added to plot files.
bool m_plotPermittivity
 If true, the permittivity will be added to plot files.
bool m_plotSigma
 If true, m_sigma will be added to plot files.
bool m_regridSlopes
 Use slopes when regridding or ont.
int m_verbosity
 Verbosity for this class.
int m_timeStep
 Current time step.
Real m_dt
 Last time step increment.
Real m_time
 Current time.
ElectrostaticDomainBc m_domainBc
 Domain boundary conditions for FieldSolver.
ElectrostaticEbBc m_ebBc
 Dirichlet boundary conditions on electrodes.
std::map< ElectrostaticDomainBc::DomainSide, ElectrostaticDomainBc::BcFunction > m_domainBcFunctions
 Domain BC functions. This is used to map space/time to a voltage/field at the domain faces.
std::vector< std::pair< Electrode, ElectrostaticEbBc::BcFunction > > m_electrodeBcFunctions
 BC functions (Dirichlet) on the electrodes. Used to map space/time to a voltage on the electrodes.
std::function< Real(const Real a_time)> m_voltage
 Voltage function.

Static Protected Attributes

static constexpr Real m_alpha = 0.0
 Operator alpha. There is no diagonal term.
static constexpr Real m_beta = -1.0
 Operator beta. The operator is -div(eps * grad(phi)).
Static Protected Attributes inherited from FieldSolver
static constexpr int m_comp = 0
 Component number where data is stored.
static constexpr int m_nComp = 1
 Number of components in data holders.

Friends

class FieldSolverMG
 FieldSolverMG owns a FieldSolverAMG as its algebraic multigrid stage, and parses its settings and shares its own data with it.

Detailed Description

Electrostatic field solver that assembles the operator as a PETSc matrix and solves it with a PETSc Krylov method, preconditioned by algebraic multigrid.

This is the PETSc counterpart of FieldSolverGMG, with the same inputs and outputs. The operator is -div(eps * grad(phi)) = rho/eps0, assembled by PetscHelmholtzOp. The operator spans all AMR levels and both phases, with electrodes on the EB (PetscHelmholtzElectrostaticEBBC) and the natural or saturation-charge condition on the interface between the gas and the dielectrics. Periodic domains and multi-valued cells are not supported.

Constructor & Destructor Documentation

◆ FieldSolverAMG() [1/2]

FieldSolverAMG::FieldSolverAMG ( const FieldSolverAMG & a_other)
delete

Disallowed copy constructor.

Parameters
[in]a_otherOther solver

◆ FieldSolverAMG() [2/2]

FieldSolverAMG::FieldSolverAMG ( const FieldSolverAMG && a_other)
delete

Disallowed move constructor.

Parameters
[in]a_otherOther solver

Member Function Documentation

◆ computeElectricField() [1/4]

void FieldSolverAMG::computeElectricField ( EBAMRCellData & a_E,
const phase::which_phase a_phase,
const MFAMRCellData & a_potential ) const
overridevirtual

Compute the cell-centered electric field on a phase.

Parameters
[out]a_EElectric field
[in]a_phasePhase
[in]a_potentialPotential

Implements FieldSolver.

◆ computeElectricField() [2/4]

void FieldSolverAMG::computeElectricField ( EBAMRFluxData & a_E,
const phase::which_phase a_phase,
const MFAMRCellData & a_potential ) const
overridevirtual

Compute the face-centered electric field on a phase.

Parameters
[out]a_EElectric field
[in]a_phasePhase
[in]a_potentialPotential

Implements FieldSolver.

◆ computeElectricField() [3/4]

void FieldSolverAMG::computeElectricField ( MFAMRCellData & a_E,
const MFAMRCellData & a_potential ) const
overridevirtual

Compute the cell-centered electric field.

Parameters
[out]a_EElectric field
[in]a_potentialPotential

Implements FieldSolver.

◆ computeElectricField() [4/4]

void FieldSolverAMG::computeElectricField ( MFAMRFluxData & a_E,
const MFAMRCellData & a_potential ) const
overridevirtual

Compute the face-centered electric field.

Parameters
[out]a_EElectric field
[in]a_potentialPotential

Implements FieldSolver.

◆ invalidateSolver()

void FieldSolverAMG::invalidateSolver ( )
overridevirtual

Destroy the PETSc solver and the operator. They are set up again before the next solve.

Implements FieldSolver.

◆ monitorResidual()

PetscErrorCode FieldSolverAMG::monitorResidual ( KSP a_ksp,
PetscInt a_iteration,
PetscReal a_residualNorm,
void * a_context )
staticprotected

KSP monitor that prints the residual at every iteration, as the Krylov solvers of FieldSolverGMG do.

The residual is in the norm the KSP tests convergence on (the preconditioned residual for left-preconditioned KSPs), relative to that norm at the first iteration. The rate is the reduction factor since the previous iteration. With petsc_verbosity 2 and above the true residual b - A*x is also printed, relative to the zero-residual b.

Parameters
[in]a_kspThe KSP
[in]a_iterationIteration number
[in]a_residualNormResidual norm of the KSP
[in]a_contextThe FieldSolverAMG instance
Returns
PETSc error code

◆ operator=() [1/2]

FieldSolverAMG & FieldSolverAMG::operator= ( const FieldSolverAMG && a_other)
delete

Disallowed move assignment operator.

Parameters
[in]a_otherOther solver
Returns
This solver.

◆ operator=() [2/2]

FieldSolverAMG & FieldSolverAMG::operator= ( const FieldSolverAMG & a_other)
delete

Disallowed copy assignment operator.

Parameters
[in]a_otherOther solver
Returns
This solver.

◆ parseOptions()

void FieldSolverAMG::parseOptions ( )
overridevirtual

Parse class options.

Implements FieldSolver.

◆ parseRuntimeOptions()

void FieldSolverAMG::parseRuntimeOptions ( )
overridevirtual

Parse class options that can change at run time.

Implements FieldSolver.

◆ registerOperators()

void FieldSolverAMG::registerOperators ( )
overridevirtual

Register the AMR operators this class needs.

Implements FieldSolver.

◆ regrid()

void FieldSolverAMG::regrid ( const int a_lmin,
const int a_oldFinestLevel,
const int a_newFinestLevel )
overridevirtual

Regrid. The operator is rebuilt on the next solve.

Parameters
[in]a_lminCoarsest level that changed
[in]a_oldFinestLevelFinest level before the regrid
[in]a_newFinestLevelFinest level after the regrid

Reimplemented from FieldSolver.

◆ setSolverPermittivities()

void FieldSolverAMG::setSolverPermittivities ( const MFAMRCellData & a_permittivityCell,
const MFAMRFluxData & a_permittivityFace,
const MFAMRIVData & a_permittivityEB )
overridevirtual

Change the permittivities used by the solver, e.g. for a semi-implicit scheme.

The solver must be set up first. The operator is refilled with the new coefficients, and the preconditioner is rebuilt at the next solve. The coefficients stay in use until the solver is set up again, e.g. after a regrid.

Parameters
[in]a_permittivityCellCell-centered permittivity
[in]a_permittivityFaceFace-centered permittivity
[in]a_permittivityEBEB-centered permittivity

Reimplemented from FieldSolver.

◆ setupSolver()

void FieldSolverAMG::setupSolver ( )
overridevirtual

Assemble the operator and set up the PETSc solver.

Implements FieldSolver.

◆ solve()

bool FieldSolverAMG::solve ( MFAMRCellData & a_potential,
const MFAMRCellData & a_rho,
const EBAMRIVData & a_sigma,
const bool a_zeroPhi = false )
overridevirtual

Solve the Poisson equation.

Parameters
[in,out]a_potentialPotential
[in]a_rhoSpace charge density
[in]a_sigmaSurface charge density on the interface between the gas and the dielectrics
[in]a_zeroPhiUse zero as the initial guess or not
Returns
True if the solver converged.

Implements FieldSolver.

Member Data Documentation

◆ m_petscVerbosity

int FieldSolverAMG::m_petscVerbosity
protected

Verbosity of the PETSc solve.

At 1 and above, the residual is printed at every Krylov iteration. At 2 and above, the true residual is printed too. At 3 and above, the solver and the preconditioner are viewed after each solve.


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