12 #ifndef CD_KMCDualStateReactionImplem_H
13 #define CD_KMCDualStateReactionImplem_H
19 #include <CD_NamespaceHeader.H>
21 template <
typename State,
typename T>
23 const std::list<size_t>& a_rhsReactives,
24 const std::list<size_t>& a_rhsNonReactives) noexcept
26 m_lhsReactives = a_lhsReactives;
27 m_rhsReactives = a_rhsReactives;
28 m_rhsNonReactives = a_rhsNonReactives;
30 CH_assert(a_lhsReactives.size() > 0);
32 this->computeStateChanges();
35 template <
typename State,
typename T>
39 template <
typename State,
typename T>
44 for (
const auto& r : m_lhsReactives) {
45 if (m_reactiveStateChange.find(r) == m_reactiveStateChange.end()) {
46 m_reactiveStateChange.emplace(r, -1);
49 m_reactiveStateChange[r]--;
54 for (
const auto& p : m_rhsReactives) {
55 if (m_reactiveStateChange.find(p) == m_reactiveStateChange.end()) {
56 m_reactiveStateChange.emplace(p, +1);
59 m_reactiveStateChange[p]++;
64 for (
const auto& p : m_rhsNonReactives) {
65 if (m_nonReactiveStateChange.find(p) == m_nonReactiveStateChange.end()) {
66 m_nonReactiveStateChange.emplace(p, +1);
69 m_nonReactiveStateChange[p]++;
86 m_propensityFactor = 1.0;
88 std::map<size_t, size_t> reactantNumbers;
89 for (
const auto& r : m_lhsReactives) {
90 if (reactantNumbers.find(r) == reactantNumbers.end()) {
91 reactantNumbers.emplace(r, 1);
99 auto factorial = [](
const T& N) -> T {
101 for (T i = 2; i <= N; i++) {
108 for (
const auto& rn : reactantNumbers) {
109 m_propensityFactor *= 1.0 / factorial(rn.second);
113 template <
typename State,
typename T>
120 template <
typename State,
typename T>
124 const auto& reactiveState = a_state.getReactiveState();
126 CH_assert(reactiveState.size() > a_reactant);
128 return reactiveState[a_reactant];
131 template <
typename State,
typename T>
136 this->sanityCheck(a_state);
139 Real A = m_rate * m_propensityFactor;
141 auto reactiveState = a_state.getReactiveState();
143 for (
const auto& r : m_lhsReactives) {
144 A *= reactiveState[r];
152 template <
typename State,
typename T>
157 this->sanityCheck(a_state);
162 const auto& reactiveState = a_state.getReactiveState();
164 for (
const auto& s : m_reactiveStateChange) {
166 const size_t rI = s.first;
167 const T nuIJ = s.second;
170 Lj =
std::min(Lj, reactiveState[rI] / std::abs(nuIJ));
177 template <
typename State,
typename T>
178 inline std::list<size_t>
181 return m_lhsReactives;
184 template <
typename State,
typename T>
185 inline std::list<size_t>
188 return m_rhsReactives;
191 template <
typename State,
typename T>
192 inline std::list<size_t>
195 return m_rhsNonReactives;
198 template <
typename State,
typename T>
204 if (m_reactiveStateChange.find(a_particleReactant) != m_reactiveStateChange.end()) {
205 nuIJ = m_reactiveStateChange.at(a_particleReactant);
211 template <
typename State,
typename T>
216 this->sanityCheck(a_state);
218 CH_assert(a_state.isValidState());
220 auto& reactiveState = a_state.getReactiveState();
221 auto& photonState = a_state.getNonReactiveState();
223 for (
const auto& s : m_reactiveStateChange) {
224 reactiveState[s.first] += a_numReactions * s.second;
227 for (
const auto& s : m_nonReactiveStateChange) {
228 photonState[s.first] += a_numReactions * s.second;
231 CH_assert(a_state.isValidState());
234 template <
typename State,
typename T>
238 const auto& reactiveState = a_state.getReactiveState();
239 const auto& photonState = a_state.getNonReactiveState();
241 for (
const auto& idx : m_lhsReactives) {
242 CH_assert(reactiveState.size() > idx);
245 for (
const auto& idx : m_rhsReactives) {
246 CH_assert(reactiveState.size() > idx);
249 for (
const auto& idx : m_rhsNonReactives) {
250 CH_assert(photonState.size() > idx);
254 #include <CD_NamespaceFooter.H>
Declaration of a simple plasma reaction type for Kinetic Monte Carlo.
T getStateChange(const size_t a_reactant) const noexcept
Get the state change due to a change in the input reactant.
Definition: CD_KMCDualStateReactionImplem.H:200
void sanityCheck(const State &a_state) const noexcept
Debugging function which ensures that the class data holders do not reach out of the incoming state.
Definition: CD_KMCDualStateReactionImplem.H:236
void computeStateChanges() noexcept
Compute state change.
Definition: CD_KMCDualStateReactionImplem.H:41
std::list< size_t > getNonReactiveProducts() const noexcept
Get the non-reactive products from the reaction.
Definition: CD_KMCDualStateReactionImplem.H:193
T population(const size_t &a_reactant, const State &a_state) const noexcept
Get the population of the reactant in the input state.
Definition: CD_KMCDualStateReactionImplem.H:122
KMCDualStateReaction()=default
Disallowed constructor. Use the full constructor.
virtual ~KMCDualStateReaction()
Destructor.
Definition: CD_KMCDualStateReactionImplem.H:36
std::list< size_t > getReactiveProducts() const noexcept
Get the products from the reaction.
Definition: CD_KMCDualStateReactionImplem.H:186
Real propensity(const State &a_state) const noexcept
Compute the propensity function for this reaction type.
Definition: CD_KMCDualStateReactionImplem.H:133
T computeCriticalNumberOfReactions(const State &a_state) const noexcept
Compute the number of times the reaction can fire before exhausting one of the reactants.
Definition: CD_KMCDualStateReactionImplem.H:154
std::list< size_t > getReactants() const noexcept
Get the reactants in the reaction.
Definition: CD_KMCDualStateReactionImplem.H:179
Real & rate() const noexcept
Get modifiable reaction rate.
Definition: CD_KMCDualStateReactionImplem.H:115
void advanceState(State &a_state, const T &a_numReactions) const noexcept
Advance the incoming state with the number of reactions.
Definition: CD_KMCDualStateReactionImplem.H:213
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