25#include <CD_NamespaceHeader.H>
59template <
typename R,
typename State,
typename T =
long long>
129 setSolverParameters(T a_numCrit, T a_numSSA, T a_maxIter, Real a_eps, Real a_SSAlim, Real a_exitTol) noexcept;
138 inline std::vector<std::vector<T>>
147 inline std::vector<Real>
156 inline std::vector<Real>
261 const std::vector<Real>& a_nonCriticalPropensities) const noexcept;
275 const std::vector<Real>& a_propensities,
276 Real a_epsilon) const noexcept;
284 stepSSA(State& a_state) const noexcept;
302 stepSSA(State& a_state, const
ReactionList& a_reactions, const std::vector<Real>& a_propensities) const noexcept;
311 advanceSSA(State& a_state, Real a_dt) const noexcept;
365 stepPRC(State& a_state, Real a_dt) const noexcept;
461 const std::function<
void(State&, const
ReactionList& a_reactions, const Real a_dt)>& a_propagator) const noexcept;
505 std::vector<std::vector<
int>>
m_nu;
552#include <CD_NamespaceFooter.H>
Implementation of CD_KMCSolver.H.
KMCLeapPropagator
Supported propagators for hybrid tau leaping.
Definition CD_KMCSolver.H:35
@ ImplicitEuler
Implicit Euler tau leaping.
@ Midpoint
Gillespie's midpoint method.
@ ExplicitEuler
Regular tau leaping.
@ PRC
Hu and Li's Poisson random correction method.
Class for running Kinetic Monte-Carlo simulations.
Definition CD_KMCSolver.H:61
std::vector< std::shared_ptr< const R > > ReactionList
Alias for the list of reactions.
Definition CD_KMCSolver.H:66
std::vector< size_t > m_reactantScratch
Scratch holding the distinct reactants of the reaction list currently being processed.
Definition CD_KMCSolver.H:531
Real m_eps
Maximum permitted change in propensities for non-critical reactions.
Definition CD_KMCSolver.H:488
void setSolverParameters(T a_numCrit, T a_numSSA, T a_maxIter, Real a_eps, Real a_SSAlim, Real a_exitTol) noexcept
Set solver parameters.
Definition CD_KMCSolverImplem.H:59
std::vector< Real > m_sigmaScratch
Scratch accumulator for the per-reactant propensity variance, indexed by species.
Definition CD_KMCSolver.H:524
Real computeDt(const State &a_state, const ReactionList &a_reactions, const std::vector< Real > &a_propensities, Real a_epsilon) const noexcept
Compute a time step using the leap condition on the mean value.
Definition CD_KMCSolverImplem.H:375
std::vector< std::vector< int > > m_nu
List of state changes for each reaction.
Definition CD_KMCSolver.H:505
void define(const ReactionList &a_reactions) noexcept
Define function. Sets the reactions.
Definition CD_KMCSolverImplem.H:49
KMCSolver() noexcept
Default constructor. Must subsequently call define.
Definition CD_KMCSolverImplem.H:32
std::vector< std::vector< T > > getNu(const State &a_state, const ReactionList &a_reactions) const noexcept
Compute the state vector changes for all reactions.
Definition CD_KMCSolverImplem.H:76
ReactionList m_reactions
List of reactions used when advancing states.
Definition CD_KMCSolver.H:467
Real m_exitTol
Exit tolerance for implicit solvers.
Definition CD_KMCSolver.H:498
std::vector< Real > m_muScratch
Scratch accumulator for the per-reactant expected state change, indexed by species.
Definition CD_KMCSolver.H:517
Real getCriticalTimeStep(const State &a_state) const noexcept
Get the time to the next critical reaction.
Definition CD_KMCSolverImplem.H:190
T m_maxIter
Maximum number of iterations for implicit solvers.
Definition CD_KMCSolver.H:483
void advanceSSA(State &a_state, Real a_dt) const noexcept
Advance with the SSA over the input time. This can end up using substepping.
Definition CD_KMCSolverImplem.H:502
void gatherDistinctReactants(const ReactionList &a_reactions) const noexcept
Fill m_reactantScratch with the distinct reactants of the input reactions.
Definition CD_KMCSolverImplem.H:258
T m_numSSA
Maximum number of SSA steps to run when switching into SSA-based advancement for non-critical reactio...
Definition CD_KMCSolver.H:478
T m_Ncrit
Definition of critical reactions.
Definition CD_KMCSolver.H:473
void stepImplicitEuler(State &a_state, Real a_dt) const noexcept
Perform one implicit Euler tau-leaping step using ALL reactions.
Definition CD_KMCSolverImplem.H:640
void advanceHybrid(State &a_state, Real a_dt, const KMCLeapPropagator &a_leapPropagator=KMCLeapPropagator::ExplicitEuler) const noexcept
Advance using Cao et. al. hybrid algorithm over the input time. This can end up using substepping.
Definition CD_KMCSolverImplem.H:919
void stepPRC(State &a_state, Real a_dt) const noexcept
Perform one leaping step using the PRC method for ALL reactions.
Definition CD_KMCSolverImplem.H:601
void stepMidpoint(State &a_state, Real a_dt) const noexcept
Perform one leaping step using the midpoint method for ALL reactions.
Definition CD_KMCSolverImplem.H:566
std::vector< char > m_seenScratch
Membership stamps used to build m_reactantScratch without sorting, indexed by species.
Definition CD_KMCSolver.H:538
std::pair< ReactionList, ReactionList > partitionReactions(const State &a_state) const noexcept
Partition reactions into critical and non-critical reactions.
Definition CD_KMCSolverImplem.H:153
void stepSSA(State &a_state) const noexcept
Perform a single SSA step.
Definition CD_KMCSolverImplem.H:441
void advanceTau(State &a_state, const Real &a_dt, const KMCLeapPropagator &a_leapPropagator=KMCLeapPropagator::ExplicitEuler) const noexcept
Advance using a specified tau-leaping algorithm.
Definition CD_KMCSolverImplem.H:839
Real getNonCriticalTimeStep(const State &a_state) const noexcept
Get the non-critical time step.
Definition CD_KMCSolverImplem.H:240
Real totalPropensity(const State &a_state) const noexcept
Compute the total propensity for ALL reactions.
Definition CD_KMCSolverImplem.H:131
Real m_SSAlim
Threshold for switching to SSA-based algorithm within the Cao algorithm.
Definition CD_KMCSolver.H:493
void stepExplicitEuler(State &a_state, Real a_dt) const noexcept
Perform one plain tau-leaping step using ALL reactions.
Definition CD_KMCSolverImplem.H:537
std::vector< Real > propensities(const State &a_state) const noexcept
Compute propensities for ALL reactions.
Definition CD_KMCSolverImplem.H:109