From ef6479f58dd7be179b6c5fff7cb9b277e19f0fe6 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 6 Jul 2013 21:43:53 +0000 Subject: [PATCH] Eliminate special case for default falloff function --- include/cantera/kinetics/FalloffFactory.h | 15 ++++++--- include/cantera/kinetics/FalloffMgr.h | 39 +++++++---------------- src/kinetics/FalloffFactory.cpp | 3 ++ 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/include/cantera/kinetics/FalloffFactory.h b/include/cantera/kinetics/FalloffFactory.h index 7928ae1d2..925521b4f 100644 --- a/include/cantera/kinetics/FalloffFactory.h +++ b/include/cantera/kinetics/FalloffFactory.h @@ -27,8 +27,9 @@ namespace Cantera */ /** - * Base class for falloff function calculators. Each instance of a - * subclass of Falloff computes one falloff function. + * Base class for falloff function calculators. Each instance of a subclass of + * Falloff computes one falloff function. This base class implements the + * trivial falloff function F = 1.0. * * @ingroup falloffGroup */ @@ -47,7 +48,7 @@ public: * @param c Vector of coefficients of the parameterization. The number and * meaning of these coefficients is subclass-dependent. */ - virtual void init(const vector_fp& c) =0; + virtual void init(const vector_fp& c) {} /** * Update the temperature-dependent portions of the falloff @@ -78,10 +79,14 @@ public: * * @return Returns the value of the falloff function \f$ F \f$ defined above */ - virtual doublereal F(doublereal pr, const doublereal* work) const =0; + virtual doublereal F(doublereal pr, const doublereal* work) const { + return 1.0; + } //! The size of the work array required. - virtual size_t workSize() =0; + virtual size_t workSize() { + return 0; + } }; /** diff --git a/include/cantera/kinetics/FalloffMgr.h b/include/cantera/kinetics/FalloffMgr.h index 109559d25..831e8e84d 100644 --- a/include/cantera/kinetics/FalloffMgr.h +++ b/include/cantera/kinetics/FalloffMgr.h @@ -22,7 +22,7 @@ class FalloffMgr public: //! Constructor. FalloffMgr(/*FalloffFactory* f = 0*/) : - m_n(0), m_n0(0), m_worksize(0) { + m_worksize(0) { //if (f == 0) m_factory = FalloffFactory::factory(); // RFB:TODO This raw pointer should be encapsulated // because accessing a 'Singleton Factory' @@ -31,8 +31,7 @@ public: //! Destructor. Deletes all installed falloff function calculators. virtual ~FalloffMgr() { - int i; - for (i = 0; i < m_n; i++) { + for (size_t i = 0; i < m_falloff.size(); i++) { delete m_falloff[i]; } //if (m_factory) { @@ -50,17 +49,11 @@ public: */ void install(size_t rxn, int type, const vector_fp& c) { - if (type != SIMPLE_FALLOFF) { - m_rxn.push_back(rxn); - Falloff* f = m_factory->newFalloff(type,c); - m_offset.push_back(m_worksize); - m_worksize += f->workSize(); - m_falloff.push_back(f); - m_n++; - } else { - m_rxn0.push_back(rxn); - m_n0++; - } + m_rxn.push_back(rxn); + Falloff* f = m_factory->newFalloff(type,c); + m_offset.push_back(m_worksize); + m_worksize += f->workSize(); + m_falloff.push_back(f); } //! Size of the work array required to store intermediate results. @@ -75,10 +68,8 @@ public: * @param work Work array. Must be dimensioned at least workSize(). */ void updateTemp(doublereal t, doublereal* work) { - int i; - for (i = 0; i < m_n; i++) { - m_falloff[i]->updateTemp(t, - work + m_offset[i]); + for (size_t i = 0; i < m_rxn.size(); i++) { + m_falloff[i]->updateTemp(t, work + m_offset[i]); } } @@ -87,24 +78,18 @@ public: * replace each entry by the value of the falloff function. */ void pr_to_falloff(doublereal* values, const doublereal* work) { - doublereal pr; - int i; - for (i = 0; i < m_n0; i++) { - values[m_rxn0[i]] /= (1.0 + values[m_rxn0[i]]); - } - for (i = 0; i < m_n; i++) { - pr = values[m_rxn[i]]; + for (size_t i = 0; i < m_rxn.size(); i++) { + double pr = values[m_rxn[i]]; values[m_rxn[i]] *= m_falloff[i]->F(pr, work + m_offset[i]) /(1.0 + pr); } } protected: - std::vector m_rxn, m_rxn0; + std::vector m_rxn; std::vector m_falloff; FalloffFactory* m_factory; vector_int m_loc; - int m_n, m_n0; std::vector m_offset; size_t m_worksize; }; diff --git a/src/kinetics/FalloffFactory.cpp b/src/kinetics/FalloffFactory.cpp index 9da6efcda..78304a2c8 100644 --- a/src/kinetics/FalloffFactory.cpp +++ b/src/kinetics/FalloffFactory.cpp @@ -535,6 +535,9 @@ Falloff* FalloffFactory::newFalloff(int type, const vector_fp& c) { Falloff* f; switch (type) { + case SIMPLE_FALLOFF: + f = new Falloff(); + break; case TROE3_FALLOFF: f = new Troe3(); break;