chombo-discharge
Loading...
Searching...
No Matches
CD_ItoKMCFieldTaggerImplem.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13#ifndef CD_ITOKMCFIELDTAGGERIMPLEM_H
14#define CD_ITOKMCFIELDTAGGERIMPLEM_H
15
16// Our includes
18#include <CD_DataOps.H>
19#include <CD_Location.H>
20#include <CD_NamespaceHeader.H>
21
22using namespace Physics::ItoKMC;
23
24template <typename S>
26{
27 CH_TIME("ItoKMCFieldTagger::ItoKMCFieldTagger");
28 if (this->m_verbosity > 5) {
29 pout() << "ItoKMCFieldTagger::ItoKMCFieldTagger" << endl;
30 }
31
32 this->m_name = "ItoKMCFieldTagger";
33}
34
35template <typename S>
38
39template <typename S>
40void
42{
43 CH_TIME("ItoKMCFieldTagger::allocateStorage");
44 if (this->m_verbosity > 5) {
45 pout() << this->m_name + "::allocateStorage" << endl;
46 }
47
48 CH_assert(this->m_isDefined);
49
50 (this->m_amr)->allocate(m_scratch, this->m_realm, this->m_phase, 1);
51 (this->m_amr)->allocate(m_E, this->m_realm, this->m_phase, SpaceDim);
52 (this->m_amr)->allocate(m_gradE, this->m_realm, this->m_phase, SpaceDim);
53}
54
55template <typename S>
56void
58{
59 CH_TIME("ItoKMCFieldTagger::deallocateStorage");
60 if (this->m_verbosity > 5) {
61 pout() << this->m_name + "::deallocateStorage" << endl;
62 }
63
64 this->m_amr->deallocate(m_scratch);
65 this->m_amr->deallocate(m_E);
66 this->m_amr->deallocate(m_gradE);
67}
68
69template <typename S>
70void
72{
73 CH_TIME("ItoKMCFieldTagger::computeElectricField");
74 if (this->m_verbosity > 5) {
75 pout() << this->m_name + "::computeElectricField" << endl;
76 }
77
78 CH_assert(this->m_isDefined);
79 CH_assert(a_E[0]->nComp() == SpaceDim);
80 CH_assert(a_gradE[0]->nComp() == SpaceDim);
81
82 this->m_timeStepper->computeElectricField(a_E, this->m_phase);
83 DataOps::vectorLength(m_scratch,
84 a_E,
85 this->m_amr->getNotCoveredCells(this->m_realm, this->m_phase),
86 this->m_amr->getMultiCutVofIterator(this->m_realm, this->m_phase));
87 this->m_amr->computeGradient(a_gradE, m_scratch, this->m_realm, this->m_phase);
88
89 this->m_amr->conservativeAverage(a_gradE, this->m_realm, this->m_phase);
90 this->m_amr->interpGhost(a_gradE, this->m_realm, this->m_phase);
91
92 // Interpolate to centroids
93 this->m_amr->interpToCentroids(a_E, this->m_realm, this->m_phase);
94 this->m_amr->interpToCentroids(a_gradE, this->m_realm, this->m_phase);
95}
96
97template <typename S>
98void
100{
101 CH_TIME("ItoKMCFieldTagger::computeTagFields");
102 if (this->m_verbosity > 5) {
103 pout() << this->m_name + "::computeTagFields" << endl;
104 }
105
106 CH_assert(this->m_isDefined);
107
108 this->allocateStorage();
109 this->computeElectricField(m_E, m_gradE);
110
111 const RealVect probLo = this->m_amr->getProbLo();
112 const Real time = this->m_timeStepper->getTime();
113
114 Real maxE, minE;
116
117 DataOps::getMaxMinNorm(maxE, minE, m_E, this->m_amr->getMultiCutVofIterator(this->m_realm, this->m_phase));
119 minGradE,
120 m_gradE,
121 this->m_amr->getMultiCutVofIterator(this->m_realm, this->m_phase));
122
123 for (int lvl = 0; lvl <= this->m_amr->getFinestLevel(); lvl++) {
124 const DisjointBoxLayout& dbl = this->m_amr->getGrids(this->m_realm)[lvl];
125 const DataIterator& dit = dbl.dataIterator();
126 const EBISLayout& ebisl = this->m_amr->getEBISLayout(this->m_realm, this->m_phase)[lvl];
127 const Real dx = this->m_amr->getDx()[lvl];
128
129 const int nbox = dit.size();
130
131#pragma omp parallel for schedule(runtime)
132 for (int mybox = 0; mybox < nbox; mybox++) {
133 const DataIndex& din = dit[mybox];
134
135 const Box& box = dbl[din];
136 const EBISBox& ebisbox = ebisl[din];
137
138 const EBCellFAB& electricField = (*m_E[lvl])[din];
139 const EBCellFAB& gradElectricField = (*m_gradE[lvl])[din];
140
141 const FArrayBox& electricFieldReg = electricField.getFArrayBox();
142 const FArrayBox& gradElectricFieldReg = gradElectricField.getFArrayBox();
143
146 for (int i = 0; i < this->m_numTagFields; i++) {
147 tagFields.push_back(&((*this->m_tagFields[i][lvl])[din]));
148 tagFieldsReg.push_back(&(tagFields[i]->getFArrayBox()));
149 }
150
151 auto regularKernel = [&](const IntVect& iv) -> void {
152 if (ebisbox.isRegular(iv)) {
153 const RealVect pos = probLo + RealVect(iv) * dx;
154
155 const RealVect E = RealVect(
157 const RealVect gradE = RealVect(
159
160 const Vector<Real>
161 compTagFields = this->computeTagFields(pos, time, dx, E, minE, maxE, gradE, minGradE, maxGradE);
162
163 for (int i = 0; i < this->m_numTagFields; i++) {
164 (*tagFieldsReg[i])(iv, 0) = compTagFields[i];
165 }
166 }
167 };
168
169 // Irregular box loop
170 auto irregularKernel = [&](const VolIndex& vof) -> void {
171 const RealVect pos = probLo + Location::position(Location::Cell::Center, vof, ebisbox, dx);
172
174 const RealVect gradE = RealVect(
176
177 const Vector<Real>
178 compTagFields = this->computeTagFields(pos, time, dx, E, minE, maxE, gradE, minGradE, maxGradE);
179
180 for (int i = 0; i < this->m_numTagFields; i++) {
181 (*tagFields[i])(vof, 0) = compTagFields[i];
182 }
183 };
184
185 // Run the kernels. Not vectorizable: computeTagFields is a virtual call per cell returning a
186 // Vector<Real> (heap allocation). Per-box writes -> no race.
187 VoFIterator& vofit = (*this->m_amr->getVofIterator(this->m_realm, this->m_phase)[lvl])[din];
188 BoxLoops::loop<D_DECL(1, 1, 1)>(box, regularKernel);
190 }
191
192 for (int i = 0; i < this->m_numTagFields; i++) {
193 this->m_amr->conservativeAverage(this->m_tagFields[i], this->m_realm, this->m_phase);
194 this->m_amr->interpGhost(this->m_tagFields[i], this->m_realm, this->m_phase);
195 }
196
197 // Compute gradient of tracers
198 for (int i = 0; i < this->m_numTagFields; i++) {
199 this->m_amr->computeGradient(this->m_gradTagFields[i], this->m_tagFields[i], this->m_realm, this->m_phase);
200 this->m_amr->conservativeAverage(this->m_gradTagFields[i], this->m_realm, this->m_phase);
201 }
202 }
203
204 this->deallocateStorage();
205}
206
207#include <CD_NamespaceFooter.H>
208
209#endif
Agglomeration of useful data operations.
Declaration of the Physics::ItoKMC::ItoKMCFieldTagger abstract CellTagger.
Declaration of cell positions.
static void getMaxMinNorm(Real &a_max, Real &a_min, EBAMRCellData &data, const Vector< RefCountedPtr< LayoutData< VoFIterator > > > &a_vofIter)
Get maximum and minimum value of normed data.
Definition CD_DataOps.cpp:1879
static void vectorLength(EBAMRCellData &a_lhs, const EBAMRCellData &a_rhs, const EBAMRCellData &a_notCovered, const Vector< RefCountedPtr< LayoutData< VoFIterator > > > &a_vofIter)
Compute the vector length of a data holder. Sets a_lhs = |a_rhs| where a_rhs contains SpaceDim compon...
Definition CD_DataOps.cpp:3500
ItoKMCFieldTagger() noexcept
Weak constructor. User MUST subsequently call define.
Definition CD_ItoKMCFieldTaggerImplem.H:25
virtual void computeElectricField(EBAMRCellData &a_E, EBAMRCellData &a_gradE) const noexcept
Compute the electric field and its gradient magnitude.
Definition CD_ItoKMCFieldTaggerImplem.H:71
virtual void allocateStorage() const noexcept
Allocate memory for scratch, electric field, and gradient of electric field.
Definition CD_ItoKMCFieldTaggerImplem.H:41
virtual ~ItoKMCFieldTagger() noexcept
Destructor.
Definition CD_ItoKMCFieldTaggerImplem.H:36
virtual void computeTagFields() const noexcept override
Compute tagging fields.
Definition CD_ItoKMCFieldTaggerImplem.H:99
virtual void deallocateStorage() const noexcept
Deallocate memory.
Definition CD_ItoKMCFieldTaggerImplem.H:57
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:38
phase::which_phase m_phase
Phase where this solver lives.
Definition CD_TracerParticleSolver.H:367
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:26
std::string m_realm
Realm where this solver lives.
Definition CD_TracerParticleSolver.H:352
int m_verbosity
Verbosity level.
Definition CD_TracerParticleSolver.H:387
RefCountedPtr< AmrMesh > m_amr
Handle to AMR mesh.
Definition CD_TracerParticleSolver.H:327
virtual void allocate()
Allocate storage for this solver.
Definition CD_TracerParticleSolverImplem.H:195
std::string m_name
Solver name.
Definition CD_TracerParticleSolver.H:357
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