Fixed an error in the GasKinetics object that occurred for calculating

equilibrium constants for reactions with fractional stoichiometric
coefficients. The member data m_dn[] was being calculated incorrectly
for theses cases and then used in the calculation of the
equilibrium constant. m_dn[] now correctly evaluates the difference in
rxn order between the reactants and products for fraction coefficient
reactions.
This commit is contained in:
Harry Moffat 2006-04-30 18:01:42 +00:00
parent 3a25b2250b
commit 43c1d33f67
6 changed files with 60 additions and 17 deletions

View file

@ -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]);

View file

@ -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++;
}
}

View file

@ -395,7 +395,13 @@ namespace Cantera {
mutable vector<map<int, doublereal> > m_rrxn;
mutable vector<map<int, doublereal> > 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<string> m_rxneqn;

View file

@ -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

View file

@ -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<vector_int> 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<vector_int> m_products;

View file

@ -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();