Cantera  2.0
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 
59 public:
60 
61  /// Constructor.
63 
64  /// Destructor.
65  virtual ~ReactionStoichMgr();
66 
68 
69  ReactionStoichMgr& operator=(const ReactionStoichMgr& right);
70 
71  /**
72  * Add a reaction with mass-action kinetics. Vectors
73  * 'reactants' and 'products' contain the integer species
74  * indices of the reactants and products, respectively. Note
75  * that if more than one molecule of a given species is
76  * involved in the reaction, then its index is repeated.
77  *
78  * For example, suppose a reaction mechanism involves the
79  * species N2, O2, O, N, NO. N2 is assigned index number 0, O2
80  * number 1, and so on through NO with number 4. Then the
81  * representation of the following reactions is as shown here.
82  *
83  * - N + O = NO
84  * - reactants: (3, 2)
85  * - products: (4)
86  *
87  * - O + O = O2
88  * - reactants: (2, 2) [ note repeated index ]
89  * - products: (1)
90  *
91  * @param rxn Reaction number. This number will be used as the index
92  * into the rate of progress vector in the methods below.
93  * @param reactants vector of integer reactant indices
94  * @param products vector of integer product indices
95  * @param reversible true if the reaction is reversible, false otherwise
96  */
97  virtual void add(size_t rxn, const std::vector<size_t>& reactants,
98  const std::vector<size_t>& products, bool reversible);
99 
100  /**
101  * Add a reaction with specified, possibly non-integral, reaction orders.
102  * @param rxn Reaction number
103  * @param r Data structure containing reactant and product vectors, etc.
104  */
105  virtual void add(size_t rxn, const ReactionData& r);
106 
107  /**
108  * Species creation rates.
109  * Given the arrays of the forward and reverse rates of
110  * progress for all reactions, compute the species creation
111  * rates, given by
112  * \f[
113  * C = N_p Q_f + N_r Q_r.
114  * \f]
115  */
116  virtual void getCreationRates(size_t nSpecies,
117  const doublereal* fwdRatesOfProgress,
118  const doublereal* revRatesOfProgress,
119  doublereal* creationRates);
120 
121 
122  /**
123  * Species destruction rates.
124  * Given the arrays of the forward and reverse rates of
125  * progress for all reactions, compute the species destruction
126  * rates, given by
127  * \f[
128  * D = N_r Q_f + N_p Q_r,
129  * \f]
130  * Note that the stoichiometric coefficient matrices are very sparse, integer
131  * matrices.
132  */
133  virtual void getDestructionRates(size_t nSpecies,
134  const doublereal* fwdRatesOfProgress,
135  const doublereal* revRatesOfProgress,
136  doublereal* destructionRates);
137 
138 
139  /**
140  * Given the array of the net rates of progress for all
141  * reactions, compute the species net production rates and
142  * return them in array w.
143  */
144  /**
145  * Species net production rates.
146  * Given the array of the net rates of
147  * progress for all reactions, compute the species net production
148  * rates, given by
149  * \f[
150  * W = (N_r - N_p) Q_{\rm net},
151  * \f]
152  */
153  virtual void getNetProductionRates(size_t nsp, const doublereal* ropnet, doublereal* w);
154 
155 
156 
157  //! Calculates the change of a molar species property in a reaction.
158  /*!
159  * Given an
160  * array of species properties 'g', return in array 'dg' the
161  * change in this quantity in the reactions. Array 'g' must
162  * have a length at least as great as the number of species,
163  * and array 'dg' must have a length as great as the total
164  * number of reactions.
165  * \f[
166  * \delta g_i = \sum_k{\nu_{i,k} g_k }
167  * \f]
168  *
169  * @param nReactions Number of reactions
170  * @param g Molar property of the species.
171  * An example would be the partial molar enthalpy
172  * Length is equal to number of kinetic species
173  * @param dg Calculated property change of the reaction.
174  * An example would be the delta change in enthalpy,
175  * i.e., the enthalpy of reaction.
176  */
177  virtual void getReactionDelta(size_t nReactions,
178  const doublereal* g,
179  doublereal* dg);
180 
181 
182  /**
183  * Given an array of species properties 'g', return in array
184  * 'dg' the change in this quantity in the reversible
185  * reactions. Array 'g' must have a length at least as great
186  * as the number of species, and array 'dg' must have a length
187  * as great as the total number of reactions. This method
188  * only computes 'dg' for the reversible reactions, and the
189  * entries of 'dg' for the irreversible reactions are
190  * unaltered. This is primarily designed for use in
191  * calculating reveerse rate coefficients from thermochemistry
192  * for reversible reactions.
193  */
194  virtual void getRevReactionDelta(size_t nr, const doublereal* g, doublereal* dg);
195 
196 
197  /**
198  * Given an array of concentrations C, multiply the entries in array R by
199  * the concentration products for the reactants:
200  * \f[
201  * R_i = R_i * \prod_k C_k^{o_{k,i}}
202  * \f]
203  *
204  * Here \f$ o_{k,i} \f$ is the reaction order of species k in reaction i.
205  */
206  virtual void multiplyReactants(const doublereal* C, doublereal* R);
207 
208 
209  /**
210  * Given an array of concentrations C, multiply the entries in array R by
211  * the concentration products for the products:
212  * \f[
213  * R_i = R_i * \prod_k C_k^{\nu^{(p)}_{k,i}}
214  * \f]
215  * Here \f$ \nu^{(p)}_{k,i} \f$ is the product stoichiometric coefficient
216  * of species k in reaction i.
217  */
218  virtual void multiplyRevProducts(const doublereal* c, doublereal* r);
219 
220  virtual void write(std::string filename);
221 
222 protected:
223 
224  void writeCreationRates(std::ostream& f);
225  void writeDestructionRates(std::ostream& f);
226  void writeNetProductionRates(std::ostream& f);
227  void writeMultiplyReactants(std::ostream& f);
228  void writeMultiplyRevProducts(std::ostream& f);
229  StoichManagerN m_reactants;
230  StoichManagerN m_revproducts;
231  StoichManagerN m_irrevproducts;
232  vector_fp m_dummy;
233 };
234 }
235 
236 #endif