13#ifndef CD_SURFACEODESOLVERIMPLEM_H
14#define CD_SURFACEODESOLVERIMPLEM_H
23#include <CD_NamespaceHeader.H>
28 CH_TIME(
"SurfaceODESolver::SurfaceODESolver");
44 CH_TIME(
"SurfaceODESolver::SurfaceODESolver");
46 pout() <<
m_name +
"::SurfaceODESolver()" << endl;
55 CH_TIME(
"SurfaceODESolver::~SurfaceODESolver");
57 pout() <<
m_name +
"::~SurfaceODESolver()" << endl;
65 CH_TIME(
"SurfaceODESolver::parseOptions");
67 pout() <<
m_name +
"::parseOptions" << endl;
79 CH_TIME(
"SurfaceODESolver::parseRuntimeOptions");
81 pout() <<
m_name +
"::parseRuntimeOptions" << endl;
93 CH_TIME(
"SurfaceODESolver::parseVerbosity");
95 pout() <<
m_name +
"::parseVerbosity" << endl;
107 CH_TIME(
"SurfaceODESolver::parseRegrid");
109 pout() <<
m_name +
"::parseRegrid" << endl;
115 pp.get(
"regrid", str);
117 if (str ==
"conservative") {
120 else if (str ==
"arithmetic") {
124 const std::string err =
"SurfaceODESolver<N>::parseRegrid() - argument '" + str +
"' not recognized";
125 MayDay::Error(err.c_str());
133 CH_TIME(
"SurfaceODESolver::parsePlotVariables");
135 pout() <<
m_name +
"::parsePlotVariables" << endl;
143 const int num = pp.countval(
"plt_vars");
146 Vector<std::string> str(num);
147 pp.getarr(
"plt_vars", str, 0, num);
149 for (
int i = 0; i < num; i++) {
150 if (str[i] ==
"phi") {
153 else if (str[i] ==
"rhs") {
164 CH_TIME(
"SurfaceODESolver::setAmr");
166 pout() <<
m_name +
"::setAmr" << endl;
169 CH_assert(!(a_amr.isNull()));
178 CH_TIME(
"SurfaceODESolver::setRealm");
180 pout() <<
m_name +
"::setRealm" << endl;
190 CH_TIME(
"SurfaceODESolver::setName");
192 pout() <<
"SurfaceODESolver::setName" << endl;
202 CH_TIME(
"SurfaceODESolver::getRealm");
204 pout() <<
"SurfaceODESolver::getRealm" << endl;
214 CH_TIME(
"SurfaceODESolver::setPhase");
216 pout() <<
m_name +
"::setPhase" << endl;
226 CH_TIME(
"SurfaceODESolver::getPhase");
228 pout() <<
m_name +
"::getPhase" << endl;
238 CH_TIME(
"SurfaceODESolver::setVerbosity");
240 pout() <<
m_name +
"::setVerbosity" << endl;
250 CH_TIME(
"SurfaceODESolver::getVerbosity");
252 pout() <<
m_name +
"::getVerbosity" << endl;
262 CH_TIME(
"SurfaceODESolver::setTime");
264 pout() <<
m_name +
"::setTime" << endl;
276 CH_TIME(
"SurfaceODESolver::computeMass(int)");
278 pout() <<
m_name +
"::computeMass(int)" << endl;
288 CH_TIME(
"SurfaceODESolver::computeMass(EBAMRIVData, int)");
290 pout() <<
m_name +
"::computeMass(EBAMRIVData, int)" << endl;
295 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
296 const DisjointBoxLayout& dbl =
m_amr->getGrids(
m_realm)[lvl];
297 const DataIterator& dit = dbl.dataIterator();
299 const Real dx =
m_amr->getDx()[lvl];
300 const Real dxArea = std::pow(dx, SpaceDim - 1);
302 CH_assert(a_data[lvl]->nComp() > a_comp);
304 const int nbox = dit.size();
306#pragma omp parallel for schedule(runtime) reduction(+ : dataSum)
307 for (
int mybox = 0; mybox < nbox; mybox++) {
308 const DataIndex& din = dit[mybox];
310 const EBISBox& ebisbox = ebisl[din];
311 const BaseFab<bool>& validCells = (*
m_amr->getValidCells(
m_realm)[lvl])[din];
312 const BaseIVFAB<Real>& data = (*a_data[lvl])[din];
314 auto irregularKernel = [&](
const VolIndex& vof) ->
void {
315 const IntVect iv = vof.gridIndex();
317 if (validCells(iv)) {
318 dataSum += data(vof, a_comp) * ebisbox.bndryArea(vof) * dxArea;
335 CH_TIME(
"SurfaceODESolver::getStep");
337 pout() <<
m_name +
"::getStep" << endl;
347 CH_TIME(
"SurfaceODESolver::getTime");
349 pout() <<
m_name +
"::getTime" << endl;
359 CH_TIME(
"SurfaceODESolver::getDt");
361 pout() <<
m_name +
"::getDt" << endl;
371 CH_TIME(
"SurfaceODESolver::setPhi(Real)");
373 pout() <<
m_name +
"::setPhi(Real)" << endl;
383 CH_TIME(
"SurfaceODESolver::setPhi(std::array<Real, N>)");
385 pout() <<
m_name +
"::setPhi(std::array<Real, N>)" << endl;
388 for (
int i = 0; i < N; i++) {
397 CH_TIME(
"SurfaceODESolver::setPhi(EBAMRIVData)");
399 pout() <<
m_name +
"::setPhi(EBAMRIVData)" << endl;
409 CH_TIME(
"SurfaceODESolver::getPhi");
411 pout() <<
m_name +
"::getPhi" << endl;
421 CH_TIME(
"SurfaceODESolver::getPhi");
423 pout() <<
m_name +
"::getPhi" << endl;
433 CH_TIME(
"SurfaceODESolver::setRHS(Real)");
435 pout() <<
m_name +
"::setRHS(Real)" << endl;
445 CH_TIME(
"SurfaceODESolver::setRHS(std::array<Real, N>)");
447 pout() <<
m_name +
"::setRHS(std::array<Real, N>)" << endl;
450 for (
int i = 0; i < N; i++) {
459 CH_TIME(
"SurfaceODESolver::setRHS(EBAMRIVData)");
461 pout() <<
m_name +
"::setRHS(EBAMRIVData)" << endl;
471 CH_TIME(
"SurfaceODESolver::getRHS");
473 pout() <<
m_name +
"::getRHS" << endl;
483 CH_TIME(
"SurfaceODESolver::getRHS");
485 pout() <<
m_name +
"::getRHS" << endl;
495 CH_TIME(
"SurfaceODESolver::allocate");
497 pout() <<
m_name +
"::allocate" << endl;
500 CH_assert(!(
m_amr.isNull()));
512 CH_TIME(
"SurfaceODESolver::deallocate");
514 pout() <<
m_name +
"::deallocate" << endl;
525 CH_TIME(
"SurfaceODESolver::defineVoFIterators");
527 pout() <<
m_name +
"::defineVoFIterators" << endl;
530 using LDVoFs = LayoutData<VoFIterator>;
532 CH_assert(!(
m_amr.isNull()));
534 const int finestLevel =
m_amr->getFinestLevel();
539 for (
int lvl = 0; lvl <= finestLevel; lvl++) {
540 const DisjointBoxLayout& dbl =
m_amr->getGrids(
m_realm)[lvl];
541 const DataIterator& dit = dbl.dataIterator();
548 const int nbox = dit.size();
550#pragma omp parallel for schedule(runtime)
551 for (
int mybox = 0; mybox < nbox; mybox++) {
552 const DataIndex& din = dit[mybox];
554 const Box& cellBox = dbl[din];
555 const EBISBox& ebisBox = ebisl[din];
556 const EBGraph& ebGraph = ebisBox.getEBGraph();
562 IntVectSet electrodeIVS = ebisBox.getIrregIVS(cellBox) - dielectricIVS;
564 dielectricVoFIt.define(dielectricIVS, ebGraph);
565 electrodeVoFIt.define(electrodeIVS, ebGraph);
574 CH_TIME(
"SurfaceODESolver::registerOperators");
576 pout() <<
m_name +
"::registerOperators" << endl;
579 CH_assert(!(
m_amr.isNull()));
588 CH_TIME(
"SurfaceODESolver::registerOperators");
590 pout() <<
m_name +
"::registerOperators" << endl;
593 CH_assert(!(
m_amr.isNull()));
606 CH_TIME(
"SurfaceODESolver::regrid");
608 pout() <<
m_name +
"::registerOperators" << endl;
614 : EBCoarseToFineInterp::Type::PWC;
625 CH_TIME(
"SurfaceODESolver::resetElectrodes");
627 pout() <<
m_name +
"::resetElectrodes" << endl;
637 CH_TIME(
"SurfaceODESolver::resetElectrodes(EBAMRIVData)");
639 pout() <<
m_name +
"::resetElectrodes(EBAMRIVData)" << endl;
642 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
643 const DisjointBoxLayout& dbl =
m_amr->getGrids(
m_realm)[lvl];
644 const DataIterator& dit = dbl.dataIterator();
646 const int nbox = dit.size();
648#pragma omp parallel for schedule(runtime)
649 for (
int mybox = 0; mybox < nbox; mybox++) {
650 const DataIndex& din = dit[mybox];
652 BaseIVFAB<Real>& phi = (*a_phi[lvl])[din];
655 auto kernel = [&](
const VolIndex& vof) ->
void {
656 for (
int comp = 0; comp < N; comp++) {
657 phi(vof, comp) = a_value;
670 CH_TIME(
"SurfaceODESolver::resetDielectrics");
672 pout() <<
m_name +
"::resetDielectrics" << endl;
682 CH_TIME(
"SurfaceODESolver::resetDielectrics(EBAMRIVData)");
684 pout() <<
m_name +
"::resetDielectrics(EBAMRIVData)" << endl;
687 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
688 const DisjointBoxLayout& dbl =
m_amr->getGrids(
m_realm)[lvl];
689 const DataIterator& dit = dbl.dataIterator();
691 const int nbox = dit.size();
693#pragma omp parallel for schedule(runtime)
694 for (
int mybox = 0; mybox < nbox; mybox++) {
695 const DataIndex& din = dit[mybox];
697 BaseIVFAB<Real>& phi = (*a_phi[lvl])[din];
700 auto kernel = [&](
const VolIndex& vof) ->
void {
701 for (
int comp = 0; comp < N; comp++) {
702 phi(vof, comp) = a_value;
716 CH_TIME(
"SurfaceODESolver::writeCheckpointLevel");
717 if (m_verbosity > 5) {
718 pout() << m_name +
"::writeCheckpointLevel" << endl;
721 const std::string
id =
"SurfaceODESolver::" + m_name +
"::phi";
723 CH_assert(!(m_amr.isNull()));
726 EBAMRCellData scratch;
728 m_amr->allocate(scratch, m_realm, m_phase, N);
731 DataOps::incr(*scratch[a_level], *m_phi[a_level], 1.0, *m_amr->getVofIterator(m_realm, m_phase)[a_level]);
733 write(a_handle, *scratch[a_level],
id);
743 CH_TIME(
"SurfaceODESolver::readCheckpointLevel");
744 if (m_verbosity > 5) {
745 pout() << m_name +
"::readCheckpointLevel" << endl;
748 const std::string
id =
"SurfaceODESolver::" + m_name +
"::phi";
750 CH_assert(!(m_amr.isNull()));
754 EBAMRCellData scratch;
756 m_amr->allocate(scratch, m_realm, m_phase, N);
758 read<EBCellFAB>(a_handle, *scratch[a_level],
id, m_amr->getGrids(m_realm)[a_level], Interval(0, N - 1),
false);
761 DataOps::incr(*m_phi[a_level], *scratch[a_level], 1.0, *m_amr->getVofIterator(m_realm, m_phase)[a_level]);
769 CH_TIME(
"SurfaceODESolver::writePlotFile");
771 pout() <<
m_name +
"::writePlotFile" << endl;
776 if (numPlotVars > 0) {
779 CH_assert(plotVarNames.size() == numPlotVars);
780 CH_assert(!(
m_amr.isNull()));
782 EBAMRCellData output;
785 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
792 sprintf(filename,
"%s.step%07d.%dd.hdf5",
m_name.c_str(),
m_step, SpaceDim);
793 std::string fname(filename);
796 Vector<LevelData<EBCellFAB>*> outputPtr;
797 m_amr->alias(outputPtr, output);
800 constexpr int numPlotGhost = 0;
802 DischargeIO::writeEBHDF5(fname,
808 m_amr->getRefinementRatios(),
812 m_amr->getFinestLevel() + 1,
822 const std::string& a_outputRealm,
823 const int a_level)
const noexcept
825 CH_TIME(
"SurfaceODESolver::writePlotData");
827 pout() <<
m_name +
"::writePlotData" << endl;
830 CH_assert(a_level >= 0);
831 CH_assert(a_level <= m_amr->getFinestLevel());
835 LevelData<EBCellFAB> scratch;
843 const Interval srcInterv(0, N - 1);
844 const Interval dstInterv(a_comp, a_comp + N - 1);
846 m_amr->copyData(a_output, scratch, a_level, a_outputRealm,
m_realm, dstInterv, srcInterv);
848 a_output.exchange(dstInterv);
858 const Interval srcInterv(0, N - 1);
859 const Interval dstInterv(a_comp, a_comp + N - 1);
861 m_amr->copyData(a_output, scratch, a_level, a_outputRealm,
m_realm, dstInterv, srcInterv);
863 a_output.exchange(dstInterv);
873 CH_TIME(
"SurfaceODESolver::getNumberOfPlotVariables");
875 pout() <<
m_name +
"::getNumberOfPlotVariables" << endl;
895 CH_TIME(
"SurfaceODESolver::getPlotVariableNames");
897 pout() <<
m_name +
"::getPlotVariablesNames" << endl;
900 Vector<std::string> plotVarNames;
903 for (
int i = 0; i < N; i++) {
905 plotVarNames.push_back(
m_name +
" phi-" + std::to_string(i));
908 plotVarNames.push_back(
m_name +
" phi");
914 for (
int i = 0; i < N; i++) {
916 plotVarNames.push_back(
m_name +
" rhs-" + std::to_string(i));
919 plotVarNames.push_back(
m_name +
" rhs");
927#include <CD_NamespaceFooter.H>
Silly, but useful functions that override standard Chombo HDF5 IO.
Declaration of a cut-cell ODE solver.
static void incr(MFAMRCellData &a_lhs, const MFAMRCellData &a_rhs, const Real a_scale) noexcept
Function which increments data in the form a_lhs = a_lhs + a_rhs*a_scale for all components.
Definition CD_DataOps.cpp:881
static void setValue(LevelData< MFInterfaceFAB< T > > &a_lhs, const T &a_value)
Set value in an MFInterfaceFAB data holder.
Definition CD_DataOpsImplem.H:24
static void copy(MFAMRCellData &a_dst, const MFAMRCellData &a_src)
Copy data from one data holder to another.
Definition CD_DataOps.cpp:1262
Type
Type of interpolation methods supported. PWC = Piecewise constant, ignoring the embedded boundary....
Definition CD_EBCoarseToFineInterp.H:43
Wrapper class for holding multifluid EBLevelGrids.
Definition CD_MFLevelGrid.H:30
virtual IntVectSet interfaceRegion(const Box &a_box, const DataIndex &a_dit, const int a_phase1=0, const int a_phase2=1) const
Get interface region between two phases.
Definition CD_MFLevelGrid.cpp:102
static const std::string Primal
Identifier for perimal realm.
Definition CD_Realm.H:44
Surface ODE solver.
Definition CD_SurfaceODESolver.H:29
Real m_dt
Time increment.
Definition CD_SurfaceODESolver.H:485
virtual int getVerbosity() const noexcept
Get verbosity.
Definition CD_SurfaceODESolverImplem.H:248
virtual EBAMRIVData & getRHS()
Get internal state.
Definition CD_SurfaceODESolverImplem.H:469
void parseVerbosity() noexcept
Parse verbosity.
Definition CD_SurfaceODESolverImplem.H:91
virtual EBAMRIVData & getPhi() noexcept
Get internal state.
Definition CD_SurfaceODESolverImplem.H:407
virtual void setRHS(const Real a_rhs)
Convenience function for setting m_rhs.
Definition CD_SurfaceODESolverImplem.H:431
virtual phase::which_phase getPhase() const noexcept
Get phase.
Definition CD_SurfaceODESolverImplem.H:224
std::string m_name
Solver name.
Definition CD_SurfaceODESolver.H:409
virtual void resetElectrodes(const Real a_value) noexcept
Reset m_phi on electrode cells.
Definition CD_SurfaceODESolverImplem.H:623
virtual int getStep() const noexcept
Get current time step.
Definition CD_SurfaceODESolverImplem.H:333
virtual void parseOptions() noexcept
Parse solver options.
Definition CD_SurfaceODESolverImplem.H:63
void parsePlotVariables() noexcept
Parse plot variables.
Definition CD_SurfaceODESolverImplem.H:131
virtual void setPhase(const phase::which_phase a_phase) noexcept
Set phase.
Definition CD_SurfaceODESolverImplem.H:212
EBAMRIVData m_cache
Cached state used during regridding.
Definition CD_SurfaceODESolver.H:460
virtual void setAmr(const RefCountedPtr< AmrMesh > &a_amrMesh) noexcept
Set the amr object.
Definition CD_SurfaceODESolverImplem.H:162
SurfaceODESolver()
Default constructor. Must subsequently set AmrMesh.
Definition CD_SurfaceODESolverImplem.H:26
void parseRegrid() noexcept
Parse regrid method.
Definition CD_SurfaceODESolverImplem.H:105
virtual void allocate() noexcept
Allocate internal storage for this class.
Definition CD_SurfaceODESolverImplem.H:493
virtual Real getDt() const noexcept
Get last time step.
Definition CD_SurfaceODESolverImplem.H:357
std::string getRealm() const noexcept
Get the realm where the solver is registered.
Definition CD_SurfaceODESolverImplem.H:200
int m_step
Time step.
Definition CD_SurfaceODESolver.H:475
Real m_time
Current time.
Definition CD_SurfaceODESolver.H:480
bool m_plotRHS
Plot rhs or not.
Definition CD_SurfaceODESolver.H:429
RefCountedPtr< AmrMesh > m_amr
AMR; needed for grid stuff.
Definition CD_SurfaceODESolver.H:439
virtual void preRegrid(const int a_lbase, const int a_oldFinestLevel) noexcept
Pre-regrid function.
Definition CD_SurfaceODESolverImplem.H:586
std::string m_className
Class name.
Definition CD_SurfaceODESolver.H:404
bool m_plotPhi
Plot phi or not.
Definition CD_SurfaceODESolver.H:424
virtual ~SurfaceODESolver()
Destructor (does nothing).
Definition CD_SurfaceODESolverImplem.H:53
virtual void setRealm(const std::string &a_realm) noexcept
Set the realm.
Definition CD_SurfaceODESolverImplem.H:176
virtual Real getTime() const noexcept
Get current time.
Definition CD_SurfaceODESolverImplem.H:345
virtual void setVerbosity(const int a_verbosity) noexcept
Set verbosity.
Definition CD_SurfaceODESolverImplem.H:236
virtual void setPhi(const Real a_phi)
Convenience function for setting m_phi.
Definition CD_SurfaceODESolverImplem.H:369
virtual void writePlotData(LevelData< EBCellFAB > &a_output, int &a_comp, const std::string &a_outputRealm, const int a_level) const noexcept
Write output data to a_output.
Definition CD_SurfaceODESolverImplem.H:820
EBAMRIVData m_phi
State. Stored on cut-cells.
Definition CD_SurfaceODESolver.H:455
bool m_conservativeRegrid
Conservative regrid or not.
Definition CD_SurfaceODESolver.H:419
std::string m_realm
Realm where this solver is registered.
Definition CD_SurfaceODESolver.H:399
virtual void setName(const std::string &a_name) noexcept
Set the solver name.
Definition CD_SurfaceODESolverImplem.H:188
virtual Real computeMass(const int a_comp=0) const noexcept
Compute the total mass for component a_comp in m_phi.
Definition CD_SurfaceODESolverImplem.H:274
virtual Vector< std::string > getPlotVariableNames() const noexcept
Get output plot names.
Definition CD_SurfaceODESolverImplem.H:893
Vector< RefCountedPtr< LayoutData< VoFIterator > > > m_dielectricVoFs
Cut-cells that are also dielectric cells. This does not include ghost cells.
Definition CD_SurfaceODESolver.H:450
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) noexcept
Regrid function.
Definition CD_SurfaceODESolverImplem.H:604
virtual void registerOperators() noexcept
Register operators.
Definition CD_SurfaceODESolverImplem.H:572
EBAMRIVData m_rhs
Right-hand side.
Definition CD_SurfaceODESolver.H:465
int m_verbosity
Solver verbosity.
Definition CD_SurfaceODESolver.H:470
virtual void deallocate() noexcept
Deallocate internal storage.
Definition CD_SurfaceODESolverImplem.H:510
virtual void parseRuntimeOptions() noexcept
Parse runtime solver options.
Definition CD_SurfaceODESolverImplem.H:77
virtual void writePlotFile() const noexcept
Write a plot file.
Definition CD_SurfaceODESolverImplem.H:767
phase::which_phase m_phase
Phase where the data lives.
Definition CD_SurfaceODESolver.H:414
virtual void setTime(const int a_step, const Real a_time, const Real a_dt) noexcept
Set the time.
Definition CD_SurfaceODESolverImplem.H:260
void defineVoFIterators() noexcept
Define iterators for iterating over cell subsets.
Definition CD_SurfaceODESolverImplem.H:523
virtual int getNumberOfPlotVariables() const noexcept
Get number of variables to be plotted.
Definition CD_SurfaceODESolverImplem.H:871
Vector< RefCountedPtr< LayoutData< VoFIterator > > > m_electrodeVoFs
Cut-cells that are electrode cells. This does not include ghost cells.
Definition CD_SurfaceODESolver.H:445
virtual void resetDielectrics(const Real a_value) noexcept
Reset m_phi on dielectric cells.
Definition CD_SurfaceODESolverImplem.H:668
ALWAYS_INLINE void loop(const Box &a_computeBox, Functor &&kernel)
Launch a C++ kernel over a regular grid with compile-time per-dimension strides.
Definition CD_BoxLoopsImplem.H:39
Real sum(const Real &a_value) noexcept
Compute the sum across all MPI ranks.
Definition CD_ParallelOpsImplem.H:354
which_phase
Enumeration of supported phases.
Definition CD_MultiFluidIndexSpace.H:38
@ gas
Gas phase.
Definition CD_MultiFluidIndexSpace.H:39