Fixed a problem with inappropriate user input causing errors within
Cantera (id 2157797). The resolution of this was to error exit when inappropriate input for Troe parameterization is attempted to be used.
This commit is contained in:
parent
c57463efa4
commit
e5f608ce3d
3 changed files with 529 additions and 381 deletions
|
|
@ -17,276 +17,355 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "FalloffFactory.h"
|
||||
#include "ctexceptions.h"
|
||||
|
||||
namespace Cantera {
|
||||
|
||||
FalloffFactory* FalloffFactory::s_factory = 0;
|
||||
#if defined(THREAD_SAFE_CANTERA)
|
||||
boost::mutex FalloffFactory::falloff_mutex ;
|
||||
#endif
|
||||
FalloffFactory* FalloffFactory::s_factory = 0;
|
||||
#if defined(THREAD_SAFE_CANTERA)
|
||||
boost::mutex FalloffFactory::falloff_mutex ;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The 3-parameter Troe falloff parameterization.
|
||||
* This parameterization is
|
||||
* defined by
|
||||
* \f[ F = F_{cent}^{1/(1 + f_1^2)} \f]
|
||||
* where
|
||||
* \f[ F_{cent} = (1 - A)\exp(-T/T_3) + A \exp(-T/T_1) \f]
|
||||
* \f[ f_1 = (\log_{10} P_r + C) / \left(N - 0.14
|
||||
* (\log_{10} P_r + C)\right) \f]
|
||||
* \f[ C = -0.4 - 0.67 \log_{10} F_{cent} \f]
|
||||
* \f[ N = 0.75 - 1.27 \log_{10} F_{cent} \f]
|
||||
*/
|
||||
class Troe3 : public Falloff {
|
||||
public:
|
||||
|
||||
//! The 3-parameter Troe falloff parameterization.
|
||||
/*!
|
||||
* This parameterization is
|
||||
* defined by
|
||||
* \f[ F = F_{cent}^{1/(1 + f_1^2)} \f]
|
||||
* where
|
||||
* \f[ F_{cent} = (1 - A)\exp(-T/T_3) + A \exp(-T/T_1) \f]
|
||||
* \f[ f_1 = (\log_{10} P_r + C) / \left(N - 0.14
|
||||
* (\log_{10} P_r + C)\right) \f]
|
||||
* \f[ C = -0.4 - 0.67 \log_{10} F_{cent} \f]
|
||||
* \f[ N = 0.75 - 1.27 \log_{10} F_{cent} \f]
|
||||
*
|
||||
* There are a few requirements for the parameters
|
||||
*
|
||||
* T_3 is required to greater than or equal to zero. If it is zero,
|
||||
* then the term is set to zero.
|
||||
*
|
||||
* T_1 is required to greater than or equal to zero. If it is zero,
|
||||
* then the term is set to zero.
|
||||
*
|
||||
* @ingroup falloffGroup
|
||||
*/
|
||||
class Troe3 : public Falloff {
|
||||
public:
|
||||
|
||||
/// Default constructor.
|
||||
Troe3() : m_a (0.0), m_rt3 (0.0), m_rt1 (0.0) {}
|
||||
|
||||
// Destructor. Does nothing.
|
||||
virtual ~Troe3() {}
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
* @param c Coefficient vector of length 3,
|
||||
* with entries \f$ (A, T_3, T_1) \f$
|
||||
*/
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
m_rt3 = 1.0/c[1];
|
||||
m_rt1 = 1.0/c[2];
|
||||
}
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
doublereal Fcent = (1.0 - m_a) * exp(- T * m_rt3 )
|
||||
+ m_a * exp(- T * m_rt1 );
|
||||
*work = log10( fmaxx( Fcent, SmallNumber ) );
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr,f1,lgf, cc, nn;
|
||||
lpr = log10( fmaxx(pr,SmallNumber) );
|
||||
cc = -0.4 - 0.67 * (*work);
|
||||
nn = 0.75 - 1.27 * (*work);
|
||||
f1 = ( lpr + cc )/ ( nn - 0.14 * ( lpr + cc ) );
|
||||
lgf = (*work) / ( 1.0 + f1 * f1 );
|
||||
return pow(10.0, lgf );
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 1; }
|
||||
|
||||
protected:
|
||||
|
||||
doublereal m_a, m_rt3, m_rt1;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
/// Default constructor.
|
||||
Troe3() : m_a (0.0), m_rt3 (0.0), m_rt1 (0.0) {}
|
||||
|
||||
// Destructor. Does nothing.
|
||||
virtual ~Troe3() {}
|
||||
|
||||
/**
|
||||
* The 4-parameter Troe falloff parameterization. This parameterization is
|
||||
* defined by
|
||||
*
|
||||
* \f[ F = F_{cent}^{1/(1 + f_1^2)} \f]
|
||||
* where
|
||||
* \f[ F_{cent} = (1 - A)\exp(-T/T_3) + A \exp(-T/T_1) + \exp(-T_2/T) \f]
|
||||
* \f[ f_1 = (\log_{10} P_r + C) / \left(N - 0.14
|
||||
* (\log_{10} P_r + C)\right) \f]
|
||||
* \f[ C = -0.4 - 0.67 \log_{10} F_{cent} \f]
|
||||
* \f[ N = 0.75 - 1.27 \log_{10} F_{cent} \f]
|
||||
*
|
||||
* Initialize.
|
||||
* @param c Coefficient vector of length 3,
|
||||
* with entries \f$ (A, T_3, T_1) \f$
|
||||
*/
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
|
||||
class Troe4 : public Falloff {
|
||||
public:
|
||||
|
||||
Troe4() : m_a (0.0), m_rt3 (0.0), m_rt1 (0.0),
|
||||
m_t2 (0.0) {}
|
||||
virtual ~Troe4() {}
|
||||
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
m_rt3 = 1.0/c[1];
|
||||
m_rt1 = 1.0/c[2];
|
||||
m_t2 = c[3];
|
||||
}
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
doublereal Fcent = (1.0 - m_a) * exp(- T * m_rt3 )
|
||||
+ m_a * exp(- T * m_rt1 )
|
||||
+ exp(- m_t2 / T );
|
||||
*work = log10( fmaxx( Fcent, SmallNumber ) );
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr,f1,lgf, cc, nn;
|
||||
lpr = log10( fmaxx(pr,SmallNumber) );
|
||||
cc = -0.4 - 0.67 * (*work);
|
||||
nn = 0.75 - 1.27 * (*work);
|
||||
f1 = ( lpr + cc )/ ( nn - 0.14 * ( lpr + cc ) );
|
||||
lgf = (*work) / ( 1.0 + f1 * f1 );
|
||||
return pow(10.0, lgf );
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 1; }
|
||||
|
||||
protected:
|
||||
|
||||
doublereal m_a, m_rt3, m_rt1;
|
||||
doublereal m_t2;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
/**
|
||||
* The 3-parameter SRI falloff function.
|
||||
*/
|
||||
class SRI3 : public Falloff {
|
||||
|
||||
public:
|
||||
|
||||
SRI3() {}
|
||||
virtual ~SRI3() {}
|
||||
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
m_b = c[1];
|
||||
m_c = c[2];
|
||||
}
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
*work = m_a * exp( - m_b / T);
|
||||
if (m_c != 0.0) *work += exp( - T/m_c );
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr = log10( fmaxx(pr,SmallNumber) );
|
||||
doublereal xx = 1.0/(1.0 + lpr*lpr);
|
||||
doublereal ff = pow( *work , xx);
|
||||
return ff;
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 1; }
|
||||
|
||||
protected:
|
||||
doublereal m_a, m_b, m_c;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The 5-parameter SRI falloff function.
|
||||
*/
|
||||
class SRI5 : public Falloff {
|
||||
|
||||
public:
|
||||
SRI5() {}
|
||||
virtual ~SRI5() {}
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
m_b = c[1];
|
||||
m_c = c[2];
|
||||
m_d = c[3];
|
||||
m_e = c[4];
|
||||
}
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
*work = m_a * exp( - m_b / T);
|
||||
if (m_c != 0.0) *work += exp( - T/m_c );
|
||||
work[1] = m_d * pow(T,m_e);
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr = log10( fmaxx(pr,SmallNumber) );
|
||||
doublereal xx = 1.0/(1.0 + lpr*lpr);
|
||||
return pow( *work, xx) * work[1];
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 2; }
|
||||
|
||||
protected:
|
||||
|
||||
doublereal m_a, m_b, m_c;
|
||||
doublereal m_d, m_e;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Wang-Frenklach falloff function. Reference: Wang, H., and
|
||||
* Frenklach, M., Chem. Phys. Lett. vol. 205, 271 (1993).
|
||||
*/
|
||||
class WF93 : public Falloff {
|
||||
|
||||
public:
|
||||
WF93() {}
|
||||
virtual ~WF93() {}
|
||||
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
m_rt1 = 1.0/c[1];
|
||||
m_t2 = c[2];
|
||||
m_rt3 = 1.0/c[3];
|
||||
m_alpha0 = c[4];
|
||||
m_alpha1 = c[5];
|
||||
m_alpha2 = c[6];
|
||||
m_sigma0 = c[7];
|
||||
m_sigma1 = c[8];
|
||||
m_sigma2 = c[9];
|
||||
}
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
work[0] = m_alpha0 + (m_alpha1 + m_alpha2*T)*T; // alpha
|
||||
work[1] = m_sigma0 + (m_sigma1 + m_sigma2*T)*T; // sigma
|
||||
doublereal Fcent = (1.0 - m_a) * exp(- T * m_rt3 )
|
||||
+ m_a * exp(- T * m_rt1 ) + exp(-m_t2/T);
|
||||
work[2] = log10(Fcent);
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr = log10( fmaxx(pr, SmallNumber) );
|
||||
doublereal x = (lpr - work[0])/work[1];
|
||||
doublereal flog = work[2]/exp(x*x);
|
||||
return pow( 10.0, flog);
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 3; }
|
||||
|
||||
protected:
|
||||
|
||||
doublereal m_alpha0, m_alpha1, m_alpha2;
|
||||
doublereal m_sigma0, m_sigma1, m_sigma2;
|
||||
doublereal m_a, m_rt1, m_t2, m_rt3;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
Falloff* FalloffFactory::newFalloff(int type, const vector_fp& c) {
|
||||
Falloff* f;
|
||||
switch(type) {
|
||||
case TROE3_FALLOFF:
|
||||
f = new Troe3(); break;
|
||||
case TROE4_FALLOFF:
|
||||
f = new Troe4(); break;
|
||||
case SRI3_FALLOFF:
|
||||
f = new SRI3(); break;
|
||||
case SRI5_FALLOFF:
|
||||
f = new SRI5(); break;
|
||||
case WF_FALLOFF:
|
||||
f = new WF93(); break;
|
||||
default: return 0;
|
||||
}
|
||||
f->init(c);
|
||||
return f;
|
||||
if (c[1] <= 0.0) {
|
||||
if (c[1] == 0.0) {
|
||||
m_rt3 = 1000.;
|
||||
} else {
|
||||
throw CanteraError("Troe3::init()", "T3 parameter is less than zero");
|
||||
}
|
||||
} else {
|
||||
m_rt3 = 1.0/c[1];
|
||||
}
|
||||
if (c[2] <= 0.0) {
|
||||
if (c[2] == 0.0) {
|
||||
m_rt1 = 1000.;
|
||||
} else {
|
||||
throw CanteraError("Troe3::init()", "T1 parameter is less than zero");
|
||||
}
|
||||
} else {
|
||||
m_rt1 = 1.0/c[2];
|
||||
}
|
||||
}
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
doublereal Fcent = (1.0 - m_a) * exp(- T * m_rt3 )
|
||||
+ m_a * exp(- T * m_rt1 );
|
||||
*work = log10( fmaxx( Fcent, SmallNumber ) );
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr,f1,lgf, cc, nn;
|
||||
lpr = log10( fmaxx(pr,SmallNumber) );
|
||||
cc = -0.4 - 0.67 * (*work);
|
||||
nn = 0.75 - 1.27 * (*work);
|
||||
f1 = ( lpr + cc )/ ( nn - 0.14 * ( lpr + cc ) );
|
||||
lgf = (*work) / ( 1.0 + f1 * f1 );
|
||||
return pow(10.0, lgf );
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 1; }
|
||||
|
||||
protected:
|
||||
|
||||
doublereal m_a, m_rt3, m_rt1;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
//! The 4-parameter Troe falloff parameterization.
|
||||
/*!
|
||||
* This parameterization is defined by
|
||||
*
|
||||
* \f[ F = F_{cent}^{1/(1 + f_1^2)} \f]
|
||||
* where
|
||||
* \f[ F_{cent} = (1 - A)\exp(-T/T_3) + A \exp(-T/T_1) + \exp(-T_2/T) \f]
|
||||
* \f[ f_1 = (\log_{10} P_r + C) / \left(N - 0.14
|
||||
* (\log_{10} P_r + C)\right) \f]
|
||||
* \f[ C = -0.4 - 0.67 \log_{10} F_{cent} \f]
|
||||
* \f[ N = 0.75 - 1.27 \log_{10} F_{cent} \f]
|
||||
*
|
||||
*
|
||||
* There are a few requirements for the parameters
|
||||
*
|
||||
* T_3 is required to greater than or equal to zero. If it is zero,
|
||||
* then the term is set to zero.
|
||||
*
|
||||
* T_1 is required to greater than or equal to zero. If it is zero,
|
||||
* then the term is set to zero.
|
||||
*
|
||||
* T_2 is required to be greater than zero.
|
||||
*
|
||||
* @ingroup falloffGroup
|
||||
*/
|
||||
class Troe4 : public Falloff {
|
||||
public:
|
||||
|
||||
Troe4() : m_a (0.0), m_rt3 (0.0), m_rt1 (0.0),
|
||||
m_t2 (0.0) {}
|
||||
virtual ~Troe4() {}
|
||||
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
if (c[1] <= 0.0) {
|
||||
if (c[1] == 0.0) {
|
||||
m_rt3 = 1000.;
|
||||
} else {
|
||||
throw CanteraError("Troe4::init()", "T3 parameter is less than zero");
|
||||
}
|
||||
} else {
|
||||
m_rt3 = 1.0/c[1];
|
||||
}
|
||||
if (c[2] <= 0.0) {
|
||||
if (c[2] == 0.0) {
|
||||
m_rt1 = 1000.;
|
||||
} else {
|
||||
throw CanteraError("Troe4::init()", "T1 parameter is less than zero");
|
||||
}
|
||||
} else {
|
||||
m_rt1 = 1.0/c[2];
|
||||
}
|
||||
if (c[3] < 0.0) {
|
||||
throw CanteraError("Troe4::init()", "T2 parameter is less than zero");
|
||||
}
|
||||
m_t2 = c[3];
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
doublereal Fcent = (1.0 - m_a) * exp(- T * m_rt3 )
|
||||
+ m_a * exp(- T * m_rt1 )
|
||||
+ exp(- m_t2 / T );
|
||||
*work = log10( fmaxx( Fcent, SmallNumber ) );
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr,f1,lgf, cc, nn;
|
||||
lpr = log10( fmaxx(pr,SmallNumber) );
|
||||
cc = -0.4 - 0.67 * (*work);
|
||||
nn = 0.75 - 1.27 * (*work);
|
||||
f1 = ( lpr + cc )/ ( nn - 0.14 * ( lpr + cc ) );
|
||||
lgf = (*work) / ( 1.0 + f1 * f1 );
|
||||
return pow(10.0, lgf );
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 1; }
|
||||
|
||||
protected:
|
||||
|
||||
doublereal m_a, m_rt3, m_rt1;
|
||||
doublereal m_t2;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
/**
|
||||
* The 3-parameter SRI falloff function.
|
||||
*
|
||||
*
|
||||
* m_c is required to greater than or equal to zero. If it is zero,
|
||||
* then the corresponding term is set to zero.
|
||||
*
|
||||
* @ingroup falloffGroup
|
||||
*/
|
||||
class SRI3 : public Falloff {
|
||||
|
||||
public:
|
||||
|
||||
SRI3() {}
|
||||
virtual ~SRI3() {}
|
||||
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
m_b = c[1];
|
||||
|
||||
m_c = c[2];
|
||||
}
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
*work = m_a * exp( - m_b / T);
|
||||
if (m_c != 0.0) *work += exp( - T/m_c );
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr = log10( fmaxx(pr,SmallNumber) );
|
||||
doublereal xx = 1.0/(1.0 + lpr*lpr);
|
||||
doublereal ff = pow( *work , xx);
|
||||
return ff;
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 1; }
|
||||
|
||||
protected:
|
||||
doublereal m_a, m_b, m_c;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The 5-parameter SRI falloff function.
|
||||
*
|
||||
*
|
||||
* m_c is required to greater than or equal to zero. If it is zero,
|
||||
* then the corresponding term is set to zero.
|
||||
*
|
||||
* m_d is required to be greater than zero.
|
||||
*
|
||||
* @ingroup falloffGroup
|
||||
*/
|
||||
class SRI5 : public Falloff {
|
||||
|
||||
public:
|
||||
SRI5() {}
|
||||
virtual ~SRI5() {}
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
m_b = c[1];
|
||||
m_c = c[2];
|
||||
m_d = c[3];
|
||||
m_e = c[4];
|
||||
}
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
*work = m_a * exp( - m_b / T);
|
||||
if (m_c != 0.0) *work += exp( - T/m_c );
|
||||
work[1] = m_d * pow(T,m_e);
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr = log10( fmaxx(pr,SmallNumber) );
|
||||
doublereal xx = 1.0/(1.0 + lpr*lpr);
|
||||
return pow( *work, xx) * work[1];
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 2; }
|
||||
|
||||
protected:
|
||||
|
||||
doublereal m_a, m_b, m_c;
|
||||
doublereal m_d, m_e;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Wang-Frenklach falloff function. Reference: Wang, H., and
|
||||
* Frenklach, M., Chem. Phys. Lett. vol. 205, 271 (1993).
|
||||
*/
|
||||
class WF93 : public Falloff {
|
||||
|
||||
public:
|
||||
WF93() {}
|
||||
virtual ~WF93() {}
|
||||
|
||||
virtual void init(const vector_fp& c) {
|
||||
m_a = c[0];
|
||||
m_rt1 = 1.0/c[1];
|
||||
m_t2 = c[2];
|
||||
m_rt3 = 1.0/c[3];
|
||||
m_alpha0 = c[4];
|
||||
m_alpha1 = c[5];
|
||||
m_alpha2 = c[6];
|
||||
m_sigma0 = c[7];
|
||||
m_sigma1 = c[8];
|
||||
m_sigma2 = c[9];
|
||||
}
|
||||
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {
|
||||
work[0] = m_alpha0 + (m_alpha1 + m_alpha2*T)*T; // alpha
|
||||
work[1] = m_sigma0 + (m_sigma1 + m_sigma2*T)*T; // sigma
|
||||
doublereal Fcent = (1.0 - m_a) * exp(- T * m_rt3 )
|
||||
+ m_a * exp(- T * m_rt1 ) + exp(-m_t2/T);
|
||||
work[2] = log10(Fcent);
|
||||
}
|
||||
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const {
|
||||
doublereal lpr = log10( fmaxx(pr, SmallNumber) );
|
||||
doublereal x = (lpr - work[0])/work[1];
|
||||
doublereal flog = work[2]/exp(x*x);
|
||||
return pow( 10.0, flog);
|
||||
}
|
||||
|
||||
virtual size_t workSize() { return 3; }
|
||||
|
||||
protected:
|
||||
//! Value of the \f$ \alpha_0 coefficient
|
||||
/*!
|
||||
* This is the fifth coefficient in the xml list
|
||||
*/
|
||||
doublereal m_alpha0;
|
||||
doublereal m_alpha1, m_alpha2;
|
||||
doublereal m_sigma0, m_sigma1, m_sigma2;
|
||||
doublereal m_a, m_rt1, m_t2, m_rt3;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
Falloff* FalloffFactory::newFalloff(int type, const vector_fp& c) {
|
||||
Falloff* f;
|
||||
switch(type) {
|
||||
case TROE3_FALLOFF:
|
||||
f = new Troe3(); break;
|
||||
case TROE4_FALLOFF:
|
||||
f = new Troe4(); break;
|
||||
case SRI3_FALLOFF:
|
||||
f = new SRI3(); break;
|
||||
case SRI5_FALLOFF:
|
||||
f = new SRI5(); break;
|
||||
case WF_FALLOFF:
|
||||
f = new WF93(); break;
|
||||
default: return 0;
|
||||
}
|
||||
f->init(c);
|
||||
return f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
/**
|
||||
* @file FalloffFactory.h
|
||||
*
|
||||
* Parameterizations for reaction falloff functions. Used by classes
|
||||
* that implement gas-phase kinetics (GasKinetics, GRI_30_Kinetics).
|
||||
* that implement gas-phase kinetics (GasKinetics, GRI_30_Kinetics)
|
||||
* (see \ref falloffGroup and class \link Cantera::Falloff Falloff\endlink).
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -28,122 +28,147 @@
|
|||
|
||||
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.
|
||||
*
|
||||
* @ingroup falloffGroup
|
||||
*/
|
||||
class Falloff {
|
||||
public:
|
||||
|
||||
//! Default constructor is empty
|
||||
Falloff(){}
|
||||
|
||||
//! default destructor is empty
|
||||
virtual ~Falloff(){}
|
||||
|
||||
/**
|
||||
* Initialize. Must be called before any other method is
|
||||
* invoked.
|
||||
*
|
||||
* @param c Vector of coefficients of the parameterization.
|
||||
* The number and meaning of these coefficients is
|
||||
* subclass-dependent.
|
||||
*/
|
||||
class Falloff {
|
||||
public:
|
||||
virtual void init(const vector_fp& c) =0;
|
||||
|
||||
Falloff(){}
|
||||
virtual ~Falloff(){}
|
||||
/**
|
||||
* Update the temperature-dependent portions of the falloff
|
||||
* function, if any. This method evaluates temperature-dependent
|
||||
* intermediate results and stores them in the 'work' array.
|
||||
* If not overloaded, the default behavior is to do nothing.
|
||||
* @param T Temperature [K].
|
||||
* @param work storage space for intermediate results.
|
||||
*/
|
||||
virtual void updateTemp(doublereal T, workPtr work) const {}
|
||||
|
||||
/**
|
||||
* Initialize. Must be called before any other method is
|
||||
* invoked.
|
||||
*
|
||||
* @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;
|
||||
/**
|
||||
* The falloff function. This is defined so that the
|
||||
* rate coefficient is
|
||||
*
|
||||
* \f[ k = F(Pr)\frac{Pr}{1 + Pr}. \f]
|
||||
*
|
||||
* Here \f$ Pr \f$ is the reduced pressure, defined by
|
||||
*
|
||||
* \f[
|
||||
* Pr = \frac{k_0 [M]}{k_\infty}.
|
||||
* \f]
|
||||
*
|
||||
* @param pr reduced pressure (dimensionless).
|
||||
* @param work array of size workSize() containing cached
|
||||
* temperature-dependent intermediate results from a prior call
|
||||
* to updateTemp.
|
||||
*
|
||||
* @return Returns the value of the falloff function \f$ F \f$ defined above
|
||||
*/
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const =0;
|
||||
|
||||
/**
|
||||
* Update the temperature-dependent portions of the falloff
|
||||
* function, if any. This method evaluates temperature-dependent
|
||||
* intermediate results and stores them in the 'work' array.
|
||||
* If not overloaded, the default behavior is to do nothing.
|
||||
* @param T Temperature [K].
|
||||
* @param work storage space for intermediate results.
|
||||
*/
|
||||
virtual void updateTemp (doublereal T, workPtr work) const {}
|
||||
/**
|
||||
* The size of the work array required.
|
||||
*/
|
||||
virtual size_t workSize() =0;
|
||||
|
||||
/**
|
||||
* The falloff function. This is defined so that the
|
||||
* rate coefficient is
|
||||
* \f[ k = F(Pr)\frac{Pr}{1 + Pr}. \f]
|
||||
* Here \f$ Pr \f$ is the reduced pressure, defined by
|
||||
* \f[
|
||||
* Pr = \frac{k_0 [M]}{k_\infty}.
|
||||
* \f]
|
||||
* @param pr reduced pressure (dimensionless).
|
||||
* @param work array of size workSize() containing cached
|
||||
* temperature-dependent intermediate results from a prior call
|
||||
* to updateTemp.
|
||||
*/
|
||||
virtual doublereal F(doublereal pr, const_workPtr work) const =0;
|
||||
|
||||
/**
|
||||
* The size of the work array required.
|
||||
*/
|
||||
virtual size_t workSize() =0;
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Factory class to construct falloff function calculators.
|
||||
* The falloff factory is accessed through static method factory:
|
||||
*
|
||||
* @code
|
||||
* Falloff* f = FalloffFactory::factory()->newFalloff(type, c)
|
||||
* @endcode
|
||||
*
|
||||
* @ingroup falloffGroup
|
||||
*/
|
||||
class FalloffFactory : public FactoryBase {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Factory class to construct falloff function calculators.
|
||||
* The falloff factory is accessed through static method factory:
|
||||
* @code
|
||||
* Falloff* f = FalloffFactory::factory()->newFalloff(type, c)
|
||||
* @endcode
|
||||
* @ingroup falloffGroup
|
||||
*/
|
||||
class FalloffFactory : public FactoryBase {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Return a pointer to the factory. On the first call, a new
|
||||
* instance is created. Since there is no need to instantiate
|
||||
* more than one factory, on all subsequent calls, a pointer
|
||||
* to the existing factory is returned.
|
||||
*/
|
||||
static FalloffFactory* factory() {
|
||||
#if defined(THREAD_SAFE_CANTERA)
|
||||
boost::mutex::scoped_lock lock(falloff_mutex) ;
|
||||
#endif
|
||||
if (!s_factory) s_factory = new FalloffFactory;
|
||||
return s_factory;
|
||||
}
|
||||
|
||||
virtual void deleteFactory() {
|
||||
#if defined(THREAD_SAFE_CANTERA)
|
||||
boost::mutex::scoped_lock lock(falloff_mutex) ;
|
||||
#endif
|
||||
if (s_factory) {
|
||||
delete s_factory;
|
||||
s_factory = 0;
|
||||
}
|
||||
* Return a pointer to the factory. On the first call, a new
|
||||
* instance is created. Since there is no need to instantiate
|
||||
* more than one factory, on all subsequent calls, a pointer
|
||||
* to the existing factory is returned.
|
||||
*/
|
||||
static FalloffFactory* factory() {
|
||||
#if defined(THREAD_SAFE_CANTERA)
|
||||
boost::mutex::scoped_lock lock(falloff_mutex) ;
|
||||
#endif
|
||||
if (!s_factory) s_factory = new FalloffFactory;
|
||||
return s_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor doesn't do anything. We do not delete statically
|
||||
virtual void deleteFactory() {
|
||||
#if defined(THREAD_SAFE_CANTERA)
|
||||
boost::mutex::scoped_lock lock(falloff_mutex) ;
|
||||
#endif
|
||||
if (s_factory) {
|
||||
delete s_factory;
|
||||
s_factory = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor doesn't do anything. We do not delete statically
|
||||
* created single instance of this class here, because it would
|
||||
* create an infinite loop if destructor is called for that
|
||||
* single instance. Instead, to delete single instance, we
|
||||
* call delete[] from FalloffMng's destructor.
|
||||
*/
|
||||
virtual ~FalloffFactory() {
|
||||
}
|
||||
*/
|
||||
virtual ~FalloffFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a pointer to a new falloff function calculator.
|
||||
* @param type Integer flag specifying the type of falloff function.
|
||||
* The standard types are defined in file reaction_defs.h. A factory
|
||||
* class derived from FalloffFactory may define other types as well.
|
||||
*/
|
||||
virtual Falloff* newFalloff(int type, const vector_fp& c);
|
||||
|
||||
//! Return a pointer to a new falloff function calculator.
|
||||
/*!
|
||||
*
|
||||
* @param type Integer flag specifying the type of falloff function.
|
||||
* The standard types are defined in file reaction_defs.h. A factory
|
||||
* class derived from FalloffFactory may define other types as well.
|
||||
*
|
||||
* @param c input vector of doubles which populates the falloff
|
||||
* parameterization.
|
||||
*
|
||||
* @return Returns a pointer to a new Falloff class.
|
||||
*/
|
||||
virtual Falloff* newFalloff(int type, const vector_fp& c);
|
||||
|
||||
private:
|
||||
static FalloffFactory* s_factory;
|
||||
FalloffFactory(){}
|
||||
#if defined(THREAD_SAFE_CANTERA)
|
||||
static boost::mutex falloff_mutex ;
|
||||
#endif
|
||||
};
|
||||
private:
|
||||
//! Pointer to the single instance of the factory
|
||||
static FalloffFactory* s_factory;
|
||||
|
||||
//! default constructor, which is defined as private
|
||||
FalloffFactory(){}
|
||||
|
||||
#if defined(THREAD_SAFE_CANTERA)
|
||||
//! Mutex for use when calling the factory
|
||||
static boost::mutex falloff_mutex ;
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -424,28 +424,72 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get falloff parameters for a reaction.
|
||||
*/
|
||||
static void getFalloff(const node_t& f, ReactionData& rdata) {
|
||||
string type = f["type"];
|
||||
vector<string> p;
|
||||
getStringArray(f,p);
|
||||
vector_fp c;
|
||||
int np = static_cast<int>(p.size());
|
||||
for (int n = 0; n < np; n++) {
|
||||
c.push_back(fpValue(p[n]));
|
||||
}
|
||||
if (type == "Troe") {
|
||||
if (np == 4) rdata.falloffType = TROE4_FALLOFF;
|
||||
else rdata.falloffType = TROE3_FALLOFF;
|
||||
}
|
||||
else if (type == "SRI") {
|
||||
if (np == 5) rdata.falloffType = SRI5_FALLOFF;
|
||||
else rdata.falloffType = SRI3_FALLOFF;
|
||||
}
|
||||
rdata.falloffParameters = c;
|
||||
|
||||
//! Get falloff parameters for a reaction.
|
||||
/*!
|
||||
* This routine reads the falloff XML node and extracts parameters into a
|
||||
* vector of doubles
|
||||
*
|
||||
*
|
||||
* @verbatim
|
||||
<falloff type="Troe"> 0.5 73.2 5000. 9999. </falloff>
|
||||
@endverbatim
|
||||
*/
|
||||
static void getFalloff(const node_t& f, ReactionData& rdata) {
|
||||
string type = f["type"];
|
||||
vector<string> p;
|
||||
getStringArray(f,p);
|
||||
vector_fp c;
|
||||
int np = static_cast<int>(p.size());
|
||||
for (int n = 0; n < np; n++) {
|
||||
c.push_back(fpValue(p[n]));
|
||||
}
|
||||
if (type == "Troe") {
|
||||
if (np == 4) {
|
||||
rdata.falloffType = TROE4_FALLOFF;
|
||||
if (c[1] < 0.0) {
|
||||
throw CanteraError("getFalloff()", "Troe4 T3 parameter is less than zero: " + fp2str(c[1]));
|
||||
}
|
||||
if (c[2] < 0.0) {
|
||||
throw CanteraError("getFalloff()", "Troe4 T1 parameter is less than zero: " + fp2str(c[2]));
|
||||
}
|
||||
if (c[3] < 0.0) {
|
||||
throw CanteraError("getFalloff()", "Troe4 T2 parameter is less than zero: " + fp2str(c[3]));
|
||||
}
|
||||
} else if (np == 3) {
|
||||
rdata.falloffType = TROE3_FALLOFF;
|
||||
if (c[1] < 0.0) {
|
||||
throw CanteraError("getFalloff()", "Troe3 T3 parameter is less than zero: " + fp2str(c[1]));
|
||||
}
|
||||
if (c[2] < 0.0) {
|
||||
throw CanteraError("getFalloff()", "Troe3 T1 parameter is less than zero: " + fp2str(c[2]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw CanteraError("getFalloff()", "Troe parameterization is specified by number of pararameters, "
|
||||
+ int2str(np) + ", is not equal to 3 or 4");
|
||||
}
|
||||
} else if (type == "SRI") {
|
||||
if (np == 5) {
|
||||
rdata.falloffType = SRI5_FALLOFF;
|
||||
if (c[2] < 0.0) {
|
||||
throw CanteraError("getFalloff()", "SRI5 m_c parameter is less than zero: " + fp2str(c[2]));
|
||||
}
|
||||
if (c[3] < 0.0) {
|
||||
throw CanteraError("getFalloff()", "SRI5 m_d parameter is less than zero: " + fp2str(c[3]));
|
||||
}
|
||||
} else if (np == 3) {
|
||||
rdata.falloffType = SRI3_FALLOFF;
|
||||
if (c[2] < 0.0) {
|
||||
throw CanteraError("getFalloff()", "SRI3 m_c parameter is less than zero: " + fp2str(c[2]));
|
||||
}
|
||||
} else {
|
||||
throw CanteraError("getFalloff()", "SRI parameterization is specified by number of pararameters, "
|
||||
+ int2str(np) + ", is not equal to 3 or 5");
|
||||
}
|
||||
}
|
||||
rdata.falloffParameters = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enhanced collision efficiencies. It is assumed that the
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue