18 Func1::Func1(
const Func1& right) :
22 m_parent(right.m_parent)
26 Func1& Func1::operator=(
const Func1& right)
34 m_parent = right.m_parent;
63 cout <<
"derivative error... ERR: ID = " << ID() << endl;
64 cout << write(
"x") << endl;
70 if ((ID() != other.ID()) || (m_c != other.m_c)) {
120 Func1& Func1::func1_dup()
const
125 Func1& Func1::func2_dup()
const
130 Func1* Func1::parent()
const
135 void Func1::setParent(Func1* p)
142 string Sin1::write(
const string& arg)
const
148 return "\\sin(" + c + arg +
")";
154 Func1* r = &newTimesConstFunction(*c, m_c);
162 Func1* r = &newTimesConstFunction(*s, -m_c);
166 std::string Cos1::write(
const std::string& arg)
const
172 return "\\cos("+c+arg+
")";
181 return newTimesConstFunction(*f, m_c);
187 std::string Exp1::write(
const std::string& arg)
const
193 return "\\exp("+c+arg+
")";
203 }
else if (m_c == 1.0) {
207 r = &newTimesConstFunction(*f, m_c);
212 string Func1::write(
const std::string& arg)
const
214 return "<unknown " +
int2str(ID()) +
">("+arg+
")";
217 string Pow1::write(
const std::string& arg)
const
222 return "\\sqrt{" + arg +
"}";
225 return "\\frac{1}{\\sqrt{" + arg +
"}}";
229 return "\\left("+arg+
"\\right)^{"+c+
"}";
235 string Const1::write(
const std::string& arg)
const
240 string Ratio1::write(
const std::string& arg)
const
242 return "\\frac{" + m_f1->write(arg) +
"}{"
243 + m_f2->write(arg) +
"}";
246 string Product1::write(
const std::string& arg)
const
248 string s = m_f1->write(arg);
250 s =
"\\left(" + s +
"\\right)";
252 string s2 = m_f2->write(arg);
254 s2 =
"\\left(" + s2 +
"\\right)";
259 string Sum1::write(
const std::string& arg)
const
261 string s1 = m_f1->write(arg);
262 string s2 = m_f2->write(arg);
264 return s1 +
" - " + s2.substr(1,s2.size());
266 return s1 +
" + " + s2;
270 string Diff1::write(
const std::string& arg)
const
272 string s1 = m_f1->write(arg);
273 string s2 = m_f2->write(arg);
275 return s1 +
" + " + s2.substr(1,s2.size());
277 return s1 +
" - " + s2;
281 string Composite1::write(
const std::string& arg)
const
283 string g = m_f2->write(arg);
284 return m_f1->write(g);
287 string TimesConstant1::write(
const std::string& arg)
const
289 string s = m_f1->write(arg);
291 s =
"\\left(" + s +
"\\right)";
300 if (n >=
'0' && n <=
'9') {
301 s =
"\\left(" + s +
"\\right)";
306 string PlusConstant1::write(
const std::string& arg)
const
309 return m_f1->write(arg);
311 return m_f1->write(arg) +
" + " +
fp2str(m_c);
314 doublereal Func1::isProportional(TimesConstant1& other)
321 doublereal Func1::isProportional(Func1& other)
330 static bool isConstant(Func1& f)
332 if (f.ID() == ConstFuncType) {
339 static bool isZero(Func1& f)
341 if (f.ID() == ConstFuncType && f.c() == 0.0) {
348 static bool isOne(Func1& f)
350 if (f.ID() == ConstFuncType && f.c() == 1.0) {
357 static bool isTimesConst(Func1& f)
359 if (f.ID() == TimesConstantFuncType) {
366 static bool isExp(Func1& f)
368 if (f.ID() == ExpFuncType) {
375 static bool isPow(Func1& f)
377 if (f.ID() == PowFuncType) {
384 Func1& newSumFunction(Func1& f1, Func1& f2)
386 if (f1.isIdentical(f2)) {
387 return newTimesConstFunction(f1, 2.0);
397 doublereal c = f1.isProportional(f2);
400 return *(
new Const1(0.0));
402 return newTimesConstFunction(f1, c + 1.0);
405 return *(
new Sum1(f1, f2));
408 Func1& newDiffFunction(Func1& f1, Func1& f2)
414 if (f1.isIdentical(f2)) {
417 return *(
new Const1(0.0));
419 doublereal c = f1.isProportional(f2);
422 return *(
new Const1(0.0));
424 return newTimesConstFunction(f1, 1.0 - c);
427 return *(
new Diff1(f1, f2));
430 Func1& newProdFunction(Func1& f1, Func1& f2)
440 if (isZero(f1) || isZero(f2)) {
443 return *(
new Const1(0.0));
445 if (isConstant(f1) && isConstant(f2)) {
446 doublereal c1c2 = f1.
c() * f2.c();
449 return *(
new Const1(c1c2));
451 if (isConstant(f1)) {
452 doublereal c = f1.c();
454 return newTimesConstFunction(f2, c);
456 if (isConstant(f2)) {
457 doublereal c = f2.c();
459 return newTimesConstFunction(f1, c);
462 if (isPow(f1) && isPow(f2)) {
463 Func1& p = *(
new Pow1(f1.c() + f2.c()));
469 if (isExp(f1) && isExp(f2)) {
470 Func1& p = *(
new Exp1(f1.c() + f2.c()));
476 bool tc1 = isTimesConst(f1);
477 bool tc2 = isTimesConst(f2);
480 doublereal c1 = 1.0, c2 = 1.0;
481 Func1* ff1 = 0, *ff2 = 0;
484 ff1 = &f1.func1_dup();
491 ff2 = &f2.func1_dup();
496 Func1& p = newProdFunction(*ff1, *ff2);
499 return newTimesConstFunction(p, c1*c2);
504 return *(
new Product1(f1, f2));
508 Func1& newRatioFunction(Func1& f1, Func1& f2)
514 return *(
new Const1(0.0));
516 if (f1.isIdentical(f2)) {
519 return *(
new Const1(1.0));
521 if (f1.ID() == PowFuncType && f2.ID() == PowFuncType) {
522 return *(
new Pow1(f1.c() - f2.c()));
524 if (f1.ID() == ExpFuncType && f2.ID() == ExpFuncType) {
525 return *(
new Exp1(f1.c() - f2.c()));
527 return *(
new Ratio1(f1, f2));
530 Func1& newCompositeFunction(Func1& f1, Func1& f2)
535 return *(
new Const1(0.0));
537 if (isConstant(f1)) {
541 if (isPow(f1) && f1.c() == 1.0) {
545 if (isPow(f1) && f1.c() == 0.0) {
548 return *(
new Const1(1.0));
550 if (isPow(f1) && isPow(f2)) {
551 doublereal c1c2 = f1.
c() * f2.c();
554 return *(
new Pow1(c1c2));
556 return *(
new Composite1(f1, f2));
559 Func1& newTimesConstFunction(Func1& f, doublereal c)
563 return *(
new Const1(0.0));
568 if (f.ID() == TimesConstantFuncType) {
572 return *(
new TimesConstant1(f, c));
575 Func1& newPlusConstFunction(Func1& f, doublereal c)
581 doublereal cc = f.
c() + c;
583 return *(
new Const1(cc));
585 if (f.ID() == PlusConstantFuncType) {
589 return *(
new PlusConstant1(f, c));
virtual int order() const
Return the order of the function, if it makes sense.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Func1 & func2() const
accessor function for m_f2
bool isIdentical(Func1 &other) const
Routine to determine if two functions are the same.
virtual Func1 & derivative() const
Creates a derivative to the current function.
implements the sin() function
virtual doublereal eval(doublereal t) const
Evaluate the function.
virtual Func1 & derivative() const
Creates a derivative to the current function.
virtual int order() const
Return the order of the function, if it makes sense.
doublereal c() const
accessor function for the stored constant
Func1 & func1() const
accessor function for m_f1
virtual Func1 & duplicate() const
Duplicate the current function.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
void setC(doublereal c)
Function to set the stored constant.
virtual Func1 & derivative() const
Creates a derivative to the current function.
Base class for 'functor' classes that evaluate a function of one variable.
virtual int order() const
Return the order of the function, if it makes sense.
virtual Func1 & derivative() const
Creates a derivative to the current function.
Contains declarations for string manipulation functions within Cantera.
doublereal operator()(doublereal t) const
Calls method eval to evaluate the function.
virtual Func1 & derivative() const
Creates a derivative to the current function.