Cantera  2.4.0
BulkKinetics.cpp
1 // This file is part of Cantera. See License.txt in the top-level directory or
2 // at http://www.cantera.org/license.txt for license and copyright information.
3 
6 
7 namespace Cantera
8 {
9 
10 BulkKinetics::BulkKinetics(thermo_t* thermo) :
11  m_ROP_ok(false),
12  m_temp(0.0)
13 {
14  if (thermo) {
15  addPhase(*thermo);
16  }
17 }
18 
20  return std::find(m_revindex.begin(), m_revindex.end(), i) < m_revindex.end();
21 }
22 
23 void BulkKinetics::getDeltaGibbs(doublereal* deltaG)
24 {
25  // Get the chemical potentials of the species in the ideal gas solution.
26  thermo().getChemPotentials(m_grt.data());
27  // Use the stoichiometric manager to find deltaG for each reaction.
28  getReactionDelta(m_grt.data(), deltaG);
29 }
30 
31 void BulkKinetics::getDeltaEnthalpy(doublereal* deltaH)
32 {
33  // Get the partial molar enthalpy of all species in the ideal gas.
34  thermo().getPartialMolarEnthalpies(m_grt.data());
35  // Use the stoichiometric manager to find deltaH for each reaction.
36  getReactionDelta(m_grt.data(), deltaH);
37 }
38 
39 void BulkKinetics::getDeltaEntropy(doublereal* deltaS)
40 {
41  // Get the partial molar entropy of all species in the solid solution.
42  thermo().getPartialMolarEntropies(m_grt.data());
43  // Use the stoichiometric manager to find deltaS for each reaction.
44  getReactionDelta(m_grt.data(), deltaS);
45 }
46 
47 void BulkKinetics::getDeltaSSGibbs(doublereal* deltaG)
48 {
49  // Get the standard state chemical potentials of the species. This is the
50  // array of chemical potentials at unit activity. We define these here as
51  // the chemical potentials of the pure species at the temperature and
52  // pressure of the solution.
53  thermo().getStandardChemPotentials(m_grt.data());
54  // Use the stoichiometric manager to find deltaG for each reaction.
55  getReactionDelta(m_grt.data(), deltaG);
56 }
57 
58 void BulkKinetics::getDeltaSSEnthalpy(doublereal* deltaH)
59 {
60  // Get the standard state enthalpies of the species.
61  thermo().getEnthalpy_RT(m_grt.data());
62  for (size_t k = 0; k < m_kk; k++) {
63  m_grt[k] *= thermo().RT();
64  }
65  // Use the stoichiometric manager to find deltaH for each reaction.
66  getReactionDelta(m_grt.data(), deltaH);
67 }
68 
69 void BulkKinetics::getDeltaSSEntropy(doublereal* deltaS)
70 {
71  // Get the standard state entropy of the species. We define these here as
72  // the entropies of the pure species at the temperature and pressure of the
73  // solution.
74  thermo().getEntropy_R(m_grt.data());
75  for (size_t k = 0; k < m_kk; k++) {
76  m_grt[k] *= GasConstant;
77  }
78  // Use the stoichiometric manager to find deltaS for each reaction.
79  getReactionDelta(m_grt.data(), deltaS);
80 }
81 
82 void BulkKinetics::getRevRateConstants(doublereal* krev, bool doIrreversible)
83 {
84  // go get the forward rate constants. -> note, we don't really care about
85  // speed or redundancy in these informational routines.
86  getFwdRateConstants(krev);
87 
88  if (doIrreversible) {
90  for (size_t i = 0; i < nReactions(); i++) {
91  krev[i] /= m_ropnet[i];
92  }
93  } else {
94  // m_rkcn[] is zero for irreversible reactions
95  for (size_t i = 0; i < nReactions(); i++) {
96  krev[i] *= m_rkcn[i];
97  }
98  }
99 }
100 
101 bool BulkKinetics::addReaction(shared_ptr<Reaction> r)
102 {
103  bool added = Kinetics::addReaction(r);
104  if (!added) {
105  return false;
106  }
107  double dn = 0.0;
108  for (const auto& sp : r->products) {
109  dn += sp.second;
110  }
111  for (const auto& sp : r->reactants) {
112  dn -= sp.second;
113  }
114 
115  m_dn.push_back(dn);
116 
117  if (r->reversible) {
118  m_revindex.push_back(nReactions()-1);
119  } else {
120  m_irrev.push_back(nReactions()-1);
121  }
122  return true;
123 }
124 
125 void BulkKinetics::addElementaryReaction(ElementaryReaction& r)
126 {
127  m_rates.install(nReactions()-1, r.rate);
128 }
129 
130 void BulkKinetics::modifyElementaryReaction(size_t i, ElementaryReaction& rNew)
131 {
132  m_rates.replace(i, rNew.rate);
133 }
134 
136 {
138  m_conc.resize(m_kk);
139  m_grt.resize(m_kk);
140 }
141 
142 void BulkKinetics::setMultiplier(size_t i, double f) {
144  m_ROP_ok = false;
145 }
146 
147 void BulkKinetics::invalidateCache()
148 {
149  Kinetics::invalidateCache();
150  m_ROP_ok = false;
151  m_temp += 0.13579;
152 }
153 
154 }
A reaction which follows mass-action kinetics with a modified Arrhenius reaction rate.
Definition: Reaction.h:79
virtual void setMultiplier(size_t i, double f)
Set the multiplier for reaction i to f.
virtual void getDeltaSSEnthalpy(doublereal *deltaH)
Return the vector of values for the change in the standard state enthalpies of reaction.
virtual void getDeltaSSGibbs(doublereal *deltaG)
Return the vector of values for the reaction standard state Gibbs free energy change.
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
Definition: Kinetics.h:227
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: ThermoPhase.h:497
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
Definition: Kinetics.h:860
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:461
virtual void resizeSpecies()
Resize arrays with sizes that depend on the total number of species.
Definition: Kinetics.cpp:449
virtual bool addReaction(shared_ptr< Reaction > r)
Add a single reaction to the mechanism.
Definition: Kinetics.cpp:461
virtual void getFwdRateConstants(doublereal *kfwd)
Return the forward rate constants.
Definition: Kinetics.h:647
virtual void getDeltaSSEntropy(doublereal *deltaS)
Return the vector of values for the change in the standard state entropies for each reaction...
vector_fp m_ropnet
Net rate-of-progress for each reaction.
Definition: Kinetics.h:924
virtual void getEquilibriumConstants(doublereal *kc)
Return a vector of Equilibrium constants.
Definition: Kinetics.h:380
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:748
ThermoPhase thermo_t
typedef for the ThermoPhase class
Definition: ThermoPhase.h:1647
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition: ThermoPhase.h:556
std::vector< size_t > m_irrev
Indices of irreversible reactions.
Definition: BulkKinetics.h:51
virtual bool addReaction(shared_ptr< Reaction > r)
Add a single reaction to the mechanism.
virtual bool isReversible(size_t i)
True if reaction i has been declared to be reversible.
virtual void getRevRateConstants(doublereal *krev, bool doIrreversible=false)
Return the reverse rate constants.
std::vector< size_t > m_revindex
Indices of reversible reactions.
Definition: BulkKinetics.h:50
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:135
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: ThermoPhase.h:487
virtual void getDeltaEntropy(doublereal *deltaS)
Return the vector of values for the reactions change in entropy.
virtual void resizeSpecies()
Resize arrays with sizes that depend on the total number of species.
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition: Kinetics.h:915
virtual void getDeltaGibbs(doublereal *deltaG)
Return the vector of values for the reaction Gibbs free energy change.
vector_fp m_dn
Difference between the global reactants order and the global products order.
Definition: BulkKinetics.h:56
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: ThermoPhase.h:546
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition: ThermoPhase.h:566
virtual void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
Definition: Kinetics.h:777
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
virtual void getDeltaEnthalpy(doublereal *deltaH)
Return the vector of values for the reactions change in enthalpy.
virtual void getReactionDelta(const doublereal *property, doublereal *deltaProperty)
Change in species properties.
Definition: Kinetics.cpp:373