65 m_nfall = right.m_nfall;
66 m_fallindx = right.m_fallindx;
67 m_falloff_low_rates = right.m_falloff_low_rates;
68 m_falloff_high_rates = right.m_falloff_high_rates;
69 m_rates = right.m_rates;
70 m_index = right.m_index;
71 m_falloffn = right.m_falloffn;
72 m_3b_concm = right.m_3b_concm;
73 m_falloff_concm = right.m_falloff_concm;
74 m_irrev = right.m_irrev;
75 m_plog_rates = right.m_plog_rates;
76 m_cheb_rates = right.m_cheb_rates;
78 m_rxnstoich = right.m_rxnstoich;
80 m_fwdOrder = right.m_fwdOrder;
81 m_nirrev = right.m_nirrev;
82 m_nrev = right.m_nrev;
83 m_rgroups = right.m_rgroups;
84 m_pgroups = right.m_pgroups;
85 m_rxntype = right.m_rxntype;
86 m_rrxn = right.m_rrxn;
87 m_prxn = right.m_prxn;
89 m_revindex = right.m_revindex;
90 m_rxneqn = right.m_rxneqn;
92 m_logp_ref = right.m_logp_ref;
93 m_logc_ref = right.m_logc_ref;
94 m_logStandConc = right.m_logStandConc;
95 m_ropf = right.m_ropf;
96 m_ropr = right.m_ropr;
97 m_ropnet = right.m_ropnet;
98 m_rfn_low = right.m_rfn_low;
99 m_rfn_high = right.m_rfn_high;
100 m_ROP_ok = right.m_ROP_ok;
101 m_temp = right.m_temp;
103 falloff_work = right.falloff_work;
104 concm_3b_values = right.concm_3b_values;
105 concm_falloff_values = right.concm_falloff_values;
106 m_rkcn = right.m_rkcn;
108 m_conc = right.m_conc;
110 m_finalized = right.m_finalized;
113 "Unfinished implementation");
129 m_logStandConc = log(
thermo().standardConcentration());
130 doublereal logT = log(T);
133 if (!m_rfn.empty()) {
134 m_rates.update(T, logT, &m_rfn[0]);
137 if (!m_rfn_low.empty()) {
138 m_falloff_low_rates.update(T, logT, &m_rfn_low[0]);
139 m_falloff_high_rates.update(T, logT, &m_rfn_high[0]);
141 if (!falloff_work.empty()) {
148 if (T != m_temp || P !=
m_pres) {
149 if (m_plog_rates.nReactions()) {
150 m_plog_rates.
update(T, logT, &m_rfn[0]);
154 if (m_cheb_rates.nReactions()) {
155 m_cheb_rates.
update(T, logT, &m_rfn[0]);
169 if (!concm_3b_values.empty()) {
170 m_3b_concm.update(m_conc, ctot, &concm_3b_values[0]);
174 if (!concm_falloff_values.empty()) {
175 m_falloff_concm.update(m_conc, ctot, &concm_falloff_values[0]);
179 if (m_plog_rates.nReactions()) {
180 double logP = log(
thermo().pressure());
185 if (m_cheb_rates.nReactions()) {
186 double log10P = log10(
thermo().pressure());
196 fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
202 for (
size_t i = 0; i < m_nrev; i++) {
203 size_t irxn = m_revindex[i];
204 m_rkcn[irxn] = std::min(exp(m_rkcn[irxn]*rrt -
m_dn[irxn]*m_logStandConc),
208 for (
size_t i = 0; i != m_nirrev; ++i) {
209 m_rkcn[ m_irrev[i] ] = 0.0;
217 fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
223 for (
size_t i = 0; i <
m_ii; i++) {
224 kc[i] = exp(-m_rkcn[i]*rrt +
m_dn[i]*m_logStandConc);
300 for (
size_t k = 0; k <
m_kk; k++) {
319 for (
size_t k = 0; k <
m_kk; k++) {
347 void GasKinetics::processFalloffReactions()
352 for (
size_t i = 0; i < m_nfall; i++) {
353 pr[i] = concm_falloff_values[i] * m_rfn_low[i] / (m_rfn_high[i] +
SmallNumber);
354 AssertFinite(pr[i],
"GasKinetics::processFalloffReactions",
355 "pr[" +
int2str(i) +
"] is not finite.");
358 double* work = (falloff_work.empty()) ? 0 : &falloff_work[0];
361 for (
size_t i = 0; i < m_nfall; i++) {
363 pr[i] *= m_rfn_high[i];
365 pr[i] *= m_rfn_low[i];
370 m_ropf.begin(), m_fallindx.begin());
373 void GasKinetics::updateROP()
383 copy(m_rfn.begin(), m_rfn.end(), m_ropf.begin());
386 if (!concm_3b_values.empty()) {
387 m_3b_concm.multiply(&m_ropf[0], &concm_3b_values[0]);
391 processFalloffReactions();
398 copy(m_ropf.begin(), m_ropf.end(), m_ropr.begin());
414 for (
size_t j = 0; j !=
m_ii; ++j) {
415 m_ropnet[j] = m_ropf[j] - m_ropr[j];
418 for (
size_t i = 0; i < m_rfn.size(); i++) {
420 "m_rfn[" +
int2str(i) +
"] is not finite.");
422 "m_ropf[" +
int2str(i) +
"] is not finite.");
424 "m_ropr[" +
int2str(i) +
"] is not finite.");
437 copy(m_rfn.begin(), m_rfn.end(), m_ropf.begin());
440 if (!concm_3b_values.empty()) {
441 m_3b_concm.multiply(&m_ropf[0], &concm_3b_values[0]);
449 processFalloffReactions();
455 for (
size_t i = 0; i <
m_ii; i++) {
470 if (doIrreversible) {
472 for (
size_t i = 0; i <
m_ii; i++) {
473 krev[i] /= m_ropnet[i];
477 for (
size_t i = 0; i <
m_ii; i++) {
478 krev[i] *= m_rkcn[i];
488 addElementaryReaction(r);
491 addThreeBodyReaction(r);
495 addFalloffReaction(r);
501 addChebyshevReaction(r);
504 throw CanteraError(
"GasKinetics::addReaction",
"Invalid reaction type specified");
520 size_t iloc = m_falloff_high_rates.install(m_nfall, r);
523 m_falloff_low_rates.install(m_nfall, r);
528 m_rfn.push_back(0.0);
532 m_fallindx.push_back(reactionNumber());
546 m_fwdOrder.push_back(r.
reactants.size());
550 registerReaction(reactionNumber(), r.
reactionType, iloc);
554 addElementaryReaction(ReactionData& r)
557 size_t iloc = m_rates.install(reactionNumber(), r);
560 m_rfn.push_back(r.rateCoeffParameters[0]);
563 m_fwdOrder.push_back(r.reactants.size());
568 addThreeBodyReaction(ReactionData& r)
571 size_t iloc = m_rates.install(reactionNumber(), r);
574 m_rfn.push_back(r.rateCoeffParameters[0]);
577 m_fwdOrder.push_back(r.reactants.size() + 1);
579 m_3b_concm.install(reactionNumber(), r.thirdBodyEfficiencies,
584 void GasKinetics::addPlogReaction(ReactionData& r)
587 size_t iloc = m_plog_rates.
install(reactionNumber(), r);
590 m_rfn.push_back(0.0);
592 m_fwdOrder.push_back(r.reactants.size());
593 registerReaction(reactionNumber(),
PLOG_RXN, iloc);
596 void GasKinetics::addChebyshevReaction(ReactionData& r)
599 size_t iloc = m_cheb_rates.
install(reactionNumber(), r);
602 m_rfn.push_back(0.0);
604 m_fwdOrder.push_back(r.reactants.size());
608 void GasKinetics::installReagents(
const ReactionData& r)
610 m_ropf.push_back(0.0);
611 m_ropr.push_back(0.0);
612 m_ropnet.push_back(0.0);
615 doublereal reactantGlobalOrder = 0.0;
616 doublereal productGlobalOrder = 0.0;
617 size_t rnum = reactionNumber();
619 std::vector<size_t> rk;
620 size_t nr = r.reactants.size();
621 for (n = 0; n < nr; n++) {
622 nsFlt = r.rstoich[n];
623 reactantGlobalOrder += nsFlt;
625 if ((doublereal) ns != nsFlt) {
630 if (r.rstoich[n] != 0.0) {
631 m_rrxn[r.reactants[n]][rnum] += r.rstoich[n];
633 for (m = 0; m < ns; m++) {
634 rk.push_back(r.reactants[n]);
639 std::vector<size_t> pk;
640 size_t np = r.products.size();
641 for (n = 0; n < np; n++) {
642 nsFlt = r.pstoich[n];
643 productGlobalOrder += nsFlt;
645 if ((
double) ns != nsFlt) {
650 if (r.pstoich[n] != 0.0) {
651 m_prxn[r.products[n]][rnum] += r.pstoich[n];
653 for (m = 0; m < ns; m++) {
654 pk.push_back(r.products[n]);
658 m_rkcn.push_back(0.0);
659 m_rxnstoich.
add(reactionNumber(), r);
662 m_dn.push_back(productGlobalOrder - reactantGlobalOrder);
663 m_revindex.push_back(reactionNumber());
666 m_dn.push_back(productGlobalOrder - reactantGlobalOrder);
667 m_irrev.push_back(reactionNumber());
672 void GasKinetics::installGroups(
size_t irxn,
673 const vector<grouplist_t>& r,
const vector<grouplist_t>& p)
677 m_rgroups[reactionNumber()] = r;
678 m_pgroups[reactionNumber()] = p;
695 falloff_work.resize(m_falloffn.
workSize());
696 concm_3b_values.resize(m_3b_concm.workSize());
697 concm_falloff_values.resize(m_falloff_concm.workSize());
704 m_ropf.resize(1, 0.0);
705 m_ropr.resize(1, 0.0);
706 m_ropnet.resize(1, 0.0);
707 m_rkcn.resize(1, 0.0);
std::vector< grouplist_t > rgroups
Optional data used in reaction path diagrams.
virtual void getNetProductionRates(size_t nsp, const doublereal *ropnet, doublereal *w)
Species net production rates.
const int PLOG_RXN
A pressure-dependent rate expression consisting of several Arrhenius rate expressions evaluated at di...
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.
void incrementRxnCount()
Increment the number of reactions in the mechanism by one.
std::vector< std::vector< size_t > > m_reactants
This is a vector of vectors containing the reactants for each reaction.
vector_fp falloffParameters
Values used in the falloff parameterization.
virtual void getDestructionRates(size_t nSpecies, const doublereal *fwdRatesOfProgress, const doublereal *revRatesOfProgress, doublereal *destructionRates)
Species destruction rates.
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.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
vector_fp m_dn
Difference between the input global reactants order and the input global products order...
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.
virtual void getCreationRates(size_t nSpecies, const doublereal *fwdRatesOfProgress, const doublereal *revRatesOfProgress, doublereal *creationRates)
Species creation rates.
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
virtual void getRevReactionDelta(size_t nr, const doublereal *g, doublereal *dg)
Given an array of species properties 'g', return in array 'dg' the change in this quantity in the rev...
virtual void getFwdRateConstants(doublereal *kfwd)
Return the forward rate constants.
int falloffType
Type of falloff parameterization to use.
const int CHEBYSHEV_RXN
A general pressure-dependent reaction where k(T,P) is defined in terms of a bivariate Chebyshev polyn...
virtual void getDeltaSSEntropy(doublereal *deltaS)
Return the vector of values for the change in the standard state entropies for each reaction...
virtual void getReactionDelta(size_t nReactions, const doublereal *g, doublereal *dg)
Calculates the change of a molar species property in a reaction.
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...
doublereal molarDensity() const
Molar density (kmol/m^3).
const int CHEMACT_RXN
A chemical activation reaction.
virtual void getNetProductionRates(doublereal *net)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
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.
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.
Base class for a phase with thermodynamic properties.
const int FALLOFF_RXN
The general form for an association or dissociation reaction, with a pressure-dependent rate...
virtual void getEquilibriumConstants(doublereal *kc)
Return a vector of Equilibrium constants.
std::string equation
The reaction equation. Used only for display purposes.
virtual void multiplyReactants(const doublereal *C, doublereal *R)
Given an array of concentrations C, multiply the entries in array R by the concentration products for...
std::vector< grouplist_t > pgroups
Optional data used in reaction path diagrams.
virtual bool ready() const
Returns true if the kinetics manager has been properly initialized and finalized. ...
virtual void getDestructionRates(doublereal *ddot)
Species destruction rates [kmol/m^3/s or kmol/m^2/s].
virtual void getDeltaEntropy(doublereal *deltaS)
Return the vector of values for the reactions change in entropy.
void update_C(const doublereal *c)
Update the concentration-dependent parts of the rate coefficient, if any.
virtual void getDeltaSSEnthalpy(doublereal *deltaH)
Return the vector of values for the change in the standard state enthalpies of reaction.
virtual void getCreationRates(doublereal *cdot)
Species creation rates [kmol/m^3/s or kmol/m^2/s].
const doublereal BigNumber
largest number to compare to inf.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
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...
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
GasKinetics(thermo_t *thermo=0)
Constructor.
Base class for exceptions thrown by Cantera classes.
size_t install(size_t rxnNumber, const ReactionData &rdata)
Install a rate coefficient calculator.
virtual Kinetics * duplMyselfAsKinetics(const std::vector< thermo_t * > &tpVector) const
Duplication routine for objects which inherit from Kinetics.
void update(doublereal T, doublereal logT, doublereal *values)
Write the rate coefficients into array values.
Kinetics & operator=(const Kinetics &right)
Assignment operator.
const int THREE_BODY_RXN
A reaction that requires a third-body collision partner.
std::vector< size_t > reactants
Indices of reactant species.
virtual void getRevRateConstants(doublereal *krev, bool doIrreversible=false)
Return the reverse rate constants.
virtual void update_rates_C()
Update properties that depend on concentrations.
GasKinetics & operator=(const GasKinetics &right)
Assignment operator.
size_t nSpecies() const
Returns the number of species in the phase.
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
doublereal temperature() const
Temperature (K).
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
virtual void getDeltaSSGibbs(doublereal *deltaG)
Return the vector of values for the reaction standard state gibbs free energy change.
virtual void getDeltaGibbs(doublereal *deltaG)
Return the vector of values for the reaction gibbs free energy change.
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.
std::vector< std::vector< size_t > > m_products
This is a vector of vectors containing the products for each reaction.
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
doublereal m_pres
Last pressure at which rates were evaluated.
void scatter_copy(InputIter begin, InputIter end, OutputIter result, IndexIter index)
Copies a contiguous range in a sequence to indexed positions in another sequence. ...
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.
virtual void multiplyRevProducts(const doublereal *c, doublereal *r)
Given an array of concentrations C, multiply the entries in array R by the concentration products for...
virtual void getDeltaEnthalpy(doublereal *deltaH)
Return the vector of values for the reactions change in enthalpy.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
void writelog(const std::string &msg)
Write a message to the screen.
virtual void addPhase(thermo_t &thermo)
Add a phase to the kinetics manager object.
virtual void finalize()
Finish adding reactions and prepare for use.
virtual void add(size_t rxn, const std::vector< size_t > &reactants, const std::vector< size_t > &products, bool reversible)
Add a reaction with mass-action kinetics.