12 #ifndef CD_TracerParticleSolverImplem_H
13 #define CD_TracerParticleSolverImplem_H
16 #include <ParmParse.H>
22 #include <CD_NamespaceHeader.H>
27 CH_TIME(
"TracerParticleSolver::TracerParticleSolver()");
31 m_name =
"TracerParticleSolver";
32 m_className =
"TracerParticleSolver";
36 m_plotVelocity =
true;
38 m_volumeScale =
false;
39 m_deposition = DepositionType::CIC;
40 m_interpolation = DepositionType::CIC;
41 m_coarseFineDeposition = CoarseFineDeposition::Halo;
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()");
66 if (m_verbosity > 5) {
67 pout() << m_name +
"::parseOptions()" << endl;
70 this->parseDeposition();
71 this->parsePlotVariables();
72 this->parseVerbosity();
79 CH_TIME(
"TracerParticleSolver::parseRuntimeOptions()");
80 if (m_verbosity > 5) {
81 pout() << m_name +
"::parseRuntimeOptions()" << endl;
84 this->parseDeposition();
85 this->parsePlotVariables();
86 this->parseVerbosity();
93 CH_TIME(
"TracerParticleSolver::parseDeposition()");
94 if (m_verbosity > 5) {
95 pout() << m_name +
"::parseDeposition()" << endl;
98 ParmParse pp(m_className.c_str());
103 pp.get(
"deposition", str);
105 m_deposition = DepositionType::NGP;
107 else if (str ==
"cic") {
108 m_deposition = DepositionType::CIC;
111 MayDay::Error(
"TracerParticleSolver::parseDeposition - unknown deposition method requested.");
114 pp.get(
"deposition_cf", str);
115 if (str ==
"interp") {
116 m_coarseFineDeposition = CoarseFineDeposition::Interp;
118 else if (str ==
"halo") {
119 m_coarseFineDeposition = CoarseFineDeposition::Halo;
121 else if (str ==
"halo_ngp") {
122 m_coarseFineDeposition = CoarseFineDeposition::HaloNGP;
125 MayDay::Error(
"TracerParticleSolver::parseDeposition - unknown coarse-fine deposition method requested.");
129 pp.get(
"interpolation", str);
131 m_interpolation = DepositionType::NGP;
133 else if (str ==
"cic") {
134 m_interpolation = DepositionType::CIC;
137 MayDay::Error(
"TracerParticleSolver::parseDeposition - unknown interpolation method requested.");
140 pp.get(
"volume_scale", m_volumeScale);
143 template <
typename P>
147 CH_TIME(
"TracerParticleSolver::parsePlotVariables()");
148 if (m_verbosity > 5) {
149 pout() << m_name +
"::parsePlotVariables()" << endl;
152 ParmParse pp(m_className.c_str());
154 pp.get(
"plot_weight", m_plotWeight);
155 pp.get(
"plot_velocity", m_plotVelocity);
158 template <
typename P>
162 CH_TIME(
"TracerParticleSolver::parseVerbosity()");
163 if (m_verbosity > 5) {
164 pout() << m_name +
"::parseVerbosity()" << endl;
167 ParmParse pp(m_className.c_str());
169 pp.get(
"verbosity", m_verbosity);
172 template <
typename P>
176 CH_TIME(
"TracerParticleSolver::registerOperators()");
177 if (m_verbosity > 5) {
178 pout() << m_name +
"::registerOperators()" << endl;
181 if (m_amr.isNull()) {
182 MayDay::Abort(
"TracerParticleSolver::registerOperators - need to set AmrMesh!");
185 m_amr->registerOperator(s_particle_mesh, m_realm, m_phase);
186 m_amr->registerOperator(s_eb_coar_ave, m_realm, m_phase);
189 m_amr->registerMask(s_particle_halo, 1, m_realm);
193 template <
typename P>
197 CH_TIME(
"TracerParticleSolver::allocate()");
198 if (m_verbosity > 5) {
199 pout() << m_name +
"::allocate()" << endl;
203 m_amr->allocate(m_particles, m_realm);
204 m_amr->allocate(m_velocityField, m_realm, m_phase, SpaceDim);
207 template <
typename P>
211 CH_TIME(
"TracerParticleSolver::setName(std::string)");
212 if (m_verbosity > 5) {
213 pout() << m_name +
"::setName(std::string)" << endl;
219 template <
typename P>
223 CH_TIME(
"TracerParticleSolver::setVolumeScale(bool)");
224 if (m_verbosity > 5) {
225 pout() << m_name +
"::setVolumeScale(bool)" << endl;
228 m_volumeScale = a_scale;
231 template <
typename P>
235 CH_TIME(
"TracerParticleSolver::setRealm(std::string)");
236 if (m_verbosity > 5) {
237 pout() << m_name +
"::setRealm(std::string)" << endl;
243 template <
typename P>
247 CH_TIME(
"TracerParticleSolver::setPhase(phase::which_phase)");
248 if (m_verbosity > 5) {
249 pout() << m_name +
"::setPhase(phase::which_phase)" << endl;
255 template <
typename P>
259 CH_TIME(
"TracerParticleSolver::setTime(int, Real, Real)");
260 if (m_verbosity > 5) {
261 pout() << m_name +
"::setTime(int, Real, Real)" << endl;
269 template <
typename P>
273 CH_TIME(
"TracerParticleSolver::setAmr(RefCountedPtr<AmrMesh>)");
274 if (m_verbosity > 5) {
275 pout() << m_name +
"::setAmr(RefCountedPtr<AmrMesh>)" << endl;
281 template <
typename P>
285 CH_TIME(
"TracerParticleSolver::setComputationalGeometry(RefCountedPtr<ComputationalGeometry>)");
286 if (m_verbosity > 5) {
287 pout() << m_name +
"::setComputationalGeometry(RefCountedPtr<ComputationalGeometry>)" << endl;
290 m_computationalGeometry = a_compGeom;
293 template <
typename P>
297 CH_TIME(
"TracerParticleSolver::setVelocity(EBAMRCellData)");
298 if (m_verbosity > 5) {
299 pout() << m_name +
"::setVelocity(EBAMRCellData)" << endl;
305 template <
typename P>
309 CH_TIME(
"TracerParticleSolver::preRegrid(int, int)");
310 if (m_verbosity > 5) {
311 pout() << m_name +
"::preRegrid(int, int)" << endl;
314 CH_assert(a_lbase >= 0);
317 m_particles.preRegrid(a_lbase);
320 template <
typename P>
324 CH_TIME(
"TracerParticleSolver::regrid(int, int, int)");
325 if (m_verbosity > 5) {
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);
333 m_amr->remapToNewGrids(m_particles, a_lmin, a_newFinestLevel);
334 m_amr->allocate(m_velocityField, m_realm, m_phase, SpaceDim);
337 template <
typename P>
341 CH_TIME(
"TracerParticleSolver::remap()");
342 if (m_verbosity > 5) {
343 pout() << m_name +
"::remap()" << endl;
349 template <
typename P>
353 CH_TIME(
"TracerParticleSolver::setDeposition");
354 if (m_verbosity > 5) {
355 pout() << m_name +
"::setDeposition" << endl;
358 m_deposition = a_deposition;
361 template <
typename P>
365 CH_TIME(
"TracerParticleSolver::deposit(EBAMRCellData)");
366 if (m_verbosity > 5) {
367 pout() << m_name +
"::deposit(EBAMRCellData)" << endl;
371 this->depositParticles<P, &P::weight>(a_phi, m_particles, m_deposition, m_coarseFineDeposition);
378 template <
typename P>
382 CH_TIME(
"TracerParticleSolver::interpolateWeight(EBAMRCellData)");
383 if (m_verbosity > 5) {
384 pout() << m_name +
"::interpolateWeight(EBAMRCellData)" << endl;
387 m_amr->interpolateParticles<P, &P::weight>(m_particles, m_realm, m_phase, a_scalar, m_interpolation,
false);
390 template <
typename P>
394 CH_TIME(
"TracerParticleSolver::interpolateVelocities()");
395 if (m_verbosity > 5) {
396 pout() << m_name +
"::interpolateVelocities()" << endl;
399 m_amr->interpolateParticles<P, &P::velocity>(m_particles, m_realm, m_phase, m_velocityField, m_interpolation,
false);
402 template <
typename P>
406 CH_TIME(
"TracerParticleSolver::writePlotFile()");
407 if (m_verbosity > 5) {
408 pout() << m_name +
"::writePlotFile()" << endl;
412 const int numPlotVars = this->getNumberOfPlotVariables();
413 const Vector<std::string> plotVarNames = this->getPlotVariableNames();
417 m_amr->allocate(output, m_realm, m_phase, numPlotVars);
422 for (
int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
423 this->writePlotData(*output[lvl], icomp, m_realm, lvl);
428 sprintf(filename,
"%s.step%07d.%dd.hdf5", m_name.c_str(), m_timeStep, SpaceDim);
429 std::string fname(filename);
432 Vector<LevelData<EBCellFAB>*> outputPtr;
433 m_amr->alias(outputPtr, output);
436 constexpr
int numPlotGhost = 0;
438 DischargeIO::writeEBHDF5(fname,
440 m_amr->getGrids(m_realm),
444 m_amr->getRefinementRatios(),
448 m_amr->getFinestLevel() + 1,
453 template <
typename P>
457 CH_TIME(
"TracerParticleSolver::getNumberOfPlotVariables()");
458 if (m_verbosity > 5) {
459 pout() << m_name +
"::getNumberOfPlotVariables()" << endl;
467 if (m_plotVelocity) {
468 numPlotVars += SpaceDim;
474 template <
typename P>
475 inline Vector<std::string>
478 CH_TIME(
"TracerParticleSolver::getPlotVariableNames()");
479 if (m_verbosity > 5) {
480 pout() << m_name +
"::getPlotVariableNames()" << endl;
483 Vector<std::string> plotVarNames(0);
486 plotVarNames.push_back(m_name +
" density");
488 if (m_plotVelocity) {
489 plotVarNames.push_back(
"x-velocity " + m_name);
491 if (m_plotVelocity) {
492 plotVarNames.push_back(
"y-velocity " + m_name);
495 if (m_plotVelocity) {
496 plotVarNames.push_back(
"z-velocity " + m_name);
503 template <
typename P>
507 const std::string a_outputRealm,
508 const int a_level)
const noexcept
510 CH_TIME(
"TracerParticleSolver::writePlotData");
511 if (m_verbosity > 5) {
512 pout() << m_name +
"::writePlotData" << endl;
518 m_amr->allocate(weight, m_realm, m_phase, 1);
520 this->deposit(weight);
522 this->writeData(a_output, a_comp, weight, a_outputRealm, a_level,
false,
true);
526 if (m_plotVelocity) {
527 this->writeData(a_output, a_comp, m_velocityField, a_outputRealm, a_level,
true,
true);
531 template <
typename P>
536 const std::string a_outputRealm,
538 const bool a_interpToCentroids,
539 const bool a_interpGhost)
const noexcept
541 CH_TIMERS(
"TracerParticleSolver::writeData");
542 CH_TIMER(
"TracerParticleSolver::writeData::allocate", t1);
543 CH_TIMER(
"TracerParticleSolver::writeData::local_copy", t2);
544 CH_TIMER(
"TracerParticleSolver::writeData::interp_ghost", t3);
545 CH_TIMER(
"TracerParticleSolver::writeData::interp_centroid", t4);
546 CH_TIMER(
"TracerParticleSolver::writeData::final_copy", t5);
547 if (m_verbosity > 5) {
548 pout() << m_name +
"::writeData" << endl;
552 const int numComp = a_data[a_level]->nComp();
555 LevelData<EBCellFAB> scratch;
556 m_amr->allocate(scratch, m_realm, m_phase, a_level, numComp);
560 m_amr->copyData(scratch, *a_data[a_level], a_level, m_realm, m_realm);
565 if (a_level > 0 && a_interpGhost) {
566 m_amr->interpGhost(scratch, *a_data[a_level - 1], a_level, m_realm, m_phase);
571 if (a_interpToCentroids) {
572 m_amr->interpToCentroids(scratch, m_realm, m_phase, a_level);
579 const Interval srcInterv(0, numComp - 1);
580 const Interval dstInterv(a_comp, a_comp + numComp - 1);
581 m_amr->copyData(a_output, scratch, a_level, a_outputRealm, m_realm, dstInterv, srcInterv);
588 template <
typename P>
592 CH_TIME(
"TracerParticleSolver::writeCheckpointLevel(HDF5Handle, int)");
593 if (m_verbosity > 5) {
594 pout() << m_name +
"::writeCheckpointLevel(HDF5Handle, int)" << endl;
597 writeParticlesToHDF(a_handle, m_particles[a_level], m_name +
"_particles");
602 template <
typename P>
606 CH_TIME(
"TracerParticleSolver::readCheckpointLevel(HDF5Handle, int)");
607 if (m_verbosity > 5) {
608 pout() << m_name +
"::readCheckpointLevel(HDF5Handle, int)" << endl;
611 readParticlesFromHDF(a_handle, m_particles[a_level], m_name +
"_particles");
615 template <
typename P>
619 CH_TIME(
"TracerParticleSolver::computeDt()");
620 if (m_verbosity > 5) {
621 pout() << m_name +
"::computeDt()" << endl;
624 Real dt = std::numeric_limits<Real>::infinity();
626 for (
int lvl = 0; lvl <= m_amr->getFinestLevel(); lvl++) {
627 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
628 const DataIterator& dit = dbl.dataIterator();
629 const Real dx = m_amr->getDx()[lvl];
631 const int nbox = dit.size();
633 #pragma omp parallel for schedule(runtime) reduction(min : dt)
634 for (
int mybox = 0; mybox < nbox; mybox++) {
635 const DataIndex& din = dit[mybox];
637 const List<P>& particles = m_particles[lvl][din].listItems();
639 for (ListIterator<P> lit(particles); lit.ok(); ++lit) {
640 const RealVect& v = lit().velocity();
642 for (
int dir = 0; dir < SpaceDim; dir++) {
643 dt =
std::min(dt, dx / std::abs(v[dir]));
655 template <
typename P>
659 CH_TIME(
"TracerParticleSolver::getParticles()");
660 if (m_verbosity > 5) {
661 pout() << m_name +
"::getParticles()" << endl;
667 template <
typename P>
671 CH_TIME(
"TracerParticleSolver::getParticles()");
672 if (m_verbosity > 5) {
673 pout() << m_name +
"::getParticles()" << endl;
679 template <
typename P>
683 CH_TIME(
"TracerParticleSolver::getVelocityField()");
684 if (m_verbosity > 5) {
685 pout() << m_name +
"::getVelocityField()" << endl;
688 return m_velocityField;
691 template <
typename P>
692 template <
typename T, const Real& (T::*particleScalarFunction)() const>
699 CH_TIME(
"TracerParticleSolver::depositParticles()");
700 if (m_verbosity > 5) {
701 pout() << m_name +
"::depositParticles()" << endl;
704 CH_assert(a_phi[0]->nComp() == 1);
709 switch (a_coarseFineDeposition) {
710 case CoarseFineDeposition::Interp: {
711 m_amr->depositParticles<T, particleScalarFunction>(a_phi,
716 CoarseFineDeposition::Interp,
721 case CoarseFineDeposition::Halo: {
724 const AMRMask& mask = m_amr->getMask(s_particle_halo, m_haloBuffer, m_realm);
728 m_amr->depositParticles<T, particleScalarFunction>(a_phi,
733 CoarseFineDeposition::Halo,
741 case CoarseFineDeposition::HaloNGP: {
742 const AMRMask& mask = m_amr->getMask(s_particle_halo, m_haloBuffer, m_realm);
747 m_amr->depositParticles<T, particleScalarFunction>(a_phi,
752 CoarseFineDeposition::HaloNGP,
761 MayDay::Error(
"TracerParticleSolver::depositParticles -- logic bust due to unsupported coarse-fine deposition");
766 #include <CD_NamespaceFooter.H>
CoarseFineDeposition
Coarse-fine deposition types (see CD_EBAMRParticleMesh for how these are handled).
Definition: CD_CoarseFineDeposition.H:26
DepositionType
Deposition types.
Definition: CD_DepositionType.H:23
Silly, but useful functions that override standard Chombo HDF5 IO.
Agglomeration of basic MPI reductions.
Vector< RefCountedPtr< LevelData< BaseFab< bool > >> > AMRMask
Alias for cutting down on the typic of booleans defined over AMR grids.
Definition: CD_Realm.H:36
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:2132
static void setValue(LevelData< MFInterfaceFAB< T >> &a_lhs, const T &a_value)
Set value in an MFInterfaceFAB data holder.
Definition: CD_DataOpsImplem.H:23
static void setCoveredValue(EBAMRCellData &a_lhs, const int a_comp, const Real a_value)
Set value in covered cells. Does specified component.
Definition: CD_DataOps.cpp:2538
static void copy(MFAMRCellData &a_dst, const MFAMRCellData &a_src)
Copy data from one data holder to another.
Definition: CD_DataOps.cpp:1118
Templated class for holding particles on an AMR hierarchy with particle remapping.
Definition: CD_ParticleContainer.H:50
void clearMaskParticles() const
Clear the "mask" particles.
Definition: CD_ParticleContainerImplem.H:1688
void transferMaskParticles(const Vector< RefCountedPtr< LevelData< BaseFab< bool >>>> &a_mask)
Copy particles to the mask particle data holder.
Definition: CD_ParticleContainerImplem.H:1599
AMRParticles< P > & getMaskParticles()
Get the mask particles.
Definition: CD_ParticleContainerImplem.H:314
void copyMaskParticles(const Vector< RefCountedPtr< LevelData< BaseFab< bool >>>> &a_mask) const
Copy particles to mask particle data holder.
Definition: CD_ParticleContainerImplem.H:1533
void transferParticles(ParticleContainer< P > &a_otherContainer)
Move particles into this container.
Definition: CD_ParticleContainerImplem.H:914
static const std::string primal
Identifier for perimal realm.
Definition: CD_Realm.H:52
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition: CD_TracerParticleSolver.H:37
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:145
virtual void registerOperators() const
Register operators needed for AMR core functionality.
Definition: CD_TracerParticleSolverImplem.H:174
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:25
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
void depositParticles(EBAMRCellData &a_phi, const ParticleContainer< T > &a_particles, const DepositionType a_baseDeposition, const CoarseFineDeposition a_coarseFineDeposition) const noexcept
Generic particle deposition method for putting a scalar field onto the mesh.
Definition: CD_TracerParticleSolverImplem.H:694
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:533
virtual ~TracerParticleSolver()
Destructor.
Definition: CD_TracerParticleSolverImplem.H:56
virtual void preRegrid(const int a_lbase, const int a_oldFinestLevel)
Perform pre-regrid operations.
Definition: CD_TracerParticleSolverImplem.H:307
virtual ParticleContainer< P > & getParticles()
Get all particles.
Definition: CD_TracerParticleSolverImplem.H:657
void parseDeposition()
Parse deposition method.
Definition: CD_TracerParticleSolverImplem.H:91
void parseVerbosity()
Parse solver verbosity.
Definition: CD_TracerParticleSolverImplem.H:160
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:505
RefCountedPtr< AmrMesh > m_amr
Handle to AMR mesh.
Definition: CD_TracerParticleSolver.H:303
virtual Vector< std::string > getPlotVariableNames() const
Get plot variable names.
Definition: CD_TracerParticleSolverImplem.H:476
RefCountedPtr< ComputationalGeometry > m_computationalGeometry
Handle to computational geometry.
Definition: CD_TracerParticleSolver.H:308
virtual void parseRuntimeOptions()
Parse solver run-time options.
Definition: CD_TracerParticleSolverImplem.H:77
virtual void writePlotFile()
Write plot file.
Definition: CD_TracerParticleSolverImplem.H:404
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 void allocate()
Allocate storage for this solver.
Definition: CD_TracerParticleSolverImplem.H:195
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:392
const EBAMRCellData & getVelocityField() const
Return the velocity field.
Definition: CD_TracerParticleSolverImplem.H:681
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
Regrid this solver.
Definition: CD_TracerParticleSolverImplem.H:322
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
virtual void interpolateWeight(const EBAMRCellData &a_scalar) noexcept
Interpolate a scalar field onto the particle weight.
Definition: CD_TracerParticleSolverImplem.H:380
virtual int getNumberOfPlotVariables() const
Get the number of plot variables.
Definition: CD_TracerParticleSolverImplem.H:455
virtual void setAmr(const RefCountedPtr< AmrMesh > &a_amrMesh)
Set AmrMesh.
Definition: CD_TracerParticleSolverImplem.H:271
virtual Real computeDt() const
Write checkpoint data into HDF5 file. @paramo[out] a_handle HDF5 file.
Definition: CD_TracerParticleSolverImplem.H:617
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:58