12 #ifndef CD_ItoKMCTaggerImplem_H
13 #define CD_ItoKMCTaggerImplem_H
16 #include <ParmParse.H>
21 #include <CD_NamespaceHeader.H>
23 using namespace Physics::ItoKMC;
28 CH_TIME(
"ItoKMCTagger::ItoKMCTagger");
30 if (m_verbosity > 5) {
31 pout() <<
"ItoKMCTagger::ItoKMCTagger" << endl;
34 m_name =
"ItoKMCTagger";
43 const RefCountedPtr<S>& a_timeStepper,
44 const RefCountedPtr<AmrMesh>& a_amr) noexcept
47 this->define(a_physics, a_timeStepper, a_amr);
57 const RefCountedPtr<S>& a_timeStepper,
58 const RefCountedPtr<AmrMesh>& a_amr) noexcept
61 CH_TIME(
"ItoKMCTagger::define");
62 if (m_verbosity > 5) {
63 pout() << m_name +
"::define" << endl;
66 m_physics = a_physics;
67 m_timeStepper = a_timeStepper;
76 CH_TIME(
"ItoKMCTagger::regrid");
77 if (m_verbosity > 5) {
78 pout() << m_name +
"::regrid" << endl;
81 CH_assert(m_isDefined);
83 if (m_numTagFields > 0) {
85 m_tagFields.resize(m_numTagFields);
86 m_gradTagFields.resize(m_numTagFields);
88 for (
int i = 0; i < m_numTagFields; i++) {
89 m_amr->allocate(m_tagFields[i], m_realm, m_phase, 1);
90 m_amr->allocate(m_gradTagFields[i], m_realm, m_phase, SpaceDim);
99 CH_TIME(
"ItoKMCTagger::setPhase");
100 if (m_verbosity > 5) {
101 pout() << m_name +
"::setPhase" << endl;
107 template <
typename S>
111 CH_TIME(
"ItoKMCTagger::getNumberOfPlotVariables");
112 if (m_verbosity > 5) {
113 pout() << m_name +
"::getNumberOfPlotVariables" << endl;
116 return m_plotData ? m_numTagFields : 0;
119 template <
typename S>
123 CH_TIME(
"ItoKMCTagger::getPlotVariableNames");
124 if (m_verbosity > 5) {
125 pout() << m_name +
"::getPlotVariableNames" << endl;
128 Vector<std::string> plotVars;
131 for (
int i = 0; i < m_numTagFields; i++) {
132 plotVars.push_back(
"Tag field-" + std::to_string(i));
139 template <
typename S>
140 Vector<EBAMRCellData>&
143 CH_TIME(
"ItoKMCTagger::getTagFields");
144 if (m_verbosity > 5) {
145 pout() << m_name +
"::getTagFields" << endl;
148 CH_assert(m_isDefined);
153 template <
typename S>
157 const std::string a_outputRealm,
158 const int a_level)
const noexcept
160 CH_TIME(
"ItoKMCTagger::writePlotData");
161 if (m_verbosity > 5) {
162 pout() << m_name +
"::writePlotData" << endl;
165 CH_assert(m_isDefined);
168 this->computeTagFields();
170 for (
int i = 0; i < m_numTagFields; i++) {
173 const Interval srcInterv(0, 0);
174 const Interval dstInterv(a_icomp, a_icomp);
176 m_amr->copyData(a_output, *tagField[a_level], a_level, a_outputRealm, tagField.
getRealm(), dstInterv, srcInterv);
185 template <
typename S>
189 CH_TIME(
"ItoKMCTagger::tagCells");
190 if (m_verbosity > 5) {
191 pout() << m_name +
"::tagCells" << endl;
194 CH_assert(m_isDefined);
198 const RealVect probLo = m_amr->getProbLo();
199 const Real curTime = m_timeStepper->getTime();
200 const int finestLevel = m_amr->getFinestLevel();
201 const int maxAmrDepth = m_amr->getMaxAmrDepth();
202 const int finestTagLevel = (finestLevel == maxAmrDepth) ? maxAmrDepth - 1 : finestLevel;
204 if (m_numTagFields > 0) {
205 this->computeTagFields();
207 for (
int lvl = 0; lvl <= finestTagLevel; lvl++) {
208 const DisjointBoxLayout& dbl = m_amr->getGrids(m_realm)[lvl];
209 const DataIterator& dit = dbl.dataIterator();
210 const EBISLayout& ebisl = m_amr->getEBISLayout(m_realm, m_phase)[lvl];
211 const Real dx = m_amr->getDx()[lvl];
213 const int nbox = dit.size();
215 #pragma omp parallel for schedule(runtime) reduction(max : gotNewTags)
216 for (
int mybox = 0; mybox < nbox; mybox++) {
217 const DataIndex& din = dit[mybox];
219 const Box box = dbl.get(din);
220 const EBISBox& ebisbox = ebisl[din];
222 const IntVectSet irregCells = ebisbox.getIrregIVS(box);
223 const IntVectSet backupTags = IntVectSet((*a_tags[lvl])[din]);
225 DenseIntVectSet coarsenCells(box,
false);
226 DenseIntVectSet refinedCells(box,
false);
228 Vector<EBCellFAB*> tagFields;
229 Vector<EBCellFAB*> gradTagFields;
231 for (
int i = 0; i < m_numTagFields; i++) {
232 tagFields.push_back(&((*m_tagFields[i][lvl])[din]));
233 gradTagFields.push_back(&((*m_gradTagFields[i][lvl])[din]));
236 this->tagCellsBox(refinedCells,
250 DenseIntVectSet& tags = (*a_tags[lvl])[din];
252 DenseIntVectSet cpy1 = tags;
253 tags -= coarsenCells;
254 tags |= refinedCells;
255 DenseIntVectSet cpy2 = tags;
259 if (cpy1.numPts() != 0 || cpy2.numPts() != 0) {
269 template <
typename S>
272 DenseIntVectSet& a_coarsenedCells,
273 const Vector<EBCellFAB*>& a_tagFields,
274 const Vector<EBCellFAB*>& a_gradTagFields,
276 const DataIndex a_dit,
278 const EBISBox& a_ebisbox,
281 const RealVect a_probLo)
const noexcept
283 CH_TIME(
"ItoKMCTagger::refineCellsBox");
284 if (m_verbosity > 5) {
285 pout() <<
"ItoKMCTagger::refineCellsBox" << endl;
288 CH_assert(m_isDefined);
290 Vector<FArrayBox*> tagFieldsReg;
291 Vector<FArrayBox*> gradTagFieldsReg;
293 for (
int i = 0; i < m_numTagFields; i++) {
294 tagFieldsReg.push_back(&(a_tagFields[i]->getFArrayBox()));
295 gradTagFieldsReg.push_back(&(a_gradTagFields[i]->getFArrayBox()));
299 auto regularKernel = [&](
const IntVect& iv) ->
void {
300 const RealVect pos = a_probLo + (0.5 * RealVect::Unit + RealVect(iv)) * a_dx;
302 if (this->insideTagBox(pos) && a_ebisbox.isRegular(iv)) {
304 Vector<Real> tr(m_numTagFields);
305 Vector<RealVect> gt(m_numTagFields);
307 for (
int i = 0; i < m_numTagFields; i++) {
308 tr[i] = (*tagFieldsReg[i])(iv, 0);
310 D_DECL((*gradTagFieldsReg[i])(iv, 0), (*gradTagFieldsReg[i])(iv, 1), (*gradTagFieldsReg[i])(iv, 2)));
313 if (this->refineCell(pos, a_time, a_dx, a_lvl, tr, gt)) {
314 a_refinedCells |= iv;
317 if (this->coarsenCell(pos, a_time, a_dx, a_lvl, tr, gt)) {
318 a_coarsenedCells |= iv;
324 auto irregularKernel = [&](
const VolIndex& vof) ->
void {
325 const RealVect pos = a_probLo +
Location::position(Location::Cell::Center, vof, a_ebisbox, a_dx);
327 if (this->insideTagBox(pos)) {
329 Vector<Real> tr(m_numTagFields);
330 Vector<RealVect> gt(m_numTagFields);
332 for (
int i = 0; i < m_numTagFields; i++) {
333 tr[i] = (*a_tagFields[i])(vof, 0);
335 D_DECL((*a_gradTagFields[i])(vof, 0), (*a_gradTagFields[i])(vof, 1), (*a_gradTagFields[i])(vof, 2)));
338 if (this->refineCell(pos, a_time, a_dx, a_lvl, tr, gt)) {
339 a_refinedCells |= vof.gridIndex();
342 if (this->coarsenCell(pos, a_time, a_dx, a_lvl, tr, gt)) {
343 a_coarsenedCells |= vof.gridIndex();
349 VoFIterator& vofit = (*m_amr->getVofIterator(m_realm, m_phase)[a_lvl])[a_dit];
355 #include <CD_NamespaceFooter.H>
Agglomeration of useful data operations.
Parent tagger class for ItoKMC.
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
const std::string getRealm() const noexcept
Returns the string identifier for whatever realm this data is supposed to be allocated over.
Definition: CD_EBAMRDataImplem.H:135
Class for tagging grid cells using the Ito-KMC-Poisson module. Note that S is the time integrator typ...
Definition: CD_ItoKMCTagger.H:30
ItoKMCTagger()
Weak constructor. User MUST subsequently call the define function.
Definition: CD_ItoKMCTaggerImplem.H:26
virtual void setPhase(const phase::which_phase a_phase) noexcept
Set the phase where we do the tagging.
Definition: CD_ItoKMCTaggerImplem.H:97
virtual bool tagCells(EBAMRTags &a_tags) noexcept override
Tag cells for refinement and coarsening.
Definition: CD_ItoKMCTaggerImplem.H:187
virtual Vector< EBAMRCellData > & getTagFields() noexcept
Get tag fields. This is data that live on the primal realm and specified input phase.
Definition: CD_ItoKMCTaggerImplem.H:141
virtual ~ItoKMCTagger() noexcept
Destructor.
Definition: CD_ItoKMCTaggerImplem.H:51
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:271
virtual int getNumberOfPlotVariables() const noexcept override
Get number of plot variables that will be written to file (by Driver).
Definition: CD_ItoKMCTaggerImplem.H:109
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:56
virtual Vector< std::string > getPlotVariableNames() const noexcept override
Get plot variable names.
Definition: CD_ItoKMCTaggerImplem.H:121
virtual void regrid() noexcept override
Regrid this class. Note that there is no preRegrid method.
Definition: CD_ItoKMCTaggerImplem.H:74
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:155
static const std::string Primal
Identifier for perimal realm.
Definition: CD_Realm.H:47
ALWAYS_INLINE void loop(const Box &a_computeBox, Functor &&kernel, const IntVect &a_stride=IntVect::Unit)
Launch a C++ kernel over a regular grid.
Definition: CD_BoxLoopsImplem.H:20
RealVect position(const 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:20
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:176