20 ReactionStoichMgr::ReactionStoichMgr()
22 m_dummy.resize(10,1.0);
25 ReactionStoichMgr::~ReactionStoichMgr()
30 m_reactants(right.m_reactants),
31 m_revproducts(right.m_revproducts),
32 m_irrevproducts(right.m_irrevproducts),
33 m_dummy(right.m_dummy)
37 ReactionStoichMgr& ReactionStoichMgr::operator=(
const ReactionStoichMgr& right)
41 m_reactants = right.m_reactants;
42 m_revproducts = right.m_revproducts;
43 m_irrevproducts = right.m_irrevproducts;
44 m_dummy = right.m_dummy;
50 add(
size_t rxn,
const std::vector<size_t>& reactants,
51 const std::vector<size_t>& products,
55 m_reactants.add(rxn, reactants);
58 m_revproducts.add(rxn, products);
60 m_irrevproducts.add(rxn, products);
68 std::vector<size_t> rk;
71 for (
size_t n = 0; n < r.
reactants.size(); n++) {
72 size_t ns = size_t(r.
rstoich[n]);
77 for (
size_t m = 0; m < ns; m++) {
84 if (isfrac || r.
global || rk.size() > 3) {
87 m_reactants.add(rxn, rk);
90 std::vector<size_t> pk;
92 for (
size_t n = 0; n < r.
products.size(); n++) {
93 size_t ns = size_t(r.
pstoich[n]);
98 for (
size_t m = 0; m < ns; m++) {
106 "Fractional product stoichiometric coefficients only allowed "
107 "\nfor irreversible reactions and most reversible reactions");
112 m_revproducts.add(rxn, pk);
114 }
else if (isfrac || pk.size() > 3) {
117 m_irrevproducts.add(rxn, pk);
123 const doublereal* ropr, doublereal* c)
126 fill(c, c + nsp, 0.0);
129 m_revproducts.incrementSpecies(ropf, c);
130 m_irrevproducts.incrementSpecies(ropf, c);
133 m_reactants.incrementSpecies(ropr, c);
138 const doublereal* ropr, doublereal* d)
140 fill(d, d + nsp, 0.0);
142 m_revproducts.incrementSpecies(ropr, d);
144 m_reactants.incrementSpecies(ropf, d);
150 fill(w, w + nsp, 0.0);
152 m_revproducts.incrementSpecies(ropnet, w);
153 m_irrevproducts.incrementSpecies(ropnet, w);
155 m_reactants.decrementSpecies(ropnet, w);
161 fill(dg, dg + nr, 0.0);
163 m_revproducts.incrementReactions(g, dg);
164 m_irrevproducts.incrementReactions(g, dg);
166 m_reactants.decrementReactions(g, dg);
172 fill(dg, dg + nr, 0.0);
173 m_revproducts.incrementReactions(g, dg);
174 m_reactants.decrementReactions(g, dg);
180 m_reactants.multiply(c, r);
186 m_revproducts.multiply(c, r);
189 void ReactionStoichMgr::
190 write(
const string& filename)
192 ofstream f(filename.c_str());
193 f <<
"namespace mech {" << endl;
194 writeCreationRates(f);
195 writeDestructionRates(f);
196 writeNetProductionRates(f);
197 writeMultiplyReactants(f);
198 writeMultiplyRevProducts(f);
199 f <<
"} // namespace mech" << endl;
203 void ReactionStoichMgr::
204 writeCreationRates(ostream& f)
206 f <<
" void getCreationRates(const doublereal* rf, const doublereal* rb," << endl;
207 f <<
" doublereal* c) {" << endl;
208 map<size_t, string> out;
209 m_revproducts.writeIncrementSpecies(
"rf",out);
210 m_irrevproducts.writeIncrementSpecies(
"rf",out);
211 m_reactants.writeIncrementSpecies(
"rb",out);
212 map<size_t, string>::iterator b;
213 for (b = out.begin(); b != out.end(); ++b) {
216 f <<
" c[" << b->first <<
"] " << rhs <<
";" << endl;
218 f <<
" }" << endl << endl << endl;
221 void ReactionStoichMgr::
222 writeDestructionRates(ostream& f)
224 f <<
" void getDestructionRates(const doublereal* rf, const doublereal* rb," << endl;
225 f <<
" doublereal* d) {" << endl;
226 map<size_t, string> out;
227 m_revproducts.writeIncrementSpecies(
"rb",out);
228 m_reactants.writeIncrementSpecies(
"rf",out);
229 map<size_t, string>::iterator b;
230 for (b = out.begin(); b != out.end(); ++b) {
233 f <<
" d[" << b->first <<
"] " << rhs <<
";" << endl;
235 f <<
" }" << endl << endl << endl;
238 void ReactionStoichMgr::
239 writeNetProductionRates(ostream& f)
241 f <<
" void getNetProductionRates(const doublereal* r, doublereal* w) {" << endl;
242 map<size_t, string> out;
243 m_revproducts.writeIncrementSpecies(
"r",out);
244 m_irrevproducts.writeIncrementSpecies(
"r",out);
245 m_reactants.writeDecrementSpecies(
"r",out);
246 map<size_t, string>::iterator b;
247 for (b = out.begin(); b != out.end(); ++b) {
250 f <<
" w[" << b->first <<
"] " << rhs <<
";" << endl;
252 f <<
" }" << endl << endl << endl;
255 void ReactionStoichMgr::
256 writeMultiplyReactants(ostream& f)
258 f <<
" void multiplyReactants(const doublereal* c, doublereal* r) {" << endl;
259 map<size_t, string> out;
260 m_reactants.writeMultiply(
"c",out);
261 map<size_t, string>::iterator b;
262 for (b = out.begin(); b != out.end(); ++b) {
263 string rhs = b->second;
264 f <<
" r[" << b->first <<
"] *= " << rhs <<
";" << endl;
266 f <<
" }" << endl << endl << endl;
269 void ReactionStoichMgr::
270 writeMultiplyRevProducts(ostream& f)
272 f <<
" void multiplyRevProducts(const doublereal* c, doublereal* r) {" << endl;
273 map<size_t, string> out;
274 m_revproducts.writeMultiply(
"c",out);
275 map<size_t, string>::iterator b;
276 for (b = out.begin(); b != out.end(); ++b) {
277 string rhs = b->second;
278 f <<
" r[" << b->first <<
"] *= " << rhs <<
";" << endl;
280 f <<
" }" << endl << endl << endl;
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.
Header file declaring class ReactionStoichMgr.
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...
vector_fp pstoich
Product stoichiometric coefficients, in the order given by products.
virtual void getReactionDelta(size_t nReactions, const doublereal *g, doublereal *dg)
Calculates the change of a molar species property in a reaction.
vector_fp porder
Reaction order of the reverse reaction with respect to each product species, in the order given by pr...
bool isReversibleWithFrac
Some reactions can be elementary reactions but have fractional stoichiometries with respect to some p...
std::vector< size_t > products
Indices of product species.
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...
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
Base class for exceptions thrown by Cantera classes.
Reaction mechanism stoichiometry manager.
std::vector< size_t > reactants
Indices of reactant species.
vector_fp rstoich
Reactant stoichiometric coefficients, in the order given by reactants.
std::string wrapString(const std::string &s, const int len)
Line wrap a string via a copy operation.
bool reversible
True if the current reaction is reversible. False otherwise.
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...
bool global
True for "global" reactions which do not follow elementary mass action kinetics, i.e.
vector_fp rorder
Reaction order with respect to each reactant species, in the order given by reactants.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
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.