13#ifndef CD_TRACERPARTICLESOLVERIMPLEM_H
14#define CD_TRACERPARTICLESOLVERIMPLEM_H
23#include <CD_NamespaceHeader.H>
28 CH_TIME(
"TracerParticleSolver::TracerParticleSolver()");
32 m_name =
"TracerParticleSolver";
46 const RefCountedPtr<ComputationalGeometry>& a_compGeom)
49 CH_TIME(
"TracerParticleSolver::TracerParticleSolver(RefCountedPtr<AmrMesh>, RefCountedPtr<ComputationalGeometry>)");
58 CH_TIME(
"TracerParticleSolver::~TracerParticleSolver()");
65 CH_TIME(
"TracerParticleSolver::parseOptions()");
67 pout() <<
m_name +
"::parseOptions()" << endl;
79 CH_TIME(
"TracerParticleSolver::parseRuntimeOptions()");
81 pout() <<
m_name +
"::parseRuntimeOptions()" << endl;
93 CH_TIME(
"TracerParticleSolver::parseDeposition()");
95 pout() <<
m_name +
"::parseDeposition()" << endl;
103 pp.get(
"deposition", str);
107 else if (str ==
"cic") {
111 MayDay::Error(
"TracerParticleSolver::parseDeposition - unknown deposition method requested.");
114 pp.get(
"deposition_cf", str);
115 if (str ==
"interp") {
118 else if (str ==
"halo") {
121 else if (str ==
"halo_ngp") {
124 else if (str ==
"transition") {
128 MayDay::Error(
"TracerParticleSolver::parseDeposition - unknown coarse-fine deposition method requested.");
132 pp.get(
"interpolation", str);
136 else if (str ==
"cic") {
140 MayDay::Error(
"TracerParticleSolver::parseDeposition - unknown interpolation method requested.");
150 CH_TIME(
"TracerParticleSolver::parsePlotVariables()");
152 pout() <<
m_name +
"::parsePlotVariables()" << endl;
165 CH_TIME(
"TracerParticleSolver::parseVerbosity()");
167 pout() <<
m_name +
"::parseVerbosity()" << endl;
179 CH_TIME(
"TracerParticleSolver::registerOperators()");
181 pout() <<
m_name +
"::registerOperators()" << endl;
184 if (
m_amr.isNull()) {
185 MayDay::Abort(
"TracerParticleSolver::registerOperators - need to set AmrMesh!");
197 CH_TIME(
"TracerParticleSolver::allocate()");
199 pout() <<
m_name +
"::allocate()" << endl;
211 CH_TIME(
"TracerParticleSolver::setName(std::string)");
213 pout() <<
m_name +
"::setName(std::string)" << endl;
223 CH_TIME(
"TracerParticleSolver::setVolumeScale(bool)");
225 pout() <<
m_name +
"::setVolumeScale(bool)" << endl;
235 CH_TIME(
"TracerParticleSolver::setRealm(std::string)");
237 pout() <<
m_name +
"::setRealm(std::string)" << endl;
247 CH_TIME(
"TracerParticleSolver::setPhase(phase::which_phase)");
249 pout() <<
m_name +
"::setPhase(phase::which_phase)" << endl;
259 CH_TIME(
"TracerParticleSolver::setTime(int, Real, Real)");
261 pout() <<
m_name +
"::setTime(int, Real, Real)" << endl;
273 CH_TIME(
"TracerParticleSolver::setAmr(RefCountedPtr<AmrMesh>)");
275 pout() <<
m_name +
"::setAmr(RefCountedPtr<AmrMesh>)" << endl;
285 CH_TIME(
"TracerParticleSolver::setComputationalGeometry(RefCountedPtr<ComputationalGeometry>)");
287 pout() <<
m_name +
"::setComputationalGeometry(RefCountedPtr<ComputationalGeometry>)" << endl;
297 CH_TIME(
"TracerParticleSolver::setVelocity(EBAMRCellData)");
299 pout() <<
m_name +
"::setVelocity(EBAMRCellData)" << endl;
309 CH_TIME(
"TracerParticleSolver::preRegrid(int, int)");
311 pout() <<
m_name +
"::preRegrid(int, int)" << endl;
314 CH_assert(a_lbase >= 0);
324 CH_TIME(
"TracerParticleSolver::regrid(int, int, int)");
326 pout() <<
m_name +
"::regrid(int, int, int)" << endl;
329 CH_assert(a_lmin >= 0);
330 CH_assert(a_oldFinestLevel >= 0);
331 CH_assert(a_newFinestLevel >= 0);
341 CH_TIME(
"TracerParticleSolver::remap()");
343 pout() <<
m_name +
"::remap()" << endl;
353 CH_TIME(
"TracerParticleSolver::setDeposition");
355 pout() <<
m_name +
"::setDeposition" << endl;
365 CH_TIME(
"TracerParticleSolver::deposit(EBAMRCellData)");
367 pout() <<
m_name +
"::deposit(EBAMRCellData)" << endl;
372 CH_assert(a_phi[0]->nComp() == 1);
374 m_amr->depositWeight(a_phi,
391 CH_TIME(
"TracerParticleSolver::interpolateWeight(EBAMRCellData)");
393 pout() <<
m_name +
"::interpolateWeight(EBAMRCellData)" << endl;
403 CH_TIME(
"TracerParticleSolver::interpolateVelocities()");
405 pout() <<
m_name +
"::interpolateVelocities()" << endl;
420 CH_TIME(
"TracerParticleSolver::writePlotFile()");
422 pout() <<
m_name +
"::writePlotFile()" << endl;
430 EBAMRCellData output;
436 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
442 sprintf(filename,
"%s.step%07d.%dd.hdf5",
m_name.c_str(),
m_timeStep, SpaceDim);
443 std::string fname(filename);
446 Vector<LevelData<EBCellFAB>*> outputPtr;
447 m_amr->alias(outputPtr, output);
450 constexpr int numPlotGhost = 0;
452 DischargeIO::writeEBHDF5(fname,
458 m_amr->getRefinementRatios(),
462 m_amr->getFinestLevel() + 1,
471 CH_TIME(
"TracerParticleSolver::getNumberOfPlotVariables()");
473 pout() <<
m_name +
"::getNumberOfPlotVariables()" << endl;
482 numPlotVars += SpaceDim;
489inline Vector<std::string>
492 CH_TIME(
"TracerParticleSolver::getPlotVariableNames()");
494 pout() <<
m_name +
"::getPlotVariableNames()" << endl;
497 Vector<std::string> plotVarNames(0);
500 plotVarNames.push_back(
m_name +
" density");
503 plotVarNames.push_back(
"x-velocity " +
m_name);
506 plotVarNames.push_back(
"y-velocity " +
m_name);
510 plotVarNames.push_back(
"z-velocity " +
m_name);
521 const std::string& a_outputRealm,
522 const int a_level)
const noexcept
524 CH_TIME(
"TracerParticleSolver::writePlotData");
526 pout() <<
m_name +
"::writePlotData" << endl;
531 EBAMRCellData weight;
536 this->
writeData(a_output, a_comp, weight, a_outputRealm, a_level,
false,
true);
549 const EBAMRCellData& a_data,
550 const std::string a_outputRealm,
552 const bool a_interpToCentroids,
553 const bool a_interpGhost)
const noexcept
555 CH_TIMERS(
"TracerParticleSolver::writeData");
556 CH_TIMER(
"TracerParticleSolver::writeData::allocate", t1);
557 CH_TIMER(
"TracerParticleSolver::writeData::local_copy", t2);
558 CH_TIMER(
"TracerParticleSolver::writeData::interp_ghost", t3);
559 CH_TIMER(
"TracerParticleSolver::writeData::interp_centroid", t4);
560 CH_TIMER(
"TracerParticleSolver::writeData::final_copy", t5);
562 pout() <<
m_name +
"::writeData" << endl;
566 const int numComp = a_data[a_level]->nComp();
569 LevelData<EBCellFAB> scratch;
579 if (a_level > 0 && a_interpGhost) {
585 if (a_interpToCentroids) {
593 const Interval srcInterv(0, numComp - 1);
594 const Interval dstInterv(a_comp, a_comp + numComp - 1);
595 m_amr->copyData(a_output, scratch, a_level, a_outputRealm,
m_realm, dstInterv, srcInterv);
606 CH_TIME(
"TracerParticleSolver::writeCheckpointLevel(HDF5Handle, int)");
607 if (m_verbosity > 5) {
608 pout() << m_name +
"::writeCheckpointLevel(HDF5Handle, int)" << endl;
611 DischargeIO::writeCheckParticlesToHDF(a_handle, m_particles[a_level], m_name +
"_particles");
620 CH_TIME(
"TracerParticleSolver::readCheckpointLevel(HDF5Handle, int)");
621 if (m_verbosity > 5) {
622 pout() << m_name +
"::readCheckpointLevel(HDF5Handle, int)" << endl;
625 DischargeIO::readCheckParticlesFromHDF(a_handle, m_particles[a_level], m_name +
"_particles");
633 CH_TIME(
"TracerParticleSolver::computeDt()");
635 pout() <<
m_name +
"::computeDt()" << endl;
638 Real dt = std::numeric_limits<Real>::infinity();
640 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
641 const DisjointBoxLayout& dbl =
m_amr->getGrids(
m_realm)[lvl];
642 const DataIterator& dit = dbl.dataIterator();
643 const Real dx =
m_amr->getDx()[lvl];
645 const int nbox = dit.size();
647#pragma omp parallel for schedule(runtime) reduction(min : dt)
648 for (
int mybox = 0; mybox < nbox; mybox++) {
649 const DataIndex& din = dit[mybox];
652 const std::size_t n = leaf.
size();
654 D_DECL(leaf.template column<&P::v_x>(), leaf.template column<&P::v_y>(), leaf.template column<&P::v_z>())};
656 for (std::size_t i = 0; i < n; i++) {
657 for (
int dir = 0; dir < SpaceDim; dir++) {
658 dt = std::min(dt, dx / std::abs(
static_cast<Real
>(v[dir][i])));
674 CH_TIME(
"TracerParticleSolver::getParticles()");
676 pout() <<
m_name +
"::getParticles()" << endl;
686 CH_TIME(
"TracerParticleSolver::getParticles()");
688 pout() <<
m_name +
"::getParticles()" << endl;
695inline const EBAMRCellData&
698 CH_TIME(
"TracerParticleSolver::getVelocityField()");
700 pout() <<
m_name +
"::getVelocityField()" << endl;
710 CH_TIME(
"TracerParticleSolver::getDepositionType");
712 pout() <<
m_name +
"::getDepositionType" << endl;
722 CH_TIME(
"TracerParticleSolver::getCoarseFineDepositionType");
724 pout() <<
m_name +
"::getCoarseFineDepositionType" << endl;
734 CH_TIME(
"TracerParticleSolver::getInterpolationType");
736 pout() <<
m_name +
"::getInterpolationType" << endl;
742#include <CD_NamespaceFooter.H>
CoarseFineDeposition
Coarse-fine deposition types (see CD_EBAMRParticleMesh for how these are handled).
Definition CD_CoarseFineDeposition.H:28
DepositionType
Deposition types.
Definition CD_DepositionType.H:24
Silly, but useful functions that override standard Chombo HDF5 IO.
@ Native
Deposit as-is, with no cut-cell treatment at all.
Definition CD_IrregularDeposition.H:41
Agglomeration of basic MPI reductions.
CD_PARTICLE_REAL ParticleReal
Floating-point type a user may use for payload columns.
Definition CD_ParticleSoA.H:156
Declaration of a solver class that advances tracer particles.
static void volumeScale(EBAMRCellData &a_data, const Vector< Real > &a_dx)
Scale data by dx^SpaceDim.
Definition CD_DataOps.cpp:2297
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
static void copy(MFAMRCellData &a_dst, const MFAMRCellData &a_src)
Copy data from one data holder to another.
Definition CD_DataOps.cpp:1262
AMR-hierarchy container of computational particles, stored per patch in Struct-of-Arrays form.
Definition CD_ParticleContainer.H:123
Arena-backed Struct-of-Arrays particle container for a single grid patch.
Definition CD_ParticleSoA.H:655
std::size_t size() const noexcept
Number of particles currently stored.
Definition CD_ParticleSoA.H:882
static const std::string primal
Identifier for perimal realm.
Definition CD_Realm.H:49
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:39
virtual CoarseFineDeposition getCoarseFineDepositionType() const
Get the coarse-fine deposition type.
Definition CD_TracerParticleSolverImplem.H:720
ParticleContainer< P > m_particles
Computational particles.
Definition CD_TracerParticleSolver.H:413
virtual void remap()
Remap particles.
Definition CD_TracerParticleSolverImplem.H:339
virtual void setRealm(const std::string &a_realm)
Set the solver realm.
Definition CD_TracerParticleSolverImplem.H:233
void parsePlotVariables()
Parse plot variables.
Definition CD_TracerParticleSolverImplem.H:148
virtual void registerOperators() const
Register operators needed for AMR core functionality.
Definition CD_TracerParticleSolverImplem.H:177
phase::which_phase m_phase
Phase where this solver lives.
Definition CD_TracerParticleSolver.H:368
virtual void setName(const std::string &a_name) noexcept
Set the solver name.
Definition CD_TracerParticleSolverImplem.H:209
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:26
virtual void setTime(const int a_step, const Real a_time, const Real a_dt)
Set the time for this solver.
Definition CD_TracerParticleSolverImplem.H:257
virtual void deposit(EBAMRCellData &a_phi) const noexcept
Deposit particle weight on mesh.
Definition CD_TracerParticleSolverImplem.H:363
CoarseFineDeposition m_coarseFineDeposition
Coarse-fine deposition strategy.
Definition CD_TracerParticleSolver.H:348
bool m_volumeScale
Do volumetric scaling when depositing (or not).
Definition CD_TracerParticleSolver.H:403
virtual void writeData(LevelData< EBCellFAB > &a_output, int &a_comp, const EBAMRCellData &a_data, const std::string a_outputRealm, const int a_level, const bool a_interpToCentroids, const bool a_interpGhost) const noexcept
Write data to output. Convenience function.
Definition CD_TracerParticleSolverImplem.H:547
virtual ~TracerParticleSolver()
Destructor.
Definition CD_TracerParticleSolverImplem.H:56
std::string m_realm
Realm where this solver lives.
Definition CD_TracerParticleSolver.H:353
virtual void preRegrid(const int a_lbase, const int a_oldFinestLevel)
Perform pre-regrid operations.
Definition CD_TracerParticleSolverImplem.H:307
DepositionType m_interpolation
Deposition type when interpolating to particles.
Definition CD_TracerParticleSolver.H:343
bool m_plotWeight
Hook for adding weight to plot file.
Definition CD_TracerParticleSolver.H:393
virtual ParticleContainer< P > & getParticles()
Get all particles.
Definition CD_TracerParticleSolverImplem.H:672
void parseDeposition()
Parse deposition method.
Definition CD_TracerParticleSolverImplem.H:91
void parseVerbosity()
Parse solver verbosity.
Definition CD_TracerParticleSolverImplem.H:163
int m_verbosity
Verbosity level.
Definition CD_TracerParticleSolver.H:388
RefCountedPtr< AmrMesh > m_amr
Handle to AMR mesh.
Definition CD_TracerParticleSolver.H:328
virtual Vector< std::string > getPlotVariableNames() const
Get plot variable names.
Definition CD_TracerParticleSolverImplem.H:490
DepositionType m_deposition
Deposition type when depositing particles to grid.
Definition CD_TracerParticleSolver.H:338
RefCountedPtr< ComputationalGeometry > m_computationalGeometry
Handle to computational geometry.
Definition CD_TracerParticleSolver.H:333
virtual void writePlotData(LevelData< EBCellFAB > &a_output, int &a_comp, const std::string &a_outputRealm, const int a_level) const noexcept
Write plot data.
Definition CD_TracerParticleSolverImplem.H:519
virtual void parseRuntimeOptions()
Parse solver run-time options.
Definition CD_TracerParticleSolverImplem.H:77
virtual void writePlotFile()
Write plot file.
Definition CD_TracerParticleSolverImplem.H:418
virtual void setDeposition(const DepositionType a_deposition) noexcept
Set deposition method.
Definition CD_TracerParticleSolverImplem.H:351
virtual void setPhase(const phase::which_phase &a_phase)
Set the solver phase.
Definition CD_TracerParticleSolverImplem.H:245
virtual DepositionType getDepositionType() const
Get the deposition type.
Definition CD_TracerParticleSolverImplem.H:708
Real m_dt
Time step.
Definition CD_TracerParticleSolver.H:373
virtual void allocate()
Allocate storage for this solver.
Definition CD_TracerParticleSolverImplem.H:195
std::string m_name
Solver name.
Definition CD_TracerParticleSolver.H:358
bool m_plotVelocity
Hook for adding velocity field to plot file.
Definition CD_TracerParticleSolver.H:398
int m_timeStep
Time step.
Definition CD_TracerParticleSolver.H:383
virtual DepositionType getInterpolationType() const
Get the interpolation type.
Definition CD_TracerParticleSolverImplem.H:732
virtual void setComputationalGeometry(const RefCountedPtr< ComputationalGeometry > &a_compGeom)
Set the computational geometry.
Definition CD_TracerParticleSolverImplem.H:283
virtual void interpolateVelocities()
Interpolate particles velocities.
Definition CD_TracerParticleSolverImplem.H:401
const EBAMRCellData & getVelocityField() const
Return the velocity field.
Definition CD_TracerParticleSolverImplem.H:696
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
Regrid this solver.
Definition CD_TracerParticleSolverImplem.H:322
std::string m_className
Class name.
Definition CD_TracerParticleSolver.H:363
virtual void parseOptions()
Parse solver options.
Definition CD_TracerParticleSolverImplem.H:63
virtual void setVelocity(const EBAMRCellData &a_velocityField)
Set the tracer particle velocity field.
Definition CD_TracerParticleSolverImplem.H:295
Real m_time
Time.
Definition CD_TracerParticleSolver.H:378
virtual void interpolateWeight(const EBAMRCellData &a_scalar) noexcept
Interpolate a scalar field onto the particle weight.
Definition CD_TracerParticleSolverImplem.H:389
EBAMRCellData m_velocityField
Mesh-based velocity field. Must be set through setVelocity.
Definition CD_TracerParticleSolver.H:408
virtual int getNumberOfPlotVariables() const
Get the number of plot variables.
Definition CD_TracerParticleSolverImplem.H:469
virtual void setAmr(const RefCountedPtr< AmrMesh > &a_amrMesh)
Set AmrMesh.
Definition CD_TracerParticleSolverImplem.H:271
virtual Real computeDt() const
Compute dt = dx/max(v_x, v_y, v_z) minimized over all particles.
Definition CD_TracerParticleSolverImplem.H:631
virtual void setVolumeScale(const bool a_scale) noexcept
Turn on/off volume scaling.
Definition CD_TracerParticleSolverImplem.H:221
Real min(const Real &a_input) noexcept
Get the minimum of the input, reduced over MPI ranks (in the Chombo communicator).
Definition CD_ParallelOpsImplem.H:59
which_phase
Enumeration of supported phases.
Definition CD_MultiFluidIndexSpace.H:38
@ gas
Gas phase.
Definition CD_MultiFluidIndexSpace.H:39