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