13#ifndef CD_ITOKMCTAGGERIMPLEM_H
14#define CD_ITOKMCTAGGERIMPLEM_H
22#include <CD_NamespaceHeader.H>
24using namespace Physics::ItoKMC;
29 CH_TIME(
"ItoKMCTagger::ItoKMCTagger");
32 pout() <<
"ItoKMCTagger::ItoKMCTagger" << endl;
44 const RefCountedPtr<S>& a_timeStepper,
45 const RefCountedPtr<AmrMesh>& a_amr) noexcept
48 this->
define(a_physics, a_timeStepper, a_amr);
58 const RefCountedPtr<S>& a_timeStepper,
59 const RefCountedPtr<AmrMesh>& a_amr)
noexcept
62 CH_TIME(
"ItoKMCTagger::define");
64 pout() <<
m_name +
"::define" << endl;
77 CH_TIME(
"ItoKMCTagger::regrid");
79 pout() <<
m_name +
"::regrid" << endl;
100 CH_TIME(
"ItoKMCTagger::setPhase");
102 pout() <<
m_name +
"::setPhase" << endl;
112 CH_TIME(
"ItoKMCTagger::getNumberOfPlotVariables");
114 pout() <<
m_name +
"::getNumberOfPlotVariables" << endl;
124 CH_TIME(
"ItoKMCTagger::getPlotVariableNames");
126 pout() <<
m_name +
"::getPlotVariableNames" << endl;
129 Vector<std::string> plotVars;
133 plotVars.push_back(
"Tag field-" + std::to_string(i));
141Vector<EBAMRCellData>&
144 CH_TIME(
"ItoKMCTagger::getTagFields");
146 pout() <<
m_name +
"::getTagFields" << endl;
158 const std::string& a_outputRealm,
159 const int a_level)
const noexcept
161 CH_TIME(
"ItoKMCTagger::writePlotData");
163 pout() <<
m_name +
"::writePlotData" << endl;
174 const Interval srcInterv(0, 0);
175 const Interval dstInterv(a_icomp, a_icomp);
177 m_amr->copyData(a_output, *tagField[a_level], a_level, a_outputRealm, tagField.getRealm(), dstInterv, srcInterv);
190 CH_TIME(
"ItoKMCTagger::tagCells");
192 pout() <<
m_name +
"::tagCells" << endl;
199 const RealVect probLo =
m_amr->getProbLo();
201 const int finestLevel =
m_amr->getFinestLevel();
202 const int maxAmrDepth =
m_amr->getMaxAmrDepth();
203 const int finestTagLevel = (finestLevel == maxAmrDepth) ? maxAmrDepth - 1 : finestLevel;
208 for (
int lvl = 0; lvl <= finestTagLevel; lvl++) {
209 const DisjointBoxLayout& dbl =
m_amr->getGrids(
m_realm)[lvl];
210 const DataIterator& dit = dbl.dataIterator();
212 const Real dx =
m_amr->getDx()[lvl];
214 const int nbox = dit.size();
216#pragma omp parallel for schedule(runtime) reduction(max : gotNewTags)
217 for (
int mybox = 0; mybox < nbox; mybox++) {
218 const DataIndex& din = dit[mybox];
220 const Box box = dbl.get(din);
221 const EBISBox& ebisbox = ebisl[din];
223 const IntVectSet irregCells = ebisbox.getIrregIVS(box);
224 const IntVectSet backupTags = IntVectSet((*a_tags[lvl])[din]);
226 DenseIntVectSet coarsenCells(box,
false);
227 DenseIntVectSet refinedCells(box,
false);
229 Vector<EBCellFAB*> tagFields;
230 Vector<EBCellFAB*> gradTagFields;
233 tagFields.push_back(&((*
m_tagFields[i][lvl])[din]));
251 DenseIntVectSet& tags = (*a_tags[lvl])[din];
253 DenseIntVectSet cpy1 = tags;
254 tags -= coarsenCells;
255 tags |= refinedCells;
256 DenseIntVectSet cpy2 = tags;
260 if (cpy1.numPts() != 0 || cpy2.numPts() != 0) {
273 DenseIntVectSet& a_coarsenedCells,
274 const Vector<EBCellFAB*>& a_tagFields,
275 const Vector<EBCellFAB*>& a_gradTagFields,
277 const DataIndex a_dit,
279 const EBISBox& a_ebisbox,
282 const RealVect a_probLo)
const noexcept
284 CH_TIME(
"ItoKMCTagger::refineCellsBox");
286 pout() <<
"ItoKMCTagger::refineCellsBox" << endl;
291 Vector<FArrayBox*> tagFieldsReg;
292 Vector<FArrayBox*> gradTagFieldsReg;
295 tagFieldsReg.push_back(&(a_tagFields[i]->getFArrayBox()));
296 gradTagFieldsReg.push_back(&(a_gradTagFields[i]->getFArrayBox()));
300 auto regularKernel = [&](
const IntVect& iv) ->
void {
301 const RealVect pos = a_probLo + (0.5 * RealVect::Unit + RealVect(iv)) * a_dx;
303 if (this->
insideTagBox(pos) && a_ebisbox.isRegular(iv)) {
309 tr[i] = (*tagFieldsReg[i])(iv, 0);
311 D_DECL((*gradTagFieldsReg[i])(iv, 0), (*gradTagFieldsReg[i])(iv, 1), (*gradTagFieldsReg[i])(iv, 2)));
314 if (this->
refineCell(pos, a_time, a_dx, a_lvl, tr, gt)) {
315 a_refinedCells |= iv;
318 if (this->
coarsenCell(pos, a_time, a_dx, a_lvl, tr, gt)) {
319 a_coarsenedCells |= iv;
325 auto irregularKernel = [&](
const VolIndex& vof) ->
void {
326 const RealVect pos = a_probLo +
Location::position(Location::Cell::Center, vof, a_ebisbox, a_dx);
334 tr[i] = (*a_tagFields[i])(vof, 0);
336 D_DECL((*a_gradTagFields[i])(vof, 0), (*a_gradTagFields[i])(vof, 1), (*a_gradTagFields[i])(vof, 2)));
339 if (this->
refineCell(pos, a_time, a_dx, a_lvl, tr, gt)) {
340 a_refinedCells |= vof.gridIndex();
343 if (this->
coarsenCell(pos, a_time, a_dx, a_lvl, tr, gt)) {
344 a_coarsenedCells |= vof.gridIndex();
357#include <CD_NamespaceFooter.H>
Agglomeration of useful data operations.
Declaration of the Physics::ItoKMC::ItoKMCTagger abstract CellTagger.
int m_verbosity
Class verbosity.
Definition CD_CellTagger.H:138
std::string m_name
Cell tagger class name (default is CellTagger).
Definition CD_CellTagger.H:133
bool insideTagBox(const RealVect &a_pos) const
Check if a point is inside a tagging box.
Definition CD_CellTagger.cpp:250
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
ItoKMCTagger()
Weak constructor. User MUST subsequently call the define function.
Definition CD_ItoKMCTaggerImplem.H:27
RefCountedPtr< S > m_timeStepper
Time stepper.
Definition CD_ItoKMCTagger.H:168
virtual void setPhase(const phase::which_phase a_phase) noexcept
Set the phase where we do the tagging.
Definition CD_ItoKMCTaggerImplem.H:98
virtual void computeTagFields() const noexcept=0
Compute tagging fields.
virtual bool tagCells(EBAMRTags &a_tags) noexcept override
Tag cells for refinement and coarsening.
Definition CD_ItoKMCTaggerImplem.H:188
virtual Vector< EBAMRCellData > & getTagFields() noexcept
Get the tagging fields (mutable reference).
Definition CD_ItoKMCTaggerImplem.H:142
virtual ~ItoKMCTagger() noexcept
Destructor.
Definition CD_ItoKMCTaggerImplem.H:52
virtual void tagCellsBox(DenseIntVectSet &a_refinedCells, DenseIntVectSet &a_coarsenedCells, const Vector< EBCellFAB * > &a_tagFields, const Vector< EBCellFAB * > &a_gradTagFields, const int a_lvl, const DataIndex a_dit, const Box a_box, const EBISBox &a_ebisbox, const Real a_time, const Real a_dx, const RealVect a_probLo) const noexcept
Per-box refinement tagging routine.
Definition CD_ItoKMCTaggerImplem.H:272
bool m_plotData
Plot data or not.
Definition CD_ItoKMCTagger.H:148
bool m_isDefined
Defined or not.
Definition CD_ItoKMCTagger.H:143
virtual void writePlotData(LevelData< EBCellFAB > &a_output, int &a_icomp, const std::string &a_outputRealm, const int a_level) const noexcept override
Write plot data.
Definition CD_ItoKMCTaggerImplem.H:156
Vector< EBAMRCellData > m_tagFields
Tagging fields.
Definition CD_ItoKMCTagger.H:183
int m_numTagFields
Number of tagging fields.
Definition CD_ItoKMCTagger.H:178
RefCountedPtr< ItoKMCPhysics > m_physics
Physics implementation.
Definition CD_ItoKMCTagger.H:163
virtual int getNumberOfPlotVariables() const noexcept override
Get number of plot variables that will be written to file (by Driver).
Definition CD_ItoKMCTaggerImplem.H:110
virtual bool coarsenCell(const RealVect &a_pos, const Real a_time, const Real a_dx, const int a_lvl, const Vector< Real > &a_tagFields, const Vector< RealVect > &a_gradTagFields) const noexcept=0
Determine if a particular cell should be coarsened or not.
virtual void define(const RefCountedPtr< ItoKMCPhysics > &a_physics, const RefCountedPtr< S > &a_timeStepper, const RefCountedPtr< AmrMesh > &a_amr) noexcept
Define function.
Definition CD_ItoKMCTaggerImplem.H:57
virtual Vector< std::string > getPlotVariableNames() const noexcept override
Get plot variable names.
Definition CD_ItoKMCTaggerImplem.H:122
virtual bool refineCell(const RealVect &a_pos, const Real a_time, const Real a_dx, const int a_lvl, const Vector< Real > &a_tagFields, const Vector< RealVect > &a_gradTagFields) const noexcept=0
Determine if a particular cell should be refined or not.
RefCountedPtr< AmrMesh > m_amr
AmrMesh. Needed for allocating memory and things like that.
Definition CD_ItoKMCTagger.H:173
virtual void regrid() noexcept override
Regrid this class. Note that there is no preRegrid method.
Definition CD_ItoKMCTaggerImplem.H:75
phase::which_phase m_phase
Phase where data is allocated.
Definition CD_ItoKMCTagger.H:158
std::string m_realm
Realm where data is allocated.
Definition CD_ItoKMCTagger.H:153
Vector< EBAMRCellData > m_gradTagFields
Gradient of tagging fields.
Definition CD_ItoKMCTagger.H:188
static const std::string Primal
Identifier for perimal realm.
Definition CD_Realm.H:44
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
Real max(const Real &a_input) noexcept
Get the maximum of the input, reduced over MPI ranks (in the Chombo communicator).
Definition CD_ParallelOpsImplem.H:177
which_phase
Enumeration of supported phases.
Definition CD_MultiFluidIndexSpace.H:38
@ gas
Gas phase.
Definition CD_MultiFluidIndexSpace.H:39