12 #ifndef CD_ItoKMCFieldTaggerImplem_H
13 #define CD_ItoKMCFieldTaggerImplem_H
19 #include <CD_NamespaceHeader.H>
21 using namespace Physics::ItoKMC;
26 CH_TIME(
"ItoKMCFieldTagger::ItoKMCFieldTagger");
27 if (this->m_verbosity > 5) {
28 pout() <<
"ItoKMCFieldTagger::ItoKMCFieldTagger" << endl;
31 this->m_name =
"ItoKMCFieldTagger";
42 CH_TIME(
"ItoKMCFieldTagger::allocateStorage");
43 if (this->m_verbosity > 5) {
44 pout() << this->m_name +
"::allocateStorage" << endl;
47 CH_assert(this->m_isDefined);
49 (this->m_amr)->allocate(m_scratch, this->m_realm, this->m_phase, 1);
50 (this->m_amr)->allocate(m_E, this->m_realm, this->m_phase, SpaceDim);
51 (this->m_amr)->allocate(m_gradE, this->m_realm, this->m_phase, SpaceDim);
58 CH_TIME(
"ItoKMCFieldTagger::deallocateStorage");
59 if (this->m_verbosity > 5) {
60 pout() << this->m_name +
"::deallocateStorage" << endl;
63 this->m_amr->deallocate(m_scratch);
64 this->m_amr->deallocate(m_E);
65 this->m_amr->deallocate(m_gradE);
72 CH_TIME(
"ItoKMCFieldTagger::computeElectricField");
73 if (this->m_verbosity > 5) {
74 pout() << this->m_name +
"::computeElectricField" << endl;
77 CH_assert(this->m_isDefined);
78 CH_assert(a_E[0]->nComp() == SpaceDim);
79 CH_assert(a_gradE[0]->nComp() == SpaceDim);
81 this->m_timeStepper->computeElectricField(a_E, this->m_phase);
83 this->m_amr->computeGradient(a_gradE, m_scratch, this->m_realm, this->m_phase);
85 this->m_amr->conservativeAverage(a_gradE, this->m_realm, this->m_phase);
86 this->m_amr->interpGhost(a_gradE, this->m_realm, this->m_phase);
89 this->m_amr->interpToCentroids(a_E, this->m_realm, this->m_phase);
90 this->m_amr->interpToCentroids(a_gradE, this->m_realm, this->m_phase);
97 CH_TIME(
"ItoKMCFieldTagger::computeTagFields");
98 if (this->m_verbosity > 5) {
99 pout() << this->m_name +
"::computeTagFields" << endl;
102 CH_assert(this->m_isDefined);
104 this->allocateStorage();
105 this->computeElectricField(m_E, m_gradE);
107 const RealVect probLo = this->m_amr->getProbLo();
108 const Real time = this->m_timeStepper->getTime();
111 Real maxGradE, minGradE;
116 for (
int lvl = 0; lvl <= this->m_amr->getFinestLevel(); lvl++) {
117 const DisjointBoxLayout& dbl = this->m_amr->getGrids(this->m_realm)[lvl];
118 const DataIterator& dit = dbl.dataIterator();
119 const EBISLayout& ebisl = this->m_amr->getEBISLayout(this->m_realm, this->m_phase)[lvl];
120 const Real dx = this->m_amr->getDx()[lvl];
122 const int nbox = dit.size();
124 #pragma omp parallel for schedule(runtime)
125 for (
int mybox = 0; mybox < nbox; mybox++) {
126 const DataIndex& din = dit[mybox];
128 const Box& box = dbl[din];
129 const EBISBox& ebisbox = ebisl[din];
131 const EBCellFAB& electricField = (*m_E[lvl])[din];
132 const EBCellFAB& gradElectricField = (*m_gradE[lvl])[din];
134 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
135 const FArrayBox& gradElectricFieldReg = gradElectricField.getFArrayBox();
137 Vector<EBCellFAB*> tagFields;
138 Vector<FArrayBox*> tagFieldsReg;
139 for (
int i = 0; i < this->m_numTagFields; i++) {
140 tagFields.push_back(&((*this->m_tagFields[i][lvl])[din]));
141 tagFieldsReg.push_back(&(tagFields[i]->getFArrayBox()));
144 auto regularKernel = [&](
const IntVect& iv) ->
void {
145 if (ebisbox.isRegular(iv)) {
146 const RealVect pos = probLo + RealVect(iv) * dx;
148 const RealVect E = RealVect(
149 D_DECL(electricFieldReg(iv, 0), electricFieldReg(iv, 1), electricFieldReg(iv, 2)));
150 const RealVect gradE = RealVect(
151 D_DECL(gradElectricFieldReg(iv, 0), gradElectricFieldReg(iv, 1), gradElectricFieldReg(iv, 2)));
154 compTagFields = this->computeTagFields(pos, time, dx, E, minE, maxE, gradE, minGradE, maxGradE);
156 for (
int i = 0; i < this->m_numTagFields; i++) {
157 (*tagFieldsReg[i])(iv, 0) = compTagFields[i];
163 auto irregularKernel = [&](
const VolIndex& vof) ->
void {
164 const RealVect pos = probLo +
Location::position(Location::Cell::Center, vof, ebisbox, dx);
166 const RealVect E = RealVect(D_DECL(electricField(vof, 0), electricField(vof, 1), electricField(vof, 2)));
167 const RealVect gradE = RealVect(
168 D_DECL(gradElectricField(vof, 0), gradElectricField(vof, 1), gradElectricField(vof, 2)));
171 compTagFields = this->computeTagFields(pos, time, dx, E, minE, maxE, gradE, minGradE, maxGradE);
173 for (
int i = 0; i < this->m_numTagFields; i++) {
174 (*tagFields[i])(vof, 0) = compTagFields[i];
179 VoFIterator& vofit = (*this->m_amr->getVofIterator(this->m_realm, this->m_phase)[lvl])[din];
184 for (
int i = 0; i < this->m_numTagFields; i++) {
185 this->m_amr->conservativeAverage(this->m_tagFields[i], this->m_realm, this->m_phase);
186 this->m_amr->interpGhost(this->m_tagFields[i], this->m_realm, this->m_phase);
190 for (
int i = 0; i < this->m_numTagFields; i++) {
191 this->m_amr->computeGradient(this->m_gradTagFields[i], this->m_tagFields[i], this->m_realm, this->m_phase);
192 this->m_amr->conservativeAverage(this->m_gradTagFields[i], this->m_realm, this->m_phase);
196 this->deallocateStorage();
199 #include <CD_NamespaceFooter.H>
Agglomeration of useful data operations.
Declaration of an abstract field-only tagging class for ito plasmas.
Declaration of cell positions.
static void vectorLength(EBAMRCellData &a_lhs, const EBAMRCellData &a_rhs)
Compute the vector length of a data holder. Sets a_lhs = |a_rhs| where a_rhs contains SpaceDim compon...
Definition: CD_DataOps.cpp:3396
static void getMaxMinNorm(Real &a_max, Real &a_min, EBAMRCellData &data)
Get maximum and minimum value of normed data.
Definition: CD_DataOps.cpp:1783
ItoKMCFieldTagger() noexcept
Weak constructor. User MUST subsequently call define.
Definition: CD_ItoKMCFieldTaggerImplem.H:24
virtual void computeElectricField(EBAMRCellData &a_E, EBAMRCellData &a_gradE) const noexcept
Compute electric field.
Definition: CD_ItoKMCFieldTaggerImplem.H:70
virtual void allocateStorage() const noexcept
Allocate memory for scratch, electric field, and gradient of electric field.
Definition: CD_ItoKMCFieldTaggerImplem.H:40
virtual ~ItoKMCFieldTagger() noexcept
Destructor.
Definition: CD_ItoKMCFieldTaggerImplem.H:35
virtual void computeTagFields() const noexcept override
Compute tagging fields.
Definition: CD_ItoKMCFieldTaggerImplem.H:95
virtual void deallocateStorage() const noexcept
Deallocate memory.
Definition: CD_ItoKMCFieldTaggerImplem.H:56
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