Cantera  2.0
AqueousKinetics.h
Go to the documentation of this file.
1 /**
2  * @file AqueousKinetics.h
3  *
4  * @ingroup chemkinetics
5  */
6 
7 // Copyright 2001 California Institute of Technology
8 
9 #ifndef CT_AQUEOUSKINETICS_H
10 #define CT_AQUEOUSKINETICS_H
11 
12 #include <fstream>
13 #include <map>
14 
15 #include "cantera/thermo/mix_defs.h"
16 #include "Kinetics.h"
17 
18 #include "cantera/base/utilities.h"
19 
20 #include "ReactionStoichMgr.h"
21 #include "ThirdBodyMgr.h"
22 #include "FalloffMgr.h"
23 #include "RateCoeffMgr.h"
24 
25 #include <cmath>
26 #include <cstdlib>
27 
28 void get_wdot(const doublereal* rop, doublereal* wdot);
29 
30 namespace Cantera
31 {
32 
33 // forward references
34 
35 class ReactionData;
36 
37 /**
38  * Kinetics manager for elementary aqueous-phase chemistry. This
39  * kinetics manager implements standard mass-action reaction rate
40  * expressions for liquids
41  *
42  *
43  * Concentration
44  *
45  * @ingroup kinetics
46  */
47 class AqueousKinetics : public Kinetics
48 {
49 
50 public:
51 
52  /**
53  * @name Constructors and General Information
54  */
55  //@{
56  /// Constructor.
58 
59  AqueousKinetics(const AqueousKinetics& right);
60 
61  AqueousKinetics& operator=(const AqueousKinetics& right);
62 
63  /// Destructor.
64  virtual ~AqueousKinetics();
65 
66 
67  //! Duplication routine for objects which inherit from Kinetics
68  /*!
69  * This virtual routine can be used to duplicate %Kinetics objects
70  * inherited from %Kinetics even if the application only has
71  * a pointer to %Kinetics to work with.
72  *
73  * These routines are basically wrappers around the derived copy constructor.
74  *
75  * @param tpVector Vector of shallow pointers to ThermoPhase objects. this is the
76  * m_thermo vector within this object
77  */
78  virtual Kinetics* duplMyselfAsKinetics(const std::vector<thermo_t*> & tpVector) const;
79 
80  /**
81  * @deprecated use type() instead
82  */
83  DEPRECATED(virtual int ID() const) {
84  return cAqueousKinetics;
85  }
86  virtual int type() const {
87  return cAqueousKinetics;
88  }
89 
90  virtual doublereal reactantStoichCoeff(size_t k, size_t i) const {
91  return m_rrxn[k][i];
92  }
93 
94  virtual doublereal productStoichCoeff(size_t k, size_t i) const {
95  return m_prxn[k][i];
96  }
97 
98  //@}
99  /**
100  * @name Reaction Rates Of Progress
101  */
102  //@{
103  /**
104  * Forward rates of progress.
105  * Return the forward rates of progress in array fwdROP, which
106  * must be dimensioned at least as large as the total number
107  * of reactions.
108  */
109  virtual void getFwdRatesOfProgress(doublereal* fwdROP) {
110  updateROP();
111  std::copy(m_ropf.begin(), m_ropf.end(), fwdROP);
112  }
113 
114  /**
115  * Reverse rates of progress.
116  * Return the reverse rates of progress in array revROP, which
117  * must be dimensioned at least as large as the total number
118  * of reactions.
119  */
120  virtual void getRevRatesOfProgress(doublereal* revROP) {
121  updateROP();
122  std::copy(m_ropr.begin(), m_ropr.end(), revROP);
123  }
124 
125  /**
126  * Net rates of progress. Return the net (forward - reverse)
127  * rates of progress in array netROP, which must be
128  * dimensioned at least as large as the total number of
129  * reactions.
130  */
131  virtual void getNetRatesOfProgress(doublereal* netROP) {
132  updateROP();
133  std::copy(m_ropnet.begin(), m_ropnet.end(), netROP);
134  }
135 
136 
137  /**
138  * Equilibrium constants. Return the equilibrium constants of
139  * the reactions in concentration units in array kc, which
140  * must be dimensioned at least as large as the total number
141  * of reactions.
142  */
143  virtual void getEquilibriumConstants(doublereal* kc);
144 
145  /**
146  * Return the array of values for the reaction gibbs free energy
147  * change.
148  * These values depend on the species concentrations.
149  *
150  * units = J kmol-1
151  */
152  virtual void getDeltaGibbs(doublereal* deltaG);
153 
154  /**
155  * Return the array of values for the reaction enthalpy change.
156  * These values depend upon the species concentrations.
157  *
158  * units = J kmol-1
159  */
160  virtual void getDeltaEnthalpy(doublereal* deltaH);
161 
162  /**
163  * Return the array of values for the reactions change in
164  * entropy.
165  * These values depend upon the concentration
166  * of the solution.
167  *
168  * units = J kmol-1 Kelvin-1
169  */
170  virtual void getDeltaEntropy(doublereal* deltaS);
171 
172  /**
173  * Return the array of values for the reaction
174  * standard state Gibbs free energy change.
175  * These values do not depend on the species
176  * concentrations.
177  *
178  * units = J kmol-1
179  */
180  virtual void getDeltaSSGibbs(doublereal* deltaG);
181 
182  /**
183  * Return the array of values for the change in the
184  * standard state enthalpies of reaction.
185  * These values do not depend upon the concentration
186  * of the solution.
187  *
188  * units = J kmol-1
189  */
190  virtual void getDeltaSSEnthalpy(doublereal* deltaH);
191 
192  /**
193  * Return the array of values for the change in the
194  * standard state entropies for each reaction.
195  * These values do not depend upon the concentration
196  * of the solution.
197  *
198  * units = J kmol-1 Kelvin-1
199  */
200  virtual void getDeltaSSEntropy(doublereal* deltaS);
201 
202  //@}
203  /**
204  * @name Species Production Rates
205  */
206  //@{
207 
208  //! Return the species net production rates
209  /*!
210  * Species net production rates [kmol/m^3/s]. Return the species
211  * net production rates (creation - destruction) in array
212  * wdot, which must be dimensioned at least as large as the
213  * total number of species.
214  *
215  * @param net Array of species production rates.
216  * units kmol m-3 s-1
217  */
218  virtual void getNetProductionRates(doublereal* net) {
219  updateROP();
220  //#ifdef HWMECH
221  //get_wdot(&m_kdata->m_ropnet[0], net);
222  //#else
223  m_rxnstoich.getNetProductionRates(m_kk, &m_ropnet[0], net);
224  //#endif
225  }
226 
227  /**
228  * Species creation rates [kmol/m^3]. Return the species
229  * creation rates in array cdot, which must be
230  * dimensioned at least as large as the total number of
231  * species.
232  *
233  */
234  virtual void getCreationRates(doublereal* cdot) {
235  updateROP();
236  m_rxnstoich.getCreationRates(m_kk, &m_ropf[0], &m_ropr[0], cdot);
237  }
238 
239  /**
240  * Species destruction rates [kmol/m^3]. Return the species
241  * destruction rates in array ddot, which must be
242  * dimensioned at least as large as the total number of
243  * species.
244  *
245  */
246  virtual void getDestructionRates(doublereal* ddot) {
247  updateROP();
248  m_rxnstoich.getDestructionRates(m_kk, &m_ropf[0], &m_ropr[0], ddot);
249  }
250 
251  //@}
252  /**
253  * @name Reaction Mechanism Informational Query Routines
254  */
255  //@{
256 
257  /**
258  * Flag specifying the type of reaction. The legal values and
259  * their meaning are specific to the particular kinetics
260  * manager.
261  */
262  virtual int reactionType(size_t i) const {
263  return m_index[i].first;
264  }
265 
266  virtual std::string reactionString(size_t i) const {
267  return m_rxneqn[i];
268  }
269 
270  /**
271  * True if reaction i has been declared to be reversible. If
272  * isReversible(i) is false, then the reverse rate of progress
273  * for reaction i is always zero.
274  */
275  virtual bool isReversible(size_t i) {
276  if (std::find(m_revindex.begin(), m_revindex.end(), i)
277  < m_revindex.end()) {
278  return true;
279  } else {
280  return false;
281  }
282  }
283 
284  /**
285  * Return the forward rate constants
286  *
287  * length is the number of reactions. units depends
288  * on many issues.
289  */
290  virtual void getFwdRateConstants(doublereal* kfwd);
291 
292  /**
293  * Return the reverse rate constants.
294  *
295  * length is the number of reactions. units depends
296  * on many issues. Note, this routine will return rate constants
297  * for irreversible reactions if the default for
298  * doIrreversible is overridden.
299  */
300  virtual void getRevRateConstants(doublereal* krev,
301  bool doIrreversible = false);
302 
303  //@}
304  /**
305  * @name Reaction Mechanism Setup Routines
306  */
307  //@{
308 
309  virtual void init();
310 
311  /// Add a reaction to the mechanism.
312  virtual void addReaction(ReactionData& r);
313 
314  virtual void finalize();
315  virtual bool ready() const;
316 
317  virtual void update_T();
318  virtual void update_C();
319 
320  void updateROP();
321 
322 
323  const std::vector<grouplist_t>& reactantGroups(size_t i) {
324  return m_rgroups[i];
325  }
326  const std::vector<grouplist_t>& productGroups(size_t i) {
327  return m_pgroups[i];
328  }
329 
330 
331  void _update_rates_T();
332  void _update_rates_C();
333 
334  //@}
335 
336 protected:
337 
338  size_t m_nfall;
339 
340  Rate1<Arrhenius> m_rates;
341 
342  mutable std::map<size_t, std::pair<int, size_t> > m_index;
343 
344  std::vector<size_t> m_irrev;
345 
346  ReactionStoichMgr m_rxnstoich;
347 
348  std::vector<size_t> m_fwdOrder;
349 
350  size_t m_nirrev;
351  size_t m_nrev;
352 
353  std::map<size_t, std::vector<grouplist_t> > m_rgroups;
354  std::map<size_t, std::vector<grouplist_t> > m_pgroups;
355 
356  std::vector<int> m_rxntype;
357 
358  mutable std::vector<std::map<size_t, doublereal> > m_rrxn;
359  mutable std::vector<std::map<size_t, doublereal> > m_prxn;
360 
361  /**
362  * Difference between the input global reactants order
363  * and the input global products order. Changed to a double
364  * to account for the fact that we can have real-valued
365  * stoichiometries.
366  */
368  std::vector<size_t> m_revindex;
369 
370  std::vector<std::string> m_rxneqn;
371 
372  vector_fp m_conc;
373  vector_fp m_grt;
374 
375  //! @name Aqueous kinetics data
376  //!@{
377  vector_fp m_ropf;
378  vector_fp m_ropr;
379  vector_fp m_ropnet;
380  bool m_ROP_ok;
381 
382  doublereal m_temp;
383  vector_fp m_rfn;
384 
385  vector_fp m_rkcn;
386  //!@}
387 
388 private:
389 
390  size_t reactionNumber() {
391  return m_ii;
392  }
393  std::vector<std::map<int, doublereal> > m_stoich;
394 
395  void addElementaryReaction(ReactionData& r);
396 
397 
398  void installReagents(const ReactionData& r);
399 
400  void installGroups(size_t irxn, const std::vector<grouplist_t>& r,
401  const std::vector<grouplist_t>& p);
402  void updateKc();
403 
404  void registerReaction(size_t rxnNumber, int type, size_t loc) {
405  m_index[rxnNumber] = std::pair<int, size_t>(type, loc);
406  }
407  bool m_finalized;
408 };
409 }
410 
411 #endif