Cantera  2.1.2
ReactionStoichMgr.h
Go to the documentation of this file.
1 /**
2  * @file ReactionStoichMgr.h
3  *
4  * Header file declaring class ReactionStoichMgr.
5  */
6 #ifndef CT_RXN_STOICH
7 #define CT_RXN_STOICH
8 
9 #include "cantera/base/ct_defs.h"
11 namespace Cantera
12 {
13 
14 class ReactionData;
15 
16 /**
17  * Reaction mechanism stoichiometry manager. This is an internal class used
18  * by kinetics manager classes, and is not meant for direct use in
19  * user programs.
20  *
21  * Class ReactionStoichMgr handles the calculation of quantities involving
22  * the stoichiometry of a set of reactions. The reactions may have integer
23  * or non-integer stoichiometric coefficients. Specifically, its methods compute
24  * - species creation rates
25  * - species destruction rates
26  * - species net production rates
27  * - the change in molar species properties in the reactions
28  * - concentration products
29  *
30  * To use this class, method add() is first used to add each reaction.
31  * Once all reactions have been added, the methods that compute various
32  * quantities may be called.
33  *
34  * The nomenclature used below to document the methods is as follows.
35  *
36  * - \f$ N_r \f$
37  * Integer reactant stoichiometric coefficient matrix. The (k,i)
38  * element of this matrix is the stoichiometric coefficient of
39  * species \e k as a reactant in reaction \e i.
40  * - \f$ N_p \f$
41  * Integer product stoichiometric coefficient matrix. The (k,i)
42  * element of this matrix is the stoichiometric coefficient of
43  * species \e k as a product in reaction \e i.
44  * - \f$ Q_{\rm fwd} \f$
45  * Vector of length I of forward rates of progress.
46  * - \f$ Q_{\rm rev} \f$
47  * Vector of length I of reverse rates of progress.
48  * - \f$ C \f$
49  * Vector of K species creation rates.
50  * - \f$ D \f$
51  * Vector of K species destruction rates.
52  * - \f$ W = C - D \f$
53  * Vector of K species net production rates.
54  *
55  */
57 {
58 public:
59  /// Constructor.
61 
62  /// Destructor.
63  virtual ~ReactionStoichMgr();
64 
66 
67  ReactionStoichMgr& operator=(const ReactionStoichMgr& right);
68 
69  /**
70  * Add a reaction with mass-action kinetics. Vectors
71  * 'reactants' and 'products' contain the integer species
72  * indices of the reactants and products, respectively. Note
73  * that if more than one molecule of a given species is
74  * involved in the reaction, then its index is repeated.
75  *
76  * For example, suppose a reaction mechanism involves the
77  * species N2, O2, O, N, NO. N2 is assigned index number 0, O2
78  * number 1, and so on through NO with number 4. Then the
79  * representation of the following reactions is as shown here.
80  *
81  * - N + O = NO
82  * - reactants: (3, 2)
83  * - products: (4)
84  *
85  * - O + O = O2
86  * - reactants: (2, 2) [ note repeated index ]
87  * - products: (1)
88  *
89  * @param rxn Reaction number. This number will be used as the index
90  * into the rate of progress vector in the methods below.
91  * @param reactants vector of integer reactant indices
92  * @param products vector of integer product indices
93  * @param reversible true if the reaction is reversible, false otherwise
94  */
95  virtual void add(size_t rxn, const std::vector<size_t>& reactants,
96  const std::vector<size_t>& products, bool reversible);
97 
98  /**
99  * Add a reaction with specified, possibly non-integral, reaction orders.
100  * @param rxn Reaction number
101  * @param r Data structure containing reactant and product vectors, etc.
102  */
103  virtual void add(size_t rxn, const ReactionData& r);
104 
105  /**
106  * Species creation rates. Given the arrays of the forward and reverse
107  * rates of progress for all reactions, compute the species creation
108  * rates, given by
109  * \f[
110  * C = N_p Q_f + N_r Q_r.
111  * \f]
112  */
113  virtual void getCreationRates(size_t nSpecies,
114  const doublereal* fwdRatesOfProgress,
115  const doublereal* revRatesOfProgress,
116  doublereal* creationRates);
117 
118  /**
119  * Species destruction rates. Given the arrays of the forward and reverse
120  * rates of progress for all reactions, compute the species destruction
121  * rates, given by
122  * \f[
123  * D = N_r Q_f + N_p Q_r,
124  * \f]
125  * Note that the stoichiometric coefficient matrices are very sparse, integer
126  * matrices.
127  */
128  virtual void getDestructionRates(size_t nSpecies,
129  const doublereal* fwdRatesOfProgress,
130  const doublereal* revRatesOfProgress,
131  doublereal* destructionRates);
132 
133  /**
134  * Species net production rates. Given the array of the net rates of
135  * progress for all reactions, compute the species net production rates,
136  * given by
137  * \f[
138  * W = (N_r - N_p) Q_{\rm net},
139  * \f]
140  */
141  virtual void getNetProductionRates(size_t nsp, const doublereal* ropnet, doublereal* w);
142 
143  //! Calculates the change of a molar species property in a reaction.
144  /*!
145  * Given an array of species properties 'g', return in array 'dg' the
146  * change in this quantity in the reactions. Array 'g' must have a length
147  * at least as great as the number of species, and array 'dg' must have a
148  * length as great as the total number of reactions.
149  * \f[
150  * \delta g_i = \sum_k{\nu_{i,k} g_k }
151  * \f]
152  *
153  * @param nReactions Number of reactions
154  * @param g Molar property of the species.
155  * An example would be the partial molar enthalpy
156  * Length is equal to number of kinetic species
157  * @param dg Calculated property change of the reaction.
158  * An example would be the delta change in enthalpy,
159  * i.e., the enthalpy of reaction.
160  */
161  virtual void getReactionDelta(size_t nReactions,
162  const doublereal* g,
163  doublereal* dg);
164 
165  /**
166  * Given an array of species properties 'g', return in array 'dg' the
167  * change in this quantity in the reversible reactions. Array 'g' must
168  * have a length at least as great as the number of species, and array
169  * 'dg' must have a length as great as the total number of reactions.
170  * This method only computes 'dg' for the reversible reactions, and the
171  * entries of 'dg' for the irreversible reactions are unaltered. This is
172  * primarily designed for use in calculating reverse rate coefficients
173  * from thermochemistry for reversible reactions.
174  */
175  virtual void getRevReactionDelta(size_t nr, const doublereal* g, doublereal* dg);
176 
177  /**
178  * Given an array of concentrations C, multiply the entries in array R by
179  * the concentration products for the reactants.
180  * \f[
181  * R_i = R_i * \prod_k C_k^{o_{k,i}}
182  * \f]
183  *
184  * Here \f$ o_{k,i} \f$ is the reaction order of species k in reaction i.
185  */
186  virtual void multiplyReactants(const doublereal* C, doublereal* R);
187 
188  /**
189  * Given an array of concentrations C, multiply the entries in array R by
190  * the concentration products for the products.
191  * \f[
192  * R_i = R_i * \prod_k C_k^{\nu^{(p)}_{k,i}}
193  * \f]
194  * Here \f$ \nu^{(p)}_{k,i} \f$ is the product stoichiometric coefficient
195  * of species k in reaction i.
196  */
197  virtual void multiplyRevProducts(const doublereal* c, doublereal* r);
198 
199  virtual void write(const std::string& filename);
200 
201 protected:
202  void writeCreationRates(std::ostream& f);
203  void writeDestructionRates(std::ostream& f);
204  void writeNetProductionRates(std::ostream& f);
205  void writeMultiplyReactants(std::ostream& f);
206  void writeMultiplyRevProducts(std::ostream& f);
207  StoichManagerN m_reactants;
208  StoichManagerN m_revproducts;
209  StoichManagerN m_irrevproducts;
210  vector_fp m_dummy;
211 };
212 }
213 
214 #endif
virtual void getNetProductionRates(size_t nsp, const doublereal *ropnet, doublereal *w)
Species net production rates.
virtual void getDestructionRates(size_t nSpecies, const doublereal *fwdRatesOfProgress, const doublereal *revRatesOfProgress, doublereal *destructionRates)
Species destruction rates.
virtual void getCreationRates(size_t nSpecies, const doublereal *fwdRatesOfProgress, const doublereal *revRatesOfProgress, doublereal *creationRates)
Species creation rates.
virtual void getRevReactionDelta(size_t nr, const doublereal *g, doublereal *dg)
Given an array of species properties 'g', return in array 'dg' the change in this quantity in the rev...
virtual void getReactionDelta(size_t nReactions, const doublereal *g, doublereal *dg)
Calculates the change of a molar species property in a reaction.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
virtual void multiplyReactants(const doublereal *C, doublereal *R)
Given an array of concentrations C, multiply the entries in array R by the concentration products for...
virtual ~ReactionStoichMgr()
Destructor.
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
Definition: ReactionData.h:16
Reaction mechanism stoichiometry manager.
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
virtual void multiplyRevProducts(const doublereal *c, doublereal *r)
Given an array of concentrations C, multiply the entries in array R by the concentration products for...
virtual void add(size_t rxn, const std::vector< size_t > &reactants, const std::vector< size_t > &products, bool reversible)
Add a reaction with mass-action kinetics.