chombo-discharge
CD_ItoPlasmaReactionImplem.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_ItoPlasmaReactionImplem_H
13 #define CD_ItoPlasmaReactionImplem_H
14 
15 // Our includes
16 #include <CD_ItoPlasmaReaction.H>
17 #include <CD_NamespaceHeader.H>
18 
19 #define ITO_REACTION_DEBUG 0
20 
21 using namespace Physics::ItoPlasma;
22 
23 inline void
24 ItoPlasmaReaction::jumpState(Vector<long long>& a_particles, const long long a_num_reactions) const
25 {
26 #if ITO_REACTION_DEBUG
27  if (a_num_reactions < 0) {
28  MayDay::Abort("ItoPlasmaReaction::jumpState - can't have negative number of reactions!");
29  }
30  for (int i = 0; i < a_particles.size(); i++) {
31  if (a_particles[i] < 0) {
32  MayDay::Abort("ItoPlasmaReaction::jumpState can't have negative particles on the way in");
33  }
34  }
35 #endif
36 
37  for (const auto& r : m_reactants) {
38  a_particles[r] -= a_num_reactions;
39  }
40 
41  for (const auto& r : m_particle_products) {
42  a_particles[r] += a_num_reactions;
43  }
44 
45 #if ITO_REACTION_DEBUG
46  for (int i = 0; i < a_particles.size(); i++) {
47  if (a_particles[i] < 0) {
48  MayDay::Abort("ItoPlasmaReaction::jumpState can't have negative particles on the way out");
49  }
50  }
51 #endif
52 }
53 
54 inline void
55 ItoPlasmaReaction::jumpState(Vector<long long>& a_particles,
56  Vector<long long>& a_Photons,
57  const long long a_num_reactions) const
58 {
59 
60  this->jumpState(a_particles, a_num_reactions);
61 
62  for (const auto& r : m_photon_products) {
63  a_Photons[r] += a_num_reactions;
64  ;
65  }
66 }
67 
68 inline void
69 ItoPlasmaReaction::jumpEnergy(Vector<Real>& a_energies,
70  const Vector<Real>& a_mean_energies,
71  const long long a_num_reactions) const
72 {
73  for (const auto& r : m_energy_jumps) {
74  if (this->getStateChange(r.first) < 0) { // Consuming reaction, this eats a_mean_energies.
75  a_energies[r.first] -= a_mean_energies[r.first] * a_num_reactions;
76  }
77  else {
78  a_energies[r.first] += r.second * a_num_reactions;
79  }
80  }
81 }
82 
83 inline void
84 ItoPlasmaReaction::jumpEnergy(Vector<Real>& a_energies,
85  const Vector<Real>& a_mean_energies,
86  const Vector<Real>& a_sources,
87  const long long a_num_reactions,
88  const Real a_dt) const
89 {
90 
91  for (const auto& r : m_energy_jumps) {
92  if (this->getStateChange(r.first) < 0) { // Consuming reaction, this eats a_mean_energies.
93  a_energies[r.first] -= a_mean_energies[r.first] * a_num_reactions;
94  }
95  else {
96  a_energies[r.first] += r.second * a_num_reactions;
97  }
98 
99  a_energies[r.first] += a_sources[r.first] * a_dt;
100  }
101 }
102 
103 inline Real&
105 {
106  return m_rate;
107 }
108 
109 inline Real
110 ItoPlasmaReaction::propensity(const Vector<long long>& a_particles) const
111 {
112  Real a = m_rate;
113 
114  // Make a local copy of the particles
115  Vector<long long> particles = a_particles;
116 
117  // Iterate over reactants, if a reactant appears twice the propensity function is X*(X-1)
118  for (const auto& r : m_reactants) {
119  a *= particles[r];
120  particles[r]--;
121  }
122 
123  return Max(0.0, a);
124 }
125 
126 inline int
127 ItoPlasmaReaction::getGi(const Vector<long long>& a_particles) const
128 {
129  return 1; // For simplicity
130 }
131 
132 inline const std::list<int>&
134 {
135  return m_reactants;
136 }
137 
138 inline const std::list<int>&
140 {
141  return m_particle_products;
142 }
143 
144 inline const std::list<int>&
146 {
147  return m_photon_products;
148 }
149 
150 inline void
152 {
153 
154  // Consumed species
155  for (const auto& r : m_reactants) {
156  if (m_phiChange.find(r) == m_phiChange.end()) {
157  m_phiChange.emplace(r, -1);
158  }
159  else {
160  m_phiChange[r]--;
161  }
162  }
163 
164  // Produced species
165  for (const auto& r : m_particle_products) {
166  if (m_phiChange.find(r) == m_phiChange.end()) {
167  m_phiChange.emplace(r, +1);
168  }
169  else {
170  m_phiChange[r]++;
171  }
172  }
173 }
174 
175 inline void
177 {
178  for (const auto& r : m_energy_jumps) {
179  if (m_energyChange.find(r.first) == m_energyChange.end()) {
180  m_energyChange.emplace(r.first, r.second);
181  }
182  }
183 }
184 
185 inline const std::map<int, int>&
187 {
188  return m_phiChange;
189 }
190 
191 inline const int
192 ItoPlasmaReaction::getStateChange(const int a_idx) const
193 {
194  int ret = 0;
195 
196  if (m_phiChange.find(a_idx) != m_phiChange.end()) {
197  ret = m_phiChange.at(a_idx);
198  }
199 
200  return ret;
201 }
202 
203 inline const std::map<int, Real>&
205 {
206  return m_energyChange;
207 }
208 
209 inline const Real
211 {
212  Real ret = 0;
213 
214  if (m_energyChange.find(a_idx) != m_energyChange.end()) {
215  ret = m_energyChange.at(a_idx);
216  }
217 
218  return ret;
219 }
220 
221 #include <CD_NamespaceFooter.H>
222 
223 #endif
Physics::ItoPlasma::ItoPlasmaReaction::getEnergychange
const std::map< int, Real > & getEnergychange() const
Get the energy change. You need to iterate through this map.
Definition: CD_ItoPlasmaReactionImplem.H:204
Physics::ItoPlasma::ItoPlasmaReaction::jumpState
void jumpState(Vector< long long > &a_particles, const long long a_num_reactions) const
Allows a state to jump with N reactions.
Definition: CD_ItoPlasmaReactionImplem.H:24
Physics::ItoPlasma::ItoPlasmaReaction::computeStateChange
void computeStateChange()
Compute the state change.
Definition: CD_ItoPlasmaReactionImplem.H:151
CD_ItoPlasmaReaction.H
Declaration of a class for holding reaction types in ito_plasma physics.
Physics::ItoPlasma::ItoPlasmaReaction::jumpEnergy
void jumpEnergy(Vector< Real > &a_energies, const Vector< Real > &a_mean_energies, const long long a_num_reactions) const
Allows the energies to jump with N reactions. Assumes no energy sources.
Definition: CD_ItoPlasmaReactionImplem.H:69
Physics::ItoPlasma::ItoPlasmaReaction::getReactants
const std::list< int > & getReactants() const
Get reactants.
Definition: CD_ItoPlasmaReactionImplem.H:133
Physics::ItoPlasma::ItoPlasmaReaction::getGi
int getGi(const Vector< long long > &a_particles) const
Get gi.
Definition: CD_ItoPlasmaReactionImplem.H:127
Physics::ItoPlasma::ItoPlasmaReaction::getParticleProdcuts
const std::list< int > & getParticleProdcuts() const
Get reactants.
Definition: CD_ItoPlasmaReactionImplem.H:139
Physics::ItoPlasma::ItoPlasmaReaction::computeEnergyChange
void computeEnergyChange()
Compute the state change.
Definition: CD_ItoPlasmaReactionImplem.H:176
Physics::ItoPlasma::ItoPlasmaReaction::getStateChange
const std::map< int, int > & getStateChange() const
Get the state change. You need to iterate through this map.
Definition: CD_ItoPlasmaReactionImplem.H:186
Physics::ItoPlasma::ItoPlasmaReaction::getPhotonProducts
const std::list< int > & getPhotonProducts() const
Get reactants.
Definition: CD_ItoPlasmaReactionImplem.H:145
Physics::ItoPlasma::ItoPlasmaReaction::propensity
Real propensity(const Vector< long long > &a_particles) const
Get propensity function.
Definition: CD_ItoPlasmaReactionImplem.H:110
Physics::ItoPlasma::ItoPlasmaReaction::rate
Real & rate() const
Return a modifiable version of the reaction rate.
Definition: CD_ItoPlasmaReactionImplem.H:104