Cantera  2.3.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 
19 Kinetics* BulkKinetics::duplMyselfAsKinetics(const std::vector<thermo_t*> & tpVector) const
20 {
21  BulkKinetics* kin = new BulkKinetics(*this);
22  kin->assignShallowPointers(tpVector);
23  return kin;
24 }
25 
27  return std::find(m_revindex.begin(), m_revindex.end(), i) < m_revindex.end();
28 }
29 
30 void BulkKinetics::getDeltaGibbs(doublereal* deltaG)
31 {
32  // Get the chemical potentials of the species in the ideal gas solution.
33  thermo().getChemPotentials(m_grt.data());
34  // Use the stoichiometric manager to find deltaG for each reaction.
35  getReactionDelta(m_grt.data(), deltaG);
36 }
37 
38 void BulkKinetics::getDeltaEnthalpy(doublereal* deltaH)
39 {
40  // Get the partial molar enthalpy of all species in the ideal gas.
41  thermo().getPartialMolarEnthalpies(m_grt.data());
42  // Use the stoichiometric manager to find deltaH for each reaction.
43  getReactionDelta(m_grt.data(), deltaH);
44 }
45 
46 void BulkKinetics::getDeltaEntropy(doublereal* deltaS)
47 {
48  // Get the partial molar entropy of all species in the solid solution.
49  thermo().getPartialMolarEntropies(m_grt.data());
50  // Use the stoichiometric manager to find deltaS for each reaction.
51  getReactionDelta(m_grt.data(), deltaS);
52 }
53 
54 void BulkKinetics::getDeltaSSGibbs(doublereal* deltaG)
55 {
56  // Get the standard state chemical potentials of the species. This is the
57  // array of chemical potentials at unit activity. We define these here as
58  // the chemical potentials of the pure species at the temperature and
59  // pressure of the solution.
60  thermo().getStandardChemPotentials(m_grt.data());
61  // Use the stoichiometric manager to find deltaG for each reaction.
62  getReactionDelta(m_grt.data(), deltaG);
63 }
64 
65 void BulkKinetics::getDeltaSSEnthalpy(doublereal* deltaH)
66 {
67  // Get the standard state enthalpies of the species.
68  thermo().getEnthalpy_RT(m_grt.data());
69  for (size_t k = 0; k < m_kk; k++) {
70  m_grt[k] *= thermo().RT();
71  }
72  // Use the stoichiometric manager to find deltaH for each reaction.
73  getReactionDelta(m_grt.data(), deltaH);
74 }
75 
76 void BulkKinetics::getDeltaSSEntropy(doublereal* deltaS)
77 {
78  // Get the standard state entropy of the species. We define these here as
79  // the entropies of the pure species at the temperature and pressure of the
80  // solution.
81  thermo().getEntropy_R(m_grt.data());
82  for (size_t k = 0; k < m_kk; k++) {
83  m_grt[k] *= GasConstant;
84  }
85  // Use the stoichiometric manager to find deltaS for each reaction.
86  getReactionDelta(m_grt.data(), deltaS);
87 }
88 
89 void BulkKinetics::getRevRateConstants(doublereal* krev, bool doIrreversible)
90 {
91  // go get the forward rate constants. -> note, we don't really care about
92  // speed or redundancy in these informational routines.
93  getFwdRateConstants(krev);
94 
95  if (doIrreversible) {
97  for (size_t i = 0; i < nReactions(); i++) {
98  krev[i] /= m_ropnet[i];
99  }
100  } else {
101  // m_rkcn[] is zero for irreversible reactions
102  for (size_t i = 0; i < nReactions(); i++) {
103  krev[i] *= m_rkcn[i];
104  }
105  }
106 }
107 
108 bool BulkKinetics::addReaction(shared_ptr<Reaction> r)
109 {
110  bool added = Kinetics::addReaction(r);
111  if (!added) {
112  return false;
113  }
114  double dn = 0.0;
115  for (const auto& sp : r->products) {
116  dn += sp.second;
117  }
118  for (const auto& sp : r->reactants) {
119  dn -= sp.second;
120  }
121 
122  m_dn.push_back(dn);
123 
124  if (r->reversible) {
125  m_revindex.push_back(nReactions()-1);
126  } else {
127  m_irrev.push_back(nReactions()-1);
128  }
129  return true;
130 }
131 
132 void BulkKinetics::addElementaryReaction(ElementaryReaction& r)
133 {
134  m_rates.install(nReactions()-1, r.rate);
135 }
136 
137 void BulkKinetics::modifyElementaryReaction(size_t i, ElementaryReaction& rNew)
138 {
139  m_rates.replace(i, rNew.rate);
140 }
141 
143 {
145  m_conc.resize(m_kk);
146  m_grt.resize(m_kk);
147 }
148 
149 void BulkKinetics::setMultiplier(size_t i, double f) {
151  m_ROP_ok = false;
152 }
153 
154 void BulkKinetics::invalidateCache()
155 {
156  Kinetics::invalidateCache();
157  m_ROP_ok = false;
158  m_temp += 0.13579;
159 }
160 
161 }
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:276
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: ThermoPhase.h:530
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
Definition: Kinetics.h:921
virtual Kinetics * duplMyselfAsKinetics(const std::vector< thermo_t *> &tpVector) const
Duplication routine for objects which inherit from Kinetics.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:494
virtual void resizeSpecies()
Resize arrays with sizes that depend on the total number of species.
Definition: Kinetics.cpp:504
virtual bool addReaction(shared_ptr< Reaction > r)
Add a single reaction to the mechanism.
Definition: Kinetics.cpp:522
virtual void getFwdRateConstants(doublereal *kfwd)
Return the forward rate constants.
Definition: Kinetics.h:693
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:985
virtual void getEquilibriumConstants(doublereal *kc)
Return a vector of Equilibrium constants.
Definition: Kinetics.h:429
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:809
ThermoPhase thermo_t
typedef for the ThermoPhase class
Definition: ThermoPhase.h:1741
Partial specialization of Kinetics for chemistry in a single bulk phase.
Definition: BulkKinetics.h:21
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:589
std::vector< size_t > m_irrev
Indices of irreversible reactions.
Definition: BulkKinetics.h:52
virtual bool addReaction(shared_ptr< Reaction > r)
Add a single reaction to the mechanism.
virtual void assignShallowPointers(const std::vector< thermo_t *> &tpVector)
Reassign the pointers within the Kinetics object.
Definition: Kinetics.cpp:129
virtual bool isReversible(size_t i)
True if reaction i has been declared to be reversible.
Public interface for kinetics managers.
Definition: Kinetics.h:111
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:51
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:184
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: ThermoPhase.h:520
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:976
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:57
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:579
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:599
virtual void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
Definition: Kinetics.h:830
Namespace for the Cantera kernel.
Definition: application.cpp:29
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:428