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");
29 m_maxFieldExitCrit = std::numeric_limits<Real>::max();
30 m_relFieldExitCrit = std::numeric_limits<Real>::max();
31 m_maxFieldChange = -1.0;
32 m_relFieldChange = -1.0;
33 m_electrodeCharge = 0.0;
35 m_opticalSolver =
"2PN2";
36 m_maxInitialTimeStep = 0.0;
39 this->m_name =
"ItoKMCBackgroundEvaluator";
44 pp.query(
"max_field_exit_crit", m_maxFieldExitCrit);
45 pp.query(
"rel_field_exit_crit", m_relFieldExitCrit);
46 pp.query(
"optical_solver", m_opticalSolver);
47 pp.query(
"max_initial_time_step", m_maxInitialTimeStep);
50template <
typename I,
typename C,
typename R,
typename F>
54 CH_TIME(
"ItoKMCBackgroundEvaluator::postInitialize");
56 pout() <<
"ItoKMCBackgroundEvaluator::postInitialize" <<
endl;
61 this->computeBackgroundField();
64template <
typename I,
typename C,
typename R,
typename F>
68 CH_TIME(
"ItoKMCBackgroundEvaluator::postRegrid");
70 pout() <<
"ItoKMCBackgroundEvaluator::postRegrid" <<
endl;
75 this->computeBackgroundField();
78template <
typename I,
typename C,
typename R,
typename F>
82 CH_TIME(
"ItoKMCBackgroundEvaluator::postCheckpointSetup");
84 pout() <<
"ItoKMCBackgroundEvaluator::postCheckpointSetup" <<
endl;
89 this->computeBackgroundField();
92template <
typename I,
typename C,
typename R,
typename F>
96 CH_TIME(
"ItoKMCBackgroundEvaluator::advance");
98 pout() <<
"ItoKMCBackgroundEvaluator::advance" <<
endl;
105 const Real ohmicQ = this->integrateOhmicCharge();
116 if ((m_maxFieldChange > m_maxFieldExitCrit) && (m_maxFieldExitCrit > 0.0)) {
117 pout() <<
"ItoKMCBackgroundEvaluator -- stopping because the max field (in any cell) "
118 <<
"changed by more than specified threshold (max_field_exit_crit)" <<
endl;
121 if ((m_relFieldChange > m_relFieldExitCrit) && (m_relFieldExitCrit > 0.0)) {
122 pout() <<
"ItoKMCBackgroundEvaluator -- stopping because the relative field change in a cell "
123 <<
"is larger than specified threshold (rel_field_exit_crit)" <<
endl;
127 this->m_keepGoing =
false;
133template <
typename I,
typename C,
typename R,
typename F>
137 CH_TIME(
"ItoKMCBackgroundEvaluator::computeDt");
139 pout() <<
"ItoKMCBackgroundEvaluator::computeDt" <<
endl;
144 if (this->
m_timeStep == 0 && m_maxInitialTimeStep > 0.0 &&
newDt > m_maxInitialTimeStep)
145 newDt = m_maxInitialTimeStep;
150template <
typename I,
typename C,
typename R,
typename F>
154 CH_TIME(
"ItoKMCBackgroundEvaluator::printStepReport");
156 pout() <<
"ItoKMCBackgroundEvaluator::printStepReport" <<
endl;
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;
176template <
typename I,
typename C,
typename R,
typename F>
180 CH_TIME(
"ItoKMCBackgroundEvaluator::computeBackgroundField");
182 pout() <<
"ItoKMCBackgroundEvaluator::computeBackgroundField" <<
endl;
193 (this->
m_amr)->
allocate(sigma, this->m_fluidRealm, this->m_plasmaPhase, 1);
198 (this->
m_amr)->copyData(
phi, (this->m_fieldSolver)->getPotential());
205 (this->m_fieldSolver)->setPermittivities();
214 (this->m_fieldSolver)->solve(
phi,
rho,
sigma,
false);
215 (this->m_fieldSolver)->computeElectricField(m_backgroundField,
phi);
218template <
typename I,
typename C,
typename R,
typename F>
222 CH_TIME(
"ItoKMCBackgroundEvaluator::evaluateSpaceChargeEffects");
224 pout() <<
"ItoKMCBackgroundEvaluator::evaluateSpaceChargeEffects" <<
endl;
233 (this->
m_amr)->
allocate(poissonNorm, this->m_fluidRealm, this->m_plasmaPhase, 1);
234 (this->
m_amr)->
allocate(laplaceNorm, this->m_fluidRealm, this->m_plasmaPhase, 1);
237 (this->
m_amr)->
allocate(deltaE, this->m_fluidRealm, this->m_plasmaPhase, 1);
245 (this->
m_amr)->interpToCentroids(
poissonField, this->m_fluidRealm, this->m_plasmaPhase);
246 (this->
m_amr)->interpToCentroids(
laplaceField, this->m_fluidRealm, this->m_plasmaPhase);
251 (this->
m_amr)->getNotCoveredCells(this->m_fluidRealm, this->m_plasmaPhase),
252 (this->
m_amr)->getMultiCutVofIterator(this->m_fluidRealm, this->m_plasmaPhase));
255 (this->
m_amr)->getNotCoveredCells(this->m_fluidRealm, this->m_plasmaPhase),
256 (this->
m_amr)->getMultiCutVofIterator(this->m_fluidRealm, this->m_plasmaPhase));
263 (this->
m_amr)->getMultiCutVofIterator(this->m_fluidRealm, this->m_plasmaPhase));
265 (this->
m_amr)->arithmeticAverage(
deltaE, this->m_fluidRealm, this->m_plasmaPhase);
266 (this->
m_amr)->interpGhost(
deltaE, this->m_fluidRealm, this->m_plasmaPhase);
284 (this->
m_amr)->getMultiCutVofIterator(this->m_fluidRealm, this->m_plasmaPhase));
289 (this->
m_amr)->getMultiCutVofIterator(this->m_fluidRealm, this->m_plasmaPhase));
291 for (
int lvl = 0;
lvl <= (this->
m_amr)->getFinestLevel();
lvl++) {
298#pragma omp parallel for schedule(runtime) reduction(max : relChange)
334template <
typename I,
typename C,
typename R,
typename F>
338 CH_TIME(
"ItoKMCBackgroundEvaluator::integrateElectrodeSurfaceCharge");
340 pout() <<
"ItoKMCBackgroundEvaluator::integrateElectrodeSurfaceCharge" <<
endl;
355 (this->
m_amr)->interpToCentroids(
electricField, this->m_fluidRealm, this->m_plasmaPhase);
357 for (
int lvl = 0;
lvl <= (this->
m_amr)->getFinestLevel();
lvl++) {
366#pragma omp parallel for schedule(runtime) reduction(+ : Enorm)
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;
420 if (
solver->getName() == m_opticalSolver) {
421 for (
int lvl = 0;
lvl <= (this->
m_amr)->getFinestLevel();
lvl++) {
430#pragma omp parallel for schedule(runtime) reduction(+ : sumPhi, sumSrc)
478#include <CD_NamespaceFooter.H>
Declaration of the Physics::ItoKMC::ItoKMCBackgroundEvaluator TimeStepper.
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:1711
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
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:820
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:1387
static void copy(MFAMRCellData &a_dst, const MFAMRCellData &a_src)
Copy data from one data holder to another.
Definition CD_DataOps.cpp:1201
virtual void postRegrid() noexcept override final
Post-regrid operations. Computes the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:66
virtual Real integrateElectrodeSurfaceCharge() const noexcept
Compute total charge on electrode.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:336
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
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
virtual Real advance(const Real a_dt) override
Advance the system by a_dt, including background-field evaluation.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:94
virtual void postInitialize() noexcept override final
Post-initialization operations. Computes the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:52
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
virtual std::pair< Real, Real > integrateOpticalExcitations() const noexcept
Integrate the sum of the optical excitations.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:407
Implementation of ItoKMCStepper that uses a semi-implicit split-step formalism for advancing the Ito-...
Definition CD_ItoKMCGodunovStepper.H:30
virtual Real advance(const Real a_dt) override
Advance the Ito-Poisson-KMC system over a_dt.
Definition CD_ItoKMCGodunovStepperImplem.H:307
virtual Real computeDt() override
Compute a time step used for the advance method.
Definition CD_ItoKMCGodunovStepperImplem.H:287
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:38
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:26
int m_verbosity
Verbosity level.
Definition CD_TracerParticleSolver.H:387
RefCountedPtr< AmrMesh > m_amr
Handle to AMR mesh.
Definition CD_TracerParticleSolver.H:327
RefCountedPtr< ComputationalGeometry > m_computationalGeometry
Handle to computational geometry.
Definition CD_TracerParticleSolver.H:332
virtual void allocate()
Allocate storage for this solver.
Definition CD_TracerParticleSolverImplem.H:195
int m_timeStep
Time step.
Definition CD_TracerParticleSolver.H:382
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