12#ifndef CD_ItoKMCBackgroundEvaluatorImplem_H
13#define CD_ItoKMCBackgroundEvaluatorImplem_H
17#include <CD_NamespaceHeader.H>
19using namespace Physics::ItoKMC;
21template <
typename I,
typename C,
typename R,
typename F>
25 CH_TIME(
"ItoKMCBackgroundEvaluator::ItoKMCBackgroundEvaluator");
28 m_maxFieldExitCrit = std::numeric_limits<Real>::max();
29 m_relFieldExitCrit = std::numeric_limits<Real>::max();
30 m_maxFieldChange = -1.0;
31 m_relFieldChange = -1.0;
32 m_electrodeCharge = 0.0;
34 m_opticalSolver =
"2PN2";
35 m_maxInitialTimeStep = 0.0;
38 this->m_name =
"ItoKMCBackgroundEvaluator";
43 pp.query(
"max_field_exit_crit", m_maxFieldExitCrit);
44 pp.query(
"rel_field_exit_crit", m_relFieldExitCrit);
45 pp.query(
"optical_solver", m_opticalSolver);
46 pp.query(
"max_initial_time_step", m_maxInitialTimeStep);
49template <
typename I,
typename C,
typename R,
typename F>
53 CH_TIME(
"ItoKMCBackgroundEvaluator::postInitialize");
55 pout() <<
"ItoKMCBackgroundEvaluator::postInitialize" <<
endl;
60 this->computeBackgroundField();
63template <
typename I,
typename C,
typename R,
typename F>
67 CH_TIME(
"ItoKMCBackgroundEvaluator::postRegrid");
69 pout() <<
"ItoKMCBackgroundEvaluator::postRegrid" <<
endl;
74 this->computeBackgroundField();
77template <
typename I,
typename C,
typename R,
typename F>
81 CH_TIME(
"ItoKMCBackgroundEvaluator::postCheckpointSetup");
83 pout() <<
"ItoKMCBackgroundEvaluator::postCheckpointSetup" <<
endl;
88 this->computeBackgroundField();
91template <
typename I,
typename C,
typename R,
typename F>
95 CH_TIME(
"ItoKMCBackgroundEvaluator::advance");
97 pout() <<
"ItoKMCBackgroundEvaluator::advance" <<
endl;
104 const Real ohmicQ = this->integrateOhmicCharge();
115 if ((m_maxFieldChange > m_maxFieldExitCrit) && (m_maxFieldExitCrit > 0.0)) {
116 pout() <<
"ItoKMCBackgroundEvaluator -- stopping because the max field (in any cell) "
117 <<
"changed by more than specified threshold (max_field_exit_crit)" <<
endl;
120 if ((m_relFieldChange > m_relFieldExitCrit) && (m_relFieldExitCrit > 0.0)) {
121 pout() <<
"ItoKMCBackgroundEvaluator -- stopping because the relative field change in a cell "
122 <<
"is larger than specified threshold (rel_field_exit_crit)" <<
endl;
126 this->m_keepGoing =
false;
132template <
typename I,
typename C,
typename R,
typename F>
136 CH_TIME(
"ItoKMCBackgroundEvaluator::computeDt");
138 pout() <<
"ItoKMCBackgroundEvaluator::computeDt" <<
endl;
143 if (this->
m_timeStep == 0 && m_maxInitialTimeStep > 0.0 &&
newDt > m_maxInitialTimeStep)
144 newDt = m_maxInitialTimeStep;
149template <
typename I,
typename C,
typename R,
typename F>
153 CH_TIME(
"ItoKMCBackgroundEvaluator::printStepReport");
155 pout() <<
"ItoKMCBackgroundEvaluator::printStepReport" <<
endl;
164 pout().precision(12);
165 pout() <<
whitespace +
"Delta E(max) = " << 100.0 * m_maxFieldChange <<
" (%)" <<
endl;
166 pout() <<
whitespace +
"Delta E(rel) = " << 100.0 * m_relFieldChange <<
" (%)" <<
endl;
175template <
typename I,
typename C,
typename R,
typename F>
179 CH_TIME(
"ItoKMCBackgroundEvaluator::computeBackgroundField");
181 pout() <<
"ItoKMCBackgroundEvaluator::computeBackgroundField" <<
endl;
192 (this->
m_amr)->
allocate(sigma, this->m_fluidRealm, this->m_plasmaPhase, 1);
197 (this->
m_amr)->copyData(
phi, (this->m_fieldSolver)->getPotential());
204 (this->m_fieldSolver)->setPermittivities();
213 (this->m_fieldSolver)->solve(
phi,
rho,
sigma,
false);
214 (this->m_fieldSolver)->computeElectricField(m_backgroundField,
phi);
217template <
typename I,
typename C,
typename R,
typename F>
221 CH_TIME(
"ItoKMCBackgroundEvaluator::evaluateSpaceChargeEffects");
223 pout() <<
"ItoKMCBackgroundEvaluator::evaluateSpaceChargeEffects" <<
endl;
232 (this->
m_amr)->
allocate(poissonNorm, this->m_fluidRealm, this->m_plasmaPhase, 1);
233 (this->
m_amr)->
allocate(laplaceNorm, this->m_fluidRealm, this->m_plasmaPhase, 1);
236 (this->
m_amr)->
allocate(deltaE, this->m_fluidRealm, this->m_plasmaPhase, 1);
244 (this->
m_amr)->interpToCentroids(
poissonField, this->m_fluidRealm, this->m_plasmaPhase);
245 (this->
m_amr)->interpToCentroids(
laplaceField, this->m_fluidRealm, this->m_plasmaPhase);
255 (this->
m_amr)->arithmeticAverage(
deltaE, this->m_fluidRealm, this->m_plasmaPhase);
256 (this->
m_amr)->interpGhost(
deltaE, this->m_fluidRealm, this->m_plasmaPhase);
273 for (
int lvl = 0;
lvl <= (this->
m_amr)->getFinestLevel();
lvl++) {
280#pragma omp parallel for schedule(runtime) reduction(max : relChange)
315template <
typename I,
typename C,
typename R,
typename F>
319 CH_TIME(
"ItoKMCBackgroundEvaluator::integrateElectrodeSurfaceCharge");
321 pout() <<
"ItoKMCBackgroundEvaluator::integrateElectrodeSurfaceCharge" <<
endl;
336 (this->
m_amr)->interpToCentroids(
electricField, this->m_fluidRealm, this->m_plasmaPhase);
338 for (
int lvl = 0;
lvl <= (this->
m_amr)->getFinestLevel();
lvl++) {
347#pragma omp parallel for schedule(runtime) reduction(+ : Enorm)
374template <
typename I,
typename C,
typename R,
typename F>
378 CH_TIME(
"ItoKMCBackgroundEvaluator::integrateOhmicCharge");
380 pout() <<
"ItoKMCBackgroundEvaluator::integrateOhmicCharge" <<
endl;
386template <
typename I,
typename C,
typename R,
typename F>
390 CH_TIME(
"ItoKMCBackgroundEvaluator::integrateOpticalExcitations");
392 pout() <<
"ItoKMCBackgroundEvaluator::integrateOpticalExcitations" <<
endl;
401 if (
solver->getName() == m_opticalSolver) {
402 for (
int lvl = 0;
lvl <= (this->
m_amr)->getFinestLevel();
lvl++) {
411#pragma omp parallel for schedule(runtime) reduction(+ : sumPhi, sumSrc)
455#include <CD_NamespaceFooter.H>
File containing a subclass of ItoKMCGodunovStepper.
static void divideFallback(EBAMRCellData &a_numerator, const EBAMRCellData &a_denominator, const Real a_fallback)
Divide data. If the denominator is zero, set the value to a fallback option.
Definition CD_DataOps.cpp:1317
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:3410
static void getMaxMin(Real &max, Real &min, EBAMRCellData &a_data, const int a_comp)
Get maximum and minimum value of specified component.
Definition CD_DataOps.cpp:1651
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:801
static void setValue(LevelData< MFInterfaceFAB< T > > &a_lhs, const T &a_value)
Set value in an MFInterfaceFAB data holder.
Definition CD_DataOpsImplem.H:23
static void copy(MFAMRCellData &a_dst, const MFAMRCellData &a_src)
Copy data from one data holder to another.
Definition CD_DataOps.cpp:1132
virtual void postRegrid() noexcept override final
Post-regrid operations. Computes the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:65
virtual Real integrateElectrodeSurfaceCharge() const noexcept
Compute total charge on electrode.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:317
virtual void computeBackgroundField() noexcept
Computes the background field. I.e., it allocates and fills m_backgroundField.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:177
virtual std::pair< Real, Real > evaluateSpaceChargeEffects() noexcept
Evaluate the maximum change in the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:219
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:151
ItoKMCBackgroundEvaluator(RefCountedPtr< ItoKMCPhysics > &a_physics) noexcept
Constructor.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:22
virtual Real integrateOhmicCharge() const noexcept
Compute the total ohmic current through the electrode.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:376
virtual Real advance(const Real a_dt) override
Overriden advance method.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:93
virtual void postInitialize() noexcept override final
Post-initialization operations. Computes the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:51
virtual void postCheckpointSetup() noexcept override final
Post-checkpoint operations. Computes the background field.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:79
virtual Real computeDt() override
Compute a time step used for the advance method.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:134
virtual std::pair< Real, Real > integrateOpticalExcitations() const noexcept
Integrate the sum of the optical excitations.
Definition CD_ItoKMCBackgroundEvaluatorImplem.H:388
Implementation of ItoKMCStepper that uses a semi-implicit split-step formalism for advancing the Ito-...
Definition CD_ItoKMCGodunovStepper.H:29
virtual Real advance(const Real a_dt) override
Advance the Ito-Poisson-KMC system over a_dt.
Definition CD_ItoKMCGodunovStepperImplem.H:306
virtual Real computeDt() override
Compute a time step used for the advance method.
Definition CD_ItoKMCGodunovStepperImplem.H:286
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:37
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:25
int m_verbosity
Verbosity level.
Definition CD_TracerParticleSolver.H:380
RefCountedPtr< AmrMesh > m_amr
Handle to AMR mesh.
Definition CD_TracerParticleSolver.H:320
RefCountedPtr< ComputationalGeometry > m_computationalGeometry
Handle to computational geometry.
Definition CD_TracerParticleSolver.H:325
virtual void allocate()
Allocate storage for this solver.
Definition CD_TracerParticleSolverImplem.H:194
int m_timeStep
Time step.
Definition CD_TracerParticleSolver.H:375
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
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
Real sum(const Real &a_value) noexcept
Compute the sum across all MPI ranks.
Definition CD_ParallelOpsImplem.H:353
constexpr Real eps0
Permittivity of free space.
Definition CD_Units.H:29