29 m_state.resize(
thermo().stateSize());
44 m_logStandConc = log(
thermo().standardConcentration());
68 bool changed = rates->update(
thermo(), *
this);
70 rates->getRateConstants(
m_rfn.data());
74 if (T != m_temp || P !=
m_pres) {
114 double logP = log(
thermo().pressure());
120 double log10P = log10(
thermo().pressure());
136 for (
size_t i = 0; i <
m_revindex.size(); i++) {
143 for (
size_t i = 0; i !=
m_irrev.size(); ++i) {
193 fill(delta_gibbs0.begin(), delta_gibbs0.end(), 0.0);
200 kc[i] = exp(-delta_gibbs0[i] * rrt +
m_dn[i] * m_logStandConc);
211 AssertFinite(pr[i],
"GasKinetics::processFalloffReactions",
212 "pr[{}] is not finite.", i);
227void GasKinetics::updateROP()
243 for (
size_t i = 0; i <
m_rfn.size(); i++) {
245 "m_rfn[{}] is not finite.", i);
247 "m_ropf[{}] is not finite.", i);
249 "m_ropr[{}] is not finite.", i);
260 "Behavior to change after Cantera 2.6;\nresults will no longer include "
261 "third-body concentrations for three-body reactions.\nTo switch to new "
262 "behavior, use 'cantera.use_legacy_rate_constants(False)' (Python),\n"
263 "'useLegacyRateConstants(0)' (MATLAB), 'Cantera::use_legacy_rate_constants"
264 "(false)' (C++),\nor 'ct_use_legacy_rate_constants(0)' (clib).");
276 settings[
"skip-falloff"] = m_jac_skip_falloff;
277 settings[
"rtol-delta"] = m_jac_rtol_delta;
282 bool force = settings.
empty();
283 if (force || settings.
hasKey(
"skip-third-bodies")) {
286 if (force || settings.
hasKey(
"skip-falloff")) {
287 m_jac_skip_falloff = settings.
getBool(
"skip-falloff",
false);
289 if (force || settings.
hasKey(
"rtol-delta")) {
290 m_jac_rtol_delta = settings.
getDouble(
"rtol-delta", 1e-8);
298 throw CanteraError(name,
"Not supported for legacy (CTI/XML) input format.");
301 if (!
thermo().isIdeal()) {
303 "Not supported for non-ideal ThermoPhase models.");
315 fill(delta_gibbs0.begin(), delta_gibbs0.end(), 0.0);
324 double Tinv = 1. / T;
325 double rrt_dTinv = rrt * Tinv / m_jac_rtol_delta;
326 double rrtt = rrt * Tinv;
327 for (
size_t i = 0; i <
m_revindex.size(); i++) {
332 drkcn[irxn] *= factor;
335 for (
size_t i = 0; i <
m_irrev.size(); ++i) {
345 copy(in.begin(), in.end(), drop);
347 rates->processRateConstants_ddT(drop,
m_rfn.data(), m_jac_rtol_delta);
370 Eigen::Map<Eigen::VectorXd> dRevRop(drop,
nReactions());
373 Eigen::Map<Eigen::VectorXd> dRevRop2(m_rbuf2.data(),
nReactions());
384 Eigen::Map<Eigen::VectorXd> dNetRop(drop,
nReactions());
387 Eigen::Map<Eigen::VectorXd> dNetRop2(m_rbuf2.data(),
nReactions());
396 copy(in.begin(), in.end(), drop);
398 rates->processRateConstants_ddP(drop,
m_rfn.data(), m_jac_rtol_delta);
432 double* drop,
bool mass_action)
434 Eigen::Map<Eigen::VectorXd> out(drop,
nReactions());
440 stoich.
scale(in.data(), out.data(), ctot_inv);
447 Eigen::Map<Eigen::VectorXd> outM(m_rbuf1.data(),
nReactions());
455 if (!m_jac_skip_falloff) {
459 rates->processRateConstants_ddM(
460 outM.data(),
m_rfn.data(), m_jac_rtol_delta);
492 Eigen::Map<Eigen::VectorXd> dNetRop(drop,
nReactions());
495 Eigen::Map<Eigen::VectorXd> dNetRop2(m_rbuf2.data(),
nReactions());
502 Eigen::SparseMatrix<double> out;
509 scaled[i] = ctot * in[i];
513 copy(scaled.begin(), scaled.end(), outV.begin());
521 copy(scaled.begin(), scaled.end(), outV.begin());
522 stoich.multiply(
m_act_conc.data(), outV.data());
525 if (!m_jac_skip_falloff) {
528 rates->processRateConstants_ddM(
529 outV.data(),
m_rfn.data(), m_jac_rtol_delta,
false);
580 }
else if (!(r->usesLegacy())) {
585 if (r->type() ==
"elementary-legacy") {
587 }
else if (r->type() ==
"three-body-legacy") {
589 }
else if (r->type() ==
"falloff-legacy") {
591 }
else if (r->type() ==
"chemically-activated-legacy") {
593 }
else if (r->type() ==
"pressure-dependent-Arrhenius-legacy") {
595 }
else if (r->type() ==
"Chebyshev-legacy") {
599 "Unknown reaction type specified: '{}'", r->type());
620 map<size_t, double> efficiencies;
624 efficiencies[k] = eff.second;
640 map<size_t, double> efficiencies;
644 efficiencies[k] = eff.second;
670 if (!(rNew->usesLegacy())) {
675 if (rNew->type() ==
"elementary-legacy") {
677 }
else if (rNew->type() ==
"three-body-legacy") {
679 }
else if (rNew->type() ==
"falloff-legacy") {
681 }
else if (rNew->type() ==
"chemically-activated-legacy") {
683 }
else if (rNew->type() ==
"pressure-dependent-Arrhenius-legacy") {
685 }
else if (rNew->type() ==
"Chebyshev-legacy") {
689 "Unknown reaction type specified: '{}'", rNew->type());
716void GasKinetics::invalidateCache()
718 BulkKinetics::invalidateCache();
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
A map of string keys to values whose type can vary at runtime.
bool empty() const
Return boolean indicating whether AnyMap is empty.
bool getBool(const std::string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
double getDouble(const std::string &key, double default_) const
If key exists, return it as a double, otherwise return default_.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Partial specialization of Kinetics for chemistry in a single bulk phase.
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
vector_fp m_act_conc
Activity concentrations, as calculated by ThermoPhase::getActivityConcentrations.
std::vector< size_t > m_revindex
Indices of reversible reactions.
std::vector< unique_ptr< MultiRateBase > > m_bulk_rates
Vector of rate handlers.
ThirdBodyCalc3 m_multi_concm
used with MultiRate evaluator
vector_fp m_dn
Difference between the global reactants order and the global products order.
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
Add a single reaction to the mechanism.
std::vector< size_t > m_irrev
Indices of irreversible reactions.
Rate1< Arrhenius2 > m_rates
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
vector_fp m_concm
Third body concentrations.
vector_fp m_phys_conc
Physical concentrations, as calculated by ThermoPhase::getConcentrations.
Base class for exceptions thrown by Cantera classes.
A pressure-dependent reaction parameterized by a bi-variate Chebyshev polynomial in temperature and p...
A reaction which follows mass-action kinetics with a modified Arrhenius reaction rate.
size_t workSize()
Size of the work array required to store intermediate results.
void pr_to_falloff(doublereal *values, const doublereal *work)
Given a vector of reduced pressures for each falloff reaction, replace each entry by the value of the...
void install(size_t rxn, int reactionType, shared_ptr< Falloff > f)
Install a new falloff function calculator.
void replace(size_t rxn, shared_ptr< Falloff > f)
void updateTemp(doublereal t, doublereal *work)
Update the cached temperature-dependent intermediate results for all installed falloff functions.
A reaction that is first-order in [M] at low pressure, like a third-body reaction,...
shared_ptr< FalloffRate > falloff
Falloff function which determines how low_rate and high_rate are combined to determine the rate const...
Arrhenius2 high_rate
The rate constant in the high-pressure limit.
ThirdBody third_body
Relative efficiencies of third-body species in enhancing the reaction rate.
virtual std::string type() const
The type of reaction.
Arrhenius2 low_rate
The rate constant in the low-pressure limit.
void processFalloffReactions(double *ropf)
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
Eigen::SparseMatrix< double > process_ddX(StoichManagerN &stoich, const vector_fp &in)
Process mole fraction derivative.
virtual void getFwdRatesOfProgress_ddP(double *drop)
Calculate derivatives for forward rates-of-progress with respect to pressure at constant temperature,...
virtual Eigen::SparseMatrix< double > revRatesOfProgress_ddX()
Calculate derivatives for reverse rates-of-progress with respect to species mole fractions at constan...
std::map< size_t, size_t > m_rfallindx
Map of reaction index to falloff reaction index (i.e indices in m_falloff_low_rates and m_falloff_hig...
virtual void getFwdRateConstants(double *kfwd)
Return the forward rate constants.
virtual void getDerivativeSettings(AnyMap &settings) const
Retrieve derivative settings.
virtual void getFwdRateConstants_ddC(double *dkfwd)
Calculate derivatives for forward rate constants with respect to molar concentration at constant temp...
Rate1< Arrhenius2 > m_falloff_low_rates
Rate expressions for falloff reactions at the low-pressure limit.
Rate1< ChebyshevRate > m_cheb_rates
virtual void getRevRatesOfProgress_ddP(double *drop)
Calculate derivatives for reverse rates-of-progress with respect to pressure at constant temperature,...
doublereal m_pres
Last pressure at which rates were evaluated.
virtual Eigen::SparseMatrix< double > netRatesOfProgress_ddX()
Calculate derivatives for net rates-of-progress with respect to species mole fractions at constant te...
void addFalloffReaction(FalloffReaction2 &r)
void processFwdRateCoefficients(double *ropf)
Calculate rate coefficients.
Rate1< Plog > m_plog_rates
virtual void getRevRatesOfProgress_ddC(double *drop)
Calculate derivatives for reverse rates-of-progress with respect to molar concentration at constant t...
virtual void getNetRatesOfProgress_ddP(double *drop)
Calculate derivatives for net rates-of-progress with respect to pressure at constant temperature,...
void addPlogReaction(PlogReaction2 &r)
void modifyFalloffReaction(size_t i, FalloffReaction2 &r)
Rate1< Arrhenius2 > m_falloff_high_rates
Rate expressions for falloff reactions at the high-pressure limit.
void modifyPlogReaction(size_t i, PlogReaction2 &r)
GasKinetics(ThermoPhase *thermo=0)
Constructor.
bool m_jac_skip_third_bodies
Derivative settings.
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
Add a single reaction to the mechanism.
void process_ddP(const vector_fp &in, double *drop)
Process pressure derivative.
void assertDerivativesValid(const std::string &name)
Helper function ensuring that all rate derivatives can be calculated.
void processEquilibriumConstants(double *rop)
Multiply rate with inverse equilibrium constant.
void updateKc()
Update the equilibrium constants in molar units.
void processThirdBodies(double *rop)
Multiply rate with third-body collider concentrations.
void process_ddC(StoichManagerN &stoich, const vector_fp &in, double *drop, bool mass_action=true)
Process concentration (molar density) derivative.
vector_fp concm_falloff_values
virtual void getFwdRateConstants_ddT(double *dkfwd)
Calculate derivatives for forward rate constants with respect to temperature at constant pressure,...
std::vector< size_t > m_legacy
Reaction index of each legacy reaction (old framework)
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
virtual void getThirdBodyConcentrations(double *concm)
Return a vector of values of effective concentrations of third-body collision partners of any reactio...
virtual void update_rates_C()
Update properties that depend on concentrations.
virtual void update_rates_T()
Update temperature-dependent portions of reaction rates and falloff functions.
virtual void getFwdRateConstants_ddP(double *dkfwd)
Calculate derivatives for forward rate constants with respect to pressure at constant temperature,...
virtual void getFwdRatesOfProgress_ddT(double *drop)
Calculate derivatives for forward rates-of-progress with respect to temperature at constant pressure,...
std::vector< size_t > m_fallindx
Reaction index of each falloff reaction.
virtual void getEquilibriumConstants(doublereal *kc)
Return a vector of Equilibrium constants.
vector_fp m_rbuf0
Buffers for partial rop results with length nReactions()
void process_ddT(const vector_fp &in, double *drop)
Process temperature derivative.
virtual void getNetRatesOfProgress_ddT(double *drop)
Calculate derivatives for net rates-of-progress with respect to temperature at constant pressure,...
virtual void getFwdRatesOfProgress_ddC(double *drop)
Calculate derivatives for forward rates-of-progress with respect to molar concentration at constant t...
virtual void setDerivativeSettings(const AnyMap &settings)
Set/modify derivative settings.
void modifyThreeBodyReaction(size_t i, ThreeBodyReaction2 &r)
void modifyChebyshevReaction(size_t i, ChebyshevReaction2 &r)
void addChebyshevReaction(ChebyshevReaction2 &r)
void addThreeBodyReaction(ThreeBodyReaction2 &r)
virtual void getNetRatesOfProgress_ddC(double *drop)
Calculate derivatives for net rates-of-progress with respect to molar concentration at constant tempe...
vector_fp concm_3b_values
virtual Eigen::SparseMatrix< double > fwdRatesOfProgress_ddX()
Calculate derivatives for forward rates-of-progress with respect to species mole fractions at constan...
void processEquilibriumConstants_ddT(double *drkcn)
Multiply rate with scaled temperature derivatives of the inverse equilibrium constant.
virtual void getRevRatesOfProgress_ddT(double *drop)
Calculate derivatives for reverse rates-of-progress with respect to temperature at constant pressure,...
ThirdBodyCalc m_falloff_concm
vector_fp m_delta_gibbs0
Delta G^0 for all reactions.
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
virtual void getRevReactionDelta(const double *g, double *dg) const
Given an array of species properties 'g', return in array 'dg' the change in this quantity in the rev...
vector_fp m_ropnet
Net rate-of-progress for each reaction.
virtual void getReactionDelta(const double *property, double *deltaProperty) const
Change in species properties.
vector_fp m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
vector_fp m_ropf
Forward rate-of-progress for each reaction.
vector_fp m_ropr
Reverse rate-of-progress for each reaction.
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
size_t nReactions() const
Number of reactions in the reaction mechanism.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
vector_fp m_rfn
Forward rate constant for each reaction.
virtual std::string reactionTypeStr(size_t i) const
String specifying the type of reaction.
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
An error indicating that an unimplemented function has been called.
void getConcentrations(double *const c) const
Get the species concentrations (kmol/m^3).
double molarDensity() const
Molar density (kmol/m^3).
void saveState(vector_fp &state) const
Save the current internal state of the phase.
doublereal temperature() const
Temperature (K).
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
virtual double pressure() const
Return the thermodynamic pressure (Pa).
A pressure-dependent reaction parameterized by logarithmically interpolating between Arrhenius rate e...
Eigen::SparseMatrix< double > derivatives(const double *conc, const double *rates)
Calculate derivatives with respect to species concentrations.
void scale(const double *in, double *out, double factor) const
Scale input by reaction order and factor.
Base class for a phase with thermodynamic properties.
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void scaleM(const double *in, double *out, const double *concm, double factor) const
Scale entries involving third-body collider in rate expression by third-body concentration and factor...
void update(const vector_fp &conc, double ctot, double *concm) const
Update third-body concentrations in full vector.
bool empty() const
Return boolean indicating whether ThirdBodyCalc3 is empty.
void multiply(double *output, const double *concm)
Multiply output with effective third-body concentration.
Eigen::SparseMatrix< double > derivatives(const double *product)
Calculate derivatives with respect to species concentrations.
void scale(const double *in, double *out, double factor) const
Scale entries involving third-body collider in law of mass action by factor.
void copy(const vector_fp &work, double *concm)
Update third-body concentrations in full vector.
double default_efficiency
The default third body efficiency for species not listed in efficiencies.
Composition efficiencies
Map of species to third body efficiency.
A reaction with a non-reacting third body "M" that acts to add or remove energy from the reacting spe...
ThirdBody third_body
Relative efficiencies of third-body species in enhancing the reaction rate.
#define AssertFinite(expr, procedure,...)
Throw an exception if the specified exception is not a finite number.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
const double SmallNumber
smallest number to compare to zero.
bool legacy_rate_constants_used()
Returns true if legacy rate constant definition should be used.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
const double BigNumber
largest number to compare to inf.