12#ifndef CD_KMCDualStateReactionImplem_H
13#define CD_KMCDualStateReactionImplem_H
23#include <CD_NamespaceHeader.H>
25template <
typename State,
typename T>
30 CH_TIME(
"KMCDualStateReaction::KMCDualStateReaction");
38 this->computeStateChanges();
41template <
typename State,
typename T>
44 CH_TIME(
"KMCDualStateReaction::~KMCDualStateReaction");
47template <
typename State,
typename T>
51 CH_TIME(
"KMCDualStateReaction::computeStateChanges");
54 for (
const auto&
r : m_lhsReactives) {
55 if (m_reactiveStateChange.find(
r) == m_reactiveStateChange.end()) {
56 m_reactiveStateChange.emplace(
r, -1);
59 m_reactiveStateChange[
r]--;
64 for (
const auto& p : m_rhsReactives) {
65 if (m_reactiveStateChange.find(p) == m_reactiveStateChange.end()) {
66 m_reactiveStateChange.emplace(p, +1);
69 m_reactiveStateChange[p]++;
74 for (
const auto& p : m_rhsNonReactives) {
75 if (m_nonReactiveStateChange.find(p) == m_nonReactiveStateChange.end()) {
76 m_nonReactiveStateChange.emplace(p, +1);
79 m_nonReactiveStateChange[p]++;
96 m_propensityFactor = 1.0;
99 for (
const auto&
r : m_lhsReactives) {
109 auto factorial = [](
const T&
N) -> T {
111 for (T
i = 2;
i <=
N;
i++) {
119 m_propensityFactor *= 1.0 / factorial(
rn.second);
123template <
typename State,
typename T>
130template <
typename State,
typename T>
134 CH_TIME(
"KMCDualStateReaction::population");
143template <
typename State,
typename T>
147 CH_TIME(
"KMCDualStateReaction::propensity");
152 Real A = m_rate * m_propensityFactor;
156 for (
const auto&
r : m_lhsReactives) {
165template <
typename State,
typename T>
169 CH_TIME(
"KMCDualStateReaction::computeCriticalNumberOfReactions");
175 T
Lj = std::numeric_limits<T>::max();
179 for (
const auto&
s : m_reactiveStateChange) {
181 const size_t rI =
s.first;
182 const T
nuIJ =
s.second;
192template <
typename State,
typename T>
196 return m_lhsReactives;
199template <
typename State,
typename T>
203 return m_rhsReactives;
206template <
typename State,
typename T>
210 return m_rhsNonReactives;
213template <
typename State,
typename T>
217 CH_TIME(
"KMCDualStateReaction::getStateChange");
228template <
typename State,
typename T>
232 CH_TIME(
"KMCDualStateReaction::advanceState");
242 for (
const auto&
s : m_reactiveStateChange) {
246 for (
const auto&
s : m_nonReactiveStateChange) {
253template <
typename State,
typename T>
257 CH_TIME(
"KMCDualStateReaction::sanityCheck");
262 for (
const auto&
idx : m_lhsReactives) {
266 for (
const auto&
idx : m_rhsReactives) {
270 for (
const auto&
idx : m_rhsNonReactives) {
275#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:215
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:255
void computeStateChanges() noexcept
Compute state change.
Definition CD_KMCDualStateReactionImplem.H:49
std::list< size_t > getNonReactiveProducts() const noexcept
Get the non-reactive products from the reaction.
Definition CD_KMCDualStateReactionImplem.H:208
KMCDualStateReaction()=default
Disallowed constructor. Use the full constructor.
virtual ~KMCDualStateReaction()
Destructor.
Definition CD_KMCDualStateReactionImplem.H:42
std::list< size_t > getReactiveProducts() const noexcept
Get the products from the reaction.
Definition CD_KMCDualStateReactionImplem.H:201
Real propensity(const State &a_state) const noexcept
Compute the propensity function for this reaction type.
Definition CD_KMCDualStateReactionImplem.H:145
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:167
std::list< size_t > getReactants() const noexcept
Get the reactants in the reaction.
Definition CD_KMCDualStateReactionImplem.H:194
Real & rate() const noexcept
Get modifiable reaction rate.
Definition CD_KMCDualStateReactionImplem.H:125
void advanceState(State &a_state, const T &a_numReactions) const noexcept
Advance the incoming state with the number of reactions.
Definition CD_KMCDualStateReactionImplem.H:230
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:132
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:37
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:25