13#ifndef CD_KMCDUALSTATEREACTIONIMPLEM_H
14#define CD_KMCDUALSTATEREACTIONIMPLEM_H
24#include <CD_NamespaceHeader.H>
26template <
typename State,
typename T>
31 CH_TIME(
"KMCDualStateReaction::KMCDualStateReaction");
39 this->computeStateChanges();
42template <
typename State,
typename T>
45 CH_TIME(
"KMCDualStateReaction::~KMCDualStateReaction");
48template <
typename State,
typename T>
52 CH_TIME(
"KMCDualStateReaction::computeStateChanges");
55 for (
const auto&
r : m_lhsReactives) {
56 if (m_reactiveStateChange.find(
r) == m_reactiveStateChange.end()) {
57 m_reactiveStateChange.emplace(
r, -1);
60 m_reactiveStateChange[
r]--;
65 for (
const auto& p : m_rhsReactives) {
66 if (m_reactiveStateChange.find(p) == m_reactiveStateChange.end()) {
67 m_reactiveStateChange.emplace(p, +1);
70 m_reactiveStateChange[p]++;
75 for (
const auto& p : m_rhsNonReactives) {
76 if (m_nonReactiveStateChange.find(p) == m_nonReactiveStateChange.end()) {
77 m_nonReactiveStateChange.emplace(p, +1);
80 m_nonReactiveStateChange[p]++;
97 m_propensityFactor = 1.0;
100 for (
const auto&
r : m_lhsReactives) {
110 auto factorial = [](
const T&
N) ->
T {
112 for (
T i = 2;
i <=
N;
i++) {
120 m_propensityFactor *= 1.0 / factorial(
rn.second);
124template <
typename State,
typename T>
131template <
typename State,
typename T>
135 CH_TIME(
"KMCDualStateReaction::population");
144template <
typename State,
typename T>
148 CH_TIME(
"KMCDualStateReaction::propensity");
153 Real A = m_rate * m_propensityFactor;
157 for (
const auto&
r : m_lhsReactives) {
166template <
typename State,
typename T>
170 CH_TIME(
"KMCDualStateReaction::computeCriticalNumberOfReactions");
176 T Lj = std::numeric_limits<T>::max();
180 for (
const auto&
s : m_reactiveStateChange) {
182 const size_t rI =
s.first;
193template <
typename State,
typename T>
197 return m_lhsReactives;
200template <
typename State,
typename T>
204 return m_rhsReactives;
207template <
typename State,
typename T>
211 return m_rhsNonReactives;
214template <
typename State,
typename T>
218 CH_TIME(
"KMCDualStateReaction::getStateChange");
229template <
typename State,
typename T>
233 CH_TIME(
"KMCDualStateReaction::advanceState");
243 for (
const auto&
s : m_reactiveStateChange) {
247 for (
const auto&
s : m_nonReactiveStateChange) {
254template <
typename State,
typename T>
258 CH_TIME(
"KMCDualStateReaction::sanityCheck");
263 for (
const auto&
idx : m_lhsReactives) {
267 for (
const auto&
idx : m_rhsReactives) {
271 for (
const auto&
idx : m_rhsNonReactives) {
276#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:216
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:256
void computeStateChanges() noexcept
Compute state change vectors from the reactant/product lists.
Definition CD_KMCDualStateReactionImplem.H:50
std::list< size_t > getNonReactiveProducts() const noexcept
Get the non-reactive products from the reaction.
Definition CD_KMCDualStateReactionImplem.H:209
KMCDualStateReaction()=default
Default constructor.
virtual ~KMCDualStateReaction()
Destructor.
Definition CD_KMCDualStateReactionImplem.H:43
std::list< size_t > getReactiveProducts() const noexcept
Get the products from the reaction.
Definition CD_KMCDualStateReactionImplem.H:202
Real propensity(const State &a_state) const noexcept
Compute the propensity function for this reaction type.
Definition CD_KMCDualStateReactionImplem.H:146
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:168
std::list< size_t > getReactants() const noexcept
Get the reactants in the reaction.
Definition CD_KMCDualStateReactionImplem.H:195
Real & rate() const noexcept
Get modifiable reaction rate.
Definition CD_KMCDualStateReactionImplem.H:126
void advanceState(State &a_state, const T &a_numReactions) const noexcept
Advance the incoming state with the number of reactions.
Definition CD_KMCDualStateReactionImplem.H:231
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:133
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:38
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:26