From d2779ddec7398eb4487a747728824f572adaa54e Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Tue, 26 Jul 2005 03:56:34 +0000 Subject: [PATCH] cleanup --- Cantera/src/EdgeKinetics.h | 2 +- Cantera/src/InterfaceKinetics.cpp | 23 +- Cantera/src/InterfaceKinetics.h | 19 +- Cantera/src/Kinetics.h | 4 +- Cantera/src/ReactionStoichMgr.cpp | 17 +- Cantera/src/ReactionStoichMgr.h | 1 - Cantera/src/StoichManager.h | 922 ++++++++++++++-------------- Cantera/src/converters/CKParser.cpp | 6 +- Cantera/src/converters/Reaction.h | 6 +- Cantera/src/converters/ck2ct.cpp | 3 - winconfig.h | 1 + 11 files changed, 508 insertions(+), 496 deletions(-) diff --git a/Cantera/src/EdgeKinetics.h b/Cantera/src/EdgeKinetics.h index eb8828b7d..57c4734f0 100644 --- a/Cantera/src/EdgeKinetics.h +++ b/Cantera/src/EdgeKinetics.h @@ -47,7 +47,7 @@ namespace Cantera { doublereal m_logp0, m_logc0; array_fp m_ropf, m_ropr, m_ropnet; - array_fp m_rfn_low, m_rfn_high; + //array_fp m_rfn_low, m_rfn_high; bool m_ROP_ok; doublereal m_temp, m_logtemp; diff --git a/Cantera/src/InterfaceKinetics.cpp b/Cantera/src/InterfaceKinetics.cpp index d9d68a400..4b68b2ff7 100644 --- a/Cantera/src/InterfaceKinetics.cpp +++ b/Cantera/src/InterfaceKinetics.cpp @@ -16,15 +16,10 @@ #include "SurfPhase.h" #include "ReactionData.h" -//#include "StoichManager.h" #include "RateCoeffMgr.h" #include "ImplicitSurfChem.h" -//#include -//using namespace std; - - namespace Cantera { ////////////////////////////////////////////////////////////////// @@ -138,7 +133,7 @@ namespace Cantera { vector_fp& m_rkc = m_kdata->m_rkcn; fill(m_rkc.begin(), m_rkc.end(), 0.0); - static vector_fp mu(nTotalSpecies()); + //static vector_fp mu(nTotalSpecies()); if (m_nrev > 0) { int n, nsp, k, ik=0; @@ -608,7 +603,7 @@ namespace Cantera { // operations common to all reaction types installReagents( r ); - installGroups(reactionNumber(), r.rgroups, r.pgroups); + //installGroups(reactionNumber(), r.rgroups, r.pgroups); incrementRxnCount(); m_rxneqn.push_back(r.equation); } @@ -749,13 +744,13 @@ namespace Cantera { } - void InterfaceKinetics::installGroups(int irxn, - const vector& r, const vector& p) { - if (!r.empty()) { - m_rgroups[reactionNumber()] = r; - m_pgroups[reactionNumber()] = p; - } - } + //void InterfaceKinetics::installGroups(int irxn, + // const vector& r, const vector& p) { + // if (!r.empty()) { + // m_rgroups[reactionNumber()] = r; + // m_pgroups[reactionNumber()] = p; + // } + //} /** * Prepare the class for the addition of reactions. This function diff --git a/Cantera/src/InterfaceKinetics.h b/Cantera/src/InterfaceKinetics.h index 7304a6afa..3777f1e61 100644 --- a/Cantera/src/InterfaceKinetics.h +++ b/Cantera/src/InterfaceKinetics.h @@ -48,7 +48,7 @@ namespace Cantera { doublereal m_logp0, m_logc0; array_fp m_ropf, m_ropr, m_ropnet; - array_fp m_rfn_low, m_rfn_high; + //array_fp m_rfn_low, m_rfn_high; bool m_ROP_ok; doublereal m_temp, m_logtemp; @@ -311,10 +311,10 @@ namespace Cantera { void updateROP(); - const vector& reactantGroups(int i) - { return m_rgroups[i]; } - const vector& productGroups(int i) - { return m_pgroups[i]; } + //const vector& reactantGroups(int i) + // { return m_rgroups[i]; } + //const vector& productGroups(int i) + // { return m_pgroups[i]; } void _update_rates_T(); void _update_rates_phi(); @@ -325,6 +325,7 @@ namespace Cantera { vector_fp m_grt; protected: + /** * m_kk here is the number of species in all of the phases * that participate in the kinetics mechanism. @@ -361,8 +362,8 @@ namespace Cantera { */ int m_nrev; - map > m_rgroups; - map > m_pgroups; + // map > m_rgroups; + //map > m_pgroups; vector m_rxntype; @@ -426,8 +427,8 @@ namespace Cantera { void addGlobalReaction(const ReactionData& r); void installReagents(const ReactionData& r); - void installGroups(int irxn, const vector& r, - const vector& p); + //void installGroups(int irxn, const vector& r, + // const vector& p); void updateKc(); void registerReaction(int rxnNumber, int type, int loc) { diff --git a/Cantera/src/Kinetics.h b/Cantera/src/Kinetics.h index dfb174741..68928314a 100755 --- a/Cantera/src/Kinetics.h +++ b/Cantera/src/Kinetics.h @@ -668,12 +668,12 @@ namespace Cantera { } virtual const vector& reactantGroups(int i) { - err("reactantGroups"); + //err("reactantGroups"); return m_dummygroups; } virtual const vector& productGroups(int i) { - err("productGroups"); + //err("productGroups"); return m_dummygroups; } diff --git a/Cantera/src/ReactionStoichMgr.cpp b/Cantera/src/ReactionStoichMgr.cpp index 3c8b5abca..68755946c 100644 --- a/Cantera/src/ReactionStoichMgr.cpp +++ b/Cantera/src/ReactionStoichMgr.cpp @@ -121,36 +121,43 @@ namespace Cantera { getCreationRates(int nsp, const doublereal* ropf, const doublereal* ropr, doublereal* c) { // zero out the output array - fill(c, c + nsp, 0.0); + fill(c, c + nsp, 0.0); - m_revproducts->incrementSpecies(ropf, c); - m_irrevproducts->incrementSpecies(ropf, c); + // the forward direction creates product species + m_revproducts->incrementSpecies(ropf, c); + m_irrevproducts->incrementSpecies(ropf, c); - // the reverse direction creates reactant species - m_reactants->incrementSpecies(ropr, c); + // the reverse direction creates reactant species + m_reactants->incrementSpecies(ropr, c); } void ReactionStoichMgr:: getDestructionRates(int nsp, const doublereal* ropf, const doublereal* ropr, doublereal* d) { fill(d, d + nsp, 0.0); + // the reverse direction destroys products in reversible reactions m_revproducts->incrementSpecies(ropr, d); + // the forward direction destroys reactants m_reactants->incrementSpecies(ropf, d); } void ReactionStoichMgr:: getNetProductionRates(int nsp, const doublereal* ropnet, doublereal* w) { fill(w, w + nsp, 0.0); + // products are created for positive net rate of progress m_revproducts->incrementSpecies(ropnet, w); m_irrevproducts->incrementSpecies(ropnet, w); + // reactants are destroyed for positive net rate of progress m_reactants->decrementSpecies(ropnet, w); } void ReactionStoichMgr:: getReactionDelta(int nr, const doublereal* g, doublereal* dg) { fill(dg, dg + nr, 0.0); + // products add m_revproducts->incrementReactions(g, dg); m_irrevproducts->incrementReactions(g, dg); + // reactants subtract m_reactants->decrementReactions(g, dg); } diff --git a/Cantera/src/ReactionStoichMgr.h b/Cantera/src/ReactionStoichMgr.h index 12e27af0b..3ad208754 100644 --- a/Cantera/src/ReactionStoichMgr.h +++ b/Cantera/src/ReactionStoichMgr.h @@ -224,7 +224,6 @@ namespace Cantera { StoichManagerN* m_reactants; StoichManagerN* m_revproducts; StoichManagerN* m_irrevproducts; - // StoichManagerN* m_global; vector_fp m_dummy; }; } diff --git a/Cantera/src/StoichManager.h b/Cantera/src/StoichManager.h index 18ac28a63..a71ee36cd 100755 --- a/Cantera/src/StoichManager.h +++ b/Cantera/src/StoichManager.h @@ -12,91 +12,87 @@ #ifndef CT_STOICH_MGR_H #define CT_STOICH_MGR_H -//#include -//#include -//using namespace std; - #include "stringUtils.h" namespace Cantera { - /** - * @defgroup Stoichiometry Stoichiometry - * - * Note: these classes are designed for internal use in class - * ReactionStoichManager. - * - * Operations on reactions that require knowing the reaction - * stoichiometry. This module consists of class StoichManager, and - * classes C1, C2, and C3. Classes C1, C2, and C3 handle operations - * involving one, two, or three species, respectively, in a - * reaction. Instances are instantiated with a reaction number, and n - * species numbers (n = 1 for C1, etc.). All three classes have the - * same interface. - * - * These classes are designed for use by StoichManager, and the - * operations implemented are those needed to efficiently compute - * quantities such as rates of progress, species production rates, - * reaction thermochemistry, etc. The compiler will inline these - * methods into the body of the corresponding StoichManager method, - * and so there is no performance penalty (unless inlining is turned - * off). - * - * To describe the methods, consider class C3 and suppose an instance - * is created with reaction number irxn and species numbers k0, k1, - * and k2. - * - * - multiply(in, out) : out[irxn] is multiplied by - * in[k0] * in[k1] * in[k2] - * - * - power(in, out) : out[irxn] is multiplied by - * (in[k0]^order0) * (in[k1]^order1) * (in[k2]^order2) - * - * - incrementReaction(in, out) : out[irxn] is incremented by - * in[k0] + in[k1] + in[k2] - * - * - decrementReaction(in, out) : out[irxn] is decremented by - * in[k0] + in[k1] + in[k2] - * - * - incrementSpecies(in, out) : out[k0], out[k1], and out[k2] - * are all incremented by in[irxn] - * - * - decrementSpecies(in, out) : out[k0], out[k1], and out[k2] - * are all decremented by in[irxn] - * - * The function multiply() is usually used when evaluating the - * forward and reverse rates of progress of reactions. - * The rate constants are usually loaded into out[]. Then - * multply() is called to add in the dependence of the - * species concentrations to yield a forward and reverse rop. - * - * The function incrementSpecies() and its cousin decrementSpecies() - * is used to translate from rates of progress to species production - * rates. The vector in[] is preloaed with the rates of progess of - * all reactions. Then incrementSpecies() is called to - * increment the species production vector, out[], with the rates - * of progress. - * - * The functions incrementReaction() and decrementReaction() are - * used to find the standard state equilibrium constant for - * a reaction. Here, output[] is a vector of length - * number of reactions, usually the standard gibbs free energies - * of reaction, while input, usually the standard state - * gibbs free energies of species, is a vector of length number of - * species. - * - * Note the stoichiometric coefficient for a species in a reaction - * is handled by always assuming it is equal to one and then - * treating reactants and products for a reaction separately. - * Bimolecular reactions involving the identical species are - * treated as involving separate species. - * - * @internal This class should be upgraded to include cases where - * real stoichiometric coefficients are used. Shouldn't be that - * hard to do, and they occur in engineering simulations with some - * regularity. - * - */ + /** + * @defgroup Stoichiometry Stoichiometry + * + * Note: these classes are designed for internal use in class + * ReactionStoichManager. + * + * Operations on reactions that require knowing the reaction + * stoichiometry. This module consists of class StoichManager, and + * classes C1, C2, and C3. Classes C1, C2, and C3 handle operations + * involving one, two, or three species, respectively, in a + * reaction. Instances are instantiated with a reaction number, and n + * species numbers (n = 1 for C1, etc.). All three classes have the + * same interface. + * + * These classes are designed for use by StoichManager, and the + * operations implemented are those needed to efficiently compute + * quantities such as rates of progress, species production rates, + * reaction thermochemistry, etc. The compiler will inline these + * methods into the body of the corresponding StoichManager method, + * and so there is no performance penalty (unless inlining is turned + * off). + * + * To describe the methods, consider class C3 and suppose an instance + * is created with reaction number irxn and species numbers k0, k1, + * and k2. + * + * - multiply(in, out) : out[irxn] is multiplied by + * in[k0] * in[k1] * in[k2] + * + * - power(in, out) : out[irxn] is multiplied by + * (in[k0]^order0) * (in[k1]^order1) * (in[k2]^order2) + * + * - incrementReaction(in, out) : out[irxn] is incremented by + * in[k0] + in[k1] + in[k2] + * + * - decrementReaction(in, out) : out[irxn] is decremented by + * in[k0] + in[k1] + in[k2] + * + * - incrementSpecies(in, out) : out[k0], out[k1], and out[k2] + * are all incremented by in[irxn] + * + * - decrementSpecies(in, out) : out[k0], out[k1], and out[k2] + * are all decremented by in[irxn] + * + * The function multiply() is usually used when evaluating the + * forward and reverse rates of progress of reactions. + * The rate constants are usually loaded into out[]. Then + * multply() is called to add in the dependence of the + * species concentrations to yield a forward and reverse rop. + * + * The function incrementSpecies() and its cousin decrementSpecies() + * is used to translate from rates of progress to species production + * rates. The vector in[] is preloaed with the rates of progess of + * all reactions. Then incrementSpecies() is called to + * increment the species production vector, out[], with the rates + * of progress. + * + * The functions incrementReaction() and decrementReaction() are + * used to find the standard state equilibrium constant for + * a reaction. Here, output[] is a vector of length + * number of reactions, usually the standard gibbs free energies + * of reaction, while input, usually the standard state + * gibbs free energies of species, is a vector of length number of + * species. + * + * Note the stoichiometric coefficient for a species in a reaction + * is handled by always assuming it is equal to one and then + * treating reactants and products for a reaction separately. + * Bimolecular reactions involving the identical species are + * treated as involving separate species. + * + * @internal This class should be upgraded to include cases where + * real stoichiometric coefficients are used. Shouldn't be that + * hard to do, and they occur in engineering simulations with some + * regularity. + * + */ static doublereal ppow(doublereal x, doublereal order) { if (x > 0.0) @@ -105,181 +101,211 @@ namespace Cantera { return 0.0; } - /** - * Handles one species in a reaction. - * @ingroup Stoichiometry - * @internal - */ - class C1 { + /** + * Handles one species in a reaction. + * @ingroup Stoichiometry + * @internal + */ + class C1 { - public: + public: - C1( int rxn = 0, int ic0 = 0) - : m_rxn (rxn), m_ic0 (ic0) {} + C1( int rxn = 0, int ic0 = 0) + : m_rxn (rxn), m_ic0 (ic0) {} - int data(vector& ic) { - ic.resize(3); - ic[0] = m_ic0; - return m_rxn; - } + int data(vector& ic) { + ic.resize(1); + ic[0] = m_ic0; + return m_rxn; + } - void multiply(const doublereal* input, doublereal* output) const { - *(output + m_rxn) *= *(input + m_ic0); - } + void incrementSpecies(const doublereal* R, doublereal* S) const { + S[m_ic0] += R[m_rxn]; + } - /** - * Add the sum of N specified elements of array 'input' - * to element I or array 'output'. - */ - void incrementSpecies(const doublereal* input, - doublereal* output) const { - *(output + m_ic0) += *(input + m_rxn); - } + void decrementSpecies(const doublereal* R, doublereal* S) const { + S[m_ic0] -= R[m_rxn]; + } + void multiply(const doublereal* S, doublereal* R) const { + R[m_rxn] *= S[m_ic0]; + } - void decrementSpecies(const doublereal* input, - doublereal* output) const { - *(output + m_ic0) -= *(input + m_rxn); - } - void incrementReaction(const doublereal* input, - doublereal* output) const { - *(output + m_rxn) += *(input + m_ic0); - } - void decrementReaction(const doublereal* input, - doublereal* output) const { - *(output + m_rxn) -= *(input + m_ic0); - } - private: - int m_rxn, m_ic0; - }; + void incrementReaction(const doublereal* S, doublereal* R) const { + R[m_rxn] += S[m_ic0]; + } + + void decrementReaction(const doublereal* S, doublereal* R) const { + R[m_rxn] -= S[m_ic0]; + } + + private: + int m_rxn, m_ic0; + }; - /** - * Handles two species in a single reaction. - * @ingroup Stoichiometry - */ - class C2 { - public: - C2( int rxn = 0, int ic0 = 0, int ic1 = 0) - : m_rxn (rxn), m_ic0 (ic0), m_ic1 (ic1) {} - - int data(vector& ic) { - ic.resize(2); - ic[0] = m_ic0; - ic[1] = m_ic1; - return m_rxn; - } - - void multiply(const doublereal* input, doublereal* output) const { - output[m_rxn] *= input[m_ic0] * input[m_ic1]; - } - - void incrementSpecies(const doublereal* input, - doublereal* output) const { - doublereal x = input[m_rxn]; - output[m_ic0] += x; - output[m_ic1] += x; - } - - void decrementSpecies(const doublereal* input, - doublereal* output) const { - doublereal x = input[m_rxn]; - output[m_ic0] -= x; - output[m_ic1] -= x; - } - - void incrementReaction(const doublereal* input, - doublereal* output) const { - *(output + m_rxn) += *(input + m_ic0) + *(input + m_ic1); - } - - void decrementReaction(const doublereal* input, - doublereal* output) const { - *(output + m_rxn) -= (*(input + m_ic0) + *(input + m_ic1)); - } - - private: - /** - * Reaction index -> index into the ROP vector + * Handles two species in a single reaction. + * @ingroup Stoichiometry */ - int m_rxn; + class C2 { + public: + C2( int rxn = 0, int ic0 = 0, int ic1 = 0) + : m_rxn (rxn), m_ic0 (ic0), m_ic1 (ic1) {} - /** - * Species indecise -> index into the species vector for the - * two species. - */ - int m_ic0, m_ic1; - }; + int data(vector& ic) { + ic.resize(2); + ic[0] = m_ic0; + ic[1] = m_ic1; + return m_rxn; + } + + void incrementSpecies(const doublereal* R, doublereal* S) const { + S[m_ic0] += R[m_rxn]; + S[m_ic1] += R[m_rxn]; + } + + void decrementSpecies(const doublereal* R, doublereal* S) const { + S[m_ic0] -= R[m_rxn]; + S[m_ic1] -= R[m_rxn]; + } + + void multiply(const doublereal* S, doublereal* R) const { + R[m_rxn] *= S[m_ic0] * S[m_ic1]; + } + + void incrementReaction(const doublereal* S, doublereal* R) const { + R[m_rxn] += S[m_ic0] + S[m_ic1]; + } + + void decrementReaction(const doublereal* S, doublereal* R) const { + R[m_rxn] -= (S[m_ic0] + S[m_ic1]); + } + + // void multiply(const doublereal* input, doublereal* output) const { + // output[m_rxn] *= input[m_ic0] * input[m_ic1]; + // } + + // void incrementSpecies(const doublereal* input, + // doublereal* output) const { + // doublereal x = input[m_rxn]; + // output[m_ic0] += x; + // output[m_ic1] += x; + // } + + // void decrementSpecies(const doublereal* input, + // doublereal* output) const { + // doublereal x = input[m_rxn]; + // output[m_ic0] -= x; + // output[m_ic1] -= x; + // } + + // void incrementReaction(const doublereal* input, + // doublereal* output) const { + // *(output + m_rxn) += *(input + m_ic0) + *(input + m_ic1); + // } + + // void decrementReaction(const doublereal* input, + // doublereal* output) const { + // *(output + m_rxn) -= (*(input + m_ic0) + *(input + m_ic1)); + // } + + private: + + /** + * Reaction index -> index into the ROP vector + */ + int m_rxn; + + /** + * Species indecise -> index into the species vector for the + * two species. + */ + int m_ic0, m_ic1; + }; - /** - * Handles three species in a reaction. - * @ingroup Stoichiometry - */ - class C3 { - public: - C3( int rxn = 0, int ic0 = 0, int ic1 = 0, int ic2 = 0, - doublereal order0 = 1.0, doublereal order1 = 1.0, - doublereal order2 = 1.0) - : m_rxn (rxn), m_ic0 (ic0), m_ic1 (ic1), m_ic2 (ic2), - m_order0(order0), m_order1(order1), m_order2(order2) {} + /** + * Handles three species in a reaction. + * @ingroup Stoichiometry + */ + class C3 { + public: + C3( int rxn = 0, int ic0 = 0, int ic1 = 0, int ic2 = 0) + : m_rxn (rxn), m_ic0 (ic0), m_ic1 (ic1), m_ic2 (ic2) {} - int data(vector& ic) { - ic.resize(3); - ic[0] = m_ic0; - ic[1] = m_ic1; - ic[2] = m_ic2; - return m_rxn; - } + int data(vector& ic) { + ic.resize(3); + ic[0] = m_ic0; + ic[1] = m_ic1; + ic[2] = m_ic2; + return m_rxn; + } - void multiply(const doublereal* input, doublereal* output) const { - *(output + m_rxn) *= (*(input + m_ic0)) * (*(input + m_ic1)) - * (*(input + m_ic2)); - } + void incrementSpecies(const doublereal* R, doublereal* S) const { + S[m_ic0] += R[m_rxn]; + S[m_ic1] += R[m_rxn]; + S[m_ic2] += R[m_rxn]; + } + + void decrementSpecies(const doublereal* R, doublereal* S) const { + S[m_ic0] -= R[m_rxn]; + S[m_ic1] -= R[m_rxn]; + S[m_ic2] -= R[m_rxn]; + } + + void multiply(const doublereal* S, doublereal* R) const { + R[m_rxn] *= S[m_ic0] * S[m_ic1] * S[m_ic2]; + } + + void incrementReaction(const doublereal* S, doublereal* R) const { + R[m_rxn] += S[m_ic0] + S[m_ic1] + S[m_ic2]; + } + + void decrementReaction(const doublereal* S, doublereal* R) const { + R[m_rxn] -= (S[m_ic0] + S[m_ic1] + S[m_ic2]); + } + + // void multiply(const doublereal* input, doublereal* output) const { +// *(output + m_rxn) *= (*(input + m_ic0)) * (*(input + m_ic1)) +// * (*(input + m_ic2)); +// } - //void power(const doublereal* input, doublereal* output) const { - //output[m_rxn] *= ppow(input[m_ic0],m_order0) * - // ppow(input[m_ic1],m_order1) * - // ppow(input[m_ic2],m_order2); - //} - - void incrementSpecies(const doublereal* input, - doublereal* output) const { - doublereal x = *(input + m_rxn); - *(output + m_ic0) += x; - *(output + m_ic1) += x; - *(output + m_ic2) += x; - } - void decrementSpecies(const doublereal* input, - doublereal* output) const { - doublereal x = *(input + m_rxn); - *(output + m_ic0) -= x; - *(output + m_ic1) -= x; - *(output + m_ic2) -= x; - } - void incrementReaction(const doublereal* input, - doublereal* output) const { - *(output + m_rxn) += *(input + m_ic0) + *(input + m_ic1) - + *(input + m_ic2); - } - void decrementReaction(const doublereal* input, - doublereal* output) const { - *(output + m_rxn) -= (*(input + m_ic0) + *(input + m_ic1) - + *(input + m_ic2)); - } - private: - int m_rxn, m_ic0, m_ic1, m_ic2; - doublereal m_order0, m_order1, m_order2; - }; +// void incrementSpecies(const doublereal* input, +// doublereal* output) const { +// doublereal x = *(input + m_rxn); +// *(output + m_ic0) += x; +// *(output + m_ic1) += x; +// *(output + m_ic2) += x; +// } +// void decrementSpecies(const doublereal* input, +// doublereal* output) const { +// doublereal x = *(input + m_rxn); +// *(output + m_ic0) -= x; +// *(output + m_ic1) -= x; +// *(output + m_ic2) -= x; +// } +// void incrementReaction(const doublereal* input, +// doublereal* output) const { +// *(output + m_rxn) += *(input + m_ic0) + *(input + m_ic1) +// + *(input + m_ic2); +// } +// void decrementReaction(const doublereal* input, +// doublereal* output) const { +// *(output + m_rxn) -= (*(input + m_ic0) + *(input + m_ic1) +// + *(input + m_ic2)); +// } + private: + int m_rxn, m_ic0, m_ic1, m_ic2; + }; - /** - * Handles any number of species in a reaction, including fractional - * stoichiometric coefficients, and arbitrary reaction orders. - * @ingroup Stoichiometry - */ + /** + * Handles any number of species in a reaction, including fractional + * stoichiometric coefficients, and arbitrary reaction orders. + * @ingroup Stoichiometry + */ class C_AnyN { public: C_AnyN() : m_rxn (-1) {} @@ -312,7 +338,7 @@ namespace Cantera { void multiply(const doublereal* input, doublereal* output) const { for (int n = 0; n < m_n; n++) output[m_rxn] *= - ppow(input[m_ic[n]],m_order[n]); //input[m_ic[n]]; + ppow(input[m_ic[n]],m_order[n]); } void incrementSpecies(const doublereal* input, @@ -327,18 +353,12 @@ namespace Cantera { for (int n = 0; n < m_n; n++) output[m_ic[n]] -= m_stoich[n]*x; } - /** - * Increment R[I] by the sum of N specified elements of array S. - */ void incrementReaction(const doublereal* input, doublereal* output) const { for (int n = 0; n < m_n; n++) output[m_rxn] += m_stoich[n]*input[m_ic[n]]; } - /** - * Decrement R[I] by the sum of N specified elements of array S. - */ void decrementReaction(const doublereal* input, doublereal* output) const { for (int n = 0; n < m_n; n++) output[m_rxn] @@ -360,13 +380,6 @@ namespace Cantera { __begin->multiply(input, output); } - //template - //inline static void _power(_InputIter __begin, _InputIter __end, - // const Vec1& input, Vec2& output) { - //for (; __begin != __end; ++__begin) - // __begin->power(input, output); - //} - template inline static void _incrementSpecies(_InputIter __begin, _InputIter __end, const Vec1& input, Vec2& output) { @@ -397,230 +410,225 @@ namespace Cantera { /* - * This class handles operations involving the stoichiometric - * coefficients on one side of a reaction (reactant or product) for - * a set of reactions comprising a reaction mechanism. This class is - * used by class ReactionStoichMgr, which contains three instances - * of this class (one to handle operations on the reactions, one for - * the products of reversible reactions, and one for the products of - * irreversible reactions). - * - * This class is designed for use with elementary reactions, or at - * least ones with integral stoichiometric coefficients. Let \f$ M(i) \f$ - * be the number of molecules on the product or reactant side of - * reaction number i. - * \f[ - * r_i = \sum_m^{M_i} s_{k_{m,i}} - * \f] - * To understand the operations performed by this class, let - * \f$ N_{k,i}\f$ denote the stoichiometric coefficient of species k on - * one side (reactant or product) in reaction i. Then \b N is a sparse - * K by I matrix of stoichiometric coefficients. - * - * The following matrix operations may be carried out with a vector - * S of length K, and a vector R of length I: - * - * - \f$ S = S + N R\f$ (incrementSpecies) - * - \f$ S = S - N R\f$ (decrementSpecies) - * - \f$ R = R + N^T S \f$ (incrementReaction) - * - \f$ R = R - N^T S \f$ (deccrementReaction) - * - * The actual implementation, however, does not compute these - * quantities by matrix multiplication. A faster algorithm is used - * that makes use of the fact that the \b integer-valued N matrix is - * very sparse, and the non-zero terms are small positive integers. - * \f[ - * S_k = R_{i1} + \dots + R_{iM} - * \f] - * where M is the number of molecules, and $\f i(m) \f$ is the - * @ingroup Stoichiometry - */ - class StoichManagerN { - public: - - /** - * Constructor for the StoichManagerN class. + * This class handles operations involving the stoichiometric + * coefficients on one side of a reaction (reactant or product) for + * a set of reactions comprising a reaction mechanism. This class is + * used by class ReactionStoichMgr, which contains three instances + * of this class (one to handle operations on the reactions, one for + * the products of reversible reactions, and one for the products of + * irreversible reactions). * - * @internal Consider adding defaulted entries here that supply - * the total number of reactions in the mechanism and the total - * number of species in the species list. Then, we could use those - * numbers to provide error checks during the construction of the - * object. Those numbers would also provide some clarity to the - * purpose and utility of this class. + * This class is designed for use with elementary reactions, or at + * least ones with integral stoichiometric coefficients. Let \f$ M(i) \f$ + * be the number of molecules on the product or reactant side of + * reaction number i. + * \f[ + * r_i = \sum_m^{M_i} s_{k_{m,i}} + * \f] + * To understand the operations performed by this class, let + * \f$ N_{k,i}\f$ denote the stoichiometric coefficient of species k on + * one side (reactant or product) in reaction i. Then \b N is a sparse + * K by I matrix of stoichiometric coefficients. + * + * The following matrix operations may be carried out with a vector + * S of length K, and a vector R of length I: + * + * - \f$ S = S + N R\f$ (incrementSpecies) + * - \f$ S = S - N R\f$ (decrementSpecies) + * - \f$ R = R + N^T S \f$ (incrementReaction) + * - \f$ R = R - N^T S \f$ (deccrementReaction) * - * DGG - the problem is that the number of reactions and species - * are not known initially. + * The actual implementation, however, does not compute these + * quantities by matrix multiplication. A faster algorithm is used + * that makes use of the fact that the \b integer-valued N matrix is + * very sparse, and the non-zero terms are small positive integers. + * \f[ + * S_k = R_{i1} + \dots + R_{iM} + * \f] + * where M is the number of molecules, and $\f i(m) \f$ is the + * @ingroup Stoichiometry */ - StoichManagerN() {} + class StoichManagerN { + public: - /** - * Add a single reaction to the list of reactions that this - * stoichiometric manager object handles. - * - * This function is the same as the add() function below. However, - * the order of each species in the power list expression is - * set to one automatically. - */ - void add(int rxn, const vector_int& k) { - vector_fp order(k.size(), 1.0); - vector_fp stoich(k.size(), 1.0); - add(rxn, k, order, stoich); - } + /** + * Constructor for the StoichManagerN class. + * + * @internal Consider adding defaulted entries here that supply + * the total number of reactions in the mechanism and the total + * number of species in the species list. Then, we could use those + * numbers to provide error checks during the construction of the + * object. Those numbers would also provide some clarity to the + * purpose and utility of this class. + * + * DGG - the problem is that the number of reactions and species + * are not known initially. + */ + StoichManagerN() {} - void add(int rxn, const vector_int& k, const vector_fp& order) { - vector_fp stoich(k.size(), 1.0); - add(rxn, k, order, stoich); - } + /** + * Add a single reaction to the list of reactions that this + * stoichiometric manager object handles. + * + * This function is the same as the add() function below. However, + * the order of each species in the power list expression is + * set to one automatically. + */ + void add(int rxn, const vector_int& k) { + vector_fp order(k.size(), 1.0); + vector_fp stoich(k.size(), 1.0); + add(rxn, k, order, stoich); + } - /** - * Add a single reaction to the list of reactions that this - * stoichiometric manager object handles. - * - * @param rxn Reaction index of the current reaction. This is used - * as an index into vectors which have length n_total_rxn. - * @param k This is a vector of integer values specifying the - * species indecises. The length of this vector species - * the number of different species in the description. - * The value of the entries are the species indices. - * These are used as indexes into vectors which have - * length n_total_species. - * @param order This is a vector of the same length as vector k. - * The order is used for the routine power(), which produces - * a power law expression involving the species vector. - * @param stoich This is used to handle fractional stoichiometric coefficients - * on the product side of irreversible reactions. - */ - void add(int rxn, const vector_int& k, const vector_fp& order, - const vector_fp& stoich) { - m_n[rxn] = static_cast(k.size()); - int ns = stoich.size(); - int n; - bool frac = false; - for (n = 0; n < ns; n++) { - if (stoich[n] != 1.0) frac = true; - } - if (frac) { - m_loc[rxn] = static_cast(m_cn_list.size()); - m_cn_list.push_back(C_AnyN(rxn, k, order, stoich)); - } - else { - switch (k.size()) { - case 1: - m_loc[rxn] = static_cast(m_c1_list.size()); - m_c1_list.push_back(C1(rxn, k[0])); - break; - case 2: - m_loc[rxn] = static_cast(m_c2_list.size()); - m_c2_list.push_back(C2(rxn, k[0], k[1])); - break; - case 3: - m_loc[rxn] = static_cast(m_c3_list.size()); - m_c3_list.push_back(C3(rxn, k[0], k[1], k[2], - order[0], order[1], order[2])); - break; - default: - m_loc[rxn] = static_cast(m_cn_list.size()); - m_cn_list.push_back(C_AnyN(rxn, k, order, stoich)); - } - } - } + void add(int rxn, const vector_int& k, const vector_fp& order) { + vector_fp stoich(k.size(), 1.0); + add(rxn, k, order, stoich); + } + + /** + * Add a single reaction to the list of reactions that this + * stoichiometric manager object handles. + * + * @param rxn Reaction index of the current reaction. This is used + * as an index into vectors which have length n_total_rxn. + * @param k This is a vector of integer values specifying the + * species indecises. The length of this vector species + * the number of different species in the description. + * The value of the entries are the species indices. + * These are used as indexes into vectors which have + * length n_total_species. + * @param order This is a vector of the same length as vector k. + * The order is used for the routine power(), which produces + * a power law expression involving the species vector. + * @param stoich This is used to handle fractional stoichiometric coefficients + * on the product side of irreversible reactions. + */ + void add(int rxn, const vector_int& k, const vector_fp& order, + const vector_fp& stoich) { + m_n[rxn] = static_cast(k.size()); + int ns = stoich.size(); + int n; + bool frac = false; + for (n = 0; n < ns; n++) { + if (stoich[n] != 1.0) frac = true; + } + if (frac) { + m_loc[rxn] = static_cast(m_cn_list.size()); + m_cn_list.push_back(C_AnyN(rxn, k, order, stoich)); + } + else { + switch (k.size()) { + case 1: + m_loc[rxn] = static_cast(m_c1_list.size()); + m_c1_list.push_back(C1(rxn, k[0])); + break; + case 2: + m_loc[rxn] = static_cast(m_c2_list.size()); + m_c2_list.push_back(C2(rxn, k[0], k[1])); + break; + case 3: + m_loc[rxn] = static_cast(m_c3_list.size()); + m_c3_list.push_back(C3(rxn, k[0], k[1], k[2])); + break; + default: + m_loc[rxn] = static_cast(m_cn_list.size()); + m_cn_list.push_back(C_AnyN(rxn, k, order, stoich)); + } + } + } - void multiply(const doublereal* input, doublereal* output) const { - _multiply(m_c1_list.begin(), m_c1_list.end(), input, output); - _multiply(m_c2_list.begin(), m_c2_list.end(), input, output); - _multiply(m_c3_list.begin(), m_c3_list.end(), input, output); - _multiply(m_cn_list.begin(), m_cn_list.end(), input, output); - } + void multiply(const doublereal* input, doublereal* output) const { + _multiply(m_c1_list.begin(), m_c1_list.end(), input, output); + _multiply(m_c2_list.begin(), m_c2_list.end(), input, output); + _multiply(m_c3_list.begin(), m_c3_list.end(), input, output); + _multiply(m_cn_list.begin(), m_cn_list.end(), input, output); + } - //void power(const doublereal* input, doublereal* output) const { - //_power(m_c1_list.begin(), m_c1_list.end(), input, output); - //_power(m_c2_list.begin(), m_c2_list.end(), input, output); - //_power(m_c3_list.begin(), m_c3_list.end(), input, output); - //_power(m_cn_list.begin(), m_cn_list.end(), input, output); - //} - - void incrementSpecies(const doublereal* input, doublereal* output) const { - _incrementSpecies(m_c1_list.begin(), m_c1_list.end(), input, output); - _incrementSpecies(m_c2_list.begin(), m_c2_list.end(), input, output); - _incrementSpecies(m_c3_list.begin(), m_c3_list.end(), input, output); - _incrementSpecies(m_cn_list.begin(), m_cn_list.end(), input, output); - } + void incrementSpecies(const doublereal* input, doublereal* output) const { + _incrementSpecies(m_c1_list.begin(), m_c1_list.end(), input, output); + _incrementSpecies(m_c2_list.begin(), m_c2_list.end(), input, output); + _incrementSpecies(m_c3_list.begin(), m_c3_list.end(), input, output); + _incrementSpecies(m_cn_list.begin(), m_cn_list.end(), input, output); + } - void decrementSpecies(const doublereal* input, doublereal* output) const { - _decrementSpecies(m_c1_list.begin(), m_c1_list.end(), input, output); - _decrementSpecies(m_c2_list.begin(), m_c2_list.end(), input, output); - _decrementSpecies(m_c3_list.begin(), m_c3_list.end(), input, output); - _decrementSpecies(m_cn_list.begin(), m_cn_list.end(), input, output); - } + void decrementSpecies(const doublereal* input, doublereal* output) const { + _decrementSpecies(m_c1_list.begin(), m_c1_list.end(), input, output); + _decrementSpecies(m_c2_list.begin(), m_c2_list.end(), input, output); + _decrementSpecies(m_c3_list.begin(), m_c3_list.end(), input, output); + _decrementSpecies(m_cn_list.begin(), m_cn_list.end(), input, output); + } - void incrementReactions(const doublereal* input, doublereal* output) const { - _incrementReactions(m_c1_list.begin(), m_c1_list.end(), input, output); - _incrementReactions(m_c2_list.begin(), m_c2_list.end(), input, output); - _incrementReactions(m_c3_list.begin(), m_c3_list.end(), input, output); - _incrementReactions(m_cn_list.begin(), m_cn_list.end(), input, output); - } + void incrementReactions(const doublereal* input, doublereal* output) const { + _incrementReactions(m_c1_list.begin(), m_c1_list.end(), input, output); + _incrementReactions(m_c2_list.begin(), m_c2_list.end(), input, output); + _incrementReactions(m_c3_list.begin(), m_c3_list.end(), input, output); + _incrementReactions(m_cn_list.begin(), m_cn_list.end(), input, output); + } - void decrementReactions(const doublereal* input, doublereal* output) const { - _decrementReactions(m_c1_list.begin(), m_c1_list.end(), input, output); - _decrementReactions(m_c2_list.begin(), m_c2_list.end(), input, output); - _decrementReactions(m_c3_list.begin(), m_c3_list.end(), input, output); - _decrementReactions(m_cn_list.begin(), m_cn_list.end(), input, output); - } + void decrementReactions(const doublereal* input, doublereal* output) const { + _decrementReactions(m_c1_list.begin(), m_c1_list.end(), input, output); + _decrementReactions(m_c2_list.begin(), m_c2_list.end(), input, output); + _decrementReactions(m_c3_list.begin(), m_c3_list.end(), input, output); + _decrementReactions(m_cn_list.begin(), m_cn_list.end(), input, output); + } - private: + private: - vector m_c1_list; - vector m_c2_list; - vector m_c3_list; - vector m_cn_list; - /** - * Mapping with the Reaction Number as key and the Number of species - * as the value. - */ - map m_n; - /** - * Mapping with the Reaction Number as key and the placement in the - * vector of reactions list( i.e., m_c1_list[]) as key - */ - map m_loc; - }; + vector m_c1_list; + vector m_c2_list; + vector m_c3_list; + vector m_cn_list; + /** + * Mapping with the Reaction Number as key and the Number of species + * as the value. + */ + map m_n; + /** + * Mapping with the Reaction Number as key and the placement in the + * vector of reactions list( i.e., m_c1_list[]) as key + */ + map m_loc; + }; +#ifdef INCL_STOICH_WRITER + + class StoichWriter { + public: + + StoichWriter() {} + + void add(int rxn, const vector_int& k) { + int n, nn = k.size(); + for (n = 0; n < nn; n++) { + if (m_mult[rxn] != "") m_mult[rxn] += " * "; + m_mult[rxn] += "c[" + int2str(k[n]) + "]"; + m_is[k[n]] += " + rop[" + int2str(rxn) + "]"; + m_ds[k[n]] += " - rop[" + int2str(rxn) + "]"; + m_ir[rxn] += " + grt[" + int2str(k[n]) + "]"; + m_dr[rxn] += " - grt[" + int2str(k[n]) + "]"; + } + } + + void writeIncSpec(ostream& s, int nsp) { + int k; + for (k = 0; k < nsp; k++) { + s << "out[" << k << "] = " << m_is[k] << ";" << endl; + } + } + + string mult(int rxn) { return m_mult[rxn]; } + string incrSpec(int k) { return m_is[k]; } + string decrSpec(int k) { return m_ds[k]; } + string incrRxn(int rxn) { return m_ir[rxn]; } + string decrRxn(int rxn) { return m_dr[rxn]; } + + private: + map m_mult, m_ir, m_dr, m_is, m_ds; + }; +#endif - class StoichWriter { - public: - - StoichWriter() {} - - void add(int rxn, const vector_int& k) { - int n, nn = k.size(); - for (n = 0; n < nn; n++) { - if (m_mult[rxn] != "") m_mult[rxn] += " * "; - m_mult[rxn] += "c[" + int2str(k[n]) + "]"; - m_is[k[n]] += " + rop[" + int2str(rxn) + "]"; - m_ds[k[n]] += " - rop[" + int2str(rxn) + "]"; - m_ir[rxn] += " + grt[" + int2str(k[n]) + "]"; - m_dr[rxn] += " - grt[" + int2str(k[n]) + "]"; - } - } - - void writeIncSpec(ostream& s, int nsp) { - int k; - for (k = 0; k < nsp; k++) { - s << "out[" << k << "] = " << m_is[k] << ";" << endl; - } - } - - string mult(int rxn) { return m_mult[rxn]; } - string incrSpec(int k) { return m_is[k]; } - string decrSpec(int k) { return m_ds[k]; } - string incrRxn(int rxn) { return m_ir[rxn]; } - string decrRxn(int rxn) { return m_dr[rxn]; } - - private: - map m_mult, m_ir, m_dr, m_is, m_ds; - }; } #endif diff --git a/Cantera/src/converters/CKParser.cpp b/Cantera/src/converters/CKParser.cpp index 192aeac03..29b0bbc30 100755 --- a/Cantera/src/converters/CKParser.cpp +++ b/Cantera/src/converters/CKParser.cpp @@ -6,7 +6,10 @@ // Copyright 2001 California Institute of Technology // // $Log$ -// Revision 1.17 2005-07-25 03:51:21 dggoodwin +// Revision 1.18 2005-07-26 03:56:35 dggoodwin +// cleanup +// +// Revision 1.17 2005/07/25 03:51:21 dggoodwin // now recognizes the FORD keyword // // Revision 1.16 2005/01/07 10:26:43 dggoodwin @@ -953,7 +956,6 @@ next: } Reaction rxn; - cout << "new rxn, fwdOrder size = " << rxn.fwdOrder.size() << endl; vector cm; bool ok = true; diff --git a/Cantera/src/converters/Reaction.h b/Cantera/src/converters/Reaction.h index 71739b358..077419fa9 100755 --- a/Cantera/src/converters/Reaction.h +++ b/Cantera/src/converters/Reaction.h @@ -109,7 +109,10 @@ namespace ckr { /// A class for reactions. - + + // Note: if you add data items to this class, be sure to update + // the copy constructor and the assignment operator ! + class Reaction { public: @@ -179,7 +182,6 @@ namespace ckr { /// Reaction number. int number; - /** * list of species that participate as reactants, diff --git a/Cantera/src/converters/ck2ct.cpp b/Cantera/src/converters/ck2ct.cpp index fd7095c82..9df047d56 100644 --- a/Cantera/src/converters/ck2ct.cpp +++ b/Cantera/src/converters/ck2ct.cpp @@ -276,11 +276,8 @@ namespace pip { } // reaction orders - cout << "checking for rxn orders..." << endl; int nord = static_cast(rxn.fwdOrder.size()); - cout << nord << endl; if (nord > 0) { - cout << "processing order..." << endl; map::const_iterator b = rxn.fwdOrder.begin(), e = rxn.fwdOrder.end(); string estr = ""; diff --git a/winconfig.h b/winconfig.h index e29d4bad5..074d1cdca 100644 --- a/winconfig.h +++ b/winconfig.h @@ -60,6 +60,7 @@ typedef int ftnlen; // Fortran hidden string length type // OS X, This used to add some Mac-specific directories to the default // data file search path. #define DARWIN 0 +#define HAS_SSTREAM /* #undef HAS_SSTREAM */ // Identify whether the operating system is cygwin's overlay of