Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AqueousKinetics.cpp
Go to the documentation of this file.
1 /**
2  * @file AqueousKinetics.cpp
3  *
4  * Homogeneous kinetics in an aqueous phase, either condensed
5  * or dilute in salts
6  */
7 /*
8  * Copyright (2006) Sandia Corporation. Under the terms of
9  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
10  * U.S. Government retains certain rights in this software.
11  */
12 
16 
17 using namespace std;
18 
19 namespace Cantera
20 {
21 
22 AqueousKinetics::AqueousKinetics(thermo_t* thermo) :
23  BulkKinetics(thermo)
24 {
25 }
26 
27 Kinetics* AqueousKinetics::duplMyselfAsKinetics(const std::vector<thermo_t*> & tpVector) const
28 {
29  AqueousKinetics* gK = new AqueousKinetics(*this);
30  gK->assignShallowPointers(tpVector);
31  return gK;
32 }
33 
35 {
36  doublereal T = thermo().temperature();
37  m_rates.update(T, log(T), &m_rfn[0]);
38 
39  m_temp = T;
40  updateKc();
41  m_ROP_ok = false;
42 }
43 
45 {
46  thermo().getActivityConcentrations(&m_conc[0]);
47  m_ROP_ok = false;
48 }
49 
51 {
52  doublereal rt = GasConstant * m_temp;
53 
54  thermo().getStandardChemPotentials(&m_grt[0]);
55  fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
56  for (size_t k = 0; k < thermo().nSpecies(); k++) {
57  doublereal logStandConc_k = thermo().logStandardConc(k);
58  m_grt[k] -= rt * logStandConc_k;
59  }
60 
61  // compute Delta G^0 for all reversible reactions
62  getRevReactionDelta(&m_grt[0], &m_rkcn[0]);
63 
64  doublereal rrt = 1.0/(GasConstant * thermo().temperature());
65  for (size_t i = 0; i < m_revindex.size(); i++) {
66  size_t irxn = m_revindex[i];
67  m_rkcn[irxn] = exp(m_rkcn[irxn]*rrt);
68  }
69 
70  for (size_t i = 0; i != m_irrev.size(); ++i) {
71  m_rkcn[ m_irrev[i] ] = 0.0;
72  }
73 }
74 
76 {
78 
79  thermo().getStandardChemPotentials(&m_grt[0]);
80  fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
81  doublereal rt = GasConstant * m_temp;
82  for (size_t k = 0; k < thermo().nSpecies(); k++) {
83  doublereal logStandConc_k = thermo().logStandardConc(k);
84  m_grt[k] -= rt * logStandConc_k;
85  }
86 
87  // compute Delta G^0 for all reactions
88  getReactionDelta(&m_grt[0], &m_rkcn[0]);
89 
90  doublereal rrt = 1.0/(GasConstant * thermo().temperature());
91  for (size_t i = 0; i < m_ii; i++) {
92  kc[i] = exp(-m_rkcn[i]*rrt);
93  }
94 
95  // force an update of T-dependent properties, so that m_rkcn will
96  // be updated before it is used next.
97  m_temp = 0.0;
98 }
99 
100 void AqueousKinetics::updateROP()
101 {
102  _update_rates_T();
103  _update_rates_C();
104 
105  if (m_ROP_ok) {
106  return;
107  }
108 
109  // copy rate coefficients into ropf
110  copy(m_rfn.begin(), m_rfn.end(), m_ropf.begin());
111 
112  // multiply by perturbation factor
113  multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin());
114 
115  // copy the forward rates to the reverse rates
116  copy(m_ropf.begin(), m_ropf.end(), m_ropr.begin());
117 
118  // for reverse rates computed from thermochemistry, multiply the forward
119  // rates copied into m_ropr by the reciprocals of the equilibrium constants
120  multiply_each(m_ropr.begin(), m_ropr.end(), m_rkcn.begin());
121 
122  // multiply ropf by concentration products
123  m_reactantStoich.multiply(&m_conc[0], &m_ropf[0]);
124 
125  // for reversible reactions, multiply ropr by concentration products
126  m_revProductStoich.multiply(&m_conc[0], &m_ropr[0]);
127 
128  for (size_t j = 0; j != m_ii; ++j) {
129  m_ropnet[j] = m_ropf[j] - m_ropr[j];
130  }
131 
132  m_ROP_ok = true;
133 }
134 
136 {
137  _update_rates_T();
138  _update_rates_C();
139 
140  // copy rate coefficients into ropf
141  copy(m_rfn.begin(), m_rfn.end(), m_ropf.begin());
142 
143  // multiply by perturbation factor
144  multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin());
145 
146  for (size_t i = 0; i < m_ii; i++) {
147  kfwd[i] = m_ropf[i];
148  }
149 }
150 
152 {
153  if (r.reactionType == ELEMENTARY_RXN) {
154  addElementaryReaction(r);
155  }
156 
158 }
159 
160 bool AqueousKinetics::addReaction(shared_ptr<Reaction> r)
161 {
162  bool added = BulkKinetics::addReaction(r);
163  if (!added) {
164  return false;
165  }
166  if (r->reaction_type == ELEMENTARY_RXN) {
167  addElementaryReaction(dynamic_cast<ElementaryReaction&>(*r));
168  } else {
169  throw CanteraError("AqueousKinetics::addReaction",
170  "Invalid reaction type: " + int2str(r->reaction_type));
171  }
172  return true;
173 }
174 
175 void AqueousKinetics::modifyReaction(size_t i, shared_ptr<Reaction> rNew)
176 {
178  modifyElementaryReaction(i, dynamic_cast<ElementaryReaction&>(*rNew));
179 
180  // invalidate all cached data
181  m_ROP_ok = false;
182  m_temp += 0.1234;
183 }
184 
185 }
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
Definition: Kinetics.cpp:773
Kinetics manager for elementary aqueous-phase chemistry.
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
Definition: Kinetics.h:971
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:39
vector_fp m_ropr
Reverse rate-of-progress for each reaction.
Definition: Kinetics.h:1107
int reactionType
Type of the reaction.
Definition: ReactionData.h:58
virtual void assignShallowPointers(const std::vector< thermo_t * > &tpVector)
Reassign the pointers within the Kinetics object.
Definition: Kinetics.cpp:140
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:285
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
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 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:670
virtual void getRevReactionDelta(const doublereal *g, doublereal *dg)
Given an array of species properties 'g', return in array 'dg' the change in this quantity in the rev...
Definition: Kinetics.cpp:466
vector_fp m_ropnet
Net rate-of-progress for each reaction.
Definition: Kinetics.h:1110
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:234
vector_fp m_ropf
Forward rate-of-progress for each reaction.
Definition: Kinetics.h:1104
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
Partial specialization of Kinetics for chemistry in a single bulk phase.
Definition: BulkKinetics.h:18
std::vector< size_t > m_irrev
Indices of irreversible reactions.
Definition: BulkKinetics.h:53
vector_fp m_rfn
Forward rate constant for each reaction.
Definition: Kinetics.h:1098
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
Definition: Kinetics.h:968
vector_fp m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
Definition: Kinetics.h:986
Public interface for kinetics managers.
Definition: Kinetics.h:128
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
Definition: ReactionData.h:22
void _update_rates_T()
Update temperature-dependent portions of reaction rates.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
std::vector< size_t > m_revindex
Indices of reversible reactions.
Definition: BulkKinetics.h:52
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition: Kinetics.h:1101
void updateKc()
Update the equilibrium constants in molar units.
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:265
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: ThermoPhase.h:425
void _update_rates_C()
Update properties that depend on concentrations.
Templates for operations on vector-like objects.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
size_t m_ii
Number of reactions in the mechanism.
Definition: Kinetics.h:978
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:30
virtual void getFwdRateConstants(doublereal *kfwd)
Return the forward rate constants.
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
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.
virtual void getReactionDelta(const doublereal *property, doublereal *deltaProperty)
Change in species properties.
Definition: Kinetics.cpp:456