|
chombo-discharge
|
Class for running Kinetic Monte-Carlo simulations. More...
#include <CD_KMCSolver.H>
Public Types | |
| using | ReactionList = std::vector< std::shared_ptr< const R > > |
| Alias for the list of reactions. | |
Public Member Functions | |
| KMCSolver () noexcept | |
| Default constructor. Must subsequently call define. | |
| KMCSolver (const KMCSolver &)=default | |
| Copy constructor. | |
| KMCSolver (const KMCSolver &&)=delete | |
| Disallowed move constructor. | |
| KMCSolver (const ReactionList &a_reactions) noexcept | |
| Full constructor. | |
| virtual | ~KMCSolver () noexcept |
| Destructor. | |
| KMCSolver & | operator= (const KMCSolver &a_other)=default |
| Copy assignment operator. | |
| KMCSolver & | operator= (const KMCSolver &&)=delete |
| Disallowed move assignment operator. | |
| void | define (const ReactionList &a_reactions) noexcept |
| Define function. Sets the reactions. | |
| void | setSolverParameters (T a_numCrit, T a_numSSA, T a_maxIter, Real a_eps, Real a_SSAlim, Real a_exitTol) noexcept |
| Set solver parameters. | |
| std::vector< std::vector< T > > | getNu (const State &a_state, const ReactionList &a_reactions) const noexcept |
| Compute the state vector changes for all reactions. | |
| std::vector< Real > | propensities (const State &a_state) const noexcept |
| Compute propensities for ALL reactions. | |
| std::vector< Real > | propensities (const State &a_state, const ReactionList &a_reactions) const noexcept |
| Compute propensities for a subset of reactions. | |
| Real | totalPropensity (const State &a_state) const noexcept |
| Compute the total propensity for ALL reactions. | |
| Real | totalPropensity (const State &a_state, const ReactionList &a_reactions) const noexcept |
| Compute the total propensity for a subset of reactions. | |
| std::pair< ReactionList, ReactionList > | partitionReactions (const State &a_state) const noexcept |
| Partition reactions into critical and non-critical reactions. | |
| std::pair< ReactionList, ReactionList > | partitionReactions (const State &a_state, const ReactionList &a_reactions) const noexcept |
| Partition reactions into critical and non-critical reactions. | |
| Real | getCriticalTimeStep (const State &a_state) const noexcept |
| Get the time to the next critical reaction. | |
| Real | getCriticalTimeStep (const State &a_state, const ReactionList &a_criticalReactions) const noexcept |
| Get the time to the next critical reaction. | |
| Real | getCriticalTimeStep (const std::vector< Real > &a_propensities) const noexcept |
| Get the time to the next critical reaction. | |
| Real | getCriticalTimeStep (const Real &a_totalPropensity) const noexcept |
| Get the time to the next critical reaction. | |
| Real | getNonCriticalTimeStep (const State &a_state) const noexcept |
| Get the non-critical time step. | |
| Real | getNonCriticalTimeStep (const State &a_state, const ReactionList &a_reactions) const noexcept |
| Get the non-critical time step. | |
| Real | getNonCriticalTimeStep (const State &a_state, const ReactionList &a_nonCriticalReactions, const std::vector< Real > &a_nonCriticalPropensities) const noexcept |
| Get the non-critical time step. | |
| 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. | |
| void | stepSSA (State &a_state) const noexcept |
| Perform a single SSA step. | |
| void | stepSSA (State &a_state, const ReactionList &a_reactions) const noexcept |
| Perform a single SSA step. | |
| void | stepSSA (State &a_state, const ReactionList &a_reactions, const std::vector< Real > &a_propensities) const noexcept |
| Perform a single SSA step with pre-computed propensities. | |
| void | advanceSSA (State &a_state, Real a_dt) const noexcept |
| Advance with the SSA over the input time. This can end up using substepping. | |
| void | advanceSSA (State &a_state, const ReactionList &a_reactions, Real a_dt) const noexcept |
| Advance with the SSA over the input time. This can end up using substepping. | |
| void | stepExplicitEuler (State &a_state, Real a_dt) const noexcept |
| Perform one plain tau-leaping step using ALL reactions. | |
| void | stepExplicitEuler (State &a_state, const ReactionList &a_reactions, Real a_dt) const noexcept |
| Perform one plain tau-leaping step over the input reactions. | |
| void | stepMidpoint (State &a_state, Real a_dt) const noexcept |
| Perform one leaping step using the midpoint method for ALL reactions. | |
| void | stepMidpoint (State &a_state, const ReactionList &a_reactions, Real a_dt) const noexcept |
| Perform one leaping step using the midpoint method for the input reactions. | |
| void | stepPRC (State &a_state, Real a_dt) const noexcept |
| Perform one leaping step using the PRC method for ALL reactions. | |
| void | stepPRC (State &a_state, const ReactionList &a_reactions, Real a_dt) const noexcept |
| Perform one leaping step using the PRC method for the input reactions. | |
| void | stepImplicitEuler (State &a_state, Real a_dt) const noexcept |
| Perform one implicit Euler tau-leaping step using ALL reactions. | |
| void | stepImplicitEuler (State &a_state, const ReactionList &a_reactions, Real a_dt) const noexcept |
| Perform one implicit Euler tau-leaping step over the input reactions. | |
| void | advanceTau (State &a_state, const Real &a_dt, const KMCLeapPropagator &a_leapPropagator=KMCLeapPropagator::ExplicitEuler) const noexcept |
| Advance using a specified tau-leaping algorithm. | |
| void | advanceTau (State &a_state, const ReactionList &a_reactions, const Real &a_dt, const KMCLeapPropagator &a_leapPropagator=KMCLeapPropagator::ExplicitEuler) const noexcept |
| Advance using a specified tau-leaping algorithm. | |
| 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. | |
| void | advanceHybrid (State &a_state, const ReactionList &a_reactions, 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. | |
| void | advanceHybrid (State &a_state, const ReactionList &a_reactions, Real a_dt, const std::function< void(State &, const ReactionList &a_reactions, const Real a_dt)> &a_propagator) const noexcept |
| Advance using Cao et. al. hybrid algorithm over the input time. This can end up using substepping. | |
Protected Member Functions | |
| void | gatherDistinctReactants (const ReactionList &a_reactions) const noexcept |
| Fill m_reactantScratch with the distinct reactants of the input reactions. | |
Protected Attributes | |
| ReactionList | m_reactions |
| List of reactions used when advancing states. | |
| T | m_Ncrit |
| Definition of critical reactions. | |
| T | m_numSSA |
| Maximum number of SSA steps to run when switching into SSA-based advancement for non-critical reactions. | |
| T | m_maxIter |
| Maximum number of iterations for implicit solvers. | |
| Real | m_eps |
| Maximum permitted change in propensities for non-critical reactions. | |
| Real | m_SSAlim |
| Threshold for switching to SSA-based algorithm within the Cao algorithm. | |
| Real | m_exitTol |
| Exit tolerance for implicit solvers. | |
| std::vector< std::vector< int > > | m_nu |
| List of state changes for each reaction. | |
| std::vector< Real > | m_muScratch |
| Scratch accumulator for the per-reactant expected state change, indexed by species. | |
| std::vector< Real > | m_sigmaScratch |
| Scratch accumulator for the per-reactant propensity variance, indexed by species. | |
| std::vector< size_t > | m_reactantScratch |
| Scratch holding the distinct reactants of the reaction list currently being processed. | |
| std::vector< char > | m_seenScratch |
| Membership stamps used to build m_reactantScratch without sorting, indexed by species. | |
Class for running Kinetic Monte-Carlo simulations.
The template parameter State is the underlying state type that KMC operators on. There are rather simple required member functions on the State parameter, but the reaction type (template parameter R) MUST be able to operate on the state through the following functions:
The template parameter T should agree across both R, State, and KMCSolver. Note that this must be a signed integer type.
|
inlinenoexcept |
Full constructor.
| [in] | a_reactions | List of reactions. |
|
inlinenoexcept |
Advance using Cao et. al. hybrid algorithm over the input time. This can end up using substepping.
| [in,out] | a_state | State vector to advance. |
| [in] | a_reactions | Reactions to advance. |
| [in] | a_dt | Time increment. |
| [in] | a_leapPropagator | Which leap propagator to use. |
|
inlinenoexcept |
Advance using Cao et. al. hybrid algorithm over the input time. This can end up using substepping.
| [in,out] | a_state | State vector to advance. |
| [in] | a_reactions | Reactions to advance with. |
| [in] | a_dt | Time increment. |
| [in] | a_propagator | Leaping propagator function. |
|
inlinenoexcept |
Advance using Cao et. al. hybrid algorithm over the input time. This can end up using substepping.
| [in,out] | a_state | State vector to advance. |
| [in] | a_dt | Time increment. |
| [in] | a_leapPropagator | Which leap propagator to use. |
|
inlinenoexcept |
Advance with the SSA over the input time. This can end up using substepping.
| [in,out] | a_state | State vector to advance. |
| [in] | a_reactions | Reactions to advance with. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Advance with the SSA over the input time. This can end up using substepping.
| [in,out] | a_state | State vector to advance. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Advance using a specified tau-leaping algorithm.
The interval a_dt is substepped, each substep being bounded by the tau-leaping condition tau = eps * X_i / |sum_j nu_ij * a_j| so that the accuracy of the leap is controlled by m_eps. Substeps that produce an invalid state are rejected and retried with half the time step.
| [in,out] | a_state | State vector to advance. |
| [in] | a_reactions | Reactions to advance. |
| [in] | a_dt | Time increment. |
| [in] | a_leapPropagator | Which leap propagator to use. |
|
inlinenoexcept |
Advance using a specified tau-leaping algorithm.
| [in,out] | a_state | State vector to advance. |
| [in] | a_dt | Time increment. |
| [in] | a_leapPropagator | Which leap propagator to use. |
|
inlinenoexcept |
Compute a time step using the leap condition on the mean value.
This is just like getNonCriticalTimeStep EXCEPT that the leap condition is not applied for the deviation.
| [in] | a_state | State vector. |
| [in] | a_reactions | Reactions. |
| [in] | a_propensities | Propensities. |
| [in] | a_epsilon | Epsilon value for maximum change in propensities. |
|
inlinenoexcept |
Define function. Sets the reactions.
| [in] | a_reactions | List of reactions. |
|
inlineprotectednoexcept |
Fill m_reactantScratch with the distinct reactants of the input reactions.
Replaces concatenating the reactions' reactant lists and then sorting and uniquing them. The distinct set is the same; only the order differs, and both callers use it purely as a set to reduce over. The scratch buffers are sized from the largest reactant index seen, which keeps the routine independent of the State type's interface.
| [in] | a_reactions | Reactions whose reactants are collected. |
|
inlinenoexcept |
Get the time to the next critical reaction.
| [in] | a_totalPropensity | Total propensity. |
|
inlinenoexcept |
Get the time to the next critical reaction.
| [in] | a_state | State vector. |
|
inlinenoexcept |
Get the time to the next critical reaction.
| [in] | a_state | State vector. |
| [in] | a_criticalReactions | Reaction list. |
|
inlinenoexcept |
Get the time to the next critical reaction.
| [in] | a_propensities | Reaction propensities. |
|
inlinenoexcept |
Get the non-critical time step.
| [in] | a_state | State vector. |
|
inlinenoexcept |
Get the non-critical time step.
| [in] | a_state | State vector. |
| [in] | a_nonCriticalReactions | Non-critical reactions. |
| [in] | a_nonCriticalPropensities | Non-critical propensities. |
|
inlinenoexcept |
Get the non-critical time step.
| [in] | a_state | State vector. |
| [in] | a_reactions | Reaction list. |
|
inlinenoexcept |
Compute the state vector changes for all reactions.
| [in] | a_state | Input state. |
| [in] | a_reactions | Reaction list. |
|
default |
Copy assignment operator.
| [in] | a_other | Other solver. |
|
inlinenoexcept |
Partition reactions into critical and non-critical reactions.
First member in the pair is the critical reactions, then the non-critical reactions.
| [in] | a_state | State vector. |
|
inlinenoexcept |
Partition reactions into critical and non-critical reactions.
First member in the pair is the critical reactions, then the non-critical reactions.
| [in] | a_state | State vector. |
| [in] | a_reactions | Reaction list to be partitioned. |
|
inlinenoexcept |
Compute propensities for ALL reactions.
| [in] | a_state | State vector. |
|
inlinenoexcept |
Compute propensities for a subset of reactions.
| [in] | a_state | State vector. |
| [in] | a_reactions | Reaction list. |
|
inlinenoexcept |
Set solver parameters.
| [in] | a_numCrit | Determines critical reactions. This is the number of reactions that need to fire before depleting a reactant. |
| [in] | a_numSSA | Maximum number of SSA steps to run when switching from tau-leaping to SSA (hybrid algorithm only). |
| [in] | a_maxIter | Maximum permitted number of iterations for the implicit solver. |
| [in] | a_eps | Maximum permitted change in propensities when performing tau-leaping for non-critical reactions. |
| [in] | a_SSAlim | Threshold for switching from tau-leaping of non-critical reactions to SSA for all reactions (hybrid algorithm only). |
| [in] | a_exitTol | Exit tolerance for implicit solvers. |
|
inlinenoexcept |
Perform one plain tau-leaping step over the input reactions.
| [in,out] | a_state | State vector to be advanced. |
| [in] | a_reactions | List of reactions to advance with. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Perform one plain tau-leaping step using ALL reactions.
| [in,out] | a_state | State vector to be advanced. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Perform one implicit Euler tau-leaping step over the input reactions.
| [in,out] | a_state | State vector to be advanced. |
| [in] | a_reactions | List of reactions to advance with. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Perform one implicit Euler tau-leaping step using ALL reactions.
| [in,out] | a_state | State vector to be advanced. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Perform one leaping step using the midpoint method for the input reactions.
| [in,out] | a_state | State vector to be advanced. |
| [in] | a_reactions | List of reactions to advance with. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Perform one leaping step using the midpoint method for ALL reactions.
| [in,out] | a_state | State vector to be advanced. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Perform one leaping step using the PRC method for the input reactions.
| [in,out] | a_state | State vector to be advanced. |
| [in] | a_reactions | List of reactions to advance with. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Perform one leaping step using the PRC method for ALL reactions.
| [in,out] | a_state | State vector to be advanced. |
| [in] | a_dt | Time increment. |
|
inlinenoexcept |
Perform a single SSA step.
| [in,out] | a_state | State vector to advance. |
|
inlinenoexcept |
Perform a single SSA step.
| [in,out] | a_state | State vector to advance. |
| [in] | a_reactions | Reactions to advance with. |
|
inlinenoexcept |
Perform a single SSA step with pre-computed propensities.
| [in,out] | a_state | State vector to advance. |
| [in] | a_reactions | Reactions to advance with. |
| [in] | a_propensities | Propensities for the reactions. |
|
inlinenoexcept |
Compute the total propensity for ALL reactions.
| [in] | a_state | State vector. |
|
inlinenoexcept |
Compute the total propensity for a subset of reactions.
| [in] | a_state | State vector. |
| [in] | a_reactions | Reaction list. |
|
mutableprotected |
Scratch accumulator for the per-reactant expected state change, indexed by species.
Used by computeDt and getNonCriticalTimeStep, which run once per grid cell (and, in the ItoKMC time step tail, once per reaction per grid cell). Holding the buffer on the solver keeps those calls free of heap traffic; previously they allocated a std::list node per reactant per reaction and then sorted it.
|
protected |
Definition of critical reactions.
A reaction is critical if it is m_Ncrit firings away from depleting a reactant.
|
protected |
List of state changes for each reaction.
The outer vector corresponds to the reactive index. The inner vector describes the change in the population of the state vector, with an indexing given by the State's linearIn/linearOut functions.
|
mutableprotected |
Scratch holding the distinct reactants of the reaction list currently being processed.
Replaces the sorted, uniqued std::list the two time step routines used to rebuild on every call. Same reentrancy caveat.
|
mutableprotected |
Membership stamps used to build m_reactantScratch without sorting, indexed by species.
Entry i is set when species i has already been added to m_reactantScratch for the call in progress, and is cleared again before the call returns. Same reentrancy caveat.
|
mutableprotected |
Scratch accumulator for the per-reactant propensity variance, indexed by species.
Companion to m_muScratch, needed only by getNonCriticalTimeStep. Same reentrancy caveat.