Cantera  2.4.0
AqueousKinetics.cpp
Go to the documentation of this file.
1 /**
2  * @file AqueousKinetics.cpp
3  *
4  * Homogeneous kinetics in an aqueous phase, either condensed or dilute in salts
5  */
6 
7 // This file is part of Cantera. See License.txt in the top-level directory or
8 // at http://www.cantera.org/license.txt for license and copyright information.
9 
12 
13 using namespace std;
14 
15 namespace Cantera
16 {
17 
18 AqueousKinetics::AqueousKinetics(thermo_t* thermo) :
19  BulkKinetics(thermo)
20 {
21  warn_deprecated("Class AqueousKinetics", "To be removed after Cantera 2.4");
22 }
23 
25 {
26  doublereal T = thermo().temperature();
27  m_rates.update(T, log(T), m_rfn.data());
28 
29  m_temp = T;
30  updateKc();
31  m_ROP_ok = false;
32 }
33 
35 {
36  thermo().getActivityConcentrations(m_conc.data());
37  m_ROP_ok = false;
38 }
39 
41 {
42  thermo().getStandardChemPotentials(m_grt.data());
43  fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
44  for (size_t k = 0; k < thermo().nSpecies(); k++) {
45  doublereal logStandConc_k = thermo().logStandardConc(k);
46  m_grt[k] -= GasConstant * m_temp * logStandConc_k;
47  }
48 
49  // compute Delta G^0 for all reversible reactions
50  getRevReactionDelta(m_grt.data(), m_rkcn.data());
51 
52  doublereal rrt = 1.0 / thermo().RT();
53  for (size_t i = 0; i < m_revindex.size(); i++) {
54  size_t irxn = m_revindex[i];
55  m_rkcn[irxn] = exp(m_rkcn[irxn]*rrt);
56  }
57 
58  for (size_t i = 0; i != m_irrev.size(); ++i) {
59  m_rkcn[ m_irrev[i] ] = 0.0;
60  }
61 }
62 
64 {
66 
67  thermo().getStandardChemPotentials(m_grt.data());
68  fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
69  for (size_t k = 0; k < thermo().nSpecies(); k++) {
70  doublereal logStandConc_k = thermo().logStandardConc(k);
71  m_grt[k] -= GasConstant * m_temp * logStandConc_k;
72  }
73 
74  // compute Delta G^0 for all reactions
75  getReactionDelta(m_grt.data(), m_rkcn.data());
76 
77  doublereal rrt = 1.0 / thermo().RT();
78  for (size_t i = 0; i < nReactions(); i++) {
79  kc[i] = exp(-m_rkcn[i]*rrt);
80  }
81 
82  // force an update of T-dependent properties, so that m_rkcn will
83  // be updated before it is used next.
84  m_temp = 0.0;
85 }
86 
87 void AqueousKinetics::updateROP()
88 {
91 
92  if (m_ROP_ok) {
93  return;
94  }
95 
96  // copy rate coefficients into ropf
97  m_ropf = m_rfn;
98 
99  // multiply by perturbation factor
100  multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin());
101 
102  // copy the forward rates to the reverse rates
103  m_ropr = m_ropf;
104 
105  // for reverse rates computed from thermochemistry, multiply the forward
106  // rates copied into m_ropr by the reciprocals of the equilibrium constants
107  multiply_each(m_ropr.begin(), m_ropr.end(), m_rkcn.begin());
108 
109  // multiply ropf by concentration products
110  m_reactantStoich.multiply(m_conc.data(), m_ropf.data());
111 
112  // for reversible reactions, multiply ropr by concentration products
113  m_revProductStoich.multiply(m_conc.data(), m_ropr.data());
114 
115  for (size_t j = 0; j != nReactions(); ++j) {
116  m_ropnet[j] = m_ropf[j] - m_ropr[j];
117  }
118 
119  m_ROP_ok = true;
120 }
121 
123 {
124  _update_rates_T();
125  _update_rates_C();
126 
127  // copy rate coefficients into ropf
128  m_ropf = m_rfn;
129 
130  // multiply by perturbation factor
131  multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin());
132 
133  for (size_t i = 0; i < nReactions(); i++) {
134  kfwd[i] = m_ropf[i];
135  }
136 }
137 
138 bool AqueousKinetics::addReaction(shared_ptr<Reaction> r)
139 {
140  bool added = BulkKinetics::addReaction(r);
141  if (!added) {
142  return false;
143  }
144  if (r->reaction_type == ELEMENTARY_RXN) {
145  addElementaryReaction(dynamic_cast<ElementaryReaction&>(*r));
146  } else {
147  throw CanteraError("AqueousKinetics::addReaction",
148  "Invalid reaction type: {}", r->reaction_type);
149  }
150  return true;
151 }
152 
153 void AqueousKinetics::modifyReaction(size_t i, shared_ptr<Reaction> rNew)
154 {
156  modifyElementaryReaction(i, dynamic_cast<ElementaryReaction&>(*rNew));
157 
158  // invalidate all cached data
159  m_ROP_ok = false;
160  m_temp += 0.1234;
161 }
162 
163 }
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
Definition: Kinetics.cpp:572
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
Definition: Kinetics.h:852
vector_fp m_ropr
Reverse rate-of-progress for each reaction.
Definition: Kinetics.h:921
doublereal temperature() const
Temperature (K).
Definition: Phase.h:601
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 modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: ThermoPhase.h:370
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:266
STL namespace.
virtual void getRevReactionDelta(const doublereal *g, doublereal *dg)
Given an array of species properties &#39;g&#39;, return in array &#39;dg&#39; the change in this quantity in the rev...
Definition: Kinetics.cpp:383
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.
void multiply_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Multiply each entry in x by the corresponding entry in y.
Definition: utilities.h:162
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:748
vector_fp m_ropf
Forward rate-of-progress for each reaction.
Definition: Kinetics.h:918
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
Partial specialization of Kinetics for chemistry in a single bulk phase.
Definition: BulkKinetics.h:21
std::vector< size_t > m_irrev
Indices of irreversible reactions.
Definition: BulkKinetics.h:51
vector_fp m_rfn
Forward rate constant for each reaction.
Definition: Kinetics.h:912
virtual bool addReaction(shared_ptr< Reaction > r)
Add a single reaction to the mechanism.
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
Definition: Kinetics.h:849
vector_fp m_perturb
Vector of perturbation factors for each reaction&#39;s rate of progress vector.
Definition: Kinetics.h:864
void _update_rates_T()
Update temperature-dependent portions of reaction rates.
virtual bool addReaction(shared_ptr< Reaction > r)
Add a single reaction to the mechanism.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
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 doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: ThermoPhase.cpp:65
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition: Kinetics.h:915
void updateKc()
Update the equilibrium constants in molar units.
void _update_rates_C()
Update properties that depend on concentrations.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
const int ELEMENTARY_RXN
A reaction with a rate coefficient that depends only on temperature and voltage that also obeys mass-...
Definition: reaction_defs.h:31
virtual void getFwdRateConstants(doublereal *kfwd)
Return the forward rate constants.
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
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
virtual void getReactionDelta(const doublereal *property, doublereal *deltaProperty)
Change in species properties.
Definition: Kinetics.cpp:373