mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
Implemented fixes, so that a python demo problem would work as advertised.
This commit is contained in:
@@ -6,11 +6,123 @@ using namespace std;
|
|||||||
|
|
||||||
namespace Cantera {
|
namespace Cantera {
|
||||||
|
|
||||||
static Func1* checkDupl(Func1& f) {
|
|
||||||
if (f.parent() != 0)
|
Func1::Func1() :
|
||||||
return &f.duplicate();
|
m_c(0.0),
|
||||||
else
|
m_f1(0),
|
||||||
return &f;
|
m_f2(0),
|
||||||
|
m_parent(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Func1::Func1(const Func1 &right) :
|
||||||
|
m_c(right.m_c),
|
||||||
|
m_f1(right.m_f1),
|
||||||
|
m_f2(right.m_f2),
|
||||||
|
m_parent(right.m_parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Func1::~Func1() {
|
||||||
|
}
|
||||||
|
|
||||||
|
Func1& Func1::operator=(const Func1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
m_c = right.m_c;
|
||||||
|
m_f1 = right.m_f1;
|
||||||
|
m_f2 = right.m_f2;
|
||||||
|
m_parent = right.m_parent;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Func1& Func1::duplicate() const {
|
||||||
|
Func1 *nfunc = new Func1(*this);
|
||||||
|
return *nfunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Func1::ID() const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calls method eval to evaluate the function
|
||||||
|
doublereal Func1::operator()(doublereal t) const {
|
||||||
|
return eval(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Evaluate the function.
|
||||||
|
doublereal Func1::eval(doublereal t) const {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Func1& Func1::derivative() const {
|
||||||
|
cout << "derivative error... ERR: ID = " << ID() << endl;
|
||||||
|
cout << write("x") << endl;
|
||||||
|
return *(new Func1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Func1::isIdentical(Func1& other) const {
|
||||||
|
if ((ID() != other.ID()) || (m_c != other.m_c))
|
||||||
|
return false;
|
||||||
|
if (m_f1) {
|
||||||
|
if (!other.m_f1) return false;
|
||||||
|
if (!m_f1->isIdentical(*other.m_f1)) return false;
|
||||||
|
}
|
||||||
|
if (m_f2) {
|
||||||
|
if (!other.m_f2) return false;
|
||||||
|
if (!m_f2->isIdentical(*other.m_f2)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! accessor function for the returned constant
|
||||||
|
doublereal Func1::c() const {
|
||||||
|
return m_c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to set the storred constant
|
||||||
|
void Func1::setC(doublereal c) {
|
||||||
|
m_c = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! accessor function for m_f1
|
||||||
|
Func1& Func1::func1() const {
|
||||||
|
return *m_f1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Func1& Func1::func2() const {
|
||||||
|
return *m_f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Func1::order() const {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Func1& Func1::func1_dup() const {
|
||||||
|
return m_f1->duplicate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Func1& Func1::func2_dup() const {
|
||||||
|
return m_f2->duplicate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Func1* Func1::parent() const {
|
||||||
|
return m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Func1::setParent(Func1* p) {
|
||||||
|
m_parent = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
string Sin1::write(string arg) const {
|
||||||
|
string c = "";
|
||||||
|
if (m_c != 1.0) c = fp2str(m_c);
|
||||||
|
return "\\sin(" + c + arg + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
Func1& Sin1::derivative() const {
|
Func1& Sin1::derivative() const {
|
||||||
@@ -23,6 +135,7 @@ namespace Cantera {
|
|||||||
#endif
|
#endif
|
||||||
return *r;
|
return *r;
|
||||||
}
|
}
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
Func1& Cos1::derivative() const {
|
Func1& Cos1::derivative() const {
|
||||||
Func1* s = new Sin1(m_c);
|
Func1* s = new Sin1(m_c);
|
||||||
@@ -35,6 +148,14 @@ namespace Cantera {
|
|||||||
return *r;
|
return *r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Cos1::write(std::string arg) const {
|
||||||
|
string c = "";
|
||||||
|
if (m_c != 1.0) c = fp2str(m_c);
|
||||||
|
return "\\cos("+c+arg+")";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
Func1& Exp1::derivative() const {
|
Func1& Exp1::derivative() const {
|
||||||
Func1* f = new Exp1(m_c);
|
Func1* f = new Exp1(m_c);
|
||||||
if (m_c != 1.0)
|
if (m_c != 1.0)
|
||||||
@@ -43,6 +164,14 @@ namespace Cantera {
|
|||||||
return *f;
|
return *f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Exp1::write(std::string arg) const {
|
||||||
|
string c = "";
|
||||||
|
if (m_c != 1.0) c = fp2str(m_c);
|
||||||
|
return "\\exp("+c+arg+")";
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
Func1& Pow1::derivative() const {
|
Func1& Pow1::derivative() const {
|
||||||
Func1* r;
|
Func1* r;
|
||||||
if (m_c == 0.0) {
|
if (m_c == 0.0) {
|
||||||
@@ -67,17 +196,8 @@ namespace Cantera {
|
|||||||
return "<unknown " + int2str(ID()) + ">("+arg+")";
|
return "<unknown " + int2str(ID()) + ">("+arg+")";
|
||||||
}
|
}
|
||||||
|
|
||||||
string Sin1::write(string arg) const {
|
|
||||||
string c = "";
|
|
||||||
if (m_c != 1.0) c = fp2str(m_c);
|
|
||||||
return "\\sin("+c+arg+")";
|
|
||||||
}
|
|
||||||
|
|
||||||
string Cos1::write(string arg) const {
|
|
||||||
string c = "";
|
|
||||||
if (m_c != 1.0) c = fp2str(m_c);
|
|
||||||
return "\\cos("+c+arg+")";
|
|
||||||
}
|
|
||||||
|
|
||||||
string Pow1::write(string arg) const {
|
string Pow1::write(string arg) const {
|
||||||
//cout << "Pow1" << endl;
|
//cout << "Pow1" << endl;
|
||||||
@@ -97,11 +217,6 @@ namespace Cantera {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string Exp1::write(string arg) const {
|
|
||||||
string c = "";
|
|
||||||
if (m_c != 1.0) c = fp2str(m_c);
|
|
||||||
return "\\exp("+c+arg+")";
|
|
||||||
}
|
|
||||||
|
|
||||||
string Const1::write(string arg) const {
|
string Const1::write(string arg) const {
|
||||||
//cout << "Const1" << endl;
|
//cout << "Const1" << endl;
|
||||||
|
|||||||
@@ -57,60 +57,83 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Func1 {
|
class Func1 {
|
||||||
public:
|
public:
|
||||||
Func1() : m_c(0.0), m_f1(0), m_f2(0), m_parent(0) {}
|
Func1();
|
||||||
virtual ~Func1() {}
|
|
||||||
virtual int ID() const { return 0; }
|
|
||||||
|
|
||||||
virtual Func1& duplicate() { cout << "DUPL ERR: ID = " << ID() << endl;
|
virtual ~Func1();
|
||||||
return *(new Func1);}
|
|
||||||
|
|
||||||
/// Calls method eval to evaluate the function
|
|
||||||
doublereal operator()(doublereal t) const { return eval(t); }
|
Func1(const Func1 &right);
|
||||||
|
|
||||||
|
Func1& operator=(const Func1 &right);
|
||||||
|
|
||||||
|
//! Duplicate the current function.
|
||||||
|
/*!
|
||||||
|
* This duplicates the current function, returning a
|
||||||
|
* reference to the new malloced function.
|
||||||
|
*/
|
||||||
|
virtual Func1& duplicate() const;
|
||||||
|
|
||||||
|
virtual int ID() const;
|
||||||
|
|
||||||
|
//! Calls method eval to evaluate the function
|
||||||
|
doublereal operator()(doublereal t) const;
|
||||||
|
|
||||||
/// Evaluate the function.
|
/// Evaluate the function.
|
||||||
virtual doublereal eval(doublereal t) const { return 0.0; }
|
virtual doublereal eval(doublereal t) const;
|
||||||
|
|
||||||
virtual Func1& derivative() const {
|
//! Creates a derivative to the current function
|
||||||
cout << "derivative error... ERR: ID = " << ID() << endl;
|
/*!
|
||||||
cout << write("x") << endl;
|
* This will malloc a derivative function and
|
||||||
return *(new Func1);
|
* return a reference to the function.
|
||||||
}
|
*/
|
||||||
|
virtual Func1& derivative() const;
|
||||||
|
|
||||||
bool isIdentical(Func1& other) const {
|
//! Routine to determine if two functions are the same.
|
||||||
if ((ID() != other.ID()) || (m_c != other.m_c))
|
/*!
|
||||||
return false;
|
* Two functions are the same if they are teh same function.
|
||||||
if (m_f1) {
|
* This means that the ID and storred constant is the same.
|
||||||
if (!other.m_f1) return false;
|
* This means that the m_f1 and m_f2 are identical if they
|
||||||
if (!m_f1->isIdentical(*other.m_f1)) return false;
|
* are non-null.
|
||||||
}
|
*/
|
||||||
if (m_f2) {
|
bool isIdentical(Func1& other) const;
|
||||||
if (!other.m_f2) return false;
|
|
||||||
if (!m_f2->isIdentical(*other.m_f2)) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual doublereal isProportional(TimesConstant1& other);
|
virtual doublereal isProportional(TimesConstant1& other);
|
||||||
virtual doublereal isProportional(Func1& other);
|
virtual doublereal isProportional(Func1& other);
|
||||||
|
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
|
|
||||||
doublereal c() const { return m_c; }
|
|
||||||
void setC(doublereal c) { m_c = c; }
|
//! accessor function for the storred constant
|
||||||
Func1& func1() { return *m_f1; }
|
doublereal c() const;
|
||||||
Func1& func2() { return *m_f2; }
|
|
||||||
virtual int order() const { return 3; }
|
//! Function to set the storred constant
|
||||||
Func1& func1_dup() const { return m_f1->duplicate(); }
|
void setC(doublereal c);
|
||||||
Func1& func2_dup() const { return m_f2->duplicate(); }
|
|
||||||
Func1* parent() { return m_parent; }
|
//! accessor function for m_f1
|
||||||
void setParent(Func1* p) { m_parent = p; }
|
Func1& func1() const;
|
||||||
|
|
||||||
|
//! accessor function for m_f2
|
||||||
|
Func1& func2() const;
|
||||||
|
|
||||||
|
//! Return the order of the function, if it makes sense
|
||||||
|
virtual int order() const;
|
||||||
|
|
||||||
|
|
||||||
|
Func1& func1_dup() const;
|
||||||
|
|
||||||
|
|
||||||
|
Func1& func2_dup() const;
|
||||||
|
|
||||||
|
Func1* parent() const;
|
||||||
|
|
||||||
|
|
||||||
|
void setParent(Func1* p);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
doublereal m_c;
|
doublereal m_c;
|
||||||
Func1 *m_f1, *m_f2;
|
Func1 *m_f1;
|
||||||
Func1* m_parent;
|
Func1 *m_f2;
|
||||||
|
Func1 *m_parent;
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -122,34 +145,73 @@ namespace Cantera {
|
|||||||
Func1& newTimesConstFunction(Func1& f1, doublereal c);
|
Func1& newTimesConstFunction(Func1& f1, doublereal c);
|
||||||
Func1& newPlusConstFunction(Func1& f1, doublereal c);
|
Func1& newPlusConstFunction(Func1& f1, doublereal c);
|
||||||
|
|
||||||
/// sin
|
//! implements the sin() function
|
||||||
|
/*!
|
||||||
|
* The argument to sin() is in radians
|
||||||
|
*/
|
||||||
class Sin1 : public Func1 {
|
class Sin1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Sin1(doublereal omega = 1.0) {
|
|
||||||
|
Sin1(doublereal omega = 1.0) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_c = omega;
|
m_c = omega;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Sin1() {}
|
virtual ~Sin1() {}
|
||||||
|
|
||||||
|
Sin1(const Sin1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Sin1& operator=(const Sin1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
|
Sin1 *nfunc = new Sin1(*this);
|
||||||
|
return (Func1&) *nfunc;
|
||||||
|
}
|
||||||
|
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
virtual Func1& duplicate() { return *(new Sin1(m_c)); }
|
|
||||||
virtual int ID() const { return SinFuncType; }
|
virtual int ID() const { return SinFuncType; }
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return sin(m_c*t);
|
return sin(m_c*t);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Func1& derivative() const;
|
virtual Func1& derivative() const;
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// cos
|
/// cos
|
||||||
class Cos1 : public Func1 {
|
class Cos1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Cos1(doublereal omega = 1.0) {
|
Cos1(doublereal omega = 1.0) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_c = omega;
|
m_c = omega;
|
||||||
}
|
}
|
||||||
virtual ~Cos1() {}
|
virtual ~Cos1() {}
|
||||||
|
Cos1(const Cos1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Cos1& operator=(const Cos1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
|
Cos1 *nfunc = new Cos1(*this);
|
||||||
|
return (Func1&) *nfunc;
|
||||||
|
}
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
virtual Func1& duplicate() { return *(new Cos1(m_c)); }
|
|
||||||
virtual int ID() const { return CosFuncType; }
|
virtual int ID() const { return CosFuncType; }
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return cos(m_c * t);
|
return cos(m_c * t);
|
||||||
@@ -162,11 +224,25 @@ namespace Cantera {
|
|||||||
/// exp
|
/// exp
|
||||||
class Exp1 : public Func1 {
|
class Exp1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Exp1(doublereal A = 1.0) {m_c = A;}
|
Exp1(doublereal A = 1.0) :
|
||||||
virtual ~Exp1() {}
|
Func1()
|
||||||
|
{
|
||||||
|
m_c = A;
|
||||||
|
}
|
||||||
|
virtual ~Exp1() {
|
||||||
|
}
|
||||||
|
Exp1(const Exp1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Exp1& operator=(const Exp1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
virtual int ID() const { return ExpFuncType; }
|
virtual int ID() const { return ExpFuncType; }
|
||||||
virtual Func1& duplicate() { return *(new Exp1(m_c)); }
|
virtual Func1& duplicate() const { return *(new Exp1(m_c)); }
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return exp(m_c*t);
|
return exp(m_c*t);
|
||||||
}
|
}
|
||||||
@@ -180,11 +256,24 @@ namespace Cantera {
|
|||||||
/// pow
|
/// pow
|
||||||
class Pow1 : public Func1 {
|
class Pow1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Pow1(doublereal n) {m_c = n;}
|
Pow1(doublereal n) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
|
m_c = n;
|
||||||
|
}
|
||||||
virtual ~Pow1() {}
|
virtual ~Pow1() {}
|
||||||
|
Pow1(const Pow1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Pow1& operator=(const Pow1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
virtual int ID() const { return PowFuncType; }
|
virtual int ID() const { return PowFuncType; }
|
||||||
virtual Func1& duplicate() { return *(new Pow1(m_c)); }
|
virtual Func1& duplicate() const { return *(new Pow1(m_c)); }
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return pow(t, m_c);
|
return pow(t, m_c);
|
||||||
}
|
}
|
||||||
@@ -199,22 +288,36 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Const1 : public Func1 {
|
class Const1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Const1(doublereal A) {
|
Const1(doublereal A) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_c = A;
|
m_c = A;
|
||||||
}
|
}
|
||||||
virtual ~Const1() {}
|
virtual ~Const1() {
|
||||||
|
}
|
||||||
|
|
||||||
|
Const1(const Const1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Const1& operator=(const Const1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
virtual int ID() const { return ConstFuncType; }
|
virtual int ID() const { return ConstFuncType; }
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return m_c;
|
return m_c;
|
||||||
}
|
}
|
||||||
virtual Func1& duplicate() { return *(new Const1(m_c)); }
|
virtual Func1& duplicate() const { return *(new Const1(m_c)); }
|
||||||
|
|
||||||
virtual Func1& derivative() const {
|
virtual Func1& derivative() const {
|
||||||
Func1* z = new Const1(0.0);
|
Func1* z = new Const1(0.0);
|
||||||
return *z;
|
return *z;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -224,26 +327,52 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Sum1 : public Func1 {
|
class Sum1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Sum1(Func1& f1, Func1& f2) {
|
Sum1(Func1& f1, Func1& f2) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_f1 = &f1;
|
m_f1 = &f1;
|
||||||
m_f2 = &f2;
|
m_f2 = &f2;
|
||||||
m_f1->setParent(this);
|
m_f1->setParent(this);
|
||||||
m_f2->setParent(this);
|
m_f2->setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Sum1() {
|
virtual ~Sum1() {
|
||||||
delete m_f1;
|
delete m_f1;
|
||||||
delete m_f2;
|
delete m_f2;
|
||||||
}
|
}
|
||||||
virtual int ID() const { return SumFuncType; }
|
|
||||||
|
Sum1(const Sum1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = Sum1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Sum1& operator=(const Sum1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_f1 = &(m_f1->duplicate());
|
||||||
|
m_f2 = &(m_f2->duplicate());
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_f2->setParent(this);
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int ID() const {
|
||||||
|
return SumFuncType;
|
||||||
|
}
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return m_f1->eval(t) + m_f2->eval(t);
|
return m_f1->eval(t) + m_f2->eval(t);
|
||||||
}
|
}
|
||||||
virtual Func1& duplicate() {
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
Func1& f1d = m_f1->duplicate();
|
Func1& f1d = m_f1->duplicate();
|
||||||
Func1& f2d = m_f2->duplicate();
|
Func1& f2d = m_f2->duplicate();
|
||||||
Func1& dup = newSumFunction(f1d, f2d);
|
Func1& dup = newSumFunction(f1d, f2d);
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Func1& derivative() const {
|
virtual Func1& derivative() const {
|
||||||
Func1& d1 = m_f1->derivative();
|
Func1& d1 = m_f1->derivative();
|
||||||
Func1& d2 = m_f2->derivative();
|
Func1& d2 = m_f2->derivative();
|
||||||
@@ -251,8 +380,8 @@ namespace Cantera {
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
virtual int order() const { return 0; }
|
virtual int order() const { return 0; }
|
||||||
|
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
protected:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -264,16 +393,41 @@ namespace Cantera {
|
|||||||
Diff1(Func1& f1, Func1& f2) {
|
Diff1(Func1& f1, Func1& f2) {
|
||||||
m_f1 = &f1;
|
m_f1 = &f1;
|
||||||
m_f2 = &f2;
|
m_f2 = &f2;
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_f2->setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Diff1() {
|
virtual ~Diff1() {
|
||||||
delete m_f1;
|
delete m_f1;
|
||||||
delete m_f2;
|
delete m_f2;
|
||||||
}
|
}
|
||||||
virtual int ID() const { return DiffFuncType; }
|
|
||||||
|
Diff1(const Diff1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = Diff1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Diff1& operator=(const Diff1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_f1 = &(m_f1->duplicate());
|
||||||
|
m_f2 = &(m_f2->duplicate());
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_f2->setParent(this);
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int ID() const {
|
||||||
|
return DiffFuncType;
|
||||||
|
}
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return m_f1->eval(t) - m_f2->eval(t);
|
return m_f1->eval(t) - m_f2->eval(t);
|
||||||
}
|
}
|
||||||
virtual Func1& duplicate() {
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
Func1& f1d = m_f1->duplicate();
|
Func1& f1d = m_f1->duplicate();
|
||||||
Func1& f2d = m_f2->duplicate();
|
Func1& f2d = m_f2->duplicate();
|
||||||
Func1& dup = newDiffFunction(f1d, f2d);
|
Func1& dup = newDiffFunction(f1d, f2d);
|
||||||
@@ -284,9 +438,9 @@ namespace Cantera {
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
virtual int order() const { return 0; }
|
virtual int order() const { return 0; }
|
||||||
|
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
|
|
||||||
protected:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -295,26 +449,54 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Product1 : public Func1 {
|
class Product1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Product1(Func1& f1, Func1& f2) {
|
Product1(Func1& f1, Func1& f2) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_f1 = &f1;
|
m_f1 = &f1;
|
||||||
m_f2 = &f2;
|
m_f2 = &f2;
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_f2->setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Product1() {
|
virtual ~Product1() {
|
||||||
delete m_f1;
|
delete m_f1;
|
||||||
delete m_f2;
|
delete m_f2;
|
||||||
}
|
}
|
||||||
virtual int ID() const { return ProdFuncType; }
|
|
||||||
virtual Func1& duplicate() {
|
Product1(const Product1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = Product1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Product1& operator=(const Product1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_f1 = &(m_f1->duplicate());
|
||||||
|
m_f2 = &(m_f2->duplicate());
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_f2->setParent(this);
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int ID() const {
|
||||||
|
return ProdFuncType;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
Func1& f1d = m_f1->duplicate();
|
Func1& f1d = m_f1->duplicate();
|
||||||
Func1& f2d = m_f2->duplicate();
|
Func1& f2d = m_f2->duplicate();
|
||||||
Func1& dup = newProdFunction(f1d, f2d);
|
Func1& dup = newProdFunction(f1d, f2d);
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return m_f1->eval(t) * m_f2->eval(t);
|
return m_f1->eval(t) * m_f2->eval(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Func1& derivative() const {
|
virtual Func1& derivative() const {
|
||||||
Func1& a1 = newProdFunction(m_f1->duplicate(), m_f2->derivative());
|
Func1& a1 = newProdFunction(m_f1->duplicate(), m_f2->derivative());
|
||||||
Func1& a2 = newProdFunction(m_f2->duplicate(), m_f1->derivative());
|
Func1& a2 = newProdFunction(m_f2->duplicate(), m_f1->derivative());
|
||||||
@@ -331,39 +513,64 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class TimesConstant1 : public Func1 {
|
class TimesConstant1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
TimesConstant1(Func1& f1, doublereal A) {
|
TimesConstant1(Func1& f1, doublereal A) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_f1 = &f1;
|
m_f1 = &f1;
|
||||||
m_c = A;
|
m_c = A;
|
||||||
|
m_f1->setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~TimesConstant1() {
|
virtual ~TimesConstant1() {
|
||||||
delete m_f1;
|
delete m_f1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TimesConstant1(const TimesConstant1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = TimesConstant1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
TimesConstant1& operator=(const TimesConstant1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_f1 = &(m_f1->duplicate());
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
virtual int ID() const { return TimesConstantFuncType; }
|
virtual int ID() const { return TimesConstantFuncType; }
|
||||||
virtual Func1& duplicate() {
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
Func1& f1 = m_f1->duplicate();
|
Func1& f1 = m_f1->duplicate();
|
||||||
Func1* dup = new TimesConstant1(f1, m_c);
|
Func1* dup = new TimesConstant1(f1, m_c);
|
||||||
return *dup;
|
return *dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual doublereal isProportional(TimesConstant1& other) {
|
virtual doublereal isProportional(TimesConstant1& other) {
|
||||||
if (func1().isIdentical(other.func1()))
|
if (func1().isIdentical(other.func1()))
|
||||||
return (other.c()/c());
|
return (other.c()/c());
|
||||||
else
|
else
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual doublereal isProportional(Func1& other) {
|
virtual doublereal isProportional(Func1& other) {
|
||||||
if (func1().isIdentical(other)) return 1.0/c();
|
if (func1().isIdentical(other)) return 1.0/c();
|
||||||
else return 0.0;
|
else return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return m_f1->eval(t) * m_c;
|
return m_f1->eval(t) * m_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Func1& derivative() const {
|
virtual Func1& derivative() const {
|
||||||
Func1& f1d = m_f1->derivative();
|
Func1& f1d = m_f1->derivative();
|
||||||
Func1* d = &newTimesConstFunction(f1d, m_c);
|
Func1* d = &newTimesConstFunction(f1d, m_c);
|
||||||
return *d;
|
return *d;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
|
|
||||||
virtual int order() const { return 0; }
|
virtual int order() const { return 0; }
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
@@ -373,16 +580,36 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class PlusConstant1 : public Func1 {
|
class PlusConstant1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
PlusConstant1(Func1& f1, doublereal A) {
|
PlusConstant1(Func1& f1, doublereal A) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_f1 = &f1;
|
m_f1 = &f1;
|
||||||
m_c = A;
|
m_c = A;
|
||||||
|
m_f1->setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~PlusConstant1() {
|
virtual ~PlusConstant1() {
|
||||||
delete m_f1;
|
delete m_f1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlusConstant1(const PlusConstant1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = PlusConstant1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlusConstant1& operator=(const PlusConstant1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_f1 = &(m_f1->duplicate());
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
virtual int ID() const { return PlusConstantFuncType; }
|
virtual int ID() const { return PlusConstantFuncType; }
|
||||||
virtual Func1& duplicate() {
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
Func1& f1 = m_f1->duplicate();
|
Func1& f1 = m_f1->duplicate();
|
||||||
Func1* dup = new PlusConstant1(f1, m_c);
|
Func1* dup = new PlusConstant1(f1, m_c);
|
||||||
return *dup;
|
return *dup;
|
||||||
@@ -396,6 +623,7 @@ namespace Cantera {
|
|||||||
return f1d;
|
return f1d;
|
||||||
}
|
}
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
|
|
||||||
virtual int order() const { return 0; }
|
virtual int order() const { return 0; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -407,24 +635,50 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Ratio1 : public Func1 {
|
class Ratio1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Ratio1(Func1& f1, Func1& f2) {
|
Ratio1(Func1& f1, Func1& f2) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_f1 = &f1;
|
m_f1 = &f1;
|
||||||
m_f2 = &f2;
|
m_f2 = &f2;
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_f2->setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Ratio1() {
|
virtual ~Ratio1() {
|
||||||
delete m_f1;
|
delete m_f1;
|
||||||
delete m_f2;
|
delete m_f2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ratio1(const Ratio1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = Ratio1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ratio1& operator=(const Ratio1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_f1 = &(m_f1->duplicate());
|
||||||
|
m_f2 = &(m_f2->duplicate());
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_f2->setParent(this);
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
virtual int ID() const { return RatioFuncType; }
|
virtual int ID() const { return RatioFuncType; }
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return m_f1->eval(t) / m_f2->eval(t);
|
return m_f1->eval(t) / m_f2->eval(t);
|
||||||
}
|
}
|
||||||
virtual Func1& duplicate() {
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
Func1& f1d = m_f1->duplicate();
|
Func1& f1d = m_f1->duplicate();
|
||||||
Func1& f2d = m_f2->duplicate();
|
Func1& f2d = m_f2->duplicate();
|
||||||
Func1& dup = newRatioFunction(f1d, f2d);
|
Func1& dup = newRatioFunction(f1d, f2d);
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Func1& derivative() const {
|
virtual Func1& derivative() const {
|
||||||
Func1& a1 = newProdFunction(m_f1->derivative(), m_f2->duplicate());
|
Func1& a1 = newProdFunction(m_f1->derivative(), m_f2->duplicate());
|
||||||
Func1& a2 = newProdFunction(m_f1->duplicate(), m_f2->derivative());
|
Func1& a2 = newProdFunction(m_f1->duplicate(), m_f2->derivative());
|
||||||
@@ -433,7 +687,9 @@ namespace Cantera {
|
|||||||
Func1& r = newRatioFunction(s, p);
|
Func1& r = newRatioFunction(s, p);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
|
|
||||||
virtual int order() const { return 1; }
|
virtual int order() const { return 1; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -444,24 +700,50 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Composite1 : public Func1 {
|
class Composite1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Composite1(Func1& f1, Func1& f2) {
|
Composite1(Func1& f1, Func1& f2) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_f1 = &f1;
|
m_f1 = &f1;
|
||||||
m_f2 = &f2;
|
m_f2 = &f2;
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_f2->setParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Composite1() {
|
virtual ~Composite1() {
|
||||||
delete m_f1;
|
delete m_f1;
|
||||||
delete m_f2;
|
delete m_f2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Composite1(const Composite1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = Composite1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Composite1& operator=(const Composite1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_f1 = &(m_f1->duplicate());
|
||||||
|
m_f2 = &(m_f2->duplicate());
|
||||||
|
m_f1->setParent(this);
|
||||||
|
m_f2->setParent(this);
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
virtual int ID() const { return CompositeFuncType; }
|
virtual int ID() const { return CompositeFuncType; }
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
return m_f1->eval( m_f2->eval(t) );
|
return m_f1->eval( m_f2->eval(t) );
|
||||||
}
|
}
|
||||||
virtual Func1& duplicate() {
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
Func1& f1d = m_f1->duplicate();
|
Func1& f1d = m_f1->duplicate();
|
||||||
Func1& f2d = m_f2->duplicate();
|
Func1& f2d = m_f2->duplicate();
|
||||||
Func1& dup = newCompositeFunction(f1d, f2d);
|
Func1& dup = newCompositeFunction(f1d, f2d);
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Func1& derivative() const {
|
virtual Func1& derivative() const {
|
||||||
Func1* d1 = &m_f1->derivative();
|
Func1* d1 = &m_f1->derivative();
|
||||||
|
|
||||||
@@ -480,8 +762,11 @@ namespace Cantera {
|
|||||||
#endif
|
#endif
|
||||||
return *p;
|
return *p;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string write(std::string arg) const;
|
virtual std::string write(std::string arg) const;
|
||||||
|
|
||||||
virtual int order() const { return 2; }
|
virtual int order() const { return 2; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -502,16 +787,42 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Gaussian : public Func1 {
|
class Gaussian : public Func1 {
|
||||||
public:
|
public:
|
||||||
Gaussian(double A, double t0, double fwhm) {
|
Gaussian(double A, double t0, double fwhm) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_A = A;
|
m_A = A;
|
||||||
m_t0 = t0;
|
m_t0 = t0;
|
||||||
m_tau = fwhm/(2.0*std::sqrt(std::log(2.0)));
|
m_tau = fwhm/(2.0*std::sqrt(std::log(2.0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Gaussian() {}
|
virtual ~Gaussian() {}
|
||||||
|
|
||||||
|
Gaussian(const Gaussian &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = Gaussian::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Gaussian& operator=(const Gaussian &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_A = right.m_A;
|
||||||
|
m_t0 = right.m_t0;
|
||||||
|
m_tau = right.m_tau;
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
|
Gaussian *np = new Gaussian(*this);
|
||||||
|
return *((Func1 *)np);
|
||||||
|
}
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
doublereal x = (t - m_t0)/m_tau;
|
doublereal x = (t - m_t0)/m_tau;
|
||||||
return m_A*std::exp(-x*x);
|
return m_A * std::exp(-x*x);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
doublereal m_A, m_t0, m_tau;
|
doublereal m_A, m_t0, m_tau;
|
||||||
private:
|
private:
|
||||||
@@ -523,26 +834,51 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Poly1 : public Func1 {
|
class Poly1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Poly1(int n, doublereal* c) {
|
Poly1(int n, doublereal* c) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_n = n+1;
|
m_n = n+1;
|
||||||
m_c.resize(n+1);
|
m_cpoly.resize(n+1);
|
||||||
std::copy(c, c+m_n, m_c.begin());
|
std::copy(c, c+m_n, m_cpoly.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Poly1() {
|
||||||
|
}
|
||||||
|
|
||||||
|
Poly1(const Poly1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = Poly1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Poly1& operator=(const Poly1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_cpoly = right.m_cpoly;
|
||||||
|
m_n = right.m_n;
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
|
Poly1 *np = new Poly1(*this);
|
||||||
|
return *((Func1 *)np);
|
||||||
}
|
}
|
||||||
virtual ~Poly1() {}
|
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
int n;
|
int n;
|
||||||
doublereal r = m_c[m_n-1];
|
doublereal r = m_cpoly[m_n-1];
|
||||||
for (n = 1; n < m_n; n++) {
|
for (n = 1; n < m_n; n++) {
|
||||||
r *= t;
|
r *= t;
|
||||||
r += m_c[m_n - n - 1];
|
r += m_cpoly[m_n - n - 1];
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_n;
|
int m_n;
|
||||||
vector_fp m_c;
|
vector_fp m_cpoly;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -557,7 +893,9 @@ namespace Cantera {
|
|||||||
class Fourier1 : public Func1 {
|
class Fourier1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Fourier1(int n, doublereal omega, doublereal a0,
|
Fourier1(int n, doublereal omega, doublereal a0,
|
||||||
doublereal* a, doublereal* b) {
|
doublereal* a, doublereal* b) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_n = n;
|
m_n = n;
|
||||||
m_omega = omega;
|
m_omega = omega;
|
||||||
m_a0_2 = 0.5*a0;
|
m_a0_2 = 0.5*a0;
|
||||||
@@ -566,8 +904,32 @@ namespace Cantera {
|
|||||||
std::copy(a, a+n, m_ccos.begin());
|
std::copy(a, a+n, m_ccos.begin());
|
||||||
std::copy(b, b+n, m_csin.begin());
|
std::copy(b, b+n, m_csin.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Fourier1() {}
|
virtual ~Fourier1() {}
|
||||||
|
|
||||||
|
Fourier1(const Fourier1 &b) :
|
||||||
|
Func1(b)
|
||||||
|
{
|
||||||
|
*this = Fourier1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Fourier1& operator=(const Fourier1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_omega = right.m_omega;
|
||||||
|
m_a0_2 = right.m_a0_2;
|
||||||
|
m_ccos = right.m_ccos;
|
||||||
|
m_csin = right.m_csin;
|
||||||
|
m_n = right.m_n;
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
|
Fourier1 *np = new Fourier1(*this);
|
||||||
|
return *((Func1 *)np);
|
||||||
|
}
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
int n, nn;
|
int n, nn;
|
||||||
doublereal sum = m_a0_2;
|
doublereal sum = m_a0_2;
|
||||||
@@ -594,7 +956,9 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Arrhenius1 : public Func1 {
|
class Arrhenius1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Arrhenius1(int n, doublereal* c) {
|
Arrhenius1(int n, doublereal* c) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_n = n;
|
m_n = n;
|
||||||
m_A.resize(n);
|
m_A.resize(n);
|
||||||
m_b.resize(n);
|
m_b.resize(n);
|
||||||
@@ -607,7 +971,31 @@ namespace Cantera {
|
|||||||
m_E[i] = c[loc+2];
|
m_E[i] = c[loc+2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual ~Arrhenius1() {}
|
virtual ~Arrhenius1() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Arrhenius1(const Arrhenius1 &b) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
|
*this = Arrhenius1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Arrhenius1& operator=(const Arrhenius1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_n = right.m_n;
|
||||||
|
m_A = right.m_A;
|
||||||
|
m_b = right.m_b;
|
||||||
|
m_E = right.m_E;
|
||||||
|
m_parent = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
|
Arrhenius1 *np = new Arrhenius1(*this);
|
||||||
|
return *((Func1 *)np);
|
||||||
|
}
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
int n;
|
int n;
|
||||||
@@ -629,16 +1017,39 @@ namespace Cantera {
|
|||||||
*/
|
*/
|
||||||
class Periodic1 : public Func1 {
|
class Periodic1 : public Func1 {
|
||||||
public:
|
public:
|
||||||
Periodic1(Func1& f, doublereal T) {
|
Periodic1(Func1& f, doublereal T) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
m_func = &f;
|
m_func = &f;
|
||||||
m_c = T;
|
m_c = T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Periodic1(const Periodic1 &b) :
|
||||||
|
Func1()
|
||||||
|
{
|
||||||
|
*this = Periodic1::operator=(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Periodic1& operator=(const Periodic1 &right) {
|
||||||
|
if (&right == this) return *this;
|
||||||
|
Func1::operator=(right);
|
||||||
|
m_func = &(right.m_func->duplicate());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Func1& duplicate() const {
|
||||||
|
Periodic1 *np = new Periodic1(*this);
|
||||||
|
return *((Func1 *)np);
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~Periodic1() { delete m_func; }
|
virtual ~Periodic1() { delete m_func; }
|
||||||
|
|
||||||
virtual doublereal eval(doublereal t) const {
|
virtual doublereal eval(doublereal t) const {
|
||||||
int np = int(t/m_c);
|
int np = int(t/m_c);
|
||||||
doublereal time = t - np*m_c;
|
doublereal time = t - np*m_c;
|
||||||
return m_func->eval(time);
|
return m_func->eval(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Func1* m_func;
|
Func1* m_func;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user