13#ifndef CD_ITOKMCBACKGROUNDEVALUATORIMPLEM_H
14#define CD_ITOKMCBACKGROUNDEVALUATORIMPLEM_H
18#include <CD_NamespaceHeader.H>
20using namespace Physics::ItoKMC;
22template <
typename I,
typename C,
typename R,
typename F>
26 CH_TIME(
"ItoKMCBackgroundEvaluator::ItoKMCBackgroundEvaluator");
39 this->
m_name =
"ItoKMCBackgroundEvaluator";
43 ParmParse pp(this->
m_name.c_str());
50template <
typename I,
typename C,
typename R,
typename F>
54 CH_TIME(
"ItoKMCBackgroundEvaluator::postInitialize");
56 pout() <<
"ItoKMCBackgroundEvaluator::postInitialize" << endl;
64template <
typename I,
typename C,
typename R,
typename F>
68 CH_TIME(
"ItoKMCBackgroundEvaluator::postRegrid");
70 pout() <<
"ItoKMCBackgroundEvaluator::postRegrid" << endl;
78template <
typename I,
typename C,
typename R,
typename F>
82 CH_TIME(
"ItoKMCBackgroundEvaluator::postCheckpointSetup");
84 pout() <<
"ItoKMCBackgroundEvaluator::postCheckpointSetup" << endl;
92template <
typename I,
typename C,
typename R,
typename F>
96 CH_TIME(
"ItoKMCBackgroundEvaluator::advance");
98 pout() <<
"ItoKMCBackgroundEvaluator::advance" << endl;
115 bool abortCondition =
false;
117 pout() <<
"ItoKMCBackgroundEvaluator -- stopping because the max field (in any cell) "
118 <<
"changed by more than specified threshold (max_field_exit_crit)" << endl;
119 abortCondition =
true;
122 pout() <<
"ItoKMCBackgroundEvaluator -- stopping because the relative field change in a cell "
123 <<
"is larger than specified threshold (rel_field_exit_crit)" << endl;
124 abortCondition =
true;
126 if (abortCondition) {
133template <
typename I,
typename C,
typename R,
typename F>
137 CH_TIME(
"ItoKMCBackgroundEvaluator::computeDt");
139 pout() <<
"ItoKMCBackgroundEvaluator::computeDt" << endl;
150template <
typename I,
typename C,
typename R,
typename F>
154 CH_TIME(
"ItoKMCBackgroundEvaluator::printStepReport");
156 pout() <<
"ItoKMCBackgroundEvaluator::printStepReport" << endl;
159 std::ios::fmtflags oldFlags = pout().flags();
164 const std::string whitespace =
" ";
165 pout().precision(12);
166 pout() << whitespace +
"Delta E(max) = " << 100.0 *
m_maxFieldChange <<
" (%)" << endl;
167 pout() << whitespace +
"Delta E(rel) = " << 100.0 *
m_relFieldChange <<
" (%)" << endl;
168 pout() << whitespace +
"Q (electrode) = " << std::scientific <<
m_electrodeCharge <<
" (C)" << endl;
169 pout() << whitespace +
"Q (ohmic) = " << std::scientific <<
m_ohmicCharge <<
" (C)" << endl;
170 pout() << whitespace +
"Sum (phi_optical) = " << std::scientific <<
m_sumOpticalPhi << endl;
171 pout() << whitespace +
"Sum (src_optical) = " << std::scientific <<
m_sumOpticalSrc <<
" (1/s)" << endl;
173 pout().flags(oldFlags);
176template <
typename I,
typename C,
typename R,
typename F>
180 CH_TIME(
"ItoKMCBackgroundEvaluator::computeBackgroundField");
182 pout() <<
"ItoKMCBackgroundEvaluator::computeBackgroundField" << endl;
207 const MFAMRCellData& permCell = (this->
m_fieldSolver)->getPermittivityCell();
208 const MFAMRFluxData& permFace = (this->
m_fieldSolver)->getPermittivityFace();
209 const MFAMRIVData& permEB = (this->
m_fieldSolver)->getPermittivityEB();
211 (this->
m_fieldSolver)->setSolverPermittivities(permCell, permFace, permEB);
218template <
typename I,
typename C,
typename R,
typename F>
222 CH_TIME(
"ItoKMCBackgroundEvaluator::evaluateSpaceChargeEffects");
224 pout() <<
"ItoKMCBackgroundEvaluator::evaluateSpaceChargeEffects" << endl;
227 EBAMRCellData poissonNorm;
228 EBAMRCellData laplaceNorm;
229 EBAMRCellData poissonField;
230 EBAMRCellData laplaceField;
231 EBAMRCellData deltaE;
240 const MFAMRCellData electricField = (this->
m_fieldSolver)->getElectricField();
272 Real relChange = -1.0;
273 Real maxChange = -1.0;
275 Real maxSpaceChargeField = 0.0;
276 Real minSpaceChargeField = 0.0;
277 Real maxBackgroundField = 0.0;
278 Real minBackgroundField = 0.0;
291 for (
int lvl = 0; lvl <= (this->
m_amr)->getFinestLevel(); lvl++) {
293 const DataIterator& dit = dbl.dataIterator();
296 const int nbox = dit.size();
298#pragma omp parallel for schedule(runtime) reduction(max : relChange)
299 for (
int mybox = 0; mybox < nbox; mybox++) {
300 const DataIndex& din = dit[mybox];
301 const Box box = dbl[din];
302 const EBISBox& ebisbox = ebisl[din];
303 const BaseFab<bool>& validCells = (*(this->
m_amr)->getValidCells(this->
m_fluidRealm)[lvl])[din];
305 const EBCellFAB& data = (*deltaE[lvl])[din];
306 const FArrayBox& dataReg = data.getFArrayBox();
308 auto regularKernel = [&](
const IntVect& iv) ->
void {
309 if (validCells(iv) && ebisbox.isRegular(iv)) {
310 relChange = std::max(relChange, std::abs(dataReg(iv, 0)));
314 auto irregularKernel = [&](
const VolIndex& vof) ->
void {
315 if (validCells(vof.gridIndex()) && ebisbox.isIrregular(vof.gridIndex())) {
316 relChange = std::max(relChange, std::abs(data(vof, 0)));
329 maxChange = maxSpaceChargeField / maxBackgroundField - 1.0;
331 return std::make_pair(relChange, maxChange);
334template <
typename I,
typename C,
typename R,
typename F>
338 CH_TIME(
"ItoKMCBackgroundEvaluator::integrateElectrodeSurfaceCharge");
340 pout() <<
"ItoKMCBackgroundEvaluator::integrateElectrodeSurfaceCharge" << endl;
347 const MFAMRCellData& electricFieldCell = (this->
m_fieldSolver)->getElectricField();
348 const MFAMRCellData& permittivityCell = (this->
m_fieldSolver)->getPermittivityCell();
349 const EBAMRCellData permittivity = (this->
m_amr)->alias(this->
m_plasmaPhase, permittivityCell);
352 EBAMRCellData electricField;
357 for (
int lvl = 0; lvl <= (this->
m_amr)->getFinestLevel(); lvl++) {
360 const DataIterator& dit = dbl.dataIterator();
361 const Real dx = (this->
m_amr)->getDx()[lvl];
362 const Real dA = std::pow(dx, SpaceDim - 1);
364 const int numBoxes = dit.size();
366#pragma omp parallel for schedule(runtime) reduction(+ : Enorm)
367 for (
int mybox = 0; mybox < numBoxes; mybox++) {
368 const DataIndex& din = dit[mybox];
369 const EBISBox& ebisbox = ebisl[din];
370 const EBCellFAB& E = (*electricField[lvl])[din];
371 const EBCellFAB& eps = (*permittivity[lvl])[din];
372 const BaseFab<bool>& validCells = (*(this->
m_amr)->getValidCells(this->
m_fluidRealm)[lvl])[din];
374 auto kernel = [&](
const VolIndex& vof) ->
void {
375 if (ebisbox.isIrregular(vof.gridIndex()) && validCells(vof.gridIndex(), 0)) {
376 const RealVect normalVector = ebisbox.normal(vof);
377 const RealVect e = RealVect(D_DECL(E(vof, 0), E(vof, 1), E(vof, 2)));
378 const Real areaFrac = ebisbox.bndryArea(vof);
380 Enorm += eps(vof, 0) * e.dotProduct(normalVector) * areaFrac * dA;
393template <
typename I,
typename C,
typename R,
typename F>
397 CH_TIME(
"ItoKMCBackgroundEvaluator::integrateOhmicCharge");
399 pout() <<
"ItoKMCBackgroundEvaluator::integrateOhmicCharge" << endl;
405template <
typename I,
typename C,
typename R,
typename F>
409 CH_TIME(
"ItoKMCBackgroundEvaluator::integrateOpticalExcitations");
411 pout() <<
"ItoKMCBackgroundEvaluator::integrateOpticalExcitations" << endl;
418 const RefCountedPtr<CdrSolver>& solver = solverIt();
421 for (
int lvl = 0; lvl <= (this->
m_amr)->getFinestLevel(); lvl++) {
424 const DataIterator& dit = dbl.dataIterator();
425 const Real dx = (this->
m_amr)->getDx()[lvl];
426 const Real dV = std::pow(dx, SpaceDim);
428 const int numBoxes = dit.size();
430#pragma omp parallel for schedule(runtime) reduction(+ : sumPhi, sumSrc)
431 for (
int mybox = 0; mybox < numBoxes; mybox++) {
432 const DataIndex& din = dit[mybox];
433 const Box cellBox = dbl[din];
434 const EBISBox& ebisbox = ebisl[din];
435 const BaseFab<bool>& validCells = (*(this->
m_amr)->getValidCells(this->
m_fluidRealm)[lvl])[din];
437 const EBCellFAB& phi = (*(solver->getPhi()[lvl]))[din];
438 const EBCellFAB& src = (*(solver->getSource()[lvl]))[din];
440 const FArrayBox& phiReg = phi.getFArrayBox();
441 const FArrayBox& srcReg = src.getFArrayBox();
443 auto regularKernel = [&](
const IntVect& iv) ->
void {
444 if (ebisbox.isRegular(iv) && validCells(iv)) {
445 sumPhi += phiReg(iv, 0) * dV;
446 sumSrc += srcReg(iv, 0) * dV;
450 auto irregularKernel = [&](
const VolIndex& vof) ->
void {
451 if (ebisbox.isIrregular(vof.gridIndex()) && validCells(vof.gridIndex(), 0)) {
452 const Real kappa = ebisbox.volFrac(vof);
457 sumPhi += kappa * phi(vof, 0) * dV;
458 sumSrc += kappa * src(vof, 0) * dV;
475 return std::make_pair(sumPhi, sumSrc);
478#include <CD_NamespaceFooter.H>
Declaration of the Physics::ItoKMC::ItoKMCBackgroundEvaluator TimeStepper.
Iterator class for CdrLayout. This allows iteration through solvers (or subsets of solvers).
Definition CD_CdrIterator.H:29
virtual bool ok() const
Check if the iterator is valid.
Definition CD_CdrIteratorImplem.H:77
static void getMaxMin(Real &max, Real &min, EBAMRCellData &a_data, const int a_comp, const Vector< RefCountedPtr< LayoutData< VoFIterator > > > &a_vofIter)
Get maximum and minimum value of specified component.
Definition CD_DataOps.cpp:1772
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:3561
static void incr(MFAMRCellData &a_lhs, const MFAMRCellData &a_rhs, const Real a_scale) noexcept
Function which increments data in the form a_lhs = a_lhs + a_rhs*a_scale for all components.
Definition CD_DataOps.cpp:881
static void setValue(LevelData< MFInterfaceFAB< T > > &a_lhs, const T &a_value)
Set value in an MFInterfaceFAB data holder.
Definition CD_DataOpsImplem.H:24
static void divideFallback(EBAMRCellData &a_numerator, const EBAMRCellData &a_denominator, const Real a_fallback, const Vector< RefCountedPtr< LayoutData< VoFIterator > > > &a_vofIter)
Divide data. If the denominator is zero, set the value to a fallback option.
Definition CD_DataOps.cpp:1448
static void copy(MFAMRCellData &a_dst, const MFAMRCellData &a_src)
Copy data from one data holder to another.
Definition CD_DataOps.cpp:1262
virtual void postRegrid() noexcept override final
Post-regrid operations. Computes the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:66
Real m_maxInitialTimeStep
Maximum time step for the very first advance, to prevent particles from moving too far during initial...
Definition CD_ItoKMCBackgroundEvaluator.H:94
virtual Real integrateElectrodeSurfaceCharge() const noexcept
Compute total charge on electrode.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:336
std::string m_opticalSolver
Name of the optical solver.
Definition CD_ItoKMCBackgroundEvaluator.H:129
virtual void computeBackgroundField() noexcept
Computes the background field. I.e., it allocates and fills m_backgroundField.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:178
virtual std::pair< Real, Real > evaluateSpaceChargeEffects() noexcept
Evaluate the maximum change in the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:220
virtual void printStepReport() noexcept override final
Print a new step report. This is the old one plus the maximum field change.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:152
Real m_maxFieldChange
Change in max field.
Definition CD_ItoKMCBackgroundEvaluator.H:99
MFAMRCellData m_backgroundField
For storing the background field.
Definition CD_ItoKMCBackgroundEvaluator.H:135
Real m_relFieldExitCrit
Exit criterion for relative field – if the relative change in the background field in any cell change...
Definition CD_ItoKMCBackgroundEvaluator.H:88
ItoKMCBackgroundEvaluator(RefCountedPtr< ItoKMCPhysics > &a_physics) noexcept
Constructor.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:23
virtual Real integrateOhmicCharge() const noexcept
Compute the total ohmic current through the electrode.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:395
Real m_relFieldChange
Change in relative field.
Definition CD_ItoKMCBackgroundEvaluator.H:104
virtual Real advance(const Real a_dt) override
Advance the system by a_dt, including background-field evaluation.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:94
Real m_sumOpticalPhi
Integrated optical emissions (phi).
Definition CD_ItoKMCBackgroundEvaluator.H:119
Real m_sumOpticalSrc
Integrated optical emissions (source term).
Definition CD_ItoKMCBackgroundEvaluator.H:124
virtual void postInitialize() noexcept override final
Post-initialization operations. Computes the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:52
Real m_electrodeCharge
Total charge on the electrode, given by .
Definition CD_ItoKMCBackgroundEvaluator.H:109
virtual void postCheckpointSetup() noexcept override final
Post-checkpoint operations. Computes the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:80
virtual Real computeDt() override
Compute a time step for the advance method.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:135
Real m_maxFieldExitCrit
Exit criterion for maximum field – if the background field changes by this much the simulation is ter...
Definition CD_ItoKMCBackgroundEvaluator.H:82
Real m_ohmicCharge
Total charge that left through the electrode in the last time step.
Definition CD_ItoKMCBackgroundEvaluator.H:114
virtual std::pair< Real, Real > integrateOpticalExcitations() const noexcept
Integrate the sum of the optical excitations.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:407
virtual void allocate() noexcept override
Definition CD_ItoKMCGodunovStepperImplem.H:101
virtual Real advance(const Real a_dt) override
Advance the Ito-Poisson-KMC system over a_dt.
Definition CD_ItoKMCGodunovStepperImplem.H:529
virtual Real computeDt() override
Compute a time step used for the advance method.
Definition CD_ItoKMCGodunovStepperImplem.H:509
ItoKMCGodunovStepper()=delete
virtual void parseOptions() noexcept override
Definition CD_ItoKMCGodunovStepperImplem.H:196
std::string m_name
Definition CD_ItoKMCStepper.H:402
phase::which_phase m_plasmaPhase
Definition CD_ItoKMCStepper.H:408
virtual void computeElectricField(EBAMRCellData &a_electricField, const phase::which_phase a_phase) const noexcept
Definition CD_ItoKMCStepperImplem.H:1978
RefCountedPtr< FieldSolver > m_fieldSolver
Definition CD_ItoKMCStepper.H:434
std::string m_fluidRealm
Definition CD_ItoKMCStepper.H:392
RefCountedPtr< CdrLayout< CdrSolver > > m_cdr
Definition CD_ItoKMCStepper.H:424
int m_verbosity
Class verbosity.
Definition CD_TimeStepper.H:343
virtual void printStepReport()=0
Print a step report.
RefCountedPtr< ComputationalGeometry > m_computationalGeometry
Computational geometry.
Definition CD_TimeStepper.H:375
virtual void postRegrid()=0
Perform post-regrid operations.
int m_timeStep
Time step.
Definition CD_TimeStepper.H:348
virtual void postInitialize()=0
Post-initialize operations to be performed at end of setup stage.
bool m_keepGoing
If false, Driver will stop the time loop after the current step.
Definition CD_TimeStepper.H:365
RefCountedPtr< AmrMesh > m_amr
AmrMesh.
Definition CD_TimeStepper.H:370
virtual void postCheckpointSetup()=0
Post-initialize operations to be performed after filling solvers with data read from checkpoint files...
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
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
Real sum(const Real &a_value) noexcept
Compute the sum across all MPI ranks.
Definition CD_ParallelOpsImplem.H:354
constexpr Real eps0
Permittivity of free space.
Definition CD_Units.H:30