diff --git a/Cantera/src/EdgeKinetics.cpp b/Cantera/src/EdgeKinetics.cpp index f8d68fcbf..c0726b972 100644 --- a/Cantera/src/EdgeKinetics.cpp +++ b/Cantera/src/EdgeKinetics.cpp @@ -420,13 +420,17 @@ namespace Cantera { m_kdata->m_ropr.push_back(0.0); m_kdata->m_ropnet.push_back(0.0); int n, ns, m; - + doublereal nsFlt; int rnum = reactionNumber(); vector_int rk; int nr = r.reactants.size(); for (n = 0; n < nr; n++) { - ns = r.rstoich[n]; + nsFlt = r.rstoich[n]; + ns = (int) nsFlt; + if ((doublereal) ns != nsFlt) { + if (ns < 1) ns = 1; + } m_rrxn[r.reactants[n]][rnum] = ns; for (m = 0; m < ns; m++) { rk.push_back(r.reactants[n]); @@ -437,7 +441,11 @@ namespace Cantera { vector_int pk; int np = r.products.size(); for (n = 0; n < np; n++) { - ns = r.pstoich[n]; + nsFlt = r.pstoich[n]; + ns = (int) nsFlt; + if ((doublereal) ns != nsFlt) { + if (ns < 1) ns = 1; + } m_prxn[r.products[n]][rnum] = ns; for (m = 0; m < ns; m++) { pk.push_back(r.products[n]); diff --git a/Cantera/src/GasKinetics.cpp b/Cantera/src/GasKinetics.cpp index b055dce25..caa07a288 100755 --- a/Cantera/src/GasKinetics.cpp +++ b/Cantera/src/GasKinetics.cpp @@ -555,13 +555,22 @@ namespace Cantera { m_kdata->m_ropr.push_back(0.0); m_kdata->m_ropnet.push_back(0.0); int n, ns, m; - + doublereal nsFlt; + doublereal reactantGlobalOrder = 0.0; + doublereal productGlobalOrder = 0.0; int rnum = reactionNumber(); vector_int rk; int nr = r.reactants.size(); for (n = 0; n < nr; n++) { - ns = r.rstoich[n]; + nsFlt = r.rstoich[n]; + reactantGlobalOrder += nsFlt; + ns = (int) nsFlt; + if ((doublereal) ns != nsFlt) { + if (ns < 1) { + ns = 1; + } + } if (r.rstoich[n] != 0.0) m_rrxn[r.reactants[n]][rnum] += r.rstoich[n]; for (m = 0; m < ns; m++) { @@ -573,7 +582,14 @@ namespace Cantera { vector_int pk; int np = r.products.size(); for (n = 0; n < np; n++) { - ns = r.pstoich[n]; + nsFlt = r.pstoich[n]; + productGlobalOrder += nsFlt; + ns = (int) nsFlt; + if ((double) ns != nsFlt) { + if (ns < 1) { + ns = 1; + } + } if (r.pstoich[n] != 0.0) m_prxn[r.products[n]][rnum] += r.pstoich[n]; for (m = 0; m < ns; m++) { @@ -587,14 +603,14 @@ namespace Cantera { m_rxnstoich->add(reactionNumber(), r); if (r.reversible) { - m_dn.push_back(pk.size() - rk.size()); - m_revindex.push_back(reactionNumber()); - m_nrev++; + m_dn.push_back(productGlobalOrder - reactantGlobalOrder); + m_revindex.push_back(reactionNumber()); + m_nrev++; } else { - m_dn.push_back(pk.size() - rk.size()); - m_irrev.push_back( reactionNumber() ); - m_nirrev++; + m_dn.push_back(productGlobalOrder - reactantGlobalOrder); + m_irrev.push_back( reactionNumber() ); + m_nirrev++; } } diff --git a/Cantera/src/GasKinetics.h b/Cantera/src/GasKinetics.h index 2efe51c02..3c60c9e20 100755 --- a/Cantera/src/GasKinetics.h +++ b/Cantera/src/GasKinetics.h @@ -395,7 +395,13 @@ namespace Cantera { mutable vector > m_rrxn; mutable vector > m_prxn; - vector_int m_dn; + /** + * Difference between the input global reactants order + * and the input global products order. Changed to a double + * to account for the fact that we can have real-valued + * stoichiometries. + */ + vector_fp m_dn; vector_int m_revindex; vector m_rxneqn; diff --git a/Cantera/src/InterfaceKinetics.cpp b/Cantera/src/InterfaceKinetics.cpp index 1fdb5faa3..73758cfa8 100644 --- a/Cantera/src/InterfaceKinetics.cpp +++ b/Cantera/src/InterfaceKinetics.cpp @@ -663,7 +663,8 @@ namespace Cantera { void InterfaceKinetics::installReagents(const ReactionData& r) { - int n, ns, m; + int n, ns, m; + doublereal nsFlt; /* * extend temporary storage by one for this rxn. */ @@ -688,7 +689,11 @@ namespace Cantera { vector_int rk; int nr = r.reactants.size(); for (n = 0; n < nr; n++) { - ns = r.rstoich[n]; + nsFlt = r.rstoich[n]; + ns = (int) nsFlt; + if ((doublereal) ns != nsFlt) { + if (ns < 1) ns = 1; + } /* * Add to m_rrxn. m_rrxn is a vector of maps. m_rrxn has a length * equal to the total number of species for each species, there @@ -710,7 +715,11 @@ namespace Cantera { vector_int pk; int np = r.products.size(); for (n = 0; n < np; n++) { - ns = r.pstoich[n]; + nsFlt = r.pstoich[n]; + ns = (int) nsFlt; + if ((doublereal) ns != nsFlt) { + if (ns < 1) ns = 1; + } /* * Add to m_prxn. m_prxn is a vector of maps. m_prxn has a length * equal to the total number of species for each species, there diff --git a/Cantera/src/Kinetics.h b/Cantera/src/Kinetics.h index d51f39c5a..0ffbc19bf 100755 --- a/Cantera/src/Kinetics.h +++ b/Cantera/src/Kinetics.h @@ -749,6 +749,8 @@ namespace Cantera { * is greater than one, then the reactant is listed * contiguously in the vector a number of times equal to its * stoichiometric coefficient. + * NOTE: These vectors will be wrong if there are real + * stoichiometric coefficients in the expression. */ vector m_reactants; @@ -760,6 +762,8 @@ namespace Cantera { * greater than one, then the reactant is listed contiguously * in the vector a number of times equal to its stoichiometric * coefficient. + * NOTE: These vectors will be wrong if there are real + * stoichiometric coefficients in the expression. */ vector m_products; diff --git a/Cantera/src/Phase.cpp b/Cantera/src/Phase.cpp index 418246e24..a4a76efbf 100755 --- a/Cantera/src/Phase.cpp +++ b/Cantera/src/Phase.cpp @@ -79,7 +79,7 @@ namespace Cantera { void Phase::saveState(vector_fp& state) const { state.resize(nSpecies() + 2); - saveState(state.size(),&state[0]); + saveState(state.size(),&(state[0])); } void Phase::saveState(int lenstate, doublereal* state) const { state[0] = temperature();