36 m_logStandConc = log(
thermo().standardConcentration());
37 doublereal logT = log(T);
41 m_rates.update(T, logT, &
m_rfn[0]);
44 if (!m_rfn_low.empty()) {
48 if (!falloff_work.empty()) {
55 if (T != m_temp || P !=
m_pres) {
56 if (m_plog_rates.nReactions()) {
57 m_plog_rates.update(T, logT, &
m_rfn[0]);
61 if (m_cheb_rates.nReactions()) {
62 m_cheb_rates.update(T, logT, &
m_rfn[0]);
76 if (!concm_3b_values.empty()) {
77 m_3b_concm.update(m_conc, ctot, &concm_3b_values[0]);
81 if (!concm_falloff_values.empty()) {
82 m_falloff_concm.update(m_conc, ctot, &concm_falloff_values[0]);
86 if (m_plog_rates.nReactions()) {
87 double logP = log(
thermo().pressure());
88 m_plog_rates.update_C(&logP);
92 if (m_cheb_rates.nReactions()) {
93 double log10P = log10(
thermo().pressure());
94 m_cheb_rates.update_C(&log10P);
109 for (
size_t i = 0; i <
m_revindex.size(); i++) {
115 for (
size_t i = 0; i !=
m_irrev.size(); ++i) {
130 for (
size_t i = 0; i <
m_ii; i++) {
131 kc[i] = exp(-
m_rkcn[i]*rrt +
m_dn[i]*m_logStandConc);
139 void GasKinetics::processFalloffReactions()
144 for (
size_t i = 0; i < m_nfall; i++) {
145 pr[i] = concm_falloff_values[i] * m_rfn_low[i] / (m_rfn_high[i] +
SmallNumber);
146 AssertFinite(pr[i],
"GasKinetics::processFalloffReactions",
147 "pr[" +
int2str(i) +
"] is not finite.");
150 double* work = (falloff_work.empty()) ? 0 : &falloff_work[0];
153 for (
size_t i = 0; i < m_nfall; i++) {
155 pr[i] *= m_rfn_high[i];
157 pr[i] *= m_rfn_low[i];
165 void GasKinetics::updateROP()
178 if (!concm_3b_values.empty()) {
179 m_3b_concm.multiply(&
m_ropf[0], &concm_3b_values[0]);
183 processFalloffReactions();
202 for (
size_t j = 0; j !=
m_ii; ++j) {
206 for (
size_t i = 0; i <
m_rfn.size(); i++) {
208 "m_rfn[" +
int2str(i) +
"] is not finite.");
210 "m_ropf[" +
int2str(i) +
"] is not finite.");
212 "m_ropr[" +
int2str(i) +
"] is not finite.");
227 if (!concm_3b_values.empty()) {
228 m_3b_concm.multiply(&
m_ropf[0], &concm_3b_values[0]);
232 processFalloffReactions();
238 for (
size_t i = 0; i <
m_ii; i++) {
247 addElementaryReaction(r);
250 addThreeBodyReaction(r);
254 addFalloffReaction(r);
260 addChebyshevReaction(r);
263 throw CanteraError(
"GasKinetics::addReaction",
"Invalid reaction type specified");
278 switch (r->reaction_type) {
280 addElementaryReaction(dynamic_cast<ElementaryReaction&>(*r));
283 addThreeBodyReaction(dynamic_cast<ThreeBodyReaction&>(*r));
287 addFalloffReaction(dynamic_cast<FalloffReaction&>(*r));
290 addPlogReaction(dynamic_cast<PlogReaction&>(*r));
293 addChebyshevReaction(dynamic_cast<ChebyshevReaction&>(*r));
297 "Unknown reaction type specified: " +
int2str(r->reaction_type));
329 void GasKinetics::addThreeBodyReaction(ReactionData& r)
332 m_3b_concm.install(
nReactions(), r.thirdBodyEfficiencies,
336 void GasKinetics::addPlogReaction(ReactionData& r)
341 void GasKinetics::addChebyshevReaction(ReactionData& r)
346 void GasKinetics::addFalloffReaction(FalloffReaction& r)
351 m_rfn_high.push_back(0.0);
353 m_rfn_low.push_back(0.0);
360 map<size_t, double> efficiencies;
361 for (Composition::const_iterator iter = r.third_body.efficiencies.begin();
362 iter != r.third_body.efficiencies.end();
366 efficiencies[k] = iter->second;
368 throw CanteraError(
"GasKinetics::addTFalloffReaction",
"Found "
369 "third-body efficiency for undefined species '" + iter->first +
370 "' while adding reaction '" + r.equation() +
"'");
373 m_falloff_concm.install(m_nfall, efficiencies,
374 r.third_body.default_efficiency);
377 m_falloffn.
install(m_nfall, r.reaction_type, r.falloff);
383 void GasKinetics::addThreeBodyReaction(ThreeBodyReaction& r)
386 map<size_t, double> efficiencies;
387 for (Composition::const_iterator iter = r.third_body.efficiencies.begin();
388 iter != r.third_body.efficiencies.end();
392 efficiencies[k] = iter->second;
394 throw CanteraError(
"GasKinetics::addThreeBodyReaction",
"Found "
395 "third-body efficiency for undefined species '" + iter->first +
396 "' while adding reaction '" + r.equation() +
"'");
399 m_3b_concm.install(
nReactions()-1, efficiencies,
400 r.third_body.default_efficiency);
403 void GasKinetics::addPlogReaction(PlogReaction& r)
408 void GasKinetics::addChebyshevReaction(ChebyshevReaction& r)
418 switch (rNew->reaction_type) {
420 modifyElementaryReaction(i, dynamic_cast<ElementaryReaction&>(*rNew));
423 modifyThreeBodyReaction(i, dynamic_cast<ThreeBodyReaction&>(*rNew));
427 modifyFalloffReaction(i, dynamic_cast<FalloffReaction&>(*rNew));
430 modifyPlogReaction(i, dynamic_cast<PlogReaction&>(*rNew));
433 modifyChebyshevReaction(i, dynamic_cast<ChebyshevReaction&>(*rNew));
437 "Unknown reaction type specified: " +
int2str(rNew->reaction_type));
448 m_rates.replace(i, r.rate);
451 void GasKinetics::modifyFalloffReaction(
size_t i, FalloffReaction& r)
456 m_falloffn.
replace(iFall, r.falloff);
459 void GasKinetics::modifyPlogReaction(
size_t i, PlogReaction& r)
461 m_plog_rates.replace(i, r.rate);
464 void GasKinetics::modifyChebyshevReaction(
size_t i, ChebyshevReaction& r)
466 m_cheb_rates.replace(i, r.rate);
478 falloff_work.resize(m_falloffn.
workSize());
479 concm_3b_values.resize(m_3b_concm.workSize());
480 concm_falloff_values.resize(m_falloff_concm.workSize());
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
const int PLOG_RXN
A pressure-dependent rate expression consisting of several Arrhenius rate expressions evaluated at di...
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
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...
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
vector_fp m_ropr
Reverse rate-of-progress for each reaction.
vector_fp falloffParameters
Values used in the falloff parameterization.
void install(size_t rxn, int falloffType, int reactionType, const vector_fp &c)
Install a new falloff function calculator.
int reactionType
Type of the reaction.
virtual void assignShallowPointers(const std::vector< thermo_t * > &tpVector)
Reassign the pointers within the Kinetics object.
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
vector_fp auxRateCoeffParameters
Vector of auxiliary rate coefficient parameters.
void replace(size_t rxn, shared_ptr< Falloff > f)
virtual void getFwdRateConstants(doublereal *kfwd)
Return the forward rate constants.
const size_t npos
index returned by functions to indicate "no position"
int falloffType
Type of falloff parameterization to use.
const int CHEBYSHEV_RXN
A general gas-phase pressure-dependent reaction where k(T,P) is defined in terms of a bivariate Cheby...
virtual void init()
Prepare the class for the addition of reactions.
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void getRevReactionDelta(const doublereal *g, doublereal *dg)
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.
doublereal molarDensity() const
Molar density (kmol/m^3).
const int CHEMACT_RXN
A chemical activation reaction.
void updateTemp(doublereal t, doublereal *work)
Update the cached temperature-dependent intermediate results for all installed falloff functions...
size_t workSize()
Size of the work array required to store intermediate results.
Kinetics manager for elementary gas-phase chemistry.
#define AssertFinite(expr, procedure, message)
Throw an exception if the specified exception is not a finite number.
void multiply_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Multiply each entry in x by the corresponding entry in y.
virtual void init()
Prepare the class for the addition of reactions.
vector_fp rateCoeffParameters
Vector of rate coefficient parameters.
std::map< size_t, doublereal > thirdBodyEfficiencies
Map of species index to third body efficiency.
virtual void update_rates_T()
Update temperature-dependent portions of reaction rates and falloff functions.
vector_fp m_ropf
Forward rate-of-progress for each reaction.
Base class for a phase with thermodynamic properties.
Partial specialization of Kinetics for chemistry in a single bulk phase.
const int FALLOFF_RXN
The general form for a gas-phase association or dissociation reaction, with a pressure-dependent rate...
virtual void getEquilibriumConstants(doublereal *kc)
Return a vector of Equilibrium constants.
virtual bool ready() const
Returns true if the kinetics manager has been properly initialized and finalized. ...
Rate1< Arrhenius > m_falloff_high_rates
Rate expressions for falloff reactions at the high-pressure limit.
std::vector< size_t > m_irrev
Indices of irreversible reactions.
const doublereal BigNumber
largest number to compare to inf.
vector_fp m_rfn
Forward rate constant for each reaction.
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
bool m_skipUndeclaredThirdBodies
void updateKc()
Update the equilibrium constants in molar units.
vector_fp m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
Public interface for kinetics managers.
doublereal default_3b_eff
The default third body efficiency for species not listed in thirdBodyEfficiencies.
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
GasKinetics(thermo_t *thermo=0)
Constructor.
Base class for exceptions thrown by Cantera classes.
std::vector< size_t > m_revindex
Indices of reversible reactions.
std::vector< size_t > m_fallindx
Reaction index of each falloff reaction.
virtual Kinetics * duplMyselfAsKinetics(const std::vector< thermo_t * > &tpVector) const
Duplication routine for objects which inherit from Kinetics.
const int THREE_BODY_RXN
A gas-phase reaction that requires a third-body collision partner.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
virtual void update_rates_C()
Update properties that depend on concentrations.
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
doublereal temperature() const
Temperature (K).
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
const doublereal SmallNumber
smallest number to compare to zero.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
doublereal m_pres
Last pressure at which rates were evaluated.
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...
A reaction with a non-reacting third body "M" that acts to add or remove energy from the reacting spe...
void scatter_copy(InputIter begin, InputIter end, OutputIter result, IndexIter index)
Copies a contiguous range in a sequence to indexed positions in another sequence. ...
vector_fp m_dn
Difference between the global reactants order and the global products order.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
size_t m_ii
Number of reactions in the mechanism.
const int ELEMENTARY_RXN
A reaction with a rate coefficient that depends only on temperature and voltage that also obeys mass-...
size_t nReactions() const
Number of reactions in the reaction mechanism.
virtual void finalize()
Finish adding reactions and prepare for use.
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
Rate1< Arrhenius > m_falloff_low_rates
Rate expressions for falloff reactions at the low-pressure limit.
virtual void finalize()
Finish adding reactions and prepare for use.
virtual void getReactionDelta(const doublereal *property, doublereal *deltaProperty)
Change in species properties.