20 Func1::Func1(
const Func1& right) :
24 m_parent(right.m_parent)
32 Func1& Func1::operator=(
const Func1& right)
40 m_parent = right.m_parent;
69 cout <<
"derivative error... ERR: ID = " << ID() << endl;
70 cout << write(
"x") << endl;
76 if ((ID() != other.ID()) || (m_c != other.m_c)) {
127 Func1& Func1::func1_dup()
const
133 Func1& Func1::func2_dup()
const
139 Func1* Func1::parent()
const
145 void Func1::setParent(Func1* p)
152 string Sin1::write(
const string& arg)
const
158 return "\\sin(" + c + arg +
")";
164 Func1* r = &newTimesConstFunction(*c, m_c);
172 Func1* r = &newTimesConstFunction(*s, -m_c);
176 std::string Cos1::write(
const std::string& arg)
const
182 return "\\cos("+c+arg+
")";
191 return newTimesConstFunction(*f, m_c);
197 std::string Exp1::write(
const std::string& arg)
const
203 return "\\exp("+c+arg+
")";
213 }
else if (m_c == 1.0) {
217 r = &newTimesConstFunction(*f, m_c);
222 string Func1::write(
const std::string& arg)
const
224 return "<unknown " +
int2str(ID()) +
">("+arg+
")";
230 string Pow1::write(
const std::string& arg)
const
235 return "\\sqrt{" + arg +
"}";
238 return "\\frac{1}{\\sqrt{" + arg +
"}}";
242 return "\\left("+arg+
"\\right)^{"+c+
"}";
249 string Const1::write(
const std::string& arg)
const
255 string Ratio1::write(
const std::string& arg)
const
258 return "\\frac{" + m_f1->write(arg) +
"}{"
259 + m_f2->write(arg) +
"}";
262 string Product1::write(
const std::string& arg)
const
265 string s = m_f1->write(arg);
267 s =
"\\left(" + s +
"\\right)";
269 string s2 = m_f2->write(arg);
271 s2 =
"\\left(" + s2 +
"\\right)";
276 string Sum1::write(
const std::string& arg)
const
279 string s1 = m_f1->write(arg);
280 string s2 = m_f2->write(arg);
282 return s1 +
" - " + s2.substr(1,s2.size());
284 return s1 +
" + " + s2;
288 string Diff1::write(
const std::string& arg)
const
291 string s1 = m_f1->write(arg);
292 string s2 = m_f2->write(arg);
294 return s1 +
" + " + s2.substr(1,s2.size());
296 return s1 +
" - " + s2;
300 string Composite1::write(
const std::string& arg)
const
303 string g = m_f2->write(arg);
304 return m_f1->write(g);
307 string TimesConstant1::write(
const std::string& arg)
const
310 string s = m_f1->write(arg);
312 s =
"\\left(" + s +
"\\right)";
321 if (n >=
'0' && n <=
'9') {
322 s =
"\\left(" + s +
"\\right)";
327 string PlusConstant1::write(
const std::string& arg)
const
331 return m_f1->write(arg);
333 return m_f1->write(arg) +
" + " +
fp2str(m_c);
336 doublereal Func1::isProportional(TimesConstant1& other)
343 doublereal Func1::isProportional(Func1& other)
352 static bool isConstant(Func1& f)
354 if (f.ID() == ConstFuncType) {
361 static bool isZero(Func1& f)
363 if (f.ID() == ConstFuncType && f.c() == 0.0) {
370 static bool isOne(Func1& f)
372 if (f.ID() == ConstFuncType && f.c() == 1.0) {
379 static bool isTimesConst(Func1& f)
381 if (f.ID() == TimesConstantFuncType) {
388 static bool isExp(Func1& f)
390 if (f.ID() == ExpFuncType) {
397 static bool isPow(Func1& f)
399 if (f.ID() == PowFuncType) {
406 Func1& newSumFunction(Func1& f1, Func1& f2)
408 if (f1.isIdentical(f2)) {
409 return newTimesConstFunction(f1, 2.0);
419 doublereal c = f1.isProportional(f2);
422 return *(
new Const1(0.0));
424 return newTimesConstFunction(f1, c + 1.0);
427 return *(
new Sum1(f1, f2));
430 Func1& newDiffFunction(Func1& f1, Func1& f2)
436 if (f1.isIdentical(f2)) {
439 return *(
new Const1(0.0));
441 doublereal c = f1.isProportional(f2);
444 return *(
new Const1(0.0));
446 return newTimesConstFunction(f1, 1.0 - c);
449 return *(
new Diff1(f1, f2));
452 Func1& newProdFunction(Func1& f1, Func1& f2)
462 if (isZero(f1) || isZero(f2)) {
465 return *(
new Const1(0.0));
467 if (isConstant(f1) && isConstant(f2)) {
468 doublereal c1c2 = f1.
c() * f2.c();
471 return *(
new Const1(c1c2));
473 if (isConstant(f1)) {
474 doublereal c = f1.c();
476 return newTimesConstFunction(f2, c);
478 if (isConstant(f2)) {
479 doublereal c = f2.c();
481 return newTimesConstFunction(f1, c);
484 if (isPow(f1) && isPow(f2)) {
485 Func1& p = *(
new Pow1(f1.c() + f2.c()));
491 if (isExp(f1) && isExp(f2)) {
492 Func1& p = *(
new Exp1(f1.c() + f2.c()));
498 bool tc1 = isTimesConst(f1);
499 bool tc2 = isTimesConst(f2);
502 doublereal c1 = 1.0, c2 = 1.0;
503 Func1* ff1 = 0, *ff2 = 0;
506 ff1 = &f1.func1_dup();
513 ff2 = &f2.func1_dup();
518 Func1& p = newProdFunction(*ff1, *ff2);
521 return newTimesConstFunction(p, c1*c2);
526 return *(
new Product1(f1, f2));
530 Func1& newRatioFunction(Func1& f1, Func1& f2)
536 return *(
new Const1(0.0));
538 if (f1.isIdentical(f2)) {
541 return *(
new Const1(1.0));
543 if (f1.ID() == PowFuncType && f2.ID() == PowFuncType) {
544 return *(
new Pow1(f1.c() - f2.c()));
546 if (f1.ID() == ExpFuncType && f2.ID() == ExpFuncType) {
547 return *(
new Exp1(f1.c() - f2.c()));
549 return *(
new Ratio1(f1, f2));
552 Func1& newCompositeFunction(Func1& f1, Func1& f2)
557 return *(
new Const1(0.0));
559 if (isConstant(f1)) {
563 if (isPow(f1) && f1.c() == 1.0) {
567 if (isPow(f1) && f1.c() == 0.0) {
570 return *(
new Const1(1.0));
572 if (isPow(f1) && isPow(f2)) {
573 doublereal c1c2 = f1.
c() * f2.c();
576 return *(
new Pow1(c1c2));
578 return *(
new Composite1(f1, f2));
581 Func1& newTimesConstFunction(Func1& f, doublereal c)
585 return *(
new Const1(0.0));
590 if (f.ID() == TimesConstantFuncType) {
594 return *(
new TimesConstant1(f, c));
597 Func1& newPlusConstFunction(Func1& f, doublereal c)
603 doublereal cc = f.
c() + c;
605 return *(
new Const1(cc));
607 if (f.ID() == PlusConstantFuncType) {
611 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
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, HTML_logs (see Input File Handling, Diagnostic Output, Writing messages to the screen and Writing HTML Logfiles).
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.