chombo-discharge
CD_FieldSolver.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_FieldSolver_H
13 #define CD_FieldSolver_H
14 
15 // Std includes
16 #include <functional>
17 
18 // Our includes
19 #include <CD_Location.H>
21 #include <CD_AmrMesh.H>
23 #include <CD_ElectrostaticEbBc.H>
24 #include <CD_NamespaceHeader.H>
25 
32 {
33 public:
37  FieldSolver();
38 
43  FieldSolver(const FieldSolver& a_other) = delete;
44 
49  FieldSolver(const FieldSolver&& a_other) = delete;
50 
56  operator=(const FieldSolver& a_other) = delete;
57 
63  operator=(const FieldSolver&& a_other) = delete;
64 
68  virtual ~FieldSolver();
69 
73  virtual void
74  setupSolver() = 0;
75 
83  virtual void
84  setSolverPermittivities(const MFAMRCellData& a_permittivityCell,
85  const MFAMRFluxData& a_permittivityFace,
86  const MFAMRIVData& a_permittivityEB);
87 
94  virtual bool
95  solve(const bool a_zeroPhi = false);
96 
104  virtual bool
105  solve(MFAMRCellData& a_potential, const bool a_zerophi = false);
106 
116  virtual bool
117  solve(MFAMRCellData& a_phi, const MFAMRCellData& a_rho, const EBAMRIVData& a_sigma, const bool a_zerophi = false) = 0;
118 
123  virtual void
125 
131  virtual void
132  computeElectricField(MFAMRCellData& a_E, const MFAMRCellData& a_potential) const = 0;
133 
139  virtual void
140  computeElectricField(MFAMRFluxData& a_E, const MFAMRCellData& a_potential) const = 0;
141 
148  virtual void
150  const phase::which_phase a_phase,
151  const MFAMRCellData& a_potential) const = 0;
152 
159  virtual void
161  const phase::which_phase a_phase,
162  const MFAMRCellData& a_potential) const = 0;
163 
167  virtual void
169 
173  virtual void
175 
179  virtual void
180  allocate();
181 
188  virtual void
189  preRegrid(const int a_lbase, const int a_oldFinestLevel);
190 
196  virtual void
197  computeDisplacementField(MFAMRCellData& a_displacementField, const MFAMRCellData& a_electricField);
198 
202  virtual void
203  deallocate();
204 
212  virtual void
213  regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel);
214 
218  virtual void
220 
225  void
226  setRho(const Real a_rho);
227 
232  void
233  setRho(const std::function<Real(const RealVect)>& a_rho);
234 
238  void
239  setSigma(const Real a_sigma);
240 
245  void
246  setSigma(const std::function<Real(const RealVect)>& a_sigma);
247 
252  void
253  setComputationalGeometry(const RefCountedPtr<ComputationalGeometry>& a_computationalGeometry);
254 
259  void
260  setAmr(const RefCountedPtr<AmrMesh>& a_amr);
261 
266  virtual void
268 
273  virtual void
274  writePlotFile();
275 
282 #ifdef CH_USE_HDF5
283  virtual void
284  writeCheckpointLevel(HDF5Handle& a_handle, const int a_level) const;
285 #endif
286 
293 #ifdef CH_USE_HDF5
294  virtual void
295  readCheckpointLevel(HDF5Handle& a_handle, const int a_level);
296 #endif
297 
302  virtual void
303  postCheckpoint();
304 
314  virtual void
315  writePlotData(LevelData<EBCellFAB>& a_output,
316  int& a_comp,
317  const std::string a_outputRealm,
318  const int a_level,
319  const bool a_forceNoInterp = false) const noexcept;
320 
332  virtual void
333  writeMultifluidData(LevelData<EBCellFAB>& a_output,
334  int& a_comp,
335  const MFAMRCellData& a_data,
336  const phase::which_phase a_phase,
337  const std::string a_outputRealm,
338  const int a_level,
339  const bool a_interp) const noexcept;
340 
350  virtual void
351  writeSurfaceData(LevelData<EBCellFAB>& a_output,
352  int& a_comp,
353  const LevelData<BaseIVFAB<Real>>& a_data,
354  const std::string a_outputRealm,
355  const int a_level) const noexcept;
356 
361  void
362  setRealm(const std::string a_realm);
363 
371  void
372  setTime(const int a_timeStep, const Real a_time, const Real a_dt);
373 
378  void
379  setVerbosity(const int a_verbosity);
380 
386  virtual void
387  setVoltage(std::function<Real(const Real a_time)> a_voltage);
388 
396  virtual void
397  setDomainSideBcFunction(const int a_dir,
398  const Side::LoHiSide a_side,
399  const ElectrostaticDomainBc::BcFunction& a_function);
400 
406  virtual void
407  setElectrodeDirichletFunction(const int a_electrode, const ElectrostaticEbBc::BcFunction& a_function);
408 
413  virtual int
414  getNumberOfPlotVariables() const;
415 
420  const std::function<Real(const Real a_time)>&
421  getVoltage() const;
422 
427  Real
428  getCurrentVoltage() const;
429 
434  Real
435  getTime() const;
436 
442  Real
444 
450  Real
451  computeEnergy(const MFAMRCellData& a_electricField);
452 
457  virtual Vector<std::string>
458  getPlotVariableNames() const;
459 
466  virtual Vector<long long>
467  computeLoads(const DisjointBoxLayout& a_dbl, const int a_level);
468 
474  void
475  setDataLocation(const Location::Cell a_dataLocation);
476 
481  std::string
482  getRealm() const;
483 
488  getPotential();
489 
495 
501  getRho();
502 
507  getResidue();
508 
514 
520 
524  MFAMRIVData&
526 
530  EBAMRIVData&
531  getSigma();
532 
536  Location::Cell
538 
539 protected:
543  constexpr static int m_comp = 0;
544 
548  constexpr static int m_nComp = 1;
549 
554 
559 
563  std::string m_realm;
564 
568  std::string m_className;
569 
574 
579 
583  RefCountedPtr<AmrMesh> m_amr;
584 
589 
594 
599 
604 
609 
614 
619 
624 
629 
634 
639 
643  bool m_plotRho;
644 
649 
654 
659 
664 
669 
674 
679 
684 
688  Real m_dt;
689 
693  Real m_time;
694 
699 
704 
709 
713  std::vector<std::pair<Electrode, ElectrostaticEbBc::BcFunction>> m_electrodeBcFunctions;
714 
718  std::function<Real(const Real a_time)> m_voltage;
719 
723  virtual void
724  parseVerbosity();
725 
729  virtual void
731 
735  virtual void
736  parseDomainBc();
737 
741  virtual void
743 
747  virtual void
749 
754  virtual void
756 
762  inline Real
763  getDielectricPermittivity(const RealVect& a_pos) const;
764 
773  virtual void
774  setCellPermittivities(EBCellFAB& a_perm,
775  const Box& a_cellBox,
776  const EBISBox& a_ebisbox,
777  const RealVect& a_probLo,
778  const Real& a_dx);
779 
788  virtual void
789  setFacePermittivities(EBFluxFAB& a_perm,
790  const Box& a_cellBox,
791  const EBISBox& a_ebisbox,
792  const RealVect& a_probLo,
793  const Real& a_dx);
794 
803  virtual void
804  setEbPermittivities(BaseIVFAB<Real>& a_perm,
805  const Box& a_cellBox,
806  const EBISBox& a_ebisbox,
807  const RealVect& a_origin,
808  const Real& a_dx);
809 
815  virtual ElectrostaticDomainBc::BcType
816  parseBcString(const std::string a_str) const;
817 
824  virtual std::string
825  makeBcString(const int a_dir, const Side::LoHiSide a_side) const;
826 };
827 
828 #include <CD_NamespaceFooter.H>
829 
830 #include <CD_FieldSolverImplem.H>
831 
832 #endif
Declaration of core class for handling AMR-related operations (with embedded boundaries)
Declaration of base class for defining geometries.
Declaration of a class for holding function-based boundary conditions on domain edges.
Data holder for holding the voltage at electrodes.
Implementation of CD_FieldSolver.H.
Declaration of cell positions.
Class for handling spatial operations.
Definition: CD_AmrMesh.H:44
Abstract base class for geometries.
Definition: CD_ComputationalGeometry.H:36
Electrode class for encapsulating the concept of an electrical conductor.
Definition: CD_Electrode.H:26
Class which maps boundary condition types to a side and direction.
Definition: CD_ElectrostaticDomainBc.H:33
Class which maps boundary condition types to a side and direction.
Definition: CD_ElectrostaticEbBc.H:33
Base class for electrostatic solvers.
Definition: CD_FieldSolver.H:32
virtual void registerOperators()=0
Register operators for AMR. Derived classes have to implement these.
MFAMRCellData & getElectricField()
Get electric field on both phases.
Definition: CD_FieldSolver.cpp:1645
void setSigma(const Real a_sigma)
Set surface charge to specified value.
Definition: CD_FieldSolver.cpp:454
const std::function< Real(const Real a_time)> & getVoltage() const
Get voltage function.
Definition: CD_FieldSolver.cpp:1601
virtual ElectrostaticDomainBc::BcType parseBcString(const std::string a_str) const
Returns BC type based on string.
Definition: CD_FieldSolver.cpp:679
FieldSolver(const FieldSolver &a_other)=delete
Disallowed copy constructor.
virtual void setEbPermittivities(BaseIVFAB< Real > &a_perm, const Box &a_cellBox, const EBISBox &a_ebisbox, const RealVect &a_origin, const Real &a_dx)
Set EB-centered permittivities.
Definition: CD_FieldSolver.cpp:996
bool m_plotSigma
If true, m_sigma will be added to plot files.
Definition: CD_FieldSolver.H:668
void setTime(const int a_timeStep, const Real a_time, const Real a_dt)
Set time for this solver.
Definition: CD_FieldSolver.cpp:543
RefCountedPtr< MultiFluidIndexSpace > m_multifluidIndexSpace
Multifluid index space.
Definition: CD_FieldSolver.H:573
void setAmr(const RefCountedPtr< AmrMesh > &a_amr)
Set the amr object.
Definition: CD_FieldSolver.cpp:496
Real getTime() const
Get time.
Definition: CD_FieldSolver.cpp:1623
std::string m_className
Class name (i.e., "FieldSolver" for the base class)
Definition: CD_FieldSolver.H:568
bool m_plotElectricFieldSolid
If true, the electric field on the inside of dielectrics will be added to plot files.
Definition: CD_FieldSolver.H:653
Location::Face m_faceLocation
Flag which specifies where the permittivities are stored.
Definition: CD_FieldSolver.H:558
void setRealm(const std::string a_realm)
Set Realm.
Definition: CD_FieldSolver.cpp:556
MFAMRCellData m_electricField
Electric field. The centering of this is the same as m_dataLocation.
Definition: CD_FieldSolver.H:598
MFAMRCellData m_potential
State data, i.e. the potential. The centering of this is the same as m_dataLocation.
Definition: CD_FieldSolver.H:593
virtual void parseRuntimeOptions()=0
Parse runtime options (for derived class)
constexpr static int m_comp
Component number where data is stored.
Definition: CD_FieldSolver.H:543
bool m_isVoltageSet
Flag for checking if voltage has been set.
Definition: CD_FieldSolver.H:633
Location::Cell m_dataLocation
Flag which specifies that data location.
Definition: CD_FieldSolver.H:553
std::string getRealm() const
Get the Realm where this solver is registered.
Definition: CD_FieldSolver.cpp:567
virtual void setDomainSideBcFunction(const int a_dir, const Side::LoHiSide a_side, const ElectrostaticDomainBc::BcFunction &a_function)
Boundary condition function on a domain side.
Definition: CD_FieldSolver.cpp:754
MFAMRCellData m_cache
Cached state used for regridding.
Definition: CD_FieldSolver.H:588
virtual bool solve(MFAMRCellData &a_phi, const MFAMRCellData &a_rho, const EBAMRIVData &a_sigma, const bool a_zerophi=false)=0
Solves Poisson equation onto a_phi using a_rho and a_sigma as right-hand sides.
FieldSolver(const FieldSolver &&a_other)=delete
Disallowed move constructor.
virtual void parseRegridSlopes()
Parse slope regrid.
Definition: CD_FieldSolver.cpp:633
virtual Vector< long long > computeLoads(const DisjointBoxLayout &a_dbl, const int a_level)
Get computational loads for a level.
Definition: CD_FieldSolver.cpp:1573
Location::Cell getDataLocation() const
Get data location.
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
Regrid method.
Definition: CD_FieldSolver.cpp:396
RefCountedPtr< ComputationalGeometry > m_computationalGeometry
Computational geometry.
Definition: CD_FieldSolver.H:578
MFAMRIVData m_permittivityEB
EB permittivity.
Definition: CD_FieldSolver.H:628
virtual void writePlotFile()
Write plot file.
Definition: CD_FieldSolver.cpp:1024
virtual void setDefaultEbBcFunctions()
Set default Dirichlet boundary conditions on the embedded boundaries.
Definition: CD_FieldSolver.cpp:723
virtual int getNumberOfPlotVariables() const
Get number of output fields.
Definition: CD_FieldSolver.cpp:1493
virtual void deallocate()
Deallocate internal storage.
Definition: CD_FieldSolver.cpp:378
FieldSolver()
Constructor.
Definition: CD_FieldSolver.cpp:33
MFAMRCellData & getPotential()
Get potential on both phases.
Definition: CD_FieldSolver.cpp:1634
Real getDielectricPermittivity(const RealVect &a_pos) const
Get relative permittivity at some point in space.
Definition: CD_FieldSolverImplem.H:20
MFAMRFluxData m_permittivityFace
Face permittivity.
Definition: CD_FieldSolver.H:623
EBAMRIVData & getSigma()
Get m_sigma.
Definition: CD_FieldSolver.cpp:1667
virtual void parsePlotVariables()
Function which parses which plot variables to write to plot files.
Definition: CD_FieldSolver.cpp:591
virtual void setSolverPermittivities(const MFAMRCellData &a_permittivityCell, const MFAMRFluxData &a_permittivityFace, const MFAMRIVData &a_permittivityEB)
A special routine for when solver permittivities need to change but solver does not.
Definition: CD_FieldSolver.cpp:117
virtual void computeElectricField(MFAMRCellData &a_E, const MFAMRCellData &a_potential) const =0
Compute the cell-centered electric field.
virtual void computeElectricField(MFAMRFluxData &a_E, const MFAMRCellData &a_potential) const =0
Compute the face-centered electric field.
void setVerbosity(const int a_verbosity)
Set verbosity.
Definition: CD_FieldSolver.cpp:532
Real computeCapacitance()
Compute the capacitance.
Definition: CD_FieldSolver.cpp:325
virtual void parseOptions()=0
Parse options (for derived class)
virtual void postCheckpoint()
Write checkpoint data for a level @paramo[out] a_handle HDF5 handle.
Definition: CD_FieldSolver.cpp:1154
MFAMRIVData & getPermittivityEB()
Get irregular b coefficient.
Definition: CD_FieldSolver.cpp:1711
virtual void computeDisplacementField(MFAMRCellData &a_displacementField, const MFAMRCellData &a_electricField)
Compute displacement field from the electric field.
Definition: CD_FieldSolver.cpp:184
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.
Definition: CD_FieldSolver.H:713
virtual void allocate()
Allocates internal storage for FieldSolver. Derived classes may want to overwrite.
Definition: CD_FieldSolver.cpp:139
virtual void computeElectricField(EBAMRCellData &a_E, const phase::which_phase a_phase, const MFAMRCellData &a_potential) const =0
Compute the cell-centered electric field on a specific phase.
void setDataLocation(const Location::Cell a_dataLocation)
Set the data location for the solver.
Definition: CD_FieldSolver.cpp:52
int m_timeStep
Current time step.
Definition: CD_FieldSolver.H:683
virtual Vector< std::string > getPlotVariableNames() const
Get output plot names.
Definition: CD_FieldSolver.cpp:1528
virtual bool solve(const bool a_zeroPhi=false)
Solve Poisson equation using m_potential, m_rho, and m_sigma.
Definition: CD_FieldSolver.cpp:87
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.
Definition: CD_FieldSolver.cpp:1205
std::string m_realm
Realm where this solver is registered.
Definition: CD_FieldSolver.H:563
MFAMRCellData & getRho()
Get storage for the space charge density.
Definition: CD_FieldSolver.cpp:1656
EBAMRIVData m_sigma
Storage for surface charge density.
Definition: CD_FieldSolver.H:608
MFAMRCellData m_residue
Residue, e.g. used after solving Poisson equation.
Definition: CD_FieldSolver.H:613
virtual void setFacePermittivities(EBFluxFAB &a_perm, const Box &a_cellBox, const EBISBox &a_ebisbox, const RealVect &a_probLo, const Real &a_dx)
Set face-centered permittivities.
Definition: CD_FieldSolver.cpp:952
constexpr static int m_nComp
Number of components in data holders.
Definition: CD_FieldSolver.H:548
Real getCurrentVoltage() const
Get current voltage.
Definition: CD_FieldSolver.cpp:1612
virtual void setVoltage(std::function< Real(const Real a_time)> a_voltage)
Set potential dependence in time.
Definition: CD_FieldSolver.cpp:509
virtual void setPermittivities()
Set the permittivities.
Definition: CD_FieldSolver.cpp:861
Real m_time
Current time.
Definition: CD_FieldSolver.H:693
virtual void parseVerbosity()
Parse solver class verbosity.
Definition: CD_FieldSolver.cpp:578
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.
Definition: CD_FieldSolver.H:708
ElectrostaticEbBc m_ebBc
Dirichlet boundary conditions on electrodes.
Definition: CD_FieldSolver.H:703
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.
Definition: CD_FieldSolver.cpp:1453
virtual void computeElectricField()
Compute the cell-centered electric field.
Definition: CD_FieldSolver.cpp:128
void setComputationalGeometry(const RefCountedPtr< ComputationalGeometry > &a_computationalGeometry)
Set the computational geometry.
Definition: CD_FieldSolver.cpp:480
MFAMRCellData & getPermittivityCell()
Get cell-centered permittivity.
Definition: CD_FieldSolver.cpp:1689
RefCountedPtr< AmrMesh > m_amr
AMR - needed for pretty much everything.
Definition: CD_FieldSolver.H:583
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.
Definition: CD_FieldSolver.cpp:1163
MFAMRCellData & getResidue()
Get the residue.
Definition: CD_FieldSolver.cpp:1678
virtual ~FieldSolver()
Constructor.
Definition: CD_FieldSolver.cpp:48
bool m_plotPotential
If true, potential will be added to plot files.
Definition: CD_FieldSolver.H:638
virtual void computeElectricField(EBAMRFluxData &a_E, const phase::which_phase a_phase, const MFAMRCellData &a_potential) const =0
Compute the face-centered electric field on a specific phase.
bool m_plotPermittivity
If true, the permittivity will be added to plot files.
Definition: CD_FieldSolver.H:663
virtual void setCellPermittivities(EBCellFAB &a_perm, const Box &a_cellBox, const EBISBox &a_ebisbox, const RealVect &a_probLo, const Real &a_dx)
Set cell-centered permittivities.
Definition: CD_FieldSolver.cpp:911
virtual void parseDomainBc()
Parse domain boundary conditions.
Definition: CD_FieldSolver.cpp:769
virtual void setupSolver()=0
Set up solver routines.
Real computeEnergy(const MFAMRCellData &a_electricField)
Compute energy density U = 0.5*int(E.dot.D dV)
Definition: CD_FieldSolver.cpp:282
void setRho(const Real a_rho)
Set space charge to constant value everywhere.
Definition: CD_FieldSolver.cpp:426
bool m_plotRho
If true, space charge will be added to plot files.
Definition: CD_FieldSolver.H:643
bool m_regridSlopes
Use slopes when regridding or ont.
Definition: CD_FieldSolver.H:673
bool m_plotElectricField
If true, the electric field will be added to plot files.
Definition: CD_FieldSolver.H:648
int m_verbosity
Verbosity for this calss.
Definition: CD_FieldSolver.H:678
bool m_plotResidue
If true, the residue will be added to plot files.
Definition: CD_FieldSolver.H:658
virtual std::string makeBcString(const int a_dir, const Side::LoHiSide a_side) const
Shortcut for making a boundary condition string.
Definition: CD_FieldSolver.cpp:646
ElectrostaticDomainBc m_domainBc
Domain boundary conditions for FieldSolver.
Definition: CD_FieldSolver.H:698
std::function< Real(const Real a_time)> m_voltage
Voltage function.
Definition: CD_FieldSolver.H:718
MFAMRCellData m_permittivityCell
Cell permittivity.
Definition: CD_FieldSolver.H:618
virtual void setDefaultDomainBcFunctions()
Set default BC functions. This sets all the m_domainBcFunction objects to s_defaultDomainBcFunction,...
Definition: CD_FieldSolver.cpp:702
virtual void preRegrid(const int a_lbase, const int a_oldFinestLevel)
Cache state before regridding.
Definition: CD_FieldSolver.cpp:167
FieldSolver & operator=(const FieldSolver &a_other)=delete
Disallowed copy assignment operator.
virtual void setElectrodeDirichletFunction(const int a_electrode, const ElectrostaticEbBc::BcFunction &a_function)
Set embedded boundary Dirichlet function on a specific electrode.
Definition: CD_FieldSolver.cpp:521
MFAMRFluxData & getPermittivityFace()
Get face-centered permittivity.
Definition: CD_FieldSolver.cpp:1700
FieldSolver & operator=(const FieldSolver &&a_other)=delete
Disallowed move assignment operator.
Real m_dt
Last time step increment.
Definition: CD_FieldSolver.H:688
MFAMRCellData m_rho
Storage for space charge density.
Definition: CD_FieldSolver.H:603
Two-fluid index space.
Definition: CD_MultiFluidIndexSpace.H:42
Namespace for encapsulating various data centerings.
Definition: CD_Location.H:24
Cell
Enum for distinguishing between cell locations.
Definition: CD_Location.H:30
Face
Enum for distinguishing between face locations.
Definition: CD_Location.H:40
phase names
Definition: CD_MultiFluidIndexSpace.H:27