Cantera  2.5.1
BulkKinetics.cpp
1 // This file is part of Cantera. See License.txt in the top-level directory or
2 // at https://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 bool BulkKinetics::isReversible(size_t i) {
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) {
89  getEquilibriumConstants(m_ropnet.data());
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 
135 void BulkKinetics::resizeSpecies()
136 {
137  Kinetics::resizeSpecies();
138  m_conc.resize(m_kk);
139  m_grt.resize(m_kk);
140 }
141 
142 void BulkKinetics::setMultiplier(size_t i, double f) {
143  Kinetics::setMultiplier(i, 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:84
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:109
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
ThermoPhase thermo_t
typedef for the ThermoPhase class
Definition: ThermoPhase.h:1908