From 37f71bd9129710b499a0339551519ca5f82bbd5b Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 7 Nov 2014 02:14:50 +0000 Subject: [PATCH] [Kinetics] Deprecate 'reactants' and 'products' methods These methods are rarely used, and they expose a now-unused internal data structure that isn't even correct for all reactions. --- include/cantera/kinetics/Kinetics.h | 9 +++++++++ src/kinetics/InterfaceKinetics.cpp | 10 ++++------ src/kinetics/ReactionPath.cpp | 25 +++++++++++++++++++------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/cantera/kinetics/Kinetics.h b/include/cantera/kinetics/Kinetics.h index b415084b45..45f94a9f89 100644 --- a/include/cantera/kinetics/Kinetics.h +++ b/include/cantera/kinetics/Kinetics.h @@ -13,6 +13,7 @@ #include "cantera/thermo/ThermoPhase.h" #include "StoichManager.h" #include "cantera/thermo/mix_defs.h" +#include "cantera/base/global.h" namespace Cantera { @@ -652,8 +653,11 @@ class Kinetics * index numbers for reaction i. * * @param i reaction index + * @deprecated To be removed after Cantera 2.2. */ virtual const std::vector& reactants(size_t i) const { + warn_deprecated("Kinetics::reactants", + "To be removed after Cantera 2.2."); return m_reactants[i]; } @@ -662,8 +666,11 @@ class Kinetics * index numbers for reaction i. * * @param i reaction index + * @deprecated To be removed after Cantera 2.2. */ virtual const std::vector& products(size_t i) const { + warn_deprecated("Kinetics::products", + "To be removed after Cantera 2.2."); return m_products[i]; } @@ -912,6 +919,7 @@ class Kinetics * stoichiometric coefficient. * NOTE: These vectors will be wrong if there are real * stoichiometric coefficients in the expression. + * @deprecated To be removed after Cantera 2.2. */ std::vector > m_reactants; @@ -925,6 +933,7 @@ class Kinetics * coefficient. * NOTE: These vectors will be wrong if there are real * stoichiometric coefficients in the expression. + * @deprecated To be removed after Cantera 2.2. */ std::vector > m_products; diff --git a/src/kinetics/InterfaceKinetics.cpp b/src/kinetics/InterfaceKinetics.cpp index b9eeef6b96..b1ef16b54a 100644 --- a/src/kinetics/InterfaceKinetics.cpp +++ b/src/kinetics/InterfaceKinetics.cpp @@ -811,15 +811,13 @@ void InterfaceKinetics::addReaction(ReactionData& r) m_rxnPhaseIsProduct.push_back(std::vector(nPhases(), false)); size_t i = m_ii - 1; - const std::vector& vr = reactants(i); - for (size_t ik = 0; ik < vr.size(); ik++) { - size_t k = vr[ik]; + for (size_t ik = 0; ik < r.reactants.size(); ik++) { + size_t k = r.reactants[ik]; size_t p = speciesPhaseIndex(k); m_rxnPhaseIsReactant[i][p] = true; } - const std::vector& vp = products(i); - for (size_t ik = 0; ik < vp.size(); ik++) { - size_t k = vp[ik]; + for (size_t ik = 0; ik < r.products.size(); ik++) { + size_t k = r.products[ik]; size_t p = speciesPhaseIndex(k); m_rxnPhaseIsProduct[i][p] = true; } diff --git a/src/kinetics/ReactionPath.cpp b/src/kinetics/ReactionPath.cpp index b232d63d2f..a38ad8b406 100644 --- a/src/kinetics/ReactionPath.cpp +++ b/src/kinetics/ReactionPath.cpp @@ -439,8 +439,15 @@ int ReactionPathBuilder::findGroups(ostream& logfile, Kinetics& s) size_t nrnet = m_reac[i].size(); size_t npnet = m_prod[i].size(); - const std::vector& r = s.reactants(i); - const std::vector& p = s.products(i); + std::vector r, p; + for (size_t k = 0; k < s.nTotalSpecies(); k++) { + if (s.reactantStoichCoeff(k,i)) { + r.push_back(k); + } + if (s.productStoichCoeff(k,i)) { + p.push_back(k); + } + } size_t nr = r.size(); size_t np = p.size(); @@ -656,11 +663,17 @@ int ReactionPathBuilder::init(ostream& logfile, Kinetics& kin) // all reactants / products, even ones appearing on both sides // of the reaction - vector > allProducts; - vector > allReactants; + vector > allProducts(m_nr); + vector > allReactants(m_nr); for (size_t i = 0; i < m_nr; i++) { - allReactants.push_back(kin.reactants(i)); - allProducts.push_back(kin.products(i)); + for (size_t k = 0; k < m_ns; k++) { + if (kin.reactantStoichCoeff(k, i)) { + allReactants[i].push_back(k); + } + if (kin.productStoichCoeff(k, i)) { + allProducts[i].push_back(k); + } + } } // m_reac and m_prod exclude indices for species that appear on