13#ifndef CD_ITOKMCTAGGERIMPLEM_H
14#define CD_ITOKMCTAGGERIMPLEM_H
22#include <CD_NamespaceHeader.H>
24using namespace Physics::ItoKMC;
29 CH_TIME(
"ItoKMCTagger::ItoKMCTagger");
31 if (m_verbosity > 5) {
32 pout() <<
"ItoKMCTagger::ItoKMCTagger" << endl;
35 m_name =
"ItoKMCTagger";
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");
63 if (m_verbosity > 5) {
64 pout() << m_name +
"::define" << endl;
67 m_physics = a_physics;
68 m_timeStepper = a_timeStepper;
77 CH_TIME(
"ItoKMCTagger::regrid");
78 if (m_verbosity > 5) {
79 pout() << m_name +
"::regrid" << endl;
82 CH_assert(m_isDefined);
84 if (m_numTagFields > 0) {
86 m_tagFields.resize(m_numTagFields);
87 m_gradTagFields.resize(m_numTagFields);
89 for (
int i = 0; i < m_numTagFields; i++) {
90 m_amr->allocate(m_tagFields[i], m_realm, m_phase, 1);
91 m_amr->allocate(m_gradTagFields[i], m_realm, m_phase, SpaceDim);
100 CH_TIME(
"ItoKMCTagger::setPhase");
101 if (m_verbosity > 5) {
102 pout() << m_name +
"::setPhase" << endl;
112 CH_TIME(
"ItoKMCTagger::getNumberOfPlotVariables");
113 if (m_verbosity > 5) {
114 pout() << m_name +
"::getNumberOfPlotVariables" << endl;
117 return m_plotData ? m_numTagFields : 0;
124 CH_TIME(
"ItoKMCTagger::getPlotVariableNames");
125 if (m_verbosity > 5) {
126 pout() << m_name +
"::getPlotVariableNames" << endl;
129 Vector<std::string> plotVars;
132 for (
int i = 0; i < m_numTagFields; i++) {
133 plotVars.push_back(
"Tag field-" + std::to_string(i));
141Vector<EBAMRCellData>&
144 CH_TIME(
"ItoKMCTagger::getTagFields");
145 if (m_verbosity > 5) {
146 pout() << m_name +
"::getTagFields" << endl;
149 CH_assert(m_isDefined);
158 const std::string& a_outputRealm,
159 const int a_level)
const noexcept
161 CH_TIME(
"ItoKMCTagger::writePlotData");
162 if (m_verbosity > 5) {
163 pout() << m_name +
"::writePlotData" << endl;
166 CH_assert(m_isDefined);
169 this->computeTagFields();
171 for (
int i = 0; i < m_numTagFields; i++) {
172 const EBAMRCellData& tagField = m_tagFields[i];
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");
191 if (m_verbosity > 5) {
192 pout() << m_name +
"::tagCells" << endl;
195 CH_assert(m_isDefined);
199 const RealVect probLo = m_amr->getProbLo();
200 const Real curTime = m_timeStepper->getTime();
201 const int finestLevel = m_amr->getFinestLevel();
202 const int maxAmrDepth = m_amr->getMaxAmrDepth();
203 const int finestTagLevel = (finestLevel == maxAmrDepth) ? maxAmrDepth - 1 : finestLevel;
205 if (m_numTagFields > 0) {
206 this->computeTagFields();
208 for (
int lvl = 0; lvl <= finestTagLevel; lvl++) {
209 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
210 const DataIterator& dit = dbl.dataIterator();
211 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
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;
232 for (
int i = 0; i < m_numTagFields; i++) {
233 tagFields.push_back(&((*m_tagFields[i][lvl])[din]));
234 gradTagFields.push_back(&((*m_gradTagFields[i][lvl])[din]));
237 this->tagCellsBox(refinedCells,
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");
285 if (m_verbosity > 5) {
286 pout() <<
"ItoKMCTagger::refineCellsBox" << endl;
289 CH_assert(m_isDefined);
291 Vector<FArrayBox*> tagFieldsReg;
292 Vector<FArrayBox*> gradTagFieldsReg;
294 for (
int i = 0; i < m_numTagFields; i++) {
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)) {
305 Vector<Real> tr(m_numTagFields);
306 Vector<RealVect> gt(m_numTagFields);
308 for (
int i = 0; i < m_numTagFields; i++) {
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);
328 if (this->insideTagBox(pos)) {
330 Vector<Real> tr(m_numTagFields);
331 Vector<RealVect> gt(m_numTagFields);
333 for (
int i = 0; i < m_numTagFields; i++) {
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();
351 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[a_lvl])[a_dit];
353 BoxLoops::loop<D_DECL(1, 1, 1)>(a_box, regularKernel);
357#include <CD_NamespaceFooter.H>
Agglomeration of useful data operations.
Declaration of the Physics::ItoKMC::ItoKMCTagger abstract CellTagger.
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
Abstract CellTagger for the Ito-KMC-Poisson physics module.
Definition CD_ItoKMCTagger.H:33
ItoKMCTagger()
Weak constructor. User MUST subsequently call the define function.
Definition CD_ItoKMCTaggerImplem.H:27
virtual void setPhase(const phase::which_phase a_phase) noexcept
Set the phase where we do the tagging.
Definition CD_ItoKMCTaggerImplem.H:98
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
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
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 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 void regrid() noexcept override
Regrid this class. Note that there is no preRegrid method.
Definition CD_ItoKMCTaggerImplem.H:75
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