chombo-discharge
CD_ItoKMCPhysics.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_ItoKMCPhysics_H
13 #define CD_ItoKMCPhysics_H
14 
15 // Std includes
16 #include <memory>
17 #include <vector>
18 
19 // Chombo includes
20 #include <RealVect.H>
21 #include <RefCountedPtr.H>
22 #include <List.H>
23 
24 // Our includes
25 #include <CD_ItoSpecies.H>
26 #include <CD_CdrSpecies.H>
27 #include <CD_RtSpecies.H>
28 #include <CD_Photon.H>
29 #include <CD_ItoParticle.H>
30 #include <CD_PointParticle.H>
31 #include <CD_ItoKMCPhotoReaction.H>
33 #include <CD_KMCDualState.H>
35 #include <CD_KMCSolver.H>
36 #include <CD_NamespaceHeader.H>
37 
38 namespace Physics {
39  namespace ItoKMC {
40 
44  using FPR = Real;
45 
50 
55 
60 
66  {
67  Ito,
68  CDR
69  };
70 
77  {
78  public:
82  inline ItoKMCPhysics() noexcept;
83 
87  inline virtual ~ItoKMCPhysics() noexcept;
88 
92  inline void
93  defineKMC() const noexcept;
94 
98  inline void
99  killKMC() const noexcept;
100 
108  inline virtual Real
109  computeDt(const RealVect a_E, const RealVect a_pos, const Vector<FPR> a_numParticles) const noexcept;
110 
117  virtual Real
118  computeAlpha(const Real a_E, const RealVect a_x) const = 0;
119 
126  virtual Real
127  computeEta(const Real a_E, const RealVect a_x) const = 0;
128 
133  const Vector<RefCountedPtr<ItoSpecies>>&
134  getItoSpecies() const;
135 
140  const Vector<RefCountedPtr<CdrSpecies>>&
141  getCdrSpecies() const;
142 
147  const Vector<RefCountedPtr<RtSpecies>>&
148  getRtSpecies() const;
149 
153  virtual Vector<std::string>
154  getPlotVariableNames() const noexcept;
155 
165  virtual Vector<Real>
166  getPlotVariables(const RealVect a_E,
167  const RealVect a_pos,
168  const Vector<Real>& a_phi,
169  const Vector<RealVect>& a_gradPhi,
170  const Real a_dx,
171  const Real a_kappa) const noexcept;
172 
176  virtual int
177  getNumberOfPlotVariables() const noexcept;
178 
182  inline int
183  getNumItoSpecies() const;
184 
188  inline int
189  getNumCdrSpecies() const;
190 
194  inline int
195  getNumPlasmaSpecies() const;
196 
200  inline int
201  getNumPhotonSpecies() const;
202 
206  virtual bool
207  needGradients() const noexcept;
208 
212  inline const std::map<int, std::pair<SpeciesType, int>>&
213  getSpeciesMap() const noexcept;
214 
218  inline virtual void
219  parseRuntimeOptions() noexcept;
220 
226  inline virtual Real
227  initialSigma(const Real a_time, const RealVect a_pos) const;
228 
236  virtual Vector<Real>
237  computeMobilities(const Real a_time, const RealVect a_pos, const RealVect a_E) const noexcept = 0;
238 
246  virtual Vector<Real>
247  computeDiffusionCoefficients(const Real a_time, const RealVect a_pos, const RealVect a_E) const noexcept = 0;
248 
271  virtual void
272  secondaryEmissionEB(Vector<List<ItoParticle>>& a_secondaryParticles,
273  Vector<Real>& a_cdrFluxes,
274  Vector<List<Photon>>& a_secondaryPhotons,
275  const Vector<List<ItoParticle>>& a_primaryParticles,
276  const Vector<Real>& a_cdrFluxesExtrap,
277  const Vector<List<Photon>>& a_primaryPhotons,
278  const RealVect& a_E,
279  const RealVect& a_physicalCellCenter,
280  const RealVect& a_cellCentroid,
281  const RealVect& a_bndryCentroid,
282  const RealVect& a_bndryNormal,
283  const Real a_bndryArea,
284  const Real a_dx,
285  const Real a_dt,
286  const bool a_isDielectric,
287  const int a_matIndex) const noexcept = 0;
288 
301  inline void
302  advanceKMC(Vector<FPR>& a_numParticles,
303  Vector<FPR>& a_numNewPhotons,
304  const Vector<Real>& a_phi,
305  const Vector<RealVect>& a_gradPhi,
306  const Real a_dt,
307  const RealVect a_E,
308  const RealVect a_pos,
309  const Real a_dx,
310  const Real a_kappa) const;
311 
328  inline void
329  reconcileParticles(Vector<List<ItoParticle>*>& a_particles,
330  const Vector<FPR>& a_newNumParticles,
331  const Vector<FPR>& a_oldNumParticles,
332  const RealVect a_cellPos,
333  const RealVect a_centroidPos,
334  const RealVect a_lo,
335  const RealVect a_hi,
336  const RealVect a_bndryCentroid,
337  const RealVect a_bndryNormal,
338  const Real a_dx,
339  const Real a_kappa) const noexcept;
340 
356  inline void
357  reconcilePhotons(Vector<List<Photon>*>& a_newPhotons,
358  const Vector<FPR>& a_numNewPhotons,
359  const RealVect a_cellPos,
360  const RealVect a_centroidPos,
361  const RealVect a_lo,
362  const RealVect a_hi,
363  const RealVect a_bndryCentroid,
364  const RealVect a_bndryNormal,
365  const Real a_dx,
366  const Real a_kappa) const noexcept;
367 
375  inline void
376  reconcilePhotoionization(Vector<List<ItoParticle>*>& a_itoParticles,
377  Vector<List<PointParticle>*>& a_cdrParticles,
378  const Vector<List<Photon>*>& a_absorbedPhotons) const noexcept;
379 
380  protected:
385  enum class Algorithm
386  {
387  SSA,
388  TauPlain,
389  TauMidpoint,
390  HybridPlain,
391  HybridMidpoint,
392  };
393 
397  enum class ParticlePlacement
398  {
399  Random,
400  Centroid
401  };
402 
407 
412 
416  std::map<int, std::pair<SpeciesType, int>> m_speciesMap;
417 
421  std::string m_className;
422 
426  bool m_debug;
427 
432 
436  static thread_local bool m_hasKMCSolver;
437 
441  static thread_local KMCSolverType m_kmcSolver;
442 
446  static thread_local KMCState m_kmcState;
447 
453  static thread_local std::vector<std::shared_ptr<const KMCReaction>> m_kmcReactionsThreadLocal;
454 
458  std::vector<KMCReaction> m_kmcReactions;
459 
463  std::vector<ItoKMCPhotoReaction> m_photoReactions;
464 
471  std::map<int, std::pair<std::discrete_distribution<int>, std::map<int, int>>> m_photoPathways;
472 
477 
481  Vector<RefCountedPtr<ItoSpecies>> m_itoSpecies;
482 
486  Vector<RefCountedPtr<CdrSpecies>> m_cdrSpecies;
487 
491  Vector<RefCountedPtr<RtSpecies>> m_rtSpecies;
492 
497 
502 
507  int m_Ncrit;
508 
513  int m_NSSA;
514 
519  Real m_SSAlim;
520 
525  Real m_eps;
526 
530  inline void
531  define() noexcept;
532 
537  inline void
538  defineSpeciesMap() noexcept;
539 
543  inline void
544  definePhotoPathways() noexcept;
545 
549  inline void
550  parsePPC() noexcept;
551 
555  inline void
556  parseDebug() noexcept;
557 
561  inline void
562  parseAlgorithm() noexcept;
563 
575  virtual void
576  updateReactionRates(std::vector<std::shared_ptr<const KMCReaction>>& a_kmcReactions,
577  const RealVect a_E,
578  const RealVect a_pos,
579  const Vector<Real>& a_phi,
580  const Vector<RealVect>& a_gradPhi,
581  const Real a_dx,
582  const Real a_kappa) const noexcept = 0;
583 
590  inline void
591  removeParticles(List<ItoParticle>& a_particles, const long long a_numToRemove) const;
592  };
593  } // namespace ItoKMC
594 } // namespace Physics
595 
596 #include <CD_NamespaceFooter.H>
597 
598 #include <CD_ItoKMCPhysicsImplem.H>
599 
600 #endif
Declaration of a class that passes information into CdrSolver (e.g., initial conditions).
Declaration of a class for holding photoionization reaction types in ito_plasma physics.
Implementation of CD_ItoKMCPhysics.H.
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
Declaration of a class that encapsulates a set of secondary emission reactions.
Declaration of a particle class for Ito diffusion.
Declaration of an ItoSpecies class that passes in names and initial data to ItoSolvers.
Declaration of a simple plasma reaction type for Kinetic Monte Carlo.
Declaration of a simple state vector for running Kinetic Monte Carlo for plasma problems.
Class for running Kinetic Monte Carlo functionality.
Declaration of a photon class for particle methods.
Declaration of a computational point particle.
Declaration of a class which supplies a user interface to radiative transfer code.
A particle class for use with ItoSolvers, i.e. drifting Brownian walkers.
Definition: CD_ItoParticle.H:40
Reaction type for advancing a KMCDualState for Kinetic Monte Carlo.
Definition: CD_KMCDualStateReaction.H:33
Declaration of a "dual state" for advancing with the Kinetic Monte Carlo module.
Definition: CD_KMCDualState.H:29
Class for running Kinetic Monte-Carlo simulations.
Definition: CD_KMCSolver.H:49
Particle class for usage with Monte Carlo radiative transfer.
Definition: CD_Photon.H:29
Base class for interaction between Kinetic Monte Carlo and Ito-based plasma solvers.
Definition: CD_ItoKMCPhysics.H:77
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 Vector< Real > computeDiffusionCoefficients(const Real a_time, const RealVect a_pos, const RealVect a_E) const noexcept=0
Compute the Ito solver diffusion coefficients.
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
virtual Vector< Real > getPlotVariables(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
Get plot variables.
Definition: CD_ItoKMCPhysics.cpp:35
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
virtual Vector< Real > computeMobilities(const Real a_time, const RealVect a_pos, const RealVect a_E) const noexcept=0
Compute the Ito solver mobilities.
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
virtual Real computeAlpha(const Real a_E, const RealVect a_x) const =0
Compute Townsend ionization coefficient.
static thread_local KMCSolverType m_kmcSolver
Kinetic Monte Carlo solver used in advanceReactionNetwork.
Definition: CD_ItoKMCPhysics.H:441
virtual void secondaryEmissionEB(Vector< List< ItoParticle >> &a_secondaryParticles, Vector< Real > &a_cdrFluxes, Vector< List< Photon >> &a_secondaryPhotons, const Vector< List< ItoParticle >> &a_primaryParticles, const Vector< Real > &a_cdrFluxesExtrap, const Vector< List< Photon >> &a_primaryPhotons, const RealVect &a_E, const RealVect &a_physicalCellCenter, const RealVect &a_cellCentroid, const RealVect &a_bndryCentroid, const RealVect &a_bndryNormal, const Real a_bndryArea, const Real a_dx, const Real a_dt, const bool a_isDielectric, const int a_matIndex) const noexcept=0
Resolve secondary emission at the EB.
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
Enum for switching between KMC algorithms.
Definition: CD_ItoKMCPhysics.H:386
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
ParticlePlacement
Enum for switching between various particle placement algorithms.
Definition: CD_ItoKMCPhysics.H:398
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
virtual Vector< std::string > getPlotVariableNames() const noexcept
Get number of plot variables.
Definition: CD_ItoKMCPhysics.cpp:27
ItoKMCSurfaceReactionSet m_surfaceReactions
Surface reactions.
Definition: CD_ItoKMCPhysics.H:476
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
virtual int getNumberOfPlotVariables() const noexcept
Get number of plot variables.
Definition: CD_ItoKMCPhysics.cpp:48
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
virtual bool needGradients() const noexcept
Return true/false if physics model needs species gradients.
Definition: CD_ItoKMCPhysics.cpp:56
bool m_isDefined
Is defined or not.
Definition: CD_ItoKMCPhysics.H:431
virtual Real computeEta(const Real a_E, const RealVect a_x) const =0
Compute Townsend attachment coefficient.
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
Class for holding a set of surface reactions.
Definition: CD_ItoKMCSurfaceReactionSet.H:26
A particle class that only has a position and a weight.
Definition: CD_PointParticle.H:29
Class for encapsulating random number generation. This class is MPI and OpenMP safe.
Definition: CD_Random.H:36
Name containing various physics models for running chombo-discharge code.
Definition: CD_AdvectionDiffusion.H:15