Cantera  2.3.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 }
22 
23 Kinetics* AqueousKinetics::duplMyselfAsKinetics(const std::vector<thermo_t*> & tpVector) const
24 {
25  AqueousKinetics* gK = new AqueousKinetics(*this);
26  gK->assignShallowPointers(tpVector);
27  return gK;
28 }
29 
31 {
32  doublereal T = thermo().temperature();
33  m_rates.update(T, log(T), m_rfn.data());
34 
35  m_temp = T;
36  updateKc();
37  m_ROP_ok = false;
38 }
39 
41 {
42  thermo().getActivityConcentrations(m_conc.data());
43  m_ROP_ok = false;
44 }
45 
47 {
48  thermo().getStandardChemPotentials(m_grt.data());
49  fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
50  for (size_t k = 0; k < thermo().nSpecies(); k++) {
51  doublereal logStandConc_k = thermo().logStandardConc(k);
52  m_grt[k] -= GasConstant * m_temp * logStandConc_k;
53  }
54 
55  // compute Delta G^0 for all reversible reactions
56  getRevReactionDelta(m_grt.data(), m_rkcn.data());
57 
58  doublereal rrt = 1.0 / thermo().RT();
59  for (size_t i = 0; i < m_revindex.size(); i++) {
60  size_t irxn = m_revindex[i];
61  m_rkcn[irxn] = exp(m_rkcn[irxn]*rrt);
62  }
63 
64  for (size_t i = 0; i != m_irrev.size(); ++i) {
65  m_rkcn[ m_irrev[i] ] = 0.0;
66  }
67 }
68 
70 {
72 
73  thermo().getStandardChemPotentials(m_grt.data());
74  fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
75  for (size_t k = 0; k < thermo().nSpecies(); k++) {
76  doublereal logStandConc_k = thermo().logStandardConc(k);
77  m_grt[k] -= GasConstant * m_temp * logStandConc_k;
78  }
79 
80  // compute Delta G^0 for all reactions
81  getReactionDelta(m_grt.data(), m_rkcn.data());
82 
83  doublereal rrt = 1.0 / thermo().RT();
84  for (size_t i = 0; i < nReactions(); i++) {
85  kc[i] = exp(-m_rkcn[i]*rrt);
86  }
87 
88  // force an update of T-dependent properties, so that m_rkcn will
89  // be updated before it is used next.
90  m_temp = 0.0;
91 }
92 
93 void AqueousKinetics::updateROP()
94 {
97 
98  if (m_ROP_ok) {
99  return;
100  }
101 
102  // copy rate coefficients into ropf
103  m_ropf = m_rfn;
104 
105  // multiply by perturbation factor
106  multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin());
107 
108  // copy the forward rates to the reverse rates
109  m_ropr = m_ropf;
110 
111  // for reverse rates computed from thermochemistry, multiply the forward
112  // rates copied into m_ropr by the reciprocals of the equilibrium constants
113  multiply_each(m_ropr.begin(), m_ropr.end(), m_rkcn.begin());
114 
115  // multiply ropf by concentration products
116  m_reactantStoich.multiply(m_conc.data(), m_ropf.data());
117 
118  // for reversible reactions, multiply ropr by concentration products
119  m_revProductStoich.multiply(m_conc.data(), m_ropr.data());
120 
121  for (size_t j = 0; j != nReactions(); ++j) {
122  m_ropnet[j] = m_ropf[j] - m_ropr[j];
123  }
124 
125  m_ROP_ok = true;
126 }
127 
129 {
130  _update_rates_T();
131  _update_rates_C();
132 
133  // copy rate coefficients into ropf
134  m_ropf = m_rfn;
135 
136  // multiply by perturbation factor
137  multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin());
138 
139  for (size_t i = 0; i < nReactions(); i++) {
140  kfwd[i] = m_ropf[i];
141  }
142 }
143 
144 bool AqueousKinetics::addReaction(shared_ptr<Reaction> r)
145 {
146  bool added = BulkKinetics::addReaction(r);
147  if (!added) {
148  return false;
149  }
150  if (r->reaction_type == ELEMENTARY_RXN) {
151  addElementaryReaction(dynamic_cast<ElementaryReaction&>(*r));
152  } else {
153  throw CanteraError("AqueousKinetics::addReaction",
154  "Invalid reaction type: {}", r->reaction_type);
155  }
156  return true;
157 }
158 
159 void AqueousKinetics::modifyReaction(size_t i, shared_ptr<Reaction> rNew)
160 {
162  modifyElementaryReaction(i, dynamic_cast<ElementaryReaction&>(*rNew));
163 
164  // invalidate all cached data
165  m_ROP_ok = false;
166  m_temp += 0.1234;
167 }
168 
169 }
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
Definition: Kinetics.cpp:622
Kinetics manager for elementary aqueous-phase chemistry.
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
Definition: Kinetics.h:913
vector_fp m_ropr
Reverse rate-of-progress for each reaction.
Definition: Kinetics.h:982
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:276
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
AqueousKinetics(thermo_t *thermo=0)
Constructor. Creates an empty reaction mechanism.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: ThermoPhase.h:403
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:262
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:438
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.
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:809
vector_fp m_ropf
Forward rate-of-progress for each reaction.
Definition: Kinetics.h:979
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:52
vector_fp m_rfn
Forward rate constant for each reaction.
Definition: Kinetics.h:973
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:910
virtual void assignShallowPointers(const std::vector< thermo_t *> &tpVector)
Reassign the pointers within the Kinetics object.
Definition: Kinetics.cpp:129
vector_fp m_perturb
Vector of perturbation factors for each reaction&#39;s rate of progress vector.
Definition: Kinetics.h:925
Public interface for kinetics managers.
Definition: Kinetics.h:111
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:51
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:184
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual Kinetics * duplMyselfAsKinetics(const std::vector< thermo_t *> &tpVector) const
Duplication routine for objects which inherit from Kinetics.
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition: Kinetics.h:976
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:579
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual void getReactionDelta(const doublereal *property, doublereal *deltaProperty)
Change in species properties.
Definition: Kinetics.cpp:428