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