13#ifndef CD_MESHODESOLVERIMPLEM_H
14#define CD_MESHODESOLVERIMPLEM_H
25#include <CD_NamespaceHeader.H>
29 : m_verbosity(-1), m_name(
"MeshODESolver"), m_className(
"MeshODESolver"), m_realm(
Realm::Primal), m_phase(
phase::gas)
31 CH_TIME(
"MeshODESolver::MeshODESolver()");
39 CH_TIME(
"MeshODESolver::MeshODESolver(AMR)");
47 CH_TIME(
"MeshODESolver::~MeshODESolver");
54 CH_TIME(
"MeshODESolver::setAmr");
55 if (m_verbosity > 5) {
56 pout() << m_name +
"::setAmr" << endl;
66 CH_TIME(
"MeshODESolver::parseOptions");
68 ParmParse pp(m_className.c_str());
70 pp.get(
"verbosity", m_verbosity);
71 pp.get(
"use_regrid_slopes", m_regridSlopes);
73 this->parsePlotVariables();
75 if (m_verbosity > 5) {
76 pout() << m_name +
"::parseOptions()" << endl;
84 CH_TIME(
"MeshODESolver::parseRuntimeOptions()");
85 if (m_verbosity > 5) {
86 pout() << m_name +
"::parseRuntimeOptions()" << endl;
89 ParmParse pp(m_className.c_str());
91 pp.get(
"verbosity", m_verbosity);
92 pp.get(
"use_regrid_slopes", m_regridSlopes);
94 this->parsePlotVariables();
101 CH_TIME(
"MeshODESolver::parsePlotVariables()");
102 if (m_verbosity > 5) {
103 pout() << m_name +
"::parsePlotVariables()" << endl;
109 ParmParse pp(m_className.c_str());
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()");
132 if (m_verbosity > 5) {
133 pout() << m_name +
"::getPhi()" << endl;
143 CH_TIME(
"MeshODESolver::getPhi()");
144 if (m_verbosity > 5) {
145 pout() << m_name +
"::getPhi()" << endl;
155 CH_TIME(
"MeshODESolver::getRHS()");
156 if (m_verbosity > 5) {
157 pout() << m_name +
"::getRHS()" << endl;
167 CH_TIME(
"MeshODESolver::getRHS()");
168 if (m_verbosity > 5) {
169 pout() << m_name +
"::getRHS()" << endl;
179 CH_TIME(
"MeshODESolver::setPhi(std::function, size_t)");
180 if (m_verbosity > 5) {
181 pout() << m_name +
"::setPhi(std::function, size_t)" << endl;
189 m_amr->getMultiCutVofIterator(m_realm, m_phase));
196 CH_TIME(
"MeshODESolver::setPhi(std::function)");
197 if (m_verbosity > 5) {
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];
207 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[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];
256 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
261 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
271 CH_TIME(
"MeshODESolver::setRHS(std::function, size_t)");
272 if (m_verbosity > 5) {
273 pout() << m_name +
"::setRHS(std::function, size_t)" << endl;
281 m_amr->getMultiCutVofIterator(m_realm, m_phase));
288 CH_TIME(
"MeshODESolver::computeRHS(std::function<std::array<Real, N>(...)>)");
289 if (m_verbosity > 5) {
290 pout() << m_name +
"::computeRHS(std::function<std::array<Real, N>(...)>)" << endl;
293 this->computeRHS(m_rhs, a_rhsFunction);
300 CH_TIME(
"MeshODESolver::computeRHS(EBAMRCellData, std::function<std::array<Real, N>(...)>)");
301 if (m_verbosity > 5) {
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];
309 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[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];
375 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[lvl])[din];
383 BoxLoops::loop<D_DECL(1, 1, 1)>(cellBox, regularKernel);
393 CH_TIME(
"MeshODESolver::allocate()");
394 if (m_verbosity > 5) {
395 pout() << m_name +
"::allocate()" << endl;
398 m_amr->allocate(m_phi, m_realm, m_phase, N);
399 m_amr->allocate(m_rhs, m_realm, m_phase, N);
406 CH_TIME(
"MeshODESolver::preRegrid(int, int)");
407 if (m_verbosity > 5) {
408 pout() << m_name +
"::preRegrid(int, int)" << endl;
411 m_amr->allocate(m_cache, m_realm, m_phase, N);
412 m_amr->copyData(m_cache, m_phi);
421 CH_TIME(
"MeshODESolver::regrid(int, int, int)");
422 if (m_verbosity > 5) {
423 pout() << m_name +
"::regrid(int, int, int)" << endl;
429 : EBCoarseToFineInterp::Type::ConservativePWC;
431 m_amr->interpToNewGrids(m_phi, m_cache, m_phase, a_lmin, a_oldFinestLevel, a_newFinestLevel, interpType);
433 m_amr->conservativeAverage(m_phi, m_realm, m_phase);
434 m_amr->interpGhost(m_phi, m_realm, m_phase);
443 CH_TIME(
"MeshODESolver::getRealm()");
444 if (m_verbosity > 5) {
445 pout() << m_name +
"::getRealm()" << endl;
455 CH_TIME(
"MeshODESolver::getName()");
456 if (m_verbosity > 5) {
457 pout() << m_name +
"::getName()" << endl;
467 CH_TIME(
"MeshODESolver::setName()");
468 if (m_verbosity > 5) {
469 pout() << m_name +
"::setName()" << endl;
479 CH_TIME(
"MeshODESolver::registerOperators()");
480 if (m_verbosity > 5) {
481 pout() << m_name +
"::registerOperators()" << endl;
484 CH_assert(!m_amr.isNull());
486 m_amr->registerOperator(s_eb_coar_ave, m_realm, m_phase);
487 m_amr->registerOperator(s_eb_fill_patch, m_realm, m_phase);
488 m_amr->registerOperator(s_eb_fine_interp, m_realm, m_phase);
495 CH_TIME(
"MeshODESolver::setRealm(std::string)");
496 if (m_verbosity > 5) {
497 pout() << m_name +
"::setRealm(std::string)" << endl;
500 m_realm.assign(a_realm);
507 CH_TIME(
"MeshODESolver::setPhase(phase)");
508 if (m_verbosity > 5) {
509 pout() << m_name +
"::setPhase(phase)" << endl;
519 CH_TIME(
"MeshODESolver::setVerbosity(int)");
520 if (m_verbosity > 5) {
521 pout() << m_name +
"::setVerbosity(int)" << endl;
524 m_verbosity = a_verbosity;
531 CH_TIME(
"MeshODESolver::setTime(int, Real, Real)");
532 if (m_verbosity > 5) {
533 pout() << m_name +
"::setTime(int, Real, Real)" << endl;
545 CH_TIME(
"MeshODESolver::writePlotFile()");
546 if (m_verbosity > 5) {
547 pout() << m_name +
"::writePlotFile()" << endl;
551 const int numPlotVars = this->getNumberOfPlotVariables();
552 const Vector<std::string> plotVarNames = this->getPlotVariableNames();
555 EBAMRCellData output;
556 m_amr->allocate(output, m_realm, m_phase, numPlotVars);
560 for (
int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
561 this->writePlotData(*output[lvl], icomp, m_realm, 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,
577 m_amr->getGrids(m_realm),
581 m_amr->getRefinementRatios(),
585 m_amr->getFinestLevel() + 1,
594 CH_TIME(
"MeshODESolver::getNumberOfPlotVariables()");
595 if (m_verbosity > 5) {
596 pout() << m_name +
"::getNumberOfPlotVariables()" << endl;
602 numPlotVars +=
static_cast<int>(N);
606 numPlotVars +=
static_cast<int>(N);
616 CH_TIME(
"MeshODESolver::getPlotVariableNames()");
617 if (m_verbosity > 5) {
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");
646 if (m_verbosity > 5) {
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);
676 if (m_verbosity > 5) {
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;
689 m_amr->allocate(scratch, m_realm, m_phase, a_level, numComp);
693 m_amr->copyData(scratch, *a_data[a_level], a_level, m_realm, m_realm);
698 if (a_level > 0 && a_interpGhost) {
699 m_amr->interpGhost(scratch, *a_data[a_level - 1], a_level, m_realm, m_phase);
704 if (a_interpToCentroids) {
705 m_amr->interpToCentroids(scratch, m_realm, m_phase, a_level);
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:2655
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
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
std::function< std::array< Real, N >(const std::array< Real, N > &, const Real)> RHSFunction
Alias for right-hand side.
Definition CD_MeshODESolver.H:34
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
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
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
EBAMRCellData & getPhi() noexcept
Get the solution vector (left-hand side of equation).
Definition CD_MeshODESolverImplem.H:129
virtual ~MeshODESolver()
Destructor.
Definition CD_MeshODESolverImplem.H:45
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
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
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
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