Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BulkKinetics.cpp
3 
4 namespace Cantera
5 {
6 
7 BulkKinetics::BulkKinetics(thermo_t* thermo) :
8  m_ROP_ok(false),
9  m_temp(0.0),
10  m_finalized(false)
11 {
12  if (thermo) {
13  addPhase(*thermo);
14  }
15 }
16 
17 
18 Kinetics* BulkKinetics::duplMyselfAsKinetics(const std::vector<thermo_t*> & tpVector) const
19 {
20  BulkKinetics* kin = new BulkKinetics(*this);
21  kin->assignShallowPointers(tpVector);
22  return kin;
23 }
24 
26  if (std::find(m_revindex.begin(), m_revindex.end(), i)
27  < m_revindex.end()) {
28  return true;
29  } else {
30  return false;
31  }
32 }
33 
34 
35 void BulkKinetics::getDeltaGibbs(doublereal* deltaG)
36 {
37  // Get the chemical potentials of the species in the ideal gas solution.
38  thermo().getChemPotentials(&m_grt[0]);
39  // Use the stoichiometric manager to find deltaG for each reaction.
40  getReactionDelta(&m_grt[0], deltaG);
41 }
42 
43 void BulkKinetics::getDeltaEnthalpy(doublereal* deltaH)
44 {
45  // Get the partial molar enthalpy of all species in the ideal gas.
46  thermo().getPartialMolarEnthalpies(&m_grt[0]);
47  // Use the stoichiometric manager to find deltaH for each reaction.
48  getReactionDelta(&m_grt[0], deltaH);
49 }
50 
51 void BulkKinetics::getDeltaEntropy(doublereal* deltaS)
52 {
53  // Get the partial molar entropy of all species in the solid solution.
54  thermo().getPartialMolarEntropies(&m_grt[0]);
55  // Use the stoichiometric manager to find deltaS for each reaction.
56  getReactionDelta(&m_grt[0], deltaS);
57 }
58 
59 void BulkKinetics::getDeltaSSGibbs(doublereal* deltaG)
60 {
61  // Get the standard state chemical potentials of the species. This is the
62  // array of chemical potentials at unit activity. We define these here as
63  // the chemical potentials of the pure species at the temperature and
64  // pressure of the solution.
65  thermo().getStandardChemPotentials(&m_grt[0]);
66  // Use the stoichiometric manager to find deltaG for each reaction.
67  getReactionDelta(&m_grt[0], deltaG);
68 }
69 
70 void BulkKinetics::getDeltaSSEnthalpy(doublereal* deltaH)
71 {
72  // Get the standard state enthalpies of the species.
73  thermo().getEnthalpy_RT(&m_grt[0]);
74  doublereal RT = thermo().temperature() * GasConstant;
75  for (size_t k = 0; k < m_kk; k++) {
76  m_grt[k] *= RT;
77  }
78  // Use the stoichiometric manager to find deltaH for each reaction.
79  getReactionDelta(&m_grt[0], deltaH);
80 }
81 
82 void BulkKinetics::getDeltaSSEntropy(doublereal* deltaS)
83 {
84  // Get the standard state entropy of the species. We define these here as
85  // the entropies of the pure species at the temperature and pressure of the
86  // solution.
87  thermo().getEntropy_R(&m_grt[0]);
88  doublereal R = GasConstant;
89  for (size_t k = 0; k < m_kk; k++) {
90  m_grt[k] *= R;
91  }
92  // Use the stoichiometric manager to find deltaS for each reaction.
93  getReactionDelta(&m_grt[0], deltaS);
94 }
95 
96 void BulkKinetics::getRevRateConstants(doublereal* krev, bool doIrreversible)
97 {
98  /*
99  * go get the forward rate constants. -> note, we don't
100  * really care about speed or redundancy in these
101  * informational routines.
102  */
103  getFwdRateConstants(krev);
104 
105  if (doIrreversible) {
107  for (size_t i = 0; i < m_ii; i++) {
108  krev[i] /= m_ropnet[i];
109  }
110  } else {
111  // m_rkcn[] is zero for irreversible reactions
112  for (size_t i = 0; i < m_ii; i++) {
113  krev[i] *= m_rkcn[i];
114  }
115  }
116 }
117 
119 {
121  m_dn.push_back(accumulate(r.pstoich.begin(), r.pstoich.end(), 0.0) -
122  accumulate(r.rstoich.begin(), r.rstoich.end(), 0.0));
123 
124  if (r.reversible) {
125  m_revindex.push_back(nReactions());
126  } else {
127  m_irrev.push_back(nReactions());
128  }
129 }
130 
131 bool BulkKinetics::addReaction(shared_ptr<Reaction> r)
132 {
133  bool added = Kinetics::addReaction(r);
134  if (!added) {
135  return false;
136  }
137  double dn = 0.0;
138  for (Composition::const_iterator iter = r->products.begin();
139  iter != r->products.end();
140  ++iter) {
141  dn += iter->second;
142  }
143  for (Composition::const_iterator iter = r->reactants.begin();
144  iter != r->reactants.end();
145  ++iter) {
146  dn -= iter->second;
147  }
148 
149  m_dn.push_back(dn);
150 
151  if (r->reversible) {
152  m_revindex.push_back(nReactions()-1);
153  } else {
154  m_irrev.push_back(nReactions()-1);
155  }
156  return true;
157 }
158 
159 void BulkKinetics::addElementaryReaction(ReactionData& r)
160 {
161  m_rates.install(nReactions(), r);
162 }
163 
164 void BulkKinetics::addElementaryReaction(ElementaryReaction& r)
165 {
166  m_rates.install(nReactions()-1, r.rate);
167 }
168 
169 void BulkKinetics::modifyElementaryReaction(size_t i, ElementaryReaction& rNew)
170 {
171  m_rates.replace(i, rNew.rate);
172 }
173 
175 {
176  m_kk = thermo().nSpecies();
177  m_rrxn.resize(m_kk);
178  m_prxn.resize(m_kk);
179  m_conc.resize(m_kk);
180  m_grt.resize(m_kk);
181 }
182 
184 {
185  m_finalized = true;
186 
187  // Guarantee that these arrays can be converted to double* even in the
188  // special case where there are no reactions defined.
189  if (!m_ii) {
190  m_perturb.resize(1, 1.0);
191  m_ropf.resize(1, 0.0);
192  m_ropr.resize(1, 0.0);
193  m_ropnet.resize(1, 0.0);
194  m_rkcn.resize(1, 0.0);
195  }
196 }
197 
199 {
200  return m_finalized;
201 }
202 
203 void BulkKinetics::setMultiplier(size_t i, double f) {
205  m_ROP_ok = false;
206 }
207 
208 }
vector_fp m_ropr
Reverse rate-of-progress for each reaction.
Definition: Kinetics.h:1107
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 assignShallowPointers(const std::vector< thermo_t * > &tpVector)
Reassign the pointers within the Kinetics object.
Definition: Kinetics.cpp:140
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:680
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:285
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
Definition: Kinetics.h:982
vector_fp pstoich
Product stoichiometric coefficients, in the order given by products.
Definition: ReactionData.h:101
virtual void getFwdRateConstants(doublereal *kfwd)
Return the forward rate constants.
Definition: Kinetics.h:728
virtual void getDeltaSSEntropy(doublereal *deltaS)
Return the vector of values for the change in the standard state entropies for each reaction...
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
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.
Definition: Kinetics.h:442
virtual void init()
Prepare the class for the addition of reactions.
ThermoPhase thermo_t
typedef for the ThermoPhase class
Definition: ThermoPhase.h:1660
vector_fp m_ropf
Forward rate-of-progress for each reaction.
Definition: Kinetics.h:1104
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
std::vector< std::map< size_t, doublereal > > m_prxn
m_prxn is a vector of maps, containing the reactant stoichiometric coefficient information ...
Definition: Kinetics.h:1037
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:554
virtual bool isReversible(size_t i)
True if reaction i has been declared to be reversible.
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
virtual void getRevRateConstants(doublereal *krev, bool doIrreversible=false)
Return the reverse rate constants.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: ThermoPhase.h:597
std::vector< size_t > m_revindex
Indices of reversible reactions.
Definition: BulkKinetics.h:52
virtual Kinetics * duplMyselfAsKinetics(const std::vector< thermo_t * > &tpVector) const
Duplication routine for objects which inherit from Kinetics.
std::vector< std::map< size_t, doublereal > > m_rrxn
m_rrxn is a vector of maps, containing the reactant stoichiometric coefficient information ...
Definition: Kinetics.h:1027
virtual void getDeltaEntropy(doublereal *deltaS)
Return the vector of values for the reactions change in entropy.
vector_fp m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition: Kinetics.h:1101
vector_fp rstoich
Reactant stoichiometric coefficients, in the order given by reactants.
Definition: ReactionData.h:94
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:265
bool reversible
True if the current reaction is reversible. False otherwise.
Definition: ReactionData.h:137
virtual void getDeltaGibbs(doublereal *deltaG)
Return the vector of values for the reaction Gibbs free energy change.
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:690
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
virtual bool ready() const
Returns true if the kinetics manager has been properly initialized and finalized. ...
vector_fp m_dn
Difference between the global reactants order and the global products order.
Definition: BulkKinetics.h:58
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
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:193
virtual void finalize()
Finish adding reactions and prepare for use.
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: ThermoPhase.h:587
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
virtual void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
Definition: Kinetics.h:884
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:456
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
Definition: Kinetics.cpp:557