Cantera  2.1.2
Kinetics.h
Go to the documentation of this file.
1 /**
2  * @file Kinetics.h
3  * Base class for kinetics managers and also contains the kineticsmgr
4  * module documentation (see \ref kineticsmgr and class
5  * \link Cantera::Kinetics Kinetics\endlink).
6  */
7 
8 // Copyright 2001-2004 California Institute of Technology
9 
10 #ifndef CT_KINETICS_H
11 #define CT_KINETICS_H
12 
16 
17 namespace Cantera
18 {
19 
20 // forward references
21 class ReactionData;
22 
23 /**
24  * @defgroup chemkinetics Chemical Kinetics
25  */
26 
27 /// @defgroup kineticsmgr Kinetics Managers
28 /// @section kinmodman Models and Managers
29 ///
30 /// A kinetics manager is a C++ class that implements a kinetics
31 /// model; a kinetics model is a set of mathematical equation
32 /// describing how various kinetic quantities are to be computed --
33 /// reaction rates, species production rates, etc. Many different
34 /// kinetics models might be defined to handle different types of
35 /// kinetic processes. For example, one kinetics model might use
36 /// expressions valid for elementary reactions in ideal gas
37 /// mixtures. It might, for example, require the reaction orders
38 /// to be integral and equal to the forward stoichiometric
39 /// coefficients, require that each reaction be reversible with a
40 /// reverse rate satisfying detailed balance, include
41 /// pressure-dependent unimolecular reactions, etc. Another
42 /// kinetics model might be designed for heterogeneous chemistry
43 /// at interfaces, and might allow empirical reaction orders,
44 /// coverage-dependent activation energies, irreversible
45 /// reactions, and include effects of potential differences across
46 /// the interface on reaction rates.
47 ///
48 /// A kinetics manager implements a kinetics model. Since the
49 /// model equations may be complex and expensive to evaluate, a
50 /// kinetics manager may adopt various strategies to 'manage' the
51 /// computation and evaluate the expressions efficiently. For
52 /// example, if there are rate coefficients or other quantities
53 /// that depend only on temperature, a manager class may choose to
54 /// store these quantities internally, and re-evaluate them only
55 /// when the temperature has actually changed. Or a manager
56 /// designed for use with reaction mechanisms with a few repeated
57 /// activation energies might precompute the terms \f$ exp(-E/RT)
58 /// \f$, instead of evaluating the exponential repeatedly for each
59 /// reaction. There are many other possible 'management styles',
60 /// each of which might be better suited to some reaction
61 /// mechanisms than others.
62 ///
63 /// But however a manager structures the internal computation, the
64 /// tasks the manager class must perform are, for the most part,
65 /// the same. It must be able to compute reaction rates, species
66 /// production rates, equilibrium constants, etc. Therefore, all
67 /// kinetics manager classes should have a common set of public
68 /// methods, but differ in how they implement these methods.
69 ///
70 /// A kinetics manager computes reaction rates of progress,
71 /// species production rates, equilibrium constants, and similar
72 /// quantities for a reaction mechanism. All kinetics manager
73 /// classes derive from class Kinetics, which defines a common
74 /// public interface for all kinetics managers. Each derived class
75 /// overloads the virtual methods of Kinetics to implement a
76 /// particular kinetics model.
77 ///
78 /// For example, class GasKinetics implements reaction rate
79 /// expressions appropriate for homogeneous reactions in ideal gas
80 /// mixtures, and class InterfaceKinetics implements expressions
81 /// appropriate for heterogeneous mechanisms at interfaces,
82 /// including how to handle reactions involving charged species of
83 /// phases with different electric potentials --- something that
84 /// class GasKinetics doesn't deal with at all.
85 ///
86 /// Kinetics managers may be also created that hard-wire a
87 /// particular reaction mechanism in C++ code. This can often
88 /// result in faster performance. An example of this is the
89 /// kinetics manager GRI30_Kinetics that hard-wires the rate
90 /// expressions for the natural gas combustion mechanism GRI-3.0.
91 ///
92 /// Many of the methods of class Kinetics write into arrays the
93 /// values of some quantity for each species, for example the net
94 /// production rate. These methods always write the results into
95 /// flat arrays, ordered by phase in the order the phase was
96 /// added, and within a phase in the order the species were added
97 /// to the phase (which is the same ordering as in the input
98 /// file). Example: suppose a heterogeneous mechanism involves
99 /// three phases -- a bulk phase 'a', another bulk phase 'b', and
100 /// the surface phase 'a:b' at the a/b interface. Phase 'a'
101 /// contains 12 species, phase 'b' contains 3, and at the
102 /// interface there are 5 adsorbed species defined in phase
103 /// 'a:b'. Then methods like getNetProductionRates(doublereal* net)
104 /// will write and output array of length 20, beginning at the location
105 /// pointed to by 'net'. The first 12 values will be the net production
106 /// rates for all 12 species of phase 'a' (even if some do not participate
107 /// in the reactions), the next 3 will be for phase 'b', and finally the
108 /// net production rates for the surface species will occupy the last
109 /// 5 locations.
110 /// @ingroup chemkinetics
111 
112 
113 //! Public interface for kinetics managers.
114 /*!
115  * This class serves as a base class to derive 'kinetics
116  * managers', which are classes that manage homogeneous chemistry
117  * within one phase, or heterogeneous chemistry at one
118  * interface. The virtual methods of this class are meant to be
119  * overloaded in subclasses. The non-virtual methods perform
120  * generic functions and are implemented in Kinetics. They should
121  * not be overloaded. Only those methods required by a subclass
122  * need to be overloaded; the rest will throw exceptions if
123  * called.
124  *
125  * When the nomenclature "kinetics species index" is used below,
126  * this means that the species index ranges over all species in
127  * all phases handled by the kinetics manager.
128  *
129  * @ingroup kineticsmgr
130  */
131 class Kinetics
132 {
133 
134 public:
135  /**
136  * @name Constructors and General Information about Mechanism
137  */
138  //@{
139 
140  /// Default constructor.
141  Kinetics();
142 
143  /// Destructor.
144  virtual ~Kinetics();
145 
146  //!Copy Constructor for the Kinetics object.
147  Kinetics(const Kinetics&);
148 
149  //! Assignment operator
150  /*!
151  * @param right Reference to Kinetics object to be copied into the
152  * current one.
153  */
154  Kinetics& operator=(const Kinetics& right);
155 
156  //! Duplication routine for objects which inherit from Kinetics
157  /*!
158  * This function can be used to duplicate objects derived from Kinetics
159  * even if the application only has a pointer to Kinetics to work with.
160  *
161  * These routines are basically wrappers around the derived copy
162  * constructor.
163  *
164  * @param tpVector Vector of pointers to ThermoPhase objects. this is the
165  * #m_thermo vector within this object
166  */
167  virtual Kinetics* duplMyselfAsKinetics(const std::vector<thermo_t*> & tpVector) const;
168 
169  //! Reassign the pointers within the Kinetics object
170  /*!
171  * This type or routine is necessary because the Kinetics object doesn't
172  * own the ThermoPhase objects. After a duplication, we need to point to
173  * different ThermoPhase objects.
174  *
175  * We check that the ThermoPhase objects are aligned in the same order and have
176  * the following identical properties to the ones that they are replacing:
177  *
178  * - ThermoPhase::id()
179  * - ThermoPhase::eosType()
180  * - ThermoPhase::nSpecies()
181  *
182  * @param tpVector Vector of pointers to ThermoPhase objects. this is the
183  * #m_thermo vector within this object
184  */
185  virtual void assignShallowPointers(const std::vector<thermo_t*> & tpVector);
186 
187  //! Identifies the kinetics manager type.
188  /*!
189  * Each class derived from Kinetics should overload this method to
190  * return a unique integer. Standard values are defined in file
191  * mix_defs.h.
192  */
193  virtual int type() const;
194 
195  //! Number of reactions in the reaction mechanism.
196  size_t nReactions() const {
197  return m_ii;
198  }
199 
200  //! Check that the specified reaction index is in range
201  //! Throws an exception if i is greater than nReactions()
202  void checkReactionIndex(size_t m) const;
203 
204  //! Check that an array size is at least nReactions()
205  //! Throws an exception if ii is less than nReactions(). Used before calls
206  //! which take an array pointer.
207  void checkReactionArraySize(size_t ii) const;
208 
209  //! Check that the specified species index is in range
210  //! Throws an exception if k is greater than nSpecies()-1
211  void checkSpeciesIndex(size_t k) const;
212 
213  //! Check that an array size is at least nSpecies()
214  //! Throws an exception if kk is less than nSpecies(). Used before calls
215  //! which take an array pointer.
216  void checkSpeciesArraySize(size_t mm) const;
217 
218  //@}
219  //! @name Information/Lookup Functions about Phases and Species
220  //@{
221 
222  /**
223  * The number of phases participating in the reaction
224  * mechanism. For a homogeneous reaction mechanism, this will
225  * always return 1, but for a heterogeneous mechanism it will
226  * return the total number of phases in the mechanism.
227  */
228  size_t nPhases() const {
229  return m_thermo.size();
230  }
231 
232  //! Check that the specified phase index is in range
233  //! Throws an exception if m is greater than nPhases()
234  void checkPhaseIndex(size_t m) const;
235 
236  //! Check that an array size is at least nPhases()
237  //! Throws an exception if mm is less than nPhases(). Used before calls
238  //! which take an array pointer.
239  void checkPhaseArraySize(size_t mm) const;
240 
241  /**
242  * Return the phase index of a phase in the list of phases
243  * defined within the object.
244  *
245  * @param ph std::string name of the phase
246  *
247  * If a -1 is returned, then the phase is not defined in
248  * the Kinetics object.
249  */
250  size_t phaseIndex(const std::string& ph) {
251  if (m_phaseindex.find(ph) == m_phaseindex.end()) {
252  return npos;
253  } else {
254  return m_phaseindex[ph] - 1;
255  }
256  }
257 
258  /**
259  * This returns the integer index of the phase which has ThermoPhase type
260  * cSurf. For heterogeneous mechanisms, this identifies the one surface
261  * phase. For homogeneous mechanisms, this returns -1.
262  */
263  size_t surfacePhaseIndex() {
264  return m_surfphase;
265  }
266 
267  /**
268  * Phase where the reactions occur. For heterogeneous mechanisms, one of
269  * the phases in the list of phases represents the 2D interface or 1D edge
270  * at which the reactions take place. This method returns the index of the
271  * phase with the smallest spatial dimension (1, 2, or 3) among the list
272  * of phases. If there is more than one, the index of the first one is
273  * returned. For homogeneous mechanisms, the value 0 is returned.
274  */
276  return m_rxnphase;
277  }
278 
279  /**
280  * This method returns a reference to the nth ThermoPhase object defined
281  * in this kinetics mechanism. It is typically used so that member
282  * functions of the ThermoPhase object may be called. For homogeneous
283  * mechanisms, there is only one object, and this method can be called
284  * without an argument to access it.
285  *
286  * @param n Index of the ThermoPhase being sought.
287  */
288  thermo_t& thermo(size_t n=0) {
289  return *m_thermo[n];
290  }
291  const thermo_t& thermo(size_t n=0) const {
292  return *m_thermo[n];
293  }
294 
295  /**
296  * The total number of species in all phases participating in the kinetics
297  * mechanism. This is useful to dimension arrays for use in calls to
298  * methods that return the species production rates, for example.
299  */
300  size_t nTotalSpecies() const {
301  size_t n=0, np;
302  np = nPhases();
303  for (size_t p = 0; p < np; p++) {
304  n += thermo(p).nSpecies();
305  }
306  return n;
307  }
308 
309  /**
310  * The location of species k of phase n in species arrays.
311  * Kinetics manager classes return species production rates in
312  * flat arrays, with the species of each phases following one
313  * another, in the order the phases were added. This method
314  * is useful to find the value for a particular species of a
315  * particular phase in arrays returned from methods like
316  * getCreationRates that return an array of species-specific
317  * quantities.
318  *
319  * Example: suppose a heterogeneous mechanism involves three
320  * phases. The first contains 12 species, the second 26, and
321  * the third 3. Then species arrays must have size at least
322  * 41, and positions 0 - 11 are the values for the species in
323  * the first phase, positions 12 - 37 are the values for the
324  * species in the second phase, etc. Then
325  * kineticsSpeciesIndex(7, 0) = 7, kineticsSpeciesIndex(4, 1)
326  * = 16, and kineticsSpeciesIndex(2, 2) = 40.
327  *
328  * @param k species index
329  * @param n phase index for the species
330  */
331  size_t kineticsSpeciesIndex(size_t k, size_t n) const {
332  return m_start[n] + k;
333  }
334 
335  //! Return the name of the kth species in the kinetics manager.
336  /*!
337  * k is an integer from 0 to ktot - 1, where ktot is the number of
338  * species in the kinetics manager, which is the sum of the number of
339  * species in all phases participating in the kinetics manager. If k is
340  * out of bounds, the string "<unknown>" is returned.
341  *
342  * @param k species index
343  */
344  std::string kineticsSpeciesName(size_t k) const;
345 
346  /**
347  * This routine will look up a species number based on the input
348  * std::string nm. The lookup of species will occur for all phases
349  * listed in the kinetics object.
350  *
351  * return
352  * - If a match is found, the position in the species list is returned.
353  * - If no match is found, the value -1 is returned.
354  *
355  * @param nm Input string name of the species
356  */
357  size_t kineticsSpeciesIndex(const std::string& nm) const;
358 
359  /**
360  * This routine will look up a species number based on the input
361  * std::string nm. The lookup of species will occur in the specified
362  * phase of the object, or all phases if ph is "<any>".
363  *
364  * return
365  * - If a match is found, the position in the species list is returned.
366  * - If no match is found, the value npos (-1) is returned.
367  *
368  * @param nm Input string name of the species
369  * @param ph Input string name of the phase.
370  */
371  size_t kineticsSpeciesIndex(const std::string& nm,
372  const std::string& ph) const;
373 
374  /**
375  * This function looks up the name of a species and returns a
376  * reference to the ThermoPhase object of the phase where the species
377  * resides. Will throw an error if the species doesn't match.
378  *
379  * @param nm String containing the name of the species.
380  */
381  thermo_t& speciesPhase(const std::string& nm);
382 
383  /**
384  * This function takes as an argument the kineticsSpecies index
385  * (i.e., the list index in the list of species in the kinetics
386  * manager) and returns the species' owning ThermoPhase object.
387  *
388  * @param k Species index
389  */
390  thermo_t& speciesPhase(size_t k) {
391  return thermo(speciesPhaseIndex(k));
392  }
393 
394  /**
395  * This function takes as an argument the kineticsSpecies index (i.e., the
396  * list index in the list of species in the kinetics manager) and returns
397  * the index of the phase owning the species.
398  *
399  * @param k Species index
400  */
401  size_t speciesPhaseIndex(size_t k);
402 
403  //! @}
404  //! @name Reaction Rates Of Progress
405  //! @{
406 
407  //! Return the forward rates of progress of the reactions
408  /*!
409  * Forward rates of progress. Return the forward rates of
410  * progress in array fwdROP, which must be dimensioned at
411  * least as large as the total number of reactions.
412  *
413  * @param fwdROP Output vector containing forward rates
414  * of progress of the reactions. Length: m_ii.
415  */
416  virtual void getFwdRatesOfProgress(doublereal* fwdROP) {
417  err("getFwdRatesOfProgress");
418  }
419 
420  //! Return the Reverse rates of progress of the reactions
421  /*!
422  * Return the reverse rates of progress in array revROP, which must be
423  * dimensioned at least as large as the total number of reactions.
424  *
425  * @param revROP Output vector containing reverse rates
426  * of progress of the reactions. Length: m_ii.
427  */
428  virtual void getRevRatesOfProgress(doublereal* revROP) {
429  err("getRevRatesOfProgress");
430  }
431 
432  /**
433  * Net rates of progress. Return the net (forward - reverse) rates of
434  * progress in array netROP, which must be dimensioned at least as large
435  * as the total number of reactions.
436  *
437  * @param netROP Output vector of the net ROP. Length: m_ii.
438  */
439  virtual void getNetRatesOfProgress(doublereal* netROP) {
440  err("getNetRatesOfProgress");
441  }
442 
443  //! Return a vector of Equilibrium constants.
444  /*!
445  * Return the equilibrium constants of the reactions in concentration
446  * units in array kc, which must be dimensioned at least as large as the
447  * total number of reactions.
448  *
449  * @param kc Output vector containing the equilibrium constants.
450  * Length: m_ii.
451  */
452  virtual void getEquilibriumConstants(doublereal* kc) {
453  err("getEquilibriumConstants");
454  }
455 
456  /**
457  * Change in species properties. Given an array of molar species
458  * property values \f$ z_k, k = 1, \dots, K \f$, return the
459  * array of reaction values
460  * \f[
461  * \Delta Z_i = \sum_k \nu_{k,i} z_k, i = 1, \dots, I.
462  * \f]
463  * For example, if this method is called with the array of
464  * standard-state molar Gibbs free energies for the species,
465  * then the values returned in array \c deltaProperty would be
466  * the standard-state Gibbs free energies of reaction for each
467  * reaction.
468  *
469  * @param property Input vector of property value. Length: m_kk.
470  * @param deltaProperty Output vector of deltaRxn. Length: m_ii.
471  */
472  virtual void getReactionDelta(const doublereal* property,
473  doublereal* deltaProperty) {
474  err("getReactionDelta");
475  }
476 
477  //! Return the vector of values for the reaction gibbs free energy change.
478  /*!
479  * These values depend upon the concentration of the solution.
480  *
481  * units = J kmol-1
482  *
483  * @param deltaG Output vector of deltaG's for reactions Length: m_ii.
484  */
485  virtual void getDeltaGibbs(doublereal* deltaG) {
486  err("getDeltaGibbs");
487  }
488 
489  //! Return the vector of values for the reaction electrochemical free
490  //! energy change.
491  /*!
492  * These values depend upon the concentration of the solution and the
493  * voltage of the phases
494  *
495  * units = J kmol-1
496  *
497  * @param deltaM Output vector of deltaM's for reactions Length: m_ii.
498  */
499  virtual void getDeltaElectrochemPotentials(doublereal* deltaM) {
500  err("getDeltaElectrochemPotentials");
501  }
502 
503  /**
504  * Return the vector of values for the reactions change in enthalpy.
505  * These values depend upon the concentration of the solution.
506  *
507  * units = J kmol-1
508  *
509  * @param deltaH Output vector of deltaH's for reactions Length: m_ii.
510  */
511  virtual void getDeltaEnthalpy(doublereal* deltaH) {
512  err("getDeltaEnthalpy");
513  }
514 
515  /**
516  * Return the vector of values for the reactions change in entropy. These
517  * values depend upon the concentration of the solution.
518  *
519  * units = J kmol-1 Kelvin-1
520  *
521  * @param deltaS Output vector of deltaS's for reactions Length: m_ii.
522  */
523  virtual void getDeltaEntropy(doublereal* deltaS) {
524  err("getDeltaEntropy");
525  }
526 
527  /**
528  * Return the vector of values for the reaction standard state
529  * gibbs free energy change. These values don't depend upon
530  * the concentration of the solution.
531  *
532  * units = J kmol-1
533  *
534  * @param deltaG Output vector of ss deltaG's for reactions Length: m_ii.
535  */
536  virtual void getDeltaSSGibbs(doublereal* deltaG) {
537  err("getDeltaSSGibbs");
538  }
539 
540  /**
541  * Return the vector of values for the change in the standard
542  * state enthalpies of reaction. These values don't depend
543  * upon the concentration of the solution.
544  *
545  * units = J kmol-1
546  *
547  * @param deltaH Output vector of ss deltaH's for reactions Length: m_ii.
548  */
549  virtual void getDeltaSSEnthalpy(doublereal* deltaH) {
550  err("getDeltaSSEnthalpy");
551  }
552 
553  /**
554  * Return the vector of values for the change in the standard
555  * state entropies for each reaction. These values don't
556  * depend upon the concentration of the solution.
557  *
558  * units = J kmol-1 Kelvin-1
559  *
560  * @param deltaS Output vector of ss deltaS's for reactions Length: m_ii.
561  */
562  virtual void getDeltaSSEntropy(doublereal* deltaS) {
563  err("getDeltaSSEntropy");
564  }
565 
566  //! @}
567  //! @name Species Production Rates
568  //! @{
569 
570  /**
571  * Species creation rates [kmol/m^3/s or kmol/m^2/s]. Return the species
572  * creation rates in array cdot, which must be dimensioned at least as
573  * large as the total number of species in all phases. @see nTotalSpecies.
574  *
575  * @param cdot Output vector of creation rates. Length: m_kk.
576  */
577  virtual void getCreationRates(doublereal* cdot) {
578  err("getCreationRates");
579  }
580 
581  /**
582  * Species destruction rates [kmol/m^3/s or kmol/m^2/s]. Return the
583  * species destruction rates in array ddot, which must be dimensioned at
584  * least as large as the total number of species. @see nTotalSpecies.
585  *
586  * @param ddot Output vector of destruction rates. Length: m_kk.
587  */
588  virtual void getDestructionRates(doublereal* ddot) {
589  err("getDestructionRates");
590  }
591 
592  /**
593  * Species net production rates [kmol/m^3/s or kmol/m^2/s]. Return
594  * the species net production rates (creation - destruction)
595  * in array wdot, which must be dimensioned at least as large
596  * as the total number of species. @see nTotalSpecies.
597  *
598  * @param wdot Output vector of net production rates. Length: m_kk.
599  */
600  virtual void getNetProductionRates(doublereal* wdot) {
601  err("getNetProductionRates");
602  }
603 
604  //! @}
605  //! @name Reaction Mechanism Informational Query Routines
606  //! @{
607 
608  /**
609  * Stoichiometric coefficient of species k as a reactant in reaction i.
610  *
611  * @param k kinetic species index
612  * @param i reaction index
613  */
614  virtual doublereal reactantStoichCoeff(size_t k, size_t i) const {
615  err("reactantStoichCoeff");
616  return -1.0;
617  }
618 
619  /**
620  * Stoichiometric coefficient of species k as a product in reaction i.
621  *
622  * @param k kinetic species index
623  * @param i reaction index
624  */
625  virtual doublereal productStoichCoeff(size_t k, size_t i) const {
626  err("productStoichCoeff");
627  return -1.0;
628  }
629 
630  //! Reactant order of species k in reaction i.
631  /*!
632  * This is the nominal order of the activity concentration in
633  * determining the forward rate of progress of the reaction
634  *
635  * @param k kinetic species index
636  * @param i reaction index
637  */
638  virtual doublereal reactantOrder(size_t k, size_t i) const {
639  err("reactantOrder");
640  return -1.0;
641  }
642 
643  //! product Order of species k in reaction i.
644  /*!
645  * This is the nominal order of the activity concentration of species k in
646  * determining the reverse rate of progress of the reaction i
647  *
648  * For irreversible reactions, this will all be zero.
649  *
650  * @param k kinetic species index
651  * @param i reaction index
652  */
653  virtual doublereal productOrder(int k, int i) const {
654  err("productOrder");
655  return -1.0;
656  }
657 
658  //! Get the vector of activity concentrations used in the kinetics object
659  /*!
660  * @param[out] conc Vector of activity concentrations. Length is equal
661  * to the number of species in the kinetics object
662  */
663  virtual void getActivityConcentrations(doublereal* const conc) {
664  err("getActivityConcentrations");
665  }
666 
667  /**
668  * Returns a read-only reference to the vector of reactant
669  * index numbers for reaction i.
670  *
671  * @param i reaction index
672  */
673  virtual const std::vector<size_t>& reactants(size_t i) const {
674  return m_reactants[i];
675  }
676 
677  /**
678  * Returns a read-only reference to the vector of product
679  * index numbers for reaction i.
680  *
681  * @param i reaction index
682  */
683  virtual const std::vector<size_t>& products(size_t i) const {
684  return m_products[i];
685  }
686 
687  /**
688  * Flag specifying the type of reaction. The legal values and
689  * their meaning are specific to the particular kinetics
690  * manager.
691  *
692  * @param i reaction index
693  */
694  virtual int reactionType(size_t i) const {
695  err("reactionType");
696  return -1;
697  }
698 
699  /**
700  * True if reaction i has been declared to be reversible. If
701  * isReversible(i) is false, then the reverse rate of progress
702  * for reaction i is always zero.
703  *
704  * @param i reaction index
705  */
706  virtual bool isReversible(size_t i) {
707  err("isReversible");
708  return false;
709  }
710 
711  /**
712  * Return a string representing the reaction.
713  *
714  * @param i reaction index
715  */
716  virtual std::string reactionString(size_t i) const {
717  err("reactionStd::String");
718  return "<null>";
719  }
720 
721  /**
722  * Return the forward rate constants
723  *
724  * length is the number of reactions. units depends on many issues.
725  *
726  * @param kfwd Output vector containing the forward reaction rate
727  * constants. Length: m_ii.
728  */
729  virtual void getFwdRateConstants(doublereal* kfwd) {
730  err("getFwdRateConstants");
731  }
732 
733  /**
734  * Return the reverse rate constants.
735  *
736  * length is the number of reactions. units depends on many issues. Note,
737  * this routine will return rate constants for irreversible reactions if
738  * the default for doIrreversible is overridden.
739  *
740  * @param krev Output vector of reverse rate constants.
741  * @param doIrreversible boolean indicating whether irreversible reactions
742  * should be included.
743  */
744  virtual void getRevRateConstants(doublereal* krev,
745  bool doIrreversible = false) {
746  err("getFwdRateConstants");
747  }
748 
749  /**
750  * Return the activation energies in Kelvin.
751  *
752  * length is the number of reactions
753  *
754  * @param E Ouptut vector of activation energies. Length: m_ii.
755  * @deprecated To be removed in Cantera 2.2.
756  */
757  virtual void getActivationEnergies(doublereal* E) {
758  err("getActivationEnergies");
759  }
760 
761  //! @}
762  //! @name Reaction Mechanism Construction
763  //! @{
764 
765  //! Add a phase to the kinetics manager object.
766  /*!
767  * This must be done before the function init() is called or before any
768  * reactions are input. The following fields are updated:
769  *
770  * - #m_start -> vector of integers, containing the starting position of
771  * the species for each phase in the kinetics mechanism.
772  * - #m_surfphase -> index of the surface phase.
773  * - #m_thermo -> vector of pointers to ThermoPhase phases that
774  * participate in the kinetics mechanism.
775  * - #m_phaseindex -> map containing the std::string id of each
776  * ThermoPhase phase as a key and the index of the phase within the
777  * kinetics manager object as the value.
778  *
779  * @param thermo Reference to the ThermoPhase to be added.
780  */
781  virtual void addPhase(thermo_t& thermo);
782 
783  /**
784  * Prepare the class for the addition of reactions. This method is called
785  * by importKinetics() after all phases have been added but before any
786  * reactions have been. The base class method does nothing, but derived
787  * classes may use this to perform any initialization (allocating arrays,
788  * etc.) that requires knowing the phases and species, but before any
789  * reactions are added.
790  */
791  virtual void init() {}
792 
793  /**
794  * Finish adding reactions and prepare for use. This method is called by
795  * importKinetics() after all reactions have been entered into the
796  * mechanism and before the mechanism is used to calculate reaction rates.
797  * The base class method does nothing, but derived classes may use this to
798  * perform any initialization (allocating arrays, etc.) that must be done
799  * after the reactions are entered.
800  */
801  virtual void finalize();
802 
803  /**
804  * Add a single reaction to the mechanism. This routine
805  * must be called after init() and before finalize().
806  *
807  * @param r Reference to the ReactionData object for the reaction
808  * to be added.
809  */
810  virtual void addReaction(ReactionData& r) {
811  err("addReaction");
812  }
813 
814  virtual const std::vector<grouplist_t>& reactantGroups(size_t i) {
815  //err("reactantGroups");
816  return m_dummygroups;
817  }
818 
819  virtual const std::vector<grouplist_t>& productGroups(size_t i) {
820  //err("productGroups");
821  return m_dummygroups;
822  }
823 
824  //@}
825  //! @name Altering Reaction Rates
826  /*!
827  * These methods alter reaction rates. They are designed primarily for
828  * carrying out sensitivity analysis, but may be used for any purpose
829  * requiring dynamic alteration of rate constants. For each reaction, a
830  * real-valued multiplier may be defined that multiplies the reaction rate
831  * coefficient. The multiplier may be set to zero to completely remove a
832  * reaction from the mechanism.
833  */
834  //@{
835 
836  //! The current value of the multiplier for reaction i.
837  /*!
838  * @param i index of the reaction
839  */
840  doublereal multiplier(size_t i) const {
841  return m_perturb[i];
842  }
843 
844  //! Set the multiplier for reaction i to f.
845  /*!
846  * @param i index of the reaction
847  * @param f value of the multiplier.
848  */
849  void setMultiplier(size_t i, doublereal f) {
850  m_perturb[i] = f;
851  }
852 
853  //@}
854 
855  /**
856  * Increment the number of reactions in the mechanism by one.
857  * @todo Should be protected?
858  */
860  m_ii++;
861  m_perturb.push_back(1.0);
862  }
863 
864  /**
865  * Returns true if the kinetics manager has been properly
866  * initialized and finalized.
867  */
868  virtual bool ready() const {
869  return false;
870  }
871 
872  /*!
873  * Takes as input an array of properties for all species in the mechanism
874  * and copies those values belonging to a particular phase to the output
875  * array.
876  * @param data Input data array.
877  * @param phase Pointer to one of the phase objects participating in this
878  * reaction mechanism
879  * @param phase_data Output array where the values for the the specified
880  * phase are to be written.
881  */
882  void selectPhase(const doublereal* data, const thermo_t* phase,
883  doublereal* phase_data);
884 
885 protected:
886  //! Number of reactions in the mechanism
887  size_t m_ii;
888 
889  //! The number of species in all of the phases
890  //! that participate in this kinetics mechanism.
891  size_t m_kk;
892 
893  /// Vector of perturbation factors for each reaction's rate of
894  /// progress vector. It is initialized to one.
896 
897  /**
898  * This is a vector of vectors containing the reactants for
899  * each reaction. The outer vector is over the number of
900  * reactions, m_ii. The inner vector is a list of species
901  * indices. If the stoichiometric coefficient for a reactant
902  * is greater than one, then the reactant is listed
903  * contiguously in the vector a number of times equal to its
904  * stoichiometric coefficient.
905  * NOTE: These vectors will be wrong if there are real
906  * stoichiometric coefficients in the expression.
907  */
908  std::vector<std::vector<size_t> > m_reactants;
909 
910  /**
911  * This is a vector of vectors containing the products for
912  * each reaction. The outer vector is over the number of
913  * reactions, m_ii. The inner vector is a list of species
914  * indices. If the stoichiometric coefficient for a product is
915  * greater than one, then the reactant is listed contiguously
916  * in the vector a number of times equal to its stoichiometric
917  * coefficient.
918  * NOTE: These vectors will be wrong if there are real
919  * stoichiometric coefficients in the expression.
920  */
921  std::vector<std::vector<size_t> > m_products;
922 
923  //! m_thermo is a vector of pointers to ThermoPhase objects that are
924  //! involved with this kinetics operator
925  /*!
926  * For homogeneous kinetics applications, this vector
927  * will only have one entry. For interfacial reactions, this
928  * vector will consist of multiple entries; some of them will
929  * be surface phases, and the other ones will be bulk phases.
930  * The order that the objects are listed determines the order
931  * in which the species comprising each phase are listed in
932  * the source term vector, originating from the reaction
933  * mechanism.
934  *
935  * Note that this kinetics object doesn't own these ThermoPhase objects
936  * and is not responsible for creating or deleting them.
937  */
938  std::vector<thermo_t*> m_thermo;
939 
940  /**
941  * m_start is a vector of integers specifying the beginning position
942  * for the species vector for the n'th phase in the kinetics
943  * class.
944  */
945  std::vector<size_t> m_start;
946 
947  /**
948  * Mapping of the phase id, i.e., the id attribute in the xml
949  * phase element to the position of the phase within the
950  * kinetics object. Positions start with the value of 1. The
951  * member function, phaseIndex() decrements by one before
952  * returning the index value, so that missing phases return
953  * -1.
954  */
955  std::map<std::string, size_t> m_phaseindex;
956 
957  //! Index in the list of phases of the one surface phase.
958  size_t m_surfphase;
959 
960  //! Phase Index where reactions are assumed to be taking place
961  /*!
962  * We calculate this by assuming that the phase with the lowest
963  * dimensionality is the phase where reactions are taking place.
964  */
965  size_t m_rxnphase;
966 
967  //! number of spatial dimensions of lowest-dimensional phase.
968  size_t m_mindim;
969 
970 private:
971  //! Vector of group lists
972  std::vector<grouplist_t> m_dummygroups;
973 
974  //! Function indicating that a function inherited from the base class
975  //! hasn't had a definition assigned to it
976  /*!
977  * @param m String message
978  */
979  void err(const std::string& m) const;
980 };
981 
982 }
983 
984 #endif
virtual void getDeltaElectrochemPotentials(doublereal *deltaM)
Return the vector of values for the reaction electrochemical free energy change.
Definition: Kinetics.h:499
virtual void getReactionDelta(const doublereal *property, doublereal *deltaProperty)
Change in species properties.
Definition: Kinetics.h:472
virtual void getDestructionRates(doublereal *ddot)
Species destruction rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.h:588
virtual void getCreationRates(doublereal *cdot)
Species creation rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.h:577
std::vector< thermo_t * > m_thermo
m_thermo is a vector of pointers to ThermoPhase objects that are involved with this kinetics operator...
Definition: Kinetics.h:938
void incrementRxnCount()
Increment the number of reactions in the mechanism by one.
Definition: Kinetics.h:859
std::vector< std::vector< size_t > > m_reactants
This is a vector of vectors containing the reactants for each reaction.
Definition: Kinetics.h:908
virtual void assignShallowPointers(const std::vector< thermo_t * > &tpVector)
Reassign the pointers within the Kinetics object.
Definition: Kinetics.cpp:144
virtual void getRevRateConstants(doublereal *krev, bool doIrreversible=false)
Return the reverse rate constants.
Definition: Kinetics.h:744
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:288
virtual void getDeltaEntropy(doublereal *deltaS)
Return the vector of values for the reactions change in entropy.
Definition: Kinetics.h:523
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
Definition: Kinetics.h:891
std::vector< size_t > m_start
m_start is a vector of integers specifying the beginning position for the species vector for the n'th...
Definition: Kinetics.h:945
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.h:600
virtual Kinetics * duplMyselfAsKinetics(const std::vector< thermo_t * > &tpVector) const
Duplication routine for objects which inherit from Kinetics.
Definition: Kinetics.cpp:89
virtual void getDeltaSSEntropy(doublereal *deltaS)
Return the vector of values for the change in the standard state entropies for each reaction...
Definition: Kinetics.h:562
virtual bool isReversible(size_t i)
True if reaction i has been declared to be reversible.
Definition: Kinetics.h:706
std::string kineticsSpeciesName(size_t k) const
Return the name of the kth species in the kinetics manager.
Definition: Kinetics.cpp:186
void selectPhase(const doublereal *data, const thermo_t *phase, doublereal *phase_data)
Definition: Kinetics.cpp:172
virtual const std::vector< size_t > & products(size_t i) const
Returns a read-only reference to the vector of product index numbers for reaction i...
Definition: Kinetics.h:683
std::vector< grouplist_t > m_dummygroups
Vector of group lists.
Definition: Kinetics.h:972
virtual void getDeltaSSGibbs(doublereal *deltaG)
Return the vector of values for the reaction standard state gibbs free energy change.
Definition: Kinetics.h:536
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition: Kinetics.h:300
virtual void getFwdRateConstants(doublereal *kfwd)
Return the forward rate constants.
Definition: Kinetics.h:729
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
Definition: Kinetics.h:840
Kinetics()
Default constructor.
Definition: Kinetics.cpp:23
size_t reactionPhaseIndex()
Phase where the reactions occur.
Definition: Kinetics.h:275
virtual doublereal reactantOrder(size_t k, size_t i) const
Reactant order of species k in reaction i.
Definition: Kinetics.h:638
virtual doublereal productStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a product in reaction i.
Definition: Kinetics.h:625
void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
Definition: Kinetics.h:849
virtual void getEquilibriumConstants(doublereal *kc)
Return a vector of Equilibrium constants.
Definition: Kinetics.h:452
virtual void getNetRatesOfProgress(doublereal *netROP)
Net rates of progress.
Definition: Kinetics.h:439
virtual void getDeltaGibbs(doublereal *deltaG)
Return the vector of values for the reaction gibbs free energy change.
Definition: Kinetics.h:485
virtual void getActivationEnergies(doublereal *E)
Return the activation energies in Kelvin.
Definition: Kinetics.h:757
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
virtual void getRevRatesOfProgress(doublereal *revROP)
Return the Reverse rates of progress of the reactions.
Definition: Kinetics.h:428
virtual void init()
Prepare the class for the addition of reactions.
Definition: Kinetics.h:791
void checkPhaseIndex(size_t m) const
Check that the specified phase index is in range Throws an exception if m is greater than nPhases() ...
Definition: Kinetics.cpp:116
size_t surfacePhaseIndex()
This returns the integer index of the phase which has ThermoPhase type cSurf.
Definition: Kinetics.h:263
size_t nPhases() const
The number of phases participating in the reaction mechanism.
Definition: Kinetics.h:228
thermo_t & speciesPhase(const std::string &nm)
This function looks up the name of a species and returns a reference to the ThermoPhase object of the...
Definition: Kinetics.cpp:229
void checkSpeciesArraySize(size_t mm) const
Check that an array size is at least nSpecies() Throws an exception if kk is less than nSpecies()...
Definition: Kinetics.cpp:137
void err(const std::string &m) const
Function indicating that a function inherited from the base class hasn't had a definition assigned to...
Definition: Kinetics.cpp:299
void checkSpeciesIndex(size_t k) const
Check that the specified species index is in range Throws an exception if k is greater than nSpecies(...
Definition: Kinetics.cpp:130
vector_fp m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
Definition: Kinetics.h:895
Public interface for kinetics managers.
Definition: Kinetics.h:131
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
Definition: ReactionData.h:16
virtual doublereal productOrder(int k, int i) const
product Order of species k in reaction i.
Definition: Kinetics.h:653
virtual doublereal reactantStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a reactant in reaction i.
Definition: Kinetics.h:614
virtual void getFwdRatesOfProgress(doublereal *fwdROP)
Return the forward rates of progress of the reactions.
Definition: Kinetics.h:416
std::map< std::string, size_t > m_phaseindex
Mapping of the phase id, i.e., the id attribute in the xml phase element to the position of the phase...
Definition: Kinetics.h:955
virtual void getDeltaEnthalpy(doublereal *deltaH)
Return the vector of values for the reactions change in enthalpy.
Definition: Kinetics.h:511
Kinetics & operator=(const Kinetics &right)
Assignment operator.
Definition: Kinetics.cpp:62
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition: Kinetics.h:331
virtual const std::vector< size_t > & reactants(size_t i) const
Returns a read-only reference to the vector of reactant index numbers for reaction i...
Definition: Kinetics.h:673
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
virtual void getActivityConcentrations(doublereal *const conc)
Get the vector of activity concentrations used in the kinetics object.
Definition: Kinetics.h:663
size_t m_mindim
number of spatial dimensions of lowest-dimensional phase.
Definition: Kinetics.h:968
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:165
thermo_t & speciesPhase(size_t k)
This function takes as an argument the kineticsSpecies index (i.e., the list index in the list of spe...
Definition: Kinetics.h:390
void checkReactionIndex(size_t m) const
Check that the specified reaction index is in range Throws an exception if i is greater than nReactio...
Definition: Kinetics.cpp:102
size_t speciesPhaseIndex(size_t k)
This function takes as an argument the kineticsSpecies index (i.e., the list index in the list of spe...
Definition: Kinetics.cpp:244
std::vector< std::vector< size_t > > m_products
This is a vector of vectors containing the products for each reaction.
Definition: Kinetics.h:921
void checkReactionArraySize(size_t ii) const
Check that an array size is at least nReactions() Throws an exception if ii is less than nReactions()...
Definition: Kinetics.cpp:109
size_t m_ii
Number of reactions in the mechanism.
Definition: Kinetics.h:887
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition: Kinetics.h:196
virtual int type() const
Identifies the kinetics manager type.
Definition: Kinetics.cpp:97
size_t m_surfphase
Index in the list of phases of the one surface phase.
Definition: Kinetics.h:958
virtual void getDeltaSSEnthalpy(doublereal *deltaH)
Return the vector of values for the change in the standard state enthalpies of reaction.
Definition: Kinetics.h:549
virtual std::string reactionString(size_t i) const
Return a string representing the reaction.
Definition: Kinetics.h:716
size_t m_rxnphase
Phase Index where reactions are assumed to be taking place.
Definition: Kinetics.h:965
virtual void addReaction(ReactionData &r)
Add a single reaction to the mechanism.
Definition: Kinetics.h:810
virtual int reactionType(size_t i) const
Flag specifying the type of reaction.
Definition: Kinetics.h:694
virtual void finalize()
Finish adding reactions and prepare for use.
Definition: Kinetics.cpp:290
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
virtual void addPhase(thermo_t &thermo)
Add a phase to the kinetics manager object.
Definition: Kinetics.cpp:255
virtual ~Kinetics()
Destructor.
Definition: Kinetics.cpp:39
void checkPhaseArraySize(size_t mm) const
Check that an array size is at least nPhases() Throws an exception if mm is less than nPhases()...
Definition: Kinetics.cpp:123
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
size_t phaseIndex(const std::string &ph)
Return the phase index of a phase in the list of phases defined within the object.
Definition: Kinetics.h:250
virtual bool ready() const
Returns true if the kinetics manager has been properly initialized and finalized. ...
Definition: Kinetics.h:868