19template <
class RateType,
class DataType>
28 virtual std::string
type()
override {
31 "Cannot determine type of empty rate handler.");
38 m_rxn_rates.emplace_back(rxn_index,
dynamic_cast<RateType&
>(rate));
45 "Invalid operation: cannot replace rate object "
46 "in empty rate handler.");
50 "Invalid operation: cannot replace rate object of type '{}' "
51 "with a new rate of type '{}'.",
type(), rate.
type());
54 if (m_indices.find(rxn_index) != m_indices.end()) {
55 size_t j = m_indices[rxn_index];
56 m_rxn_rates.at(j).second =
dynamic_cast<RateType&
>(rate);
62 virtual void resize(
size_t nSpecies,
size_t nReactions,
size_t nPhases)
override {
63 m_shared.resize(nSpecies, nReactions, nPhases);
69 kf[rxn.first] = rxn.second.evalFromStruct(
m_shared);
75 double deltaT)
override
84 double deltaP)
override
94 bool overwrite=
true)
override
106 virtual void update(
double T,
double extra)
override {
117 bool changed =
m_shared.update(phase, kin);
127 RateType& R =
static_cast<RateType&
>(rate);
135 template <
typename T=RateType,
136 typename std::enable_if<has_update<T>::value,
bool>
::type =
true>
139 rxn.second.updateFromStruct(
m_shared);
145 template <
typename T=RateType,
146 typename std::enable_if<!has_update<T>::value,
bool>
::type =
true>
151 template <
typename T=RateType,
152 typename std::enable_if<has_update<T>::value,
bool>
::type =
true>
159 template <
typename T=RateType,
160 typename std::enable_if<!has_update<T>::value,
bool>
::type =
true>
166 template <
typename T=RateType,
167 typename std::enable_if<has_ddT<T>::value,
bool>
::type =
true>
170 rop[rxn.first] *= rxn.second.ddTScaledFromStruct(
m_shared);
175 template <
typename T=RateType,
176 typename std::enable_if<!has_ddT<T>::value,
bool>
::type =
true>
180 double dTinv = 1. / (
m_shared.temperature * deltaT);
181 m_shared.perturbTemperature(deltaT);
186 if (kf[rxn.first] != 0.) {
187 double k1 = rxn.second.evalFromStruct(
m_shared);
188 rop[rxn.first] *= dTinv * (k1 / kf[rxn.first] - 1.);
199 template <
typename T=RateType,
typename D=DataType,
200 typename std::enable_if<has_ddM<D>::value,
bool>
::type =
true>
201 void _process_ddM(
double* rop,
const double* kf,
double deltaM,
bool overwrite) {
202 double dMinv = 1. / deltaM;
203 m_shared.perturbThirdBodies(deltaM);
207 if (kf[rxn.first] != 0. &&
m_shared.conc_3b[rxn.first] > 0.) {
208 double k1 = rxn.second.evalFromStruct(
m_shared);
209 rop[rxn.first] *= dMinv * (k1 / kf[rxn.first] - 1.);
210 rop[rxn.first] /=
m_shared.conc_3b[rxn.first];
222 template <
typename T=RateType,
typename D=DataType,
223 typename std::enable_if<!has_ddM<D>::value,
bool>
::type =
true>
224 void _process_ddM(
double* rop,
const double* kf,
double deltaM,
bool overwrite) {
236 template <
typename T=RateType,
typename D=DataType,
237 typename std::enable_if<has_ddP<D>::value,
bool>
::type =
true>
239 double dPinv = 1. / (
m_shared.pressure * deltaP);
244 if (kf[rxn.first] != 0.) {
245 double k1 = rxn.second.evalFromStruct(
m_shared);
246 rop[rxn.first] *= dPinv * (k1 / kf[rxn.first] - 1.);
256 template <
typename T=RateType,
typename D=DataType,
257 typename std::enable_if<!has_ddP<D>::value,
bool>
::type =
true>
266 std::map<size_t, size_t> m_indices;
Base class for exceptions thrown by Cantera classes.
Public interface for kinetics managers.
An abstract base class for evaluating all reactions of a particular type.
A class template handling ReactionRate specializations.
virtual bool update(const ThermoPhase &phase, const Kinetics &kin) override
Update data common to reaction rates of a specific type.
std::vector< std::pair< size_t, RateType > > m_rxn_rates
Vector of pairs of reaction rates indices and reaction rates.
virtual void processRateConstants_ddP(double *rop, const double *kf, double deltaP) override
Evaluate all rate constant pressure derivatives handled by the evaluator; which are multiplied with t...
virtual void resize(size_t nSpecies, size_t nReactions, size_t nPhases) override
Update number of species and reactions.
virtual bool replace(size_t rxn_index, ReactionRate &rate) override
Replace reaction rate object handled by the evaluator.
virtual void processRateConstants_ddM(double *rop, const double *kf, double deltaM, bool overwrite=true) override
Evaluate all rate constant third-body derivatives handled by the evaluator; which are multiplied with...
virtual void getRateConstants(double *kf) override
Evaluate all rate constants handled by the evaluator.
void _process_ddT(double *rop, const double *kf, double deltaT)
Helper function to process temperature derivatives for rate types that implement the ddTScaledFromStr...
virtual void update(double T) override
Update common reaction rate data based on temperature.
virtual std::string type() override
Identifier of reaction rate type.
virtual double evalSingle(ReactionRate &rate) override
Get the rate for a single reaction.
void _process_ddP(double *rop, const double *kf, double deltaP)
Helper function to process pressure derivatives for rate data that implement the perturbPressure meth...
void _update()
Helper function to process updates for rate types that implement the updateFromStruct method.
void _updateRate(RateType &rate)
Helper function to update a single rate that has an updateFromStruct method`.
virtual void update(double T, const vector_fp &extra) override
Update common reaction rate data based on temperature and extra parameter.
void _process_ddM(double *rop, const double *kf, double deltaM, bool overwrite)
Helper function to process third-body derivatives for rate data that implement the perturbThirdBodies...
DataType m_shared
Mapping of indices.
virtual void processRateConstants_ddT(double *rop, const double *kf, double deltaT) override
Evaluate all rate constant temperature derivatives handled by the evaluator; which are multiplied wit...
virtual void add(size_t rxn_index, ReactionRate &rate) override
Add reaction rate object to the evaluator.
virtual void update(double T, double extra) override
Update common reaction rate data based on temperature and extra parameter.
Abstract base class for reaction rate definitions; this base class is used by user-facing APIs to acc...
virtual const std::string type() const =0
String identifying reaction rate specialization.
Base class for a phase with thermodynamic properties.
Namespace for the Cantera kernel.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
#define CT_DEFINE_HAS_MEMBER(detector_name, func_name)
A macro for generating member function detectors, which can then be used in combination with std::ena...