13#ifndef CD_MESHODESOLVERIMPLEM_H
14#define CD_MESHODESOLVERIMPLEM_H
25#include <CD_NamespaceHeader.H>
31 CH_TIME(
"MeshODESolver::MeshODESolver()");
39 CH_TIME(
"MeshODESolver::MeshODESolver(AMR)");
47 CH_TIME(
"MeshODESolver::~MeshODESolver");
54 CH_TIME(
"MeshODESolver::setAmr");
56 pout() <<
m_name +
"::setAmr" << endl;
66 CH_TIME(
"MeshODESolver::parseOptions");
76 pout() <<
m_name +
"::parseOptions()" << endl;
84 CH_TIME(
"MeshODESolver::parseRuntimeOptions()");
86 pout() <<
m_name +
"::parseRuntimeOptions()" << endl;
101 CH_TIME(
"MeshODESolver::parsePlotVariables()");
103 pout() <<
m_name +
"::parsePlotVariables()" << endl;
110 const int num = pp.countval(
"plt_vars");
113 Vector<std::string> str(num);
114 pp.getarr(
"plt_vars", str, 0, num);
116 for (
int i = 0; i < num; i++) {
117 if (str[i] ==
"phi") {
120 else if (str[i] ==
"rhs") {
131 CH_TIME(
"MeshODESolver::getPhi()");
133 pout() <<
m_name +
"::getPhi()" << endl;
143 CH_TIME(
"MeshODESolver::getPhi()");
145 pout() <<
m_name +
"::getPhi()" << endl;
155 CH_TIME(
"MeshODESolver::getRHS()");
157 pout() <<
m_name +
"::getRHS()" << endl;
167 CH_TIME(
"MeshODESolver::getRHS()");
169 pout() <<
m_name +
"::getRHS()" << endl;
179 CH_TIME(
"MeshODESolver::setPhi(std::function, size_t)");
181 pout() <<
m_name +
"::setPhi(std::function, size_t)" << endl;
196 CH_TIME(
"MeshODESolver::setPhi(std::function)");
198 pout() <<
m_name +
"::setPhi(std::function)" << endl;
201 constexpr int comp = 0;
203 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
204 const DisjointBoxLayout& dbl =
m_amr->getGrids(
m_realm)[lvl];
205 const DataIterator& dit = dbl.dataIterator();
206 const Real& dx =
m_amr->getDx()[lvl];
208 const RealVect& probLo =
m_amr->getProbLo();
210 const int nbox = dit.size();
212#pragma omp parallel for schedule(runtime)
213 for (
int mybox = 0; mybox < nbox; mybox++) {
214 const DataIndex& din = dit[mybox];
216 EBCellFAB& phi = (*
m_phi[lvl])[din];
217 const EBISBox& ebisbox = ebisl[din];
218 FArrayBox& phiFAB = phi.getFArrayBox();
219 const BaseFab<bool>& validCells = (*
m_amr->getValidCells(
m_realm)[lvl])[din];
222 auto regularKernel = [&](
const IntVect& iv) ->
void {
223 std::array<Real, N> y{};
225 if (validCells(iv, comp) && ebisbox.isRegular(iv)) {
226 const RealVect pos = probLo + (0.5 * RealVect::Unit + RealVect(iv)) * dx;
232 for (
size_t i = 0; i < N; i++) {
233 phiFAB(iv,
static_cast<int>(i)) = y[i];
238 auto irregularKernel = [&](
const VolIndex& vof) ->
void {
239 std::array<Real, N> y{};
240 const IntVect iv = vof.gridIndex();
242 if (validCells(iv, comp)) {
243 const RealVect pos = probLo +
Location::position(Location::Cell::Centroid, vof, ebisbox, dx);
249 for (
size_t i = 0; i < N; i++) {
255 const Box cellBox = dbl[din];
271 CH_TIME(
"MeshODESolver::setRHS(std::function, size_t)");
273 pout() <<
m_name +
"::setRHS(std::function, size_t)" << endl;
288 CH_TIME(
"MeshODESolver::computeRHS(std::function<std::array<Real, N>(...)>)");
290 pout() <<
m_name +
"::computeRHS(std::function<std::array<Real, N>(...)>)" << endl;
300 CH_TIME(
"MeshODESolver::computeRHS(EBAMRCellData, std::function<std::array<Real, N>(...)>)");
302 pout() <<
m_name +
"::computeRHS(EBAMRCellData, std::function<std::array<Real, N>(...)>)" << endl;
305 constexpr int comp = 0;
307 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
308 const DisjointBoxLayout& dbl =
m_amr->getGrids(
m_realm)[lvl];
310 const DataIterator& dit = dbl.dataIterator();
312 const int nbox = dit.size();
314#pragma omp parallel for schedule(runtime)
315 for (
int mybox = 0; mybox < nbox; mybox++) {
316 const DataIndex& din = dit[mybox];
318 EBCellFAB& rhs = (*a_rhs[lvl])[din];
319 const EBCellFAB& phi = (*
m_phi[lvl])[din];
320 const EBISBox& ebisbox = ebisl[din];
322 FArrayBox& rhsFAB = rhs.getFArrayBox();
323 const FArrayBox& phiFAB = phi.getFArrayBox();
325 const BaseFab<bool>& validCells = (*
m_amr->getValidCells(
m_realm)[lvl])[din];
328 auto regularKernel = [&](
const IntVect& iv) ->
void {
329 std::array<Real, N> y{};
330 std::array<Real, N> f{};
332 if (validCells(iv, comp) && ebisbox.isRegular(iv)) {
335 for (
size_t i = 0; i < N; i++) {
336 y[i] = phiFAB(iv,
static_cast<int>(i));
340 f = a_rhsFunction(y,
m_time);
344 for (
size_t i = 0; i < N; i++) {
345 rhsFAB(iv,
static_cast<int>(i)) = f[i];
350 auto irregularKernel = [&](
const VolIndex& vof) ->
void {
351 std::array<Real, N> y{};
352 std::array<Real, N> f{};
354 const IntVect iv = vof.gridIndex();
356 if (validCells(iv, comp)) {
359 for (
size_t i = 0; i < N; i++) {
364 f = a_rhsFunction(y,
m_time);
368 for (
size_t i = 0; i < N; i++) {
374 const Box cellBox = dbl[din];
393 CH_TIME(
"MeshODESolver::allocate()");
395 pout() <<
m_name +
"::allocate()" << endl;
406 CH_TIME(
"MeshODESolver::preRegrid(int, int)");
408 pout() <<
m_name +
"::preRegrid(int, int)" << endl;
421 CH_TIME(
"MeshODESolver::regrid(int, int, int)");
423 pout() <<
m_name +
"::regrid(int, int, int)" << endl;
429 : EBCoarseToFineInterp::Type::ConservativePWC;
443 CH_TIME(
"MeshODESolver::getRealm()");
445 pout() <<
m_name +
"::getRealm()" << endl;
455 CH_TIME(
"MeshODESolver::getName()");
457 pout() <<
m_name +
"::getName()" << endl;
467 CH_TIME(
"MeshODESolver::setName()");
469 pout() <<
m_name +
"::setName()" << endl;
479 CH_TIME(
"MeshODESolver::registerOperators()");
481 pout() <<
m_name +
"::registerOperators()" << endl;
484 CH_assert(!
m_amr.isNull());
495 CH_TIME(
"MeshODESolver::setRealm(std::string)");
497 pout() <<
m_name +
"::setRealm(std::string)" << endl;
507 CH_TIME(
"MeshODESolver::setPhase(phase)");
509 pout() <<
m_name +
"::setPhase(phase)" << endl;
519 CH_TIME(
"MeshODESolver::setVerbosity(int)");
521 pout() <<
m_name +
"::setVerbosity(int)" << endl;
531 CH_TIME(
"MeshODESolver::setTime(int, Real, Real)");
533 pout() <<
m_name +
"::setTime(int, Real, Real)" << endl;
545 CH_TIME(
"MeshODESolver::writePlotFile()");
547 pout() <<
m_name +
"::writePlotFile()" << endl;
555 EBAMRCellData output;
560 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
565 sprintf(filename,
"%s.step%07d.%dd.hdf5",
m_name.c_str(),
m_timeStep, SpaceDim);
566 std::string fname(filename);
569 Vector<LevelData<EBCellFAB>*> outputPtr;
570 m_amr->alias(outputPtr, output);
573 constexpr int numPlotGhost = 0;
575 DischargeIO::writeEBHDF5(fname,
581 m_amr->getRefinementRatios(),
585 m_amr->getFinestLevel() + 1,
594 CH_TIME(
"MeshODESolver::getNumberOfPlotVariables()");
596 pout() <<
m_name +
"::getNumberOfPlotVariables()" << endl;
602 numPlotVars +=
static_cast<int>(N);
606 numPlotVars +=
static_cast<int>(N);
616 CH_TIME(
"MeshODESolver::getPlotVariableNames()");
618 pout() <<
m_name +
"::getPlotVariableNames()" << endl;
621 Vector<std::string> plotVarNames(0);
624 for (
size_t i = 0; i < N; i++) {
625 plotVarNames.push_back(
m_name +
" phi-" + std::to_string(i));
630 for (
size_t i = 0; i < N; i++) {
631 plotVarNames.push_back(
m_name +
" source-" + std::to_string(i));
642 const std::string& a_outputRealm,
643 const int a_level)
const noexcept
645 CH_TIME(
"MeshODESolver::writePlotData");
647 pout() <<
m_name +
"::writePlotData" << endl;
651 this->
writeData(a_output, a_icomp,
m_phi, a_outputRealm, a_level,
false,
true);
655 this->
writeData(a_output, a_icomp,
m_rhs, a_outputRealm, a_level,
false,
true);
663 const EBAMRCellData& a_data,
664 const std::string a_outputRealm,
666 const bool a_interpToCentroids,
667 const bool a_interpGhost)
const noexcept
670 CH_TIMERS(
"MeshODESolver::writeData");
671 CH_TIMER(
"MeshODESolver::writeData::allocate", t1);
672 CH_TIMER(
"MeshODESolver::writeData::local_copy", t2);
673 CH_TIMER(
"MeshODESolver::writeData::interp_ghost", t3);
674 CH_TIMER(
"MeshODESolver::writeData::interp_centroid", t4);
675 CH_TIMER(
"MeshODESolver::writeData::final_copy", t5);
677 pout() <<
m_name +
"::writeData" << endl;
681 const int numComp = a_data[a_level]->nComp();
684 const Interval srcInterv(0, numComp - 1);
685 const Interval dstInterv(a_comp, a_comp + numComp - 1);
688 LevelData<EBCellFAB> scratch;
698 if (a_level > 0 && a_interpGhost) {
704 if (a_interpToCentroids) {
712 m_amr->copyData(a_output, scratch, a_level, a_outputRealm,
m_realm, dstInterv, srcInterv);
723 CH_TIME(
"MeshODESolver::writeCheckpointLevel(HDF5Handle, int)");
724 if (m_verbosity > 5) {
725 pout() << m_name +
"::writeCheckpointLevel(HDF5Handle, int)" << endl;
728 write(a_handle, *m_phi[a_level], m_name);
729 write(a_handle, *m_rhs[a_level], m_name +
"_src");
738 CH_TIME(
"MeshODESolver::writeCheckpointLevel(HDF5Handle, int)");
739 if (m_verbosity > 5) {
740 pout() << m_name +
"::writeCheckpointLevel(HDF5Handle, int)" << endl;
743 read<EBCellFAB>(a_handle,
746 m_amr->getGrids(m_realm)[a_level],
747 Interval(0,
static_cast<int>(N) - 1),
749 read<EBCellFAB>(a_handle,
752 m_amr->getGrids(m_realm)[a_level],
753 Interval(0,
static_cast<int>(N) - 1),
758#include <CD_NamespaceFooter.H>
Declaration of a namespace for proto-typing grid and EB loops.
Silly, but useful functions that override standard Chombo HDF5 IO.
Declaration of cell positions.
Encapsulation of an ODE solver on the mesh.
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 setCoveredValue(EBAMRCellData &a_lhs, const EBAMRCellData &a_coveredMask, const int a_comp, const Real a_value)
Set value in covered cells. Does specified component.
Definition CD_DataOps.cpp:2716
Type
Type of interpolation methods supported. PWC = Piecewise constant, ignoring the embedded boundary....
Definition CD_EBCoarseToFineInterp.H:43
Class for solving dy/dt = f on an AMR hierarchy.
Definition CD_MeshODESolver.H:29
virtual std::string getRealm() const noexcept
Get the realm where this solver is registered.
Definition CD_MeshODESolverImplem.H:441
virtual void setRHS(const std::function< Real(const RealVect &a_pos)> &a_srcFunc, size_t a_comp) noexcept
Set right-hand side for specified component.
Definition CD_MeshODESolverImplem.H:269
int m_verbosity
Chattiness.
Definition CD_MeshODESolver.H:309
virtual Vector< std::string > getPlotVariableNames() const noexcept
Get output plot names.
Definition CD_MeshODESolverImplem.H:614
virtual void writePlotFile() const noexcept
Write plot file.
Definition CD_MeshODESolverImplem.H:543
bool m_regridSlopes
Use slopes when regridding.
Definition CD_MeshODESolver.H:339
std::function< std::array< Real, N >(const std::array< Real, N > &, const Real)> RHSFunction
Alias for right-hand side.
Definition CD_MeshODESolver.H:34
bool m_plotPhi
Plot solution vector or not.
Definition CD_MeshODESolver.H:329
virtual void writePlotData(LevelData< EBCellFAB > &a_output, int &a_icomp, const std::string &a_outputRealm, int a_level) const noexcept
Write plot data to output holder.
Definition CD_MeshODESolverImplem.H:640
virtual void setName(const std::string &a_name) noexcept
Set solver name.
Definition CD_MeshODESolverImplem.H:465
virtual void writeData(LevelData< EBCellFAB > &a_output, int &a_comp, const EBAMRCellData &a_data, std::string a_outputRealm, int a_level, bool a_interpToCentroids, bool a_interpGhost) const noexcept
Write data to output. Convenience function.
Definition CD_MeshODESolverImplem.H:661
bool m_plotRHS
Plot source term or not.
Definition CD_MeshODESolver.H:334
virtual void parseRuntimeOptions() noexcept
Parse run-time configurable class options.
Definition CD_MeshODESolverImplem.H:82
MeshODESolver()
Default constructor. Must subsequently set everything through public member functions.
Definition CD_MeshODESolverImplem.H:28
EBAMRCellData m_cache
Cache storage when doing regrids.
Definition CD_MeshODESolver.H:375
virtual void setPhi(const std::function< Real(const RealVect &a_pos)> &a_phiFunc, size_t a_comp) noexcept
Set phi for a specific component.
Definition CD_MeshODESolverImplem.H:177
virtual void registerOperators() const noexcept
Register operators for AMR operations.
Definition CD_MeshODESolverImplem.H:477
std::string m_name
Solver name.
Definition CD_MeshODESolver.H:344
std::string m_className
Class name.
Definition CD_MeshODESolver.H:350
Real m_dt
Last time step increment.
Definition CD_MeshODESolver.H:324
RefCountedPtr< AmrMesh > m_amr
Write checkpoint data into HDF5 file.
Definition CD_MeshODESolver.H:304
EBAMRCellData & getPhi() noexcept
Get the solution vector (left-hand side of equation).
Definition CD_MeshODESolverImplem.H:129
EBAMRCellData m_rhs
Source term (right-hand side of equation).
Definition CD_MeshODESolver.H:370
virtual ~MeshODESolver()
Destructor.
Definition CD_MeshODESolverImplem.H:45
std::string m_realm
Realm where solver is registered.
Definition CD_MeshODESolver.H:355
virtual void setRealm(const std::string &a_realm) noexcept
Set the realm for this solver.
Definition CD_MeshODESolverImplem.H:493
virtual int getNumberOfPlotVariables() const noexcept
Get number of output fields.
Definition CD_MeshODESolverImplem.H:592
virtual void preRegrid(int a_lbase, int a_oldFinestLevel) noexcept
Perform pre-regrid operations.
Definition CD_MeshODESolverImplem.H:404
virtual void parseOptions() noexcept
Parse class options.
Definition CD_MeshODESolverImplem.H:64
Real m_time
Current time.
Definition CD_MeshODESolver.H:319
int m_timeStep
Time step.
Definition CD_MeshODESolver.H:314
virtual void parsePlotVariables() noexcept
Parse plot variables.
Definition CD_MeshODESolverImplem.H:99
EBAMRCellData & getRHS() noexcept
Get the right-hand side vector.
Definition CD_MeshODESolverImplem.H:153
virtual void setAmr(const RefCountedPtr< AmrMesh > &a_amrMesh) noexcept
Set AmrMesh.
Definition CD_MeshODESolverImplem.H:52
EBAMRCellData m_phi
Solution vector (left hand side of equation).
Definition CD_MeshODESolver.H:365
virtual void setVerbosity(int a_verbosity) noexcept
Set verbosity.
Definition CD_MeshODESolverImplem.H:517
virtual void setPhase(phase::which_phase a_phase) noexcept
Set phase.
Definition CD_MeshODESolverImplem.H:505
virtual void allocate() noexcept
Allocate internal storage.
Definition CD_MeshODESolverImplem.H:391
phase::which_phase m_phase
Phase where solver data lives.
Definition CD_MeshODESolver.H:360
virtual void regrid(int a_lmin, int a_oldFinestLevel, int a_newFinestLevel) noexcept
Regrid this solver.
Definition CD_MeshODESolverImplem.H:419
virtual std::string getName() const noexcept
Get solver name.
Definition CD_MeshODESolverImplem.H:453
virtual void setTime(int a_step, Real a_time, Real a_dt) noexcept
Set the time for this solver.
Definition CD_MeshODESolverImplem.H:529
virtual void computeRHS(const RHSFunction &a_rhsFunction) noexcept
Compute right-hand side from left-hand side. I.e. compute f = f(y,t).
Definition CD_MeshODESolverImplem.H:286
Class for holding multifluid Realms, which are the Realms that we actually use.
Definition CD_Realm.H:39
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
RealVect position(Location::Cell a_location, const VolIndex &a_vof, const EBISBox &a_ebisbox, const Real &a_dx)
Compute the position (ignoring the "origin) of a Vof.
Definition CD_LocationImplem.H:21
Phase names namespace.
Definition CD_MultiFluidIndexSpace.H:28
which_phase
Enumeration of supported phases.
Definition CD_MultiFluidIndexSpace.H:38