chombo-discharge
CD_ItoKMCPhysicsImplem.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_ItoKMCPhysicsImplem_H
13 #define CD_ItoKMCPhysicsImplem_H
14 
15 // Chombo includes
16 #include <ParmParse.H>
17 
18 // Our includes
19 #include <CD_ItoKMCPhysics.H>
20 #include <CD_ParticleManagement.H>
21 #include <CD_Random.H>
22 #include <CD_Units.H>
23 #include <CD_NamespaceHeader.H>
24 
25 using namespace Physics::ItoKMC;
26 
28 {
29  CH_TIME("ItoKMCPhysics::ItoKMCPhysics");
30 
31  m_className = "ItoKMCPhysics";
32 
33  m_kmcReactions.clear();
34  m_photoReactions.clear();
35 
36  // Some default settings in case user forgets to call the parsing algorithms.
37  m_isDefined = false;
38  m_debug = true;
39  m_hasKMCSolver = false;
40  m_maxNewParticles = 32;
41  m_maxNewPhotons = 32;
42  m_Ncrit = 5;
43  m_eps = 0.1;
44  m_NSSA = 10;
45  m_SSAlim = 5.0;
46  m_algorithm = Algorithm::TauPlain;
47  m_particlePlacement = ParticlePlacement::Random;
48 
49  // Development code for switching to centroid for secondary emission. Will be removed.
50 #if 0
51  bool useCentroid = false;
52  ParmParse pp("ItoKMCPhysics");
53  pp.query("use_centroid", useCentroid);
54  if (useCentroid) {
55  m_particlePlacement = ParticlePlacement::Centroid;
56  }
57 #endif
58 }
59 
61 {
62  CH_TIME("ItoKMCPhysics::~ItoKMCPhysics");
63 }
64 
65 inline void
67 {
68  CH_TIME("ItoKMCPhysics::define");
69 
70  this->defineSpeciesMap();
71  this->definePhotoPathways();
72 
73  // Safety hook -- make sure no one defines reactions using an out-of-range species index.
74 #ifndef NDEBUG
75  for (const auto& R : m_kmcReactions) {
76  const auto& lhsReactants = R.getReactants();
77  const auto& rhsReactants = R.getReactiveProducts();
78  const auto& rhsPhotons = R.getNonReactiveProducts();
79 
80  for (const auto& r : lhsReactants) {
81  CH_assert(r < m_itoSpecies.size() + m_cdrSpecies.size());
82  }
83  for (const auto& r : rhsReactants) {
84  CH_assert(r < m_itoSpecies.size() + m_cdrSpecies.size());
85  }
86  for (const auto& r : rhsPhotons) {
87  CH_assert(r < m_rtSpecies.size());
88  }
89  }
90 #endif
91 
92  m_isDefined = true;
93 }
94 
95 inline void
97 {
98  CH_TIME("ItoKMCPhysics::defineSpeciesMap");
99 
100  const int numItoSpecies = this->getNumItoSpecies();
101  const int numCdrSpecies = this->getNumCdrSpecies();
102 
103  int species = 0;
104  for (int i = 0; i < numItoSpecies; i++, species++) {
105  m_speciesMap.emplace(species, std::make_pair(SpeciesType::Ito, i));
106  }
107 
108  for (int i = 0; i < numCdrSpecies; i++, species++) {
109  m_speciesMap.emplace(species, std::make_pair(SpeciesType::CDR, i));
110  }
111 }
112 
113 inline void
114 ItoKMCPhysics::defineKMC() const noexcept
115 {
116  CH_TIME("ItoKMCPhysics::defineKMC");
117 
118  CH_assert(!m_hasKMCSolver);
119 
120  // Deep copy of reaction rates
121  m_kmcReactionsThreadLocal.resize(0);
122  for (const auto& r : m_kmcReactions) {
123  m_kmcReactionsThreadLocal.emplace_back(std::make_shared<const KMCReaction>(r));
124  }
125 
128  m_kmcState.define(m_itoSpecies.size() + m_cdrSpecies.size(), m_rtSpecies.size());
129 
130  m_hasKMCSolver = true;
131 }
132 
133 inline void
134 ItoKMCPhysics::killKMC() const noexcept
135 {
136  CH_TIME("ItoKMCPhysics::defineKMC");
137 
138  CH_assert(m_hasKMCSolver);
139 
140  m_kmcReactionsThreadLocal.resize(0);
142  m_kmcState.define(0, 0);
143 
144  m_hasKMCSolver = false;
145 }
146 
147 inline void
149 {
150  CH_TIME("ItoKMCPhysics::definePhotoPathways");
151 
152  // Build a temporary list of pathways. I.e. restructure the list of reactions
153  //
154  // Y1 -> A
155  // Y1 -> B
156  // Y2 -> C
157  // Y2 -> D
158  //
159  // into separate lists for Y1, Y2, ....
160  //
161  std::map<int, std::vector<std::pair<int, Real>>> pathways;
162 
163  for (int i = 0; i < m_photoReactions.size(); i++) {
165 
166  const size_t& src = r.getSourcePhoton();
167  const Real efficiency = r.getEfficiency();
168 
169  pathways[src].emplace_back(std::make_pair(i, efficiency));
170  }
171 
172  // Go through the temporary pathways list and compute the relative efficiencies of one of the
173  // photons triggering a reaction. The relative efficiencies are given by
174  //
175  // p(i) = R(i)/sum_j R(j).
176  //
177  for (const auto& p : pathways) {
178  const int photoSpecies = p.first;
179  const std::vector<std::pair<int, Real>> reactionsAndEfficiencies = p.second;
180 
181  std::map<int, int> localToGlobalMap;
182  std::list<double> efficiencies;
183  double sumEfficiencies = 0.0;
184 
185  for (int i = 0; i < reactionsAndEfficiencies.size(); i++) {
186  sumEfficiencies += (double)reactionsAndEfficiencies[i].second;
187  }
188 
189  for (int i = 0; i < reactionsAndEfficiencies.size(); i++) {
190  localToGlobalMap.emplace(i, reactionsAndEfficiencies[i].first);
191  efficiencies.emplace_back((double)reactionsAndEfficiencies[i].second / sumEfficiencies);
192  }
193 
194  std::discrete_distribution<int> distribution(efficiencies.begin(), efficiencies.end());
195 
196  m_photoPathways.insert(std::make_pair((int)photoSpecies, std::make_pair(distribution, localToGlobalMap)));
197  }
198 }
199 
200 inline const std::map<int, std::pair<SpeciesType, int>>&
202 {
203  CH_TIME("ItoKMCPhysics::getSpeciesMap");
204 
205  return m_speciesMap;
206 }
207 
208 inline Real
209 ItoKMCPhysics::computeDt(const RealVect a_E, const RealVect a_pos, const Vector<FPR> a_numParticles) const noexcept
210 {
211  CH_TIME("ItoKMCPhysics::computeDt");
212 
213  CH_assert(m_isDefined);
214 
216 }
217 
218 inline void
220 {
221  CH_TIME("ItoKMCPhysics::parseRuntimeOptions");
222 
223  this->parsePPC();
224  this->parseDebug();
225  this->parseAlgorithm();
226 }
227 
228 inline void
230 {
231  CH_TIME("ItoKMCPhysics::parsePPC");
232 
233  ParmParse pp(m_className.c_str());
234 
235  pp.get("max_new_particles", m_maxNewParticles);
236  pp.get("max_new_photons", m_maxNewPhotons);
237 }
238 
239 inline void
241 {
242  CH_TIME("ItoKMCPhysics::parseDebug");
243 
244  ParmParse pp(m_className.c_str());
245 
246  pp.get("debug", m_debug);
247 }
248 
249 inline void
251 {
252  CH_TIME("ItoKMCPhysics::parseAlgorithm");
253 
254  ParmParse pp(m_className.c_str());
255 
256  std::string str;
257 
258  pp.get("algorithm", str);
259  pp.get("Ncrit", m_Ncrit);
260  pp.get("NSSA", m_NSSA);
261  pp.get("prop_eps", m_eps);
262  pp.get("SSAlim", m_SSAlim);
263 
264  if (str == "ssa") {
265  m_algorithm = Algorithm::SSA;
266  }
267  else if (str == "tau_plain") {
268  m_algorithm = Algorithm::TauPlain;
269  }
270  else if (str == "tau_midpoint") {
271  m_algorithm = Algorithm::TauMidpoint;
272  }
273  else if (str == "hybrid_plain") {
274  m_algorithm = Algorithm::HybridPlain;
275  }
276  else if (str == "hybrid_midpoint") {
277  m_algorithm = Algorithm::HybridMidpoint;
278  }
279  else {
280  MayDay::Error("ItoKMCPhysics::parseAlgorithm - unknown algorithm requested");
281  }
282 }
283 
284 inline const Vector<RefCountedPtr<ItoSpecies>>&
286 {
287  return m_itoSpecies;
288 }
289 
290 inline const Vector<RefCountedPtr<CdrSpecies>>&
292 {
293  return m_cdrSpecies;
294 }
295 
296 inline const Vector<RefCountedPtr<RtSpecies>>&
298 {
299  return m_rtSpecies;
300 }
301 
302 inline int
304 {
305  return m_itoSpecies.size();
306 }
307 
308 inline int
310 {
311  return m_cdrSpecies.size();
312 }
313 
314 inline int
316 {
317  return m_itoSpecies.size() + m_cdrSpecies.size();
318 }
319 
320 inline int
322 {
323  return m_rtSpecies.size();
324 }
325 
326 inline Real
327 ItoKMCPhysics::initialSigma(const Real a_time, const RealVect a_pos) const
328 {
329  return 0.0;
330 }
331 
332 inline void
333 ItoKMCPhysics::advanceKMC(Vector<FPR>& a_numParticles,
334  Vector<FPR>& a_numNewPhotons,
335  const Vector<Real>& a_phi,
336  const Vector<RealVect>& a_gradPhi,
337  const Real a_dt,
338  const RealVect a_E,
339  const RealVect a_pos,
340  const Real a_dx,
341  const Real a_kappa) const
342 {
343  CH_TIME("ItoKMCPhysics::advanceKMC");
344 
345  // Note: This is called PER GRID CELL, i.e. within OpenMP parallel regions. For this reason the KMC solver
346  // must be defined through defineKMC() (which must be later killed).
347  CH_assert(m_isDefined);
348  CH_assert(m_hasKMCSolver);
349 
350  std::vector<FPR>& kmcParticles = m_kmcState.getReactiveState();
351  std::vector<FPR>& kmcPhotons = m_kmcState.getNonReactiveState();
352 
353  for (size_t i = 0; i < a_numParticles.size(); i++) {
354  kmcParticles[i] = a_numParticles[i];
355  }
356 
357  for (auto& p : kmcPhotons) {
358  p = 0LL;
359  }
360 
361  // Update the reaction rates to be used by the KMC solver.
362  this->updateReactionRates(m_kmcReactionsThreadLocal, a_E, a_pos, a_phi, a_gradPhi, a_dx, a_kappa);
363 
364  // Run the KMC solver.
365  switch (m_algorithm) {
366  case Algorithm::SSA: {
368 
369  break;
370  }
371  case Algorithm::TauPlain: {
373 
374  break;
375  }
376  case Algorithm::TauMidpoint: {
378 
379  break;
380  }
381  case Algorithm::HybridPlain: {
382  m_kmcSolver.advanceHybrid(m_kmcState, a_dt, KMCLeapPropagator::TauPlain);
383 
384  break;
385  }
386  case Algorithm::HybridMidpoint: {
387  m_kmcSolver.advanceHybrid(m_kmcState, a_dt, KMCLeapPropagator::TauMidpoint);
388 
389  break;
390  }
391  default: {
392  MayDay::Error("ItoKMCPhysics::advanceKMC - logic bust");
393  }
394  }
395 
396  // Put KMC back into ItoKMC
397  for (size_t i = 0; i < a_numParticles.size(); i++) {
398  a_numParticles[i] = (FPR)kmcParticles[i];
399  }
400  for (size_t i = 0; i < a_numNewPhotons.size(); i++) {
401  a_numNewPhotons[i] = (FPR)kmcPhotons[i];
402  }
403 }
404 
405 inline void
406 ItoKMCPhysics::reconcileParticles(Vector<List<ItoParticle>*>& a_particles,
407  const Vector<FPR>& a_newNumParticles,
408  const Vector<FPR>& a_oldNumParticles,
409  const RealVect a_cellPos,
410  const RealVect a_centroidPos,
411  const RealVect a_lo,
412  const RealVect a_hi,
413  const RealVect a_bndryCentroid,
414  const RealVect a_bndryNormal,
415  const Real a_dx,
416  const Real a_kappa) const noexcept
417 {
418  CH_TIME("ItoKMCPhysics::reconcileParticles(Vector<List<ItoParticle>*>, ...)");
419 
420  CH_assert(m_isDefined);
421  CH_assert(a_particles.size() == a_newNumParticles.size());
422  CH_assert(a_oldNumParticles.size() == a_newNumParticles.size());
423 
424  if (m_debug) {
425  for (int i = 0; i < a_particles.size(); i++) {
426  const FPR& numNew = a_newNumParticles[i];
427  const FPR& numOld = a_oldNumParticles[i];
428 
429  if (numNew < (FPR)0) {
430  MayDay::Warning("ItoKMCPhysics::reconcileParticles - new number of particles is < 0 (overflow issue?)");
431  }
432  else if ((long long)numNew < 0LL) {
433  MayDay::Warning("ItoKMCPhysics::reconcileParticles - integer overflow!");
434  }
435 
436  if (numOld < 0) {
437  MayDay::Warning("ItoKMCPhysics::reconcileParticles - old number of particles is < 0");
438  }
439  else if ((long long)numOld < 0LL) {
440  MayDay::Warning("ItoKMCPhysics::reconcileParticles - integer overflow for old particles!");
441  }
442  }
443  }
444 
445  for (int i = 0; i < a_particles.size(); i++) {
446  const long long diff = (long long)(a_newNumParticles[i] - a_oldNumParticles[i]);
447 
448  if (diff > 0LL) {
449  // Adding particles, which is fairly simple. Just choose weights for the particles and go.
450  const std::vector<long long> particleWeights = ParticleManagement::partitionParticleWeights(
451  diff,
452  (long long)m_maxNewParticles);
453 
454  for (const auto& w : particleWeights) {
455  RealVect x = RealVect::Zero;
456 
457  // Figure out where to place the particles.
458  switch (m_particlePlacement) {
459  case ParticlePlacement::Random: {
460  x = Random::randomPosition(a_cellPos, a_lo, a_hi, a_bndryCentroid, a_bndryNormal, a_dx, a_kappa);
461 
462  break;
463  }
464  case ParticlePlacement::Centroid: {
465  x = a_cellPos + a_centroidPos * a_dx;
466 
467  break;
468  }
469  default: {
470  MayDay::Error("ItoKMCPhysics::reconcileParticles - logic bust");
471 
472  break;
473  }
474  }
475 
476  a_particles[i]->add(ItoParticle(1.0 * w, x));
477  }
478  }
479  else if (diff < 0LL) {
480  // Removing particles is a bit more difficult because we need to manipulate weights.
481  this->removeParticles(*a_particles[i], -diff);
482  }
483  }
484 }
485 
486 inline void
487 ItoKMCPhysics::removeParticles(List<ItoParticle>& a_particles, const long long a_numParticlesToRemove) const
488 {
489  CH_TIME("ItoKMCPhysics::removeParticles");
490 
491  constexpr long long zero = 0LL;
492 
493  CH_assert(m_isDefined);
494  CH_assert(a_numParticlesToRemove >= zero);
495 
496  // Quick lambda for getting total particle weight. Used for debugging.
497  auto getTotalWeight = [&]() -> long long {
498  long long W = zero;
499 
500  for (ListIterator<ItoParticle> lit(a_particles); lit.ok(); ++lit) {
501  W += (long long)lit().weight();
502 
503  if (lit().weight() < 1.0) {
504  MayDay::Error("ItoKMCPhysics::removeParticles -- bad particle mass!");
505  }
506  }
507 
508  return W;
509  };
510 
511  if (a_numParticlesToRemove > zero) {
512 
513  // For debugging only.
514  long long totalWeightBefore = 0;
515  long long totalWeightAfter = 0;
516 
517  // Debug hook, compute the total particle weight before we start removing weights.
518  if (m_debug) {
519  totalWeightBefore = getTotalWeight();
520 
521  if (totalWeightBefore < a_numParticlesToRemove) {
522  MayDay::Error("ItoKMCPhysics::removeParticles: logic bust (trying to remove too many particles)");
523  }
524  }
525 
526  // Remove physical particles.
527  ParticleManagement::removePhysicalParticles(a_particles, a_numParticlesToRemove);
528 
529  // Remove particles with too low weight.
530  ParticleManagement::deleteParticles(a_particles, std::numeric_limits<Real>::min());
531 
532  // Debug hook, make sure that particle weights are > 0 AND we've removed the desired
533  // particle weight.
534  if (m_debug) {
535  totalWeightAfter = getTotalWeight();
536 
537  const long long errDiff = std::abs(totalWeightBefore - totalWeightAfter) - a_numParticlesToRemove;
538  if (std::abs(errDiff) != zero) {
539 
540  pout() << "ItoKMCPhysics::removeParticles: Total weight before = " << totalWeightBefore << endl;
541  pout() << "ItoKMCPhysics::removeParticles: Total weight after = " << totalWeightAfter << endl;
542  pout() << "ItoKMCPhysics::removeParticles: Should have removed = " << a_numParticlesToRemove << endl;
543  pout() << "ItoKMCPhysics::removeParticles: Error = " << errDiff << endl;
544 
545  MayDay::Abort("ItoKMCPhysics::removeParticles - incorrect mass removed");
546  }
547  }
548  }
549 }
550 
551 inline void
552 ItoKMCPhysics::reconcilePhotons(Vector<List<Photon>*>& a_newPhotons,
553  const Vector<FPR>& a_numNewPhotons,
554  const RealVect a_cellPos,
555  const RealVect a_centroidPos,
556  const RealVect a_lo,
557  const RealVect a_hi,
558  const RealVect a_bndryCentroid,
559  const RealVect a_bndryNormal,
560  const Real a_dx,
561  const Real a_kappa) const noexcept
562 {
563  CH_TIME("ItoKMCPhysics::reconcilePhotons");
564 
565  CH_assert(m_isDefined);
566 
567  for (int i = 0; i < a_newPhotons.size(); i++) {
568  if (a_numNewPhotons[i] > 0LL) {
569 
570  const std::vector<long long> photonWeights = ParticleManagement::partitionParticleWeights(
571  (long long)a_numNewPhotons[i],
572  (long long)m_maxNewPhotons);
573 
574  for (const auto& w : photonWeights) {
575  const RealVect x = Random::randomPosition(a_cellPos, a_lo, a_hi, a_bndryCentroid, a_bndryNormal, a_dx, a_kappa);
576  const RealVect v = Units::c * Random::getDirection();
577 
578  a_newPhotons[i]->add(Photon(x, v, m_rtSpecies[i]->getAbsorptionCoefficient(x), 1.0 * w));
579  }
580  }
581  }
582 }
583 
584 inline void
585 ItoKMCPhysics::reconcilePhotoionization(Vector<List<ItoParticle>*>& a_itoParticles,
586  Vector<List<PointParticle>*>& a_cdrParticles,
587  const Vector<List<Photon>*>& a_absorbedPhotons) const noexcept
588 {
589  CH_TIME("ItoKMCPhysics::reconcilePhotoionization");
590 
591  CH_assert(m_isDefined);
592  CH_assert(a_itoParticles.size() == m_itoSpecies.size());
593  CH_assert(a_cdrParticles.size() == m_cdrSpecies.size());
594 
595  for (int i = 0; i < a_absorbedPhotons.size(); i++) {
596  if (m_photoPathways.find(i) != m_photoPathways.end()) {
597  std::discrete_distribution<int> d = m_photoPathways.at(i).first;
598  const std::map<int, int>& localToGlobalMap = m_photoPathways.at(i).second;
599 
600  for (ListIterator<Photon> lit(*a_absorbedPhotons[i]); lit.ok(); ++lit) {
601  const RealVect x = lit().position();
602  const Real w = lit().weight();
603 
604  // Determine the photo-reaction type.
605  const int localReaction = Random::get(d);
606  const int globalReaction = localToGlobalMap.at(localReaction);
607 
608  const ItoKMCPhotoReaction& photoReaction = m_photoReactions[globalReaction];
609  const std::list<size_t>& plasmaTargets = photoReaction.getTargetSpecies();
610 
611  for (const auto& t : plasmaTargets) {
612  const SpeciesType& type = m_speciesMap.at(t).first;
613  const int& localIndex = m_speciesMap.at(t).second;
614 
615  if (type == SpeciesType::Ito) {
616  a_itoParticles[localIndex]->add(ItoParticle(w, x));
617  }
618  else if (type == SpeciesType::CDR) {
619  a_cdrParticles[localIndex]->add(PointParticle(x, w));
620  }
621  else {
622  MayDay::Error("CD_ItoKMCPhysics.H - logic bust in reconcilePhotoionization");
623  }
624  }
625  }
626  }
627  }
628 }
629 
630 #include <CD_NamespaceFooter.H>
631 
632 #endif
Main file for describing Ito-based plasma physics.
Real FPR
Numerical representation of the KMC state. Can be floating-point or integer type.
Definition: CD_ItoKMCPhysics.H:44
SpeciesType
Map to species type.
Definition: CD_ItoKMCPhysics.H:66
Namespace containing various particle management utilities.
File containing some useful static methods related to random number generation.
Declaration of various useful units.
A particle class for use with ItoSolvers, i.e. drifting Brownian walkers.
Definition: CD_ItoParticle.H:40
State & getNonReactiveState() noexcept
Get modifiable non-reactive state.
Definition: CD_KMCDualStateImplem.H:80
void define(const size_t a_numReactiveSpecies, const size_t a_numNonReactiveSpecies) noexcept
Define function constructor.
Definition: CD_KMCDualStateImplem.H:33
State & getReactiveState() noexcept
Get modifiable reactive state.
Definition: CD_KMCDualStateImplem.H:66
void setSolverParameters(const T a_numCrit, const T a_numSSA, const Real a_eps, const Real a_SSAlim) noexcept
Set solver parameters.
Definition: CD_KMCSolverImplem.H:59
void advanceTauMidpoint(State &a_state, const Real a_dt) const noexcept
Perform one leaping step using the midpoint method all reactions over a time step a_dt.
Definition: CD_KMCSolverImplem.H:445
void define(const ReactionList &a_reactions) noexcept
Define function. Sets the reactions.
Definition: CD_KMCSolverImplem.H:47
void advanceSSA(State &a_state, const Real a_dt) const noexcept
Advance with the SSA over the input time. This can end up using substepping.
Definition: CD_KMCSolverImplem.H:562
void advanceTauPlain(State &a_state, const Real a_dt) const noexcept
Advance with plain tau-leaping step over the input time. This can end up using substepping.
Definition: CD_KMCSolverImplem.H:358
void advanceHybrid(State &a_state, const Real a_dt, const KMCLeapPropagator &a_leapPropagator=KMCLeapPropagator::TauPlain) const noexcept
Advance using Cao et. al. hybrid algorithm over the input time. This can end up using substepping.
Definition: CD_KMCSolverImplem.H:601
Particle class for usage with Monte Carlo radiative transfer.
Definition: CD_Photon.H:29
Reaction class for describing photoionization in ItoKMCPhysics.
Definition: CD_ItoKMCPhotoReaction.H:31
const Real & getEfficiency() const noexcept
Get reaction efficiency.
Definition: CD_ItoKMCPhotoReactionImplem.H:59
const size_t & getSourcePhoton() const noexcept
Get the photon source.
Definition: CD_ItoKMCPhotoReactionImplem.H:47
const std::list< size_t > & getTargetSpecies() const noexcept
Get the photon target products.
Definition: CD_ItoKMCPhotoReactionImplem.H:53
int m_maxNewParticles
Maximum new number of particles generated by the chemistry advance.
Definition: CD_ItoKMCPhysics.H:496
void reconcilePhotons(Vector< List< Photon > * > &a_newPhotons, const Vector< FPR > &a_numNewPhotons, const RealVect a_cellPos, const RealVect a_centroidPos, const RealVect a_lo, const RealVect a_hi, const RealVect a_bndryCentroid, const RealVect a_bndryNormal, const Real a_dx, const Real a_kappa) const noexcept
Generate new photons.
Definition: CD_ItoKMCPhysicsImplem.H:552
int m_NSSA
Solver setting for the Cao et. al algorithm.
Definition: CD_ItoKMCPhysics.H:513
Vector< RefCountedPtr< RtSpecies > > m_rtSpecies
List of solver-tracked photon species.
Definition: CD_ItoKMCPhysics.H:491
virtual Real computeDt(const RealVect a_E, const RealVect a_pos, const Vector< FPR > a_numParticles) const noexcept
Compute a time step to use.
Definition: CD_ItoKMCPhysicsImplem.H:209
Real m_eps
Solver setting for the Cao et. al. algorithm.
Definition: CD_ItoKMCPhysics.H:525
bool m_debug
Turn on/off debugging.
Definition: CD_ItoKMCPhysics.H:426
void reconcilePhotoionization(Vector< List< ItoParticle > * > &a_itoParticles, Vector< List< PointParticle > * > &a_cdrParticles, const Vector< List< Photon > * > &a_absorbedPhotons) const noexcept
Reconcile photoionization reactions.
Definition: CD_ItoKMCPhysicsImplem.H:585
int m_maxNewPhotons
Maximum new number of photons generated by the chemistry advance.
Definition: CD_ItoKMCPhysics.H:501
void defineKMC() const noexcept
Define the KMC solver and state.
Definition: CD_ItoKMCPhysicsImplem.H:114
std::string m_className
Class name. Used for options parsing.
Definition: CD_ItoKMCPhysics.H:421
std::vector< ItoKMCPhotoReaction > m_photoReactions
List of photoionization reactions.
Definition: CD_ItoKMCPhysics.H:463
const Vector< RefCountedPtr< RtSpecies > > & getRtSpecies() const
Get all photon species.
Definition: CD_ItoKMCPhysicsImplem.H:297
Vector< RefCountedPtr< ItoSpecies > > m_itoSpecies
List of solver-tracked particle drift-diffusion species.
Definition: CD_ItoKMCPhysics.H:481
Vector< RefCountedPtr< CdrSpecies > > m_cdrSpecies
List of solver-tracked fluid drift-diffusion species.
Definition: CD_ItoKMCPhysics.H:486
virtual ~ItoKMCPhysics() noexcept
Destructor. Does nothing.
Definition: CD_ItoKMCPhysicsImplem.H:60
static thread_local KMCSolverType m_kmcSolver
Kinetic Monte Carlo solver used in advanceReactionNetwork.
Definition: CD_ItoKMCPhysics.H:441
void defineSpeciesMap() noexcept
Build internal representation of how we distinguish the Ito and CDR solvers.
Definition: CD_ItoKMCPhysicsImplem.H:96
const Vector< RefCountedPtr< ItoSpecies > > & getItoSpecies() const
Get all particle drift-diffusion species.
Definition: CD_ItoKMCPhysicsImplem.H:285
Real m_SSAlim
Solver setting for the Cao et. al. algorithm.
Definition: CD_ItoKMCPhysics.H:519
void parseAlgorithm() noexcept
Parse reaction algorithm.
Definition: CD_ItoKMCPhysicsImplem.H:250
int m_Ncrit
Solver setting for the Cao et. al algorithm.
Definition: CD_ItoKMCPhysics.H:507
const std::map< int, std::pair< SpeciesType, int > > & getSpeciesMap() const noexcept
Get the internal mapping between plasma species and Ito solvers.
Definition: CD_ItoKMCPhysicsImplem.H:201
virtual void updateReactionRates(std::vector< std::shared_ptr< const KMCReaction >> &a_kmcReactions, const RealVect a_E, const RealVect a_pos, const Vector< Real > &a_phi, const Vector< RealVect > &a_gradPhi, const Real a_dx, const Real a_kappa) const noexcept=0
Update reaction rates.
void advanceKMC(Vector< FPR > &a_numParticles, Vector< FPR > &a_numNewPhotons, const Vector< Real > &a_phi, const Vector< RealVect > &a_gradPhi, const Real a_dt, const RealVect a_E, const RealVect a_pos, const Real a_dx, const Real a_kappa) const
Advance particles.
Definition: CD_ItoKMCPhysicsImplem.H:333
void reconcileParticles(Vector< List< ItoParticle > * > &a_particles, const Vector< FPR > &a_newNumParticles, const Vector< FPR > &a_oldNumParticles, const RealVect a_cellPos, const RealVect a_centroidPos, const RealVect a_lo, const RealVect a_hi, const RealVect a_bndryCentroid, const RealVect a_bndryNormal, const Real a_dx, const Real a_kappa) const noexcept
Reconcile the number of particles.
Definition: CD_ItoKMCPhysicsImplem.H:406
std::map< int, std::pair< std::discrete_distribution< int >, std::map< int, int > > > m_photoPathways
Random number generators for photoionization pathways.
Definition: CD_ItoKMCPhysics.H:471
Algorithm m_algorithm
Algorithm to use for KMC advance.
Definition: CD_ItoKMCPhysics.H:406
virtual void parseRuntimeOptions() noexcept
Parse run-time options.
Definition: CD_ItoKMCPhysicsImplem.H:219
void removeParticles(List< ItoParticle > &a_particles, const long long a_numToRemove) const
Remove particles from the input list.
Definition: CD_ItoKMCPhysicsImplem.H:487
const Vector< RefCountedPtr< CdrSpecies > > & getCdrSpecies() const
Get all fluid drift-diffusion species.
Definition: CD_ItoKMCPhysicsImplem.H:291
static thread_local std::vector< std::shared_ptr< const KMCReaction > > m_kmcReactionsThreadLocal
KMC reactions used in advanceReactionNetowkr.
Definition: CD_ItoKMCPhysics.H:453
std::vector< KMCReaction > m_kmcReactions
List of reactions for the KMC solver.
Definition: CD_ItoKMCPhysics.H:458
int getNumPhotonSpecies() const
Return number of RTE solvers.
Definition: CD_ItoKMCPhysicsImplem.H:321
int getNumPlasmaSpecies() const
Return total number of plasma species.
Definition: CD_ItoKMCPhysicsImplem.H:315
int getNumItoSpecies() const
Return number of Ito solvers.
Definition: CD_ItoKMCPhysicsImplem.H:303
virtual Real initialSigma(const Real a_time, const RealVect a_pos) const
Set initial surface charge. Default is 0, override if you want.
Definition: CD_ItoKMCPhysicsImplem.H:327
void define() noexcept
Define method – defines all the internal machinery.
Definition: CD_ItoKMCPhysicsImplem.H:66
std::map< int, std::pair< SpeciesType, int > > m_speciesMap
Map for associating a plasma species with an Ito solver or CDR solver.
Definition: CD_ItoKMCPhysics.H:416
void killKMC() const noexcept
Kill the KMC solver.
Definition: CD_ItoKMCPhysicsImplem.H:134
void definePhotoPathways() noexcept
Define pathways for photo-reactions.
Definition: CD_ItoKMCPhysicsImplem.H:148
void parsePPC() noexcept
Parse the maximum number of particles generated per cell.
Definition: CD_ItoKMCPhysicsImplem.H:229
static thread_local bool m_hasKMCSolver
Is the KMC solver defined or not.
Definition: CD_ItoKMCPhysics.H:436
int getNumCdrSpecies() const
Return number of CDR solvers.
Definition: CD_ItoKMCPhysicsImplem.H:309
ParticlePlacement m_particlePlacement
Particle placement algorithm.
Definition: CD_ItoKMCPhysics.H:411
void parseDebug() noexcept
Parse the maximum number of particles generated per cell.
Definition: CD_ItoKMCPhysicsImplem.H:240
bool m_isDefined
Is defined or not.
Definition: CD_ItoKMCPhysics.H:431
static thread_local KMCState m_kmcState
KMC state used in advanceReactionNetwork.
Definition: CD_ItoKMCPhysics.H:446
ItoKMCPhysics() noexcept
Constructor. Does nothing.
Definition: CD_ItoKMCPhysicsImplem.H:27
A particle class that only has a position and a weight.
Definition: CD_PointParticle.H:29
static Real get(T &a_distribution)
For getting a random number from a user-supplied distribution. T must be a distribution for which we ...
Definition: CD_RandomImplem.H:208
static RealVect getDirection()
Get a random direction in space.
Definition: CD_RandomImplem.H:171
static RealVect randomPosition(const RealVect a_lo, const RealVect a_hi) noexcept
Return a random position in the cube (a_lo, a_hi);.
Definition: CD_RandomImplem.H:270
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 min(const Real &a_input) noexcept
Get the minimum of the input, reduced over MPI ranks (in the Chombo communicator)
Definition: CD_ParallelOpsImplem.H:58
constexpr Real R
Universal gas constant.
Definition: CD_Units.H:64
constexpr Real c
Speed of light.
Definition: CD_Units.H:39