13#ifndef CD_KMCDUALSTATEREACTIONIMPLEM_H
14#define CD_KMCDUALSTATEREACTIONIMPLEM_H
24#include <CD_NamespaceHeader.H>
26template <
typename State,
typename T>
28 const std::list<size_t>& a_rhsReactives,
29 const std::list<size_t>& a_rhsNonReactives)
noexcept
35 CH_assert(a_lhsReactives.size() > 0);
40template <
typename State,
typename T>
44template <
typename State,
typename T>
94 std::map<size_t, size_t> reactantNumbers;
96 if (reactantNumbers.find(r) == reactantNumbers.end()) {
97 reactantNumbers.emplace(r, 1);
100 reactantNumbers[r]++;
105 auto factorial = [](
const T& N) -> T {
107 for (T i = 2; i <= N; i++) {
114 for (
const auto& rn : reactantNumbers) {
123 for (
const auto& rn : reactantNumbers) {
143template <
typename State,
typename T>
150template <
typename State,
typename T>
154 const auto& reactiveState = a_state.getReactiveState();
156 CH_assert(reactiveState.size() > a_reactant);
158 return reactiveState[a_reactant];
161template <
typename State,
typename T>
171 const auto& reactiveState = a_state.getReactiveState();
178 T X = reactiveState[lhs.first];
180 for (
size_t k = 0; k < lhs.second; k++) {
190template <
typename State,
typename T>
198 T Lj = std::numeric_limits<T>::max();
200 const auto& reactiveState = a_state.getReactiveState();
204 const size_t rI = s.first;
205 const T nuIJ = s.second;
208 Lj = std::min(Lj, reactiveState[rI] / std::abs(nuIJ));
215template <
typename State,
typename T>
216inline const std::list<size_t>&
222template <
typename State,
typename T>
223inline const std::list<size_t>&
229template <
typename State,
typename T>
230inline const std::list<size_t>&
236template <
typename State,
typename T>
251template <
typename State,
typename T>
258 CH_assert(a_state.isValidState());
260 auto& reactiveState = a_state.getReactiveState();
261 auto& photonState = a_state.getNonReactiveState();
264 reactiveState[s.first] += a_numReactions * s.second;
268 photonState[s.first] += a_numReactions * s.second;
271 CH_assert(a_state.isValidState());
274template <
typename State,
typename T>
278 const auto& reactiveState = a_state.getReactiveState();
279 const auto& photonState = a_state.getNonReactiveState();
282 CH_assert(reactiveState.size() > idx);
286 CH_assert(reactiveState.size() > idx);
290 CH_assert(photonState.size() > idx);
294#include <CD_NamespaceFooter.H>
Declaration of a simple plasma reaction type for Kinetic Monte Carlo.
const std::list< size_t > & getReactiveProducts() const noexcept
Get the products from the reaction.
Definition CD_KMCDualStateReactionImplem.H:224
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:238
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:276
void computeStateChanges() noexcept
Compute state change vectors from the reactant/product lists.
Definition CD_KMCDualStateReactionImplem.H:46
std::list< size_t > m_lhsReactives
Reactive species (left-hand side).
Definition CD_KMCDualStateReaction.H:156
std::map< size_t, T > m_reactiveStateChange
State change for reactants/products.
Definition CD_KMCDualStateReaction.H:171
KMCDualStateReaction()=default
Default constructor.
virtual ~KMCDualStateReaction()
Destructor.
Definition CD_KMCDualStateReactionImplem.H:41
Real propensity(const State &a_state) const noexcept
Compute the propensity function for this reaction type.
Definition CD_KMCDualStateReactionImplem.H:163
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:192
std::list< size_t > m_rhsReactives
Product species (right-hand side reactive).
Definition CD_KMCDualStateReaction.H:161
std::map< size_t, T > m_nonReactiveStateChange
State change for non-reactive products.
Definition CD_KMCDualStateReaction.H:197
Real & rate() const noexcept
Get modifiable reaction rate.
Definition CD_KMCDualStateReactionImplem.H:145
void advanceState(State &a_state, const T &a_numReactions) const noexcept
Advance the incoming state with the number of reactions.
Definition CD_KMCDualStateReactionImplem.H:253
std::vector< std::pair< size_t, size_t > > m_lhsOrders
Reactants of the left-hand side, compacted to (species, order) pairs.
Definition CD_KMCDualStateReaction.H:192
std::vector< T > m_reactiveStateChangeDense
Dense form of m_reactiveStateChange, indexed by reactive species.
Definition CD_KMCDualStateReaction.H:183
const std::list< size_t > & getReactants() const noexcept
Get the reactants in the reaction.
Definition CD_KMCDualStateReactionImplem.H:217
Real m_propensityFactor
Factor for the case where two or more particles of the same species react.
Definition CD_KMCDualStateReaction.H:151
std::list< size_t > m_rhsNonReactives
Non-reactive product species.
Definition CD_KMCDualStateReaction.H:166
const std::list< size_t > & getNonReactiveProducts() const noexcept
Get the non-reactive products from the reaction.
Definition CD_KMCDualStateReactionImplem.H:231
Real m_rate
Reaction rate.
Definition CD_KMCDualStateReaction.H:144
static T population(const size_t &a_reactant, const State &a_state) noexcept
Get the population of the reactant in the input state.
Definition CD_KMCDualStateReactionImplem.H:152