diff --git a/include/cantera/kinetics/Enhanced3BConc.h b/include/cantera/kinetics/Enhanced3BConc.h index fc9114dc6..4a3b200b2 100644 --- a/include/cantera/kinetics/Enhanced3BConc.h +++ b/include/cantera/kinetics/Enhanced3BConc.h @@ -8,12 +8,14 @@ #define CT_ENH_CONC_H #include "cantera/base/ct_defs.h" +#include "cantera/base/global.h" namespace Cantera { /** * Computes enhanced third-body concentrations. + * @deprecated Replaced by ThirdBodyCalc. To be removed after Cantera 2.2. * @see GasKinetics */ class Enhanced3BConc @@ -21,45 +23,38 @@ class Enhanced3BConc public: - Enhanced3BConc() : m_n(0), m_deflt(1.0) {} + Enhanced3BConc() : m_deflt(1.0) { + warn_deprecated("class Enhanced3BConc", + "To be removed after Cantera 2.2."); + } - Enhanced3BConc(size_t n, const std::map& enhanced, + Enhanced3BConc(const std::map& enhanced, doublereal deflt = 1.0) { + warn_deprecated("class Enhanced3BConc", + "To be removed after Cantera 2.2."); std::map::const_iterator iter; for (iter = enhanced.begin(); iter != enhanced.end(); ++iter) { m_index.push_back(iter->first); m_eff.push_back(iter->second - deflt); } m_deflt = deflt; - m_n = n; - } - - Enhanced3BConc(size_t n, const std::vector& e_index, - const vector_fp& efficiencies, doublereal deflt = 1.0) - : m_index(e_index), m_eff(efficiencies) { - m_n = n; - m_deflt = deflt; - for (size_t i = 0; i < m_n; i++) { - m_eff[i] -= m_deflt; - } } doublereal update(const vector_fp& c, doublereal ctot) const { doublereal sum = 0.0; - for (size_t i = 0; i < m_n; i++) { + for (size_t i = 0; i < m_eff.size(); i++) { sum += m_eff[i] * c[m_index[i]]; } return m_deflt * ctot + sum; } void getEfficiencies(vector_fp& eff) const { - for (size_t i = 0; i < m_n; i++) { + for (size_t i = 0; i < m_eff.size(); i++) { eff[m_index[i]] = m_eff[i] + m_deflt; } } private: - size_t m_n; std::vector m_index; vector_fp m_eff; doublereal m_deflt; diff --git a/include/cantera/kinetics/GasKinetics.h b/include/cantera/kinetics/GasKinetics.h index d7aee795c..824da902b 100644 --- a/include/cantera/kinetics/GasKinetics.h +++ b/include/cantera/kinetics/GasKinetics.h @@ -10,7 +10,7 @@ #define CT_GASKINETICS_H #include "BulkKinetics.h" -#include "ThirdBodyMgr.h" +#include "ThirdBodyCalc.h" #include "FalloffMgr.h" #include "Reaction.h" @@ -80,8 +80,8 @@ protected: FalloffMgr m_falloffn; - ThirdBodyMgr m_3b_concm; - ThirdBodyMgr m_falloff_concm; + ThirdBodyCalc m_3b_concm; + ThirdBodyCalc m_falloff_concm; Rate1 m_plog_rates; Rate1 m_cheb_rates; diff --git a/include/cantera/kinetics/ThirdBodyCalc.h b/include/cantera/kinetics/ThirdBodyCalc.h new file mode 100644 index 000000000..97cd51862 --- /dev/null +++ b/include/cantera/kinetics/ThirdBodyCalc.h @@ -0,0 +1,69 @@ +/** + * @file ThirdBodyCalc.h + */ + +#ifndef CT_THIRDBODYCALC_H +#define CT_THIRDBODYCALC_H + +#include "cantera/base/utilities.h" + +namespace Cantera +{ + +//! Calculate and apply third-body effects on reaction rates, including non- +//! unity third-body efficiencies. +class ThirdBodyCalc +{ +public: + void install(size_t rxnNumber, const std::map& enhanced, + double dflt=1.0) { + m_reaction_index.push_back(rxnNumber); + m_default.push_back(dflt); + + m_species.push_back(std::vector()); + m_eff.push_back(vector_fp()); + for (std::map::const_iterator iter = enhanced.begin(); + iter != enhanced.end(); + ++iter) + { + m_species.back().push_back(iter->first); + m_eff.back().push_back(iter->second - dflt); + } + } + + void update(const vector_fp& conc, double ctot, double* work) { + for (size_t i = 0; i < m_species.size(); i++) { + double sum = 0.0; + for (size_t j = 0; j < m_species[i].size(); j++) { + sum += m_eff[i][j] * conc[m_species[i][j]]; + } + work[i] = m_default[i] * ctot + sum; + } + } + + void multiply(double* output, const double* work) { + scatter_mult(work, work + m_reaction_index.size(), + output, m_reaction_index.begin()); + } + + size_t workSize() { + return m_reaction_index.size(); + } + +protected: + //! Indices of third-body reactions within the full reaction array + std::vector m_reaction_index; + + //! m_species[i][j] is the index of the j-th species in reaction i. + std::vector > m_species; + + //! m_eff[i][j] is the efficiency of the j-th species in reaction i. + std::vector m_eff; + + //! The default efficiency for each reaction + vector_fp m_default; +}; + +} + +#endif diff --git a/include/cantera/kinetics/ThirdBodyMgr.h b/include/cantera/kinetics/ThirdBodyMgr.h index ed1c78ae2..ed3f8d147 100644 --- a/include/cantera/kinetics/ThirdBodyMgr.h +++ b/include/cantera/kinetics/ThirdBodyMgr.h @@ -15,32 +15,31 @@ namespace Cantera { +//! @deprecated Replaced by ThirdBodyCalc. To be removed after Cantera 2.2. template class ThirdBodyMgr { public: - - ThirdBodyMgr<_E>() : m_n(0) {} + ThirdBodyMgr() { + warn_deprecated("class ThirdBodyMgr", "To be removed after Cantera 2.2."); + } void install(size_t rxnNumber, const std::map& enhanced, doublereal dflt=1.0) { - m_n++; m_reaction_index.push_back(rxnNumber); - m_concm.push_back(_E(static_cast(enhanced.size()), - enhanced, dflt)); + m_concm.push_back(_E(enhanced, dflt)); } void update(const vector_fp& conc, doublereal ctot, doublereal* work) { typename std::vector<_E>::const_iterator b = m_concm.begin(); - //doublereal* v = m_values.begin(); for (; b != m_concm.end(); ++b, ++work) { *work = b->update(conc, ctot); } } void multiply(doublereal* output, const doublereal* work) { - scatter_mult(work, work + m_n, + scatter_mult(work, work + m_reaction_index.size(), output, m_reaction_index.begin()); } @@ -54,8 +53,6 @@ public: } protected: - - int m_n; std::vector m_reaction_index; std::vector<_E> m_concm; };