24 ReactionStoichMgr::ReactionStoichMgr()
26 m_dummy.resize(10,1.0);
29 ReactionStoichMgr::~ReactionStoichMgr()
35 m_reactants(right.m_reactants),
36 m_revproducts(right.m_revproducts),
37 m_irrevproducts(right.m_irrevproducts),
38 m_dummy(right.m_dummy)
43 ReactionStoichMgr& ReactionStoichMgr::operator=(
const ReactionStoichMgr& right)
47 m_reactants = right.m_reactants;
48 m_revproducts = right.m_revproducts;
49 m_irrevproducts = right.m_irrevproducts;
50 m_dummy = right.m_dummy;
56 add(
size_t rxn,
const std::vector<size_t>& reactants,
57 const std::vector<size_t>& products,
61 m_reactants.add(rxn, reactants);
64 m_revproducts.add(rxn, products);
66 m_irrevproducts.add(rxn, products);
72 add(
size_t rxn,
const ReactionData& r)
75 std::vector<size_t> rk;
78 for (
size_t n = 0; n < r.reactants.size(); n++) {
79 size_t ns = size_t(r.rstoich[n]);
80 frac = r.rstoich[n] - 1.0*int(r.rstoich[n]);
84 for (
size_t m = 0; m < ns; m++) {
85 rk.push_back(r.reactants[n]);
91 if (isfrac || r.global || rk.size() > 3) {
92 m_reactants.add(rxn, r.reactants, r.rorder, r.rstoich);
94 m_reactants.add(rxn, rk);
97 std::vector<size_t> pk;
99 for (
size_t n = 0; n < r.products.size(); n++) {
100 size_t ns = size_t(r.pstoich[n]);
101 frac = r.pstoich[n] - 1.0*int(r.pstoich[n]);
105 for (
size_t m = 0; m < ns; m++) {
106 pk.push_back(r.products[n]);
111 if (isfrac && !r.isReversibleWithFrac) {
113 "Fractional product stoichiometric coefficients only allowed "
114 "\nfor irreversible reactions and most reversible reactions");
116 if (pk.size() > 3 || r.isReversibleWithFrac) {
117 m_revproducts.add(rxn, r.products, r.porder, r.pstoich);
119 m_revproducts.add(rxn, pk);
121 }
else if (isfrac || pk.size() > 3) {
122 m_irrevproducts.add(rxn, r.products, r.porder, r.pstoich);
124 m_irrevproducts.add(rxn, pk);
130 const doublereal* ropr, doublereal* c)
133 fill(c, c + nsp, 0.0);
136 m_revproducts.incrementSpecies(ropf, c);
137 m_irrevproducts.incrementSpecies(ropf, c);
140 m_reactants.incrementSpecies(ropr, c);
145 const doublereal* ropr, doublereal* d)
147 fill(d, d + nsp, 0.0);
149 m_revproducts.incrementSpecies(ropr, d);
151 m_reactants.incrementSpecies(ropf, d);
157 fill(w, w + nsp, 0.0);
159 m_revproducts.incrementSpecies(ropnet, w);
160 m_irrevproducts.incrementSpecies(ropnet, w);
162 m_reactants.decrementSpecies(ropnet, w);
168 fill(dg, dg + nr, 0.0);
170 m_revproducts.incrementReactions(g, dg);
171 m_irrevproducts.incrementReactions(g, dg);
173 m_reactants.decrementReactions(g, dg);
179 fill(dg, dg + nr, 0.0);
180 m_revproducts.incrementReactions(g, dg);
181 m_reactants.decrementReactions(g, dg);
187 m_reactants.multiply(c, r);
193 m_revproducts.multiply(c, r);
197 void ReactionStoichMgr::
198 write(
string filename)
200 ofstream f(filename.c_str());
201 f <<
"namespace mech {" << endl;
202 writeCreationRates(f);
203 writeDestructionRates(f);
204 writeNetProductionRates(f);
205 writeMultiplyReactants(f);
206 writeMultiplyRevProducts(f);
207 f <<
"} // namespace mech" << endl;
211 void ReactionStoichMgr::
212 writeCreationRates(ostream& f)
214 f <<
" void getCreationRates(const doublereal* rf, const doublereal* rb," << endl;
215 f <<
" doublereal* c) {" << endl;
216 map<size_t, string> out;
217 m_revproducts.writeIncrementSpecies(
"rf",out);
218 m_irrevproducts.writeIncrementSpecies(
"rf",out);
219 m_reactants.writeIncrementSpecies(
"rb",out);
220 map<size_t, string>::iterator b;
221 for (b = out.begin(); b != out.end(); ++b) {
224 f <<
" c[" << b->first <<
"] " << rhs <<
";" << endl;
226 f <<
" }" << endl << endl << endl;
229 void ReactionStoichMgr::
230 writeDestructionRates(ostream& f)
232 f <<
" void getDestructionRates(const doublereal* rf, const doublereal* rb," << endl;
233 f <<
" doublereal* d) {" << endl;
234 map<size_t, string> out;
235 m_revproducts.writeIncrementSpecies(
"rb",out);
236 m_reactants.writeIncrementSpecies(
"rf",out);
237 map<size_t, string>::iterator b;
238 for (b = out.begin(); b != out.end(); ++b) {
241 f <<
" d[" << b->first <<
"] " << rhs <<
";" << endl;
243 f <<
" }" << endl << endl << endl;
246 void ReactionStoichMgr::
247 writeNetProductionRates(ostream& f)
249 f <<
" void getNetProductionRates(const doublereal* r, doublereal* w) {" << endl;
250 map<size_t, string> out;
251 m_revproducts.writeIncrementSpecies(
"r",out);
252 m_irrevproducts.writeIncrementSpecies(
"r",out);
253 m_reactants.writeDecrementSpecies(
"r",out);
254 map<size_t, string>::iterator b;
255 for (b = out.begin(); b != out.end(); ++b) {
258 f <<
" w[" << b->first <<
"] " << rhs <<
";" << endl;
260 f <<
" }" << endl << endl << endl;
263 void ReactionStoichMgr::
264 writeMultiplyReactants(ostream& f)
266 f <<
" void multiplyReactants(const doublereal* c, doublereal* r) {" << endl;
267 map<size_t, string> out;
268 m_reactants.writeMultiply(
"c",out);
269 map<size_t, string>::iterator b;
270 for (b = out.begin(); b != out.end(); ++b) {
271 string rhs = b->second;
272 f <<
" r[" << b->first <<
"] *= " << rhs <<
";" << endl;
274 f <<
" }" << endl << endl << endl;
277 void ReactionStoichMgr::
278 writeMultiplyRevProducts(ostream& f)
280 f <<
" void multiplyRevProducts(const doublereal* c, doublereal* r) {" << endl;
281 map<size_t, string> out;
282 m_revproducts.writeMultiply(
"c",out);
283 map<size_t, string>::iterator b;
284 for (b = out.begin(); b != out.end(); ++b) {
285 string rhs = b->second;
286 f <<
" r[" << b->first <<
"] *= " << rhs <<
";" << endl;
288 f <<
" }" << endl << endl << endl;