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