Eliminate special case for default falloff function

This commit is contained in:
Ray Speth 2013-07-06 21:43:53 +00:00
parent ff1473fab7
commit ef6479f58d
3 changed files with 25 additions and 32 deletions

View file

@ -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;
}
};
/**

View file

@ -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<size_t> m_rxn, m_rxn0;
std::vector<size_t> m_rxn;
std::vector<Falloff*> m_falloff;
FalloffFactory* m_factory;
vector_int m_loc;
int m_n, m_n0;
std::vector<vector_fp::difference_type> m_offset;
size_t m_worksize;
};

View file

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