22 Func1::Func1(
const Func1& right) :
26 m_parent(right.m_parent)
30 Func1& Func1::operator=(
const Func1& right)
38 m_parent = right.m_parent;
67 cout <<
"derivative error... ERR: ID = " << ID() << endl;
68 cout << write(
"x") << endl;
74 if (ID() != other.ID() || m_c != other.m_c) {
124 Func1& Func1::func1_dup()
const 129 Func1& Func1::func2_dup()
const 134 Func1* Func1::parent()
const 139 void Func1::setParent(Func1* p)
146 string Sin1::write(
const string& arg)
const 149 return fmt::format(
"\\sin({})", arg);
151 return fmt::format(
"\\sin({}{})", m_c, arg);
158 Func1* r = &newTimesConstFunction(*
c, m_c);
166 Func1* r = &newTimesConstFunction(*s, -m_c);
170 std::string Cos1::write(
const std::string& arg)
const 173 return fmt::format(
"\\cos({})", arg);
175 return fmt::format(
"\\cos({}{})", m_c, arg);
185 return newTimesConstFunction(*f, m_c);
191 std::string Exp1::write(
const std::string& arg)
const 194 return fmt::format(
"\\exp({})", arg);
196 return fmt::format(
"\\exp({}{})", m_c, arg);
207 }
else if (m_c == 1.0) {
211 r = &newTimesConstFunction(*f, m_c);
216 string Func1::write(
const std::string& arg)
const 218 return fmt::format(
"<unknown {}>({})", ID(), arg);
221 string Pow1::write(
const std::string& arg)
const 224 return "\\sqrt{" + arg +
"}";
227 return "\\frac{1}{\\sqrt{" + arg +
"}}";
230 return fmt::format(
"\\left({}\\right)^{{{}}}", arg, m_c);
236 string Const1::write(
const std::string& arg)
const 238 return fmt::format(
"{}", m_c);
241 string Ratio1::write(
const std::string& arg)
const 243 return "\\frac{" + m_f1->write(arg) +
"}{" 244 + m_f2->write(arg) +
"}";
247 string Product1::write(
const std::string& arg)
const 249 string s = m_f1->write(arg);
251 s =
"\\left(" + s +
"\\right)";
253 string s2 = m_f2->write(arg);
255 s2 =
"\\left(" + s2 +
"\\right)";
260 string Sum1::write(
const std::string& arg)
const 262 string s1 = m_f1->write(arg);
263 string s2 = m_f2->write(arg);
265 return s1 +
" - " + s2.substr(1,s2.size());
267 return s1 +
" + " + s2;
271 string Diff1::write(
const std::string& arg)
const 273 string s1 = m_f1->write(arg);
274 string s2 = m_f2->write(arg);
276 return s1 +
" + " + s2.substr(1,s2.size());
278 return s1 +
" - " + s2;
282 string Composite1::write(
const std::string& arg)
const 284 string g = m_f2->write(arg);
285 return m_f1->write(g);
288 string TimesConstant1::write(
const std::string& arg)
const 290 string s = m_f1->write(arg);
292 s =
"\\left(" + s +
"\\right)";
301 if (n >=
'0' && n <=
'9') {
302 s =
"\\left(" + s +
"\\right)";
304 return fmt::format(
"{}{}", m_c, s);
307 string PlusConstant1::write(
const std::string& arg)
const 310 return m_f1->write(arg);
312 return fmt::format(
"{} + {}", m_f1->write(arg), m_c);
315 doublereal Func1::isProportional(TimesConstant1& other)
322 doublereal Func1::isProportional(Func1& other)
331 static bool isConstant(Func1& f)
333 if (f.ID() == ConstFuncType) {
340 static bool isZero(Func1& f)
342 if (f.ID() == ConstFuncType && f.c() == 0.0) {
349 static bool isOne(Func1& f)
351 if (f.ID() == ConstFuncType && f.c() == 1.0) {
358 static bool isTimesConst(Func1& f)
360 if (f.ID() == TimesConstantFuncType) {
367 static bool isExp(Func1& f)
369 if (f.ID() == ExpFuncType) {
376 static bool isPow(Func1& f)
378 if (f.ID() == PowFuncType) {
385 Func1& newSumFunction(Func1& f1, Func1& f2)
387 if (f1.isIdentical(f2)) {
388 return newTimesConstFunction(f1, 2.0);
398 doublereal c = f1.isProportional(f2);
401 return *(
new Const1(0.0));
403 return newTimesConstFunction(f1, c + 1.0);
406 return *(
new Sum1(f1, f2));
409 Func1& newDiffFunction(Func1& f1, Func1& f2)
415 if (f1.isIdentical(f2)) {
418 return *(
new Const1(0.0));
420 doublereal c = f1.isProportional(f2);
423 return *(
new Const1(0.0));
425 return newTimesConstFunction(f1, 1.0 - c);
428 return *(
new Diff1(f1, f2));
431 Func1& newProdFunction(Func1& f1, Func1& f2)
441 if (isZero(f1) || isZero(f2)) {
444 return *(
new Const1(0.0));
446 if (isConstant(f1) && isConstant(f2)) {
447 doublereal c1c2 = f1.
c() * f2.c();
450 return *(
new Const1(c1c2));
452 if (isConstant(f1)) {
453 doublereal c = f1.c();
455 return newTimesConstFunction(f2, c);
457 if (isConstant(f2)) {
458 doublereal c = f2.c();
460 return newTimesConstFunction(f1, c);
463 if (isPow(f1) && isPow(f2)) {
464 Func1& p = *(
new Pow1(f1.c() + f2.c()));
470 if (isExp(f1) && isExp(f2)) {
471 Func1& p = *(
new Exp1(f1.c() + f2.c()));
477 bool tc1 = isTimesConst(f1);
478 bool tc2 = isTimesConst(f2);
481 doublereal c1 = 1.0, c2 = 1.0;
482 Func1* ff1 = 0, *ff2 = 0;
485 ff1 = &f1.func1_dup();
492 ff2 = &f2.func1_dup();
497 Func1& p = newProdFunction(*ff1, *ff2);
500 return newTimesConstFunction(p, c1*c2);
505 return *(
new Product1(f1, f2));
509 Func1& newRatioFunction(Func1& f1, Func1& f2)
515 return *(
new Const1(0.0));
517 if (f1.isIdentical(f2)) {
520 return *(
new Const1(1.0));
522 if (f1.ID() == PowFuncType && f2.ID() == PowFuncType) {
523 return *(
new Pow1(f1.c() - f2.c()));
525 if (f1.ID() == ExpFuncType && f2.ID() == ExpFuncType) {
526 return *(
new Exp1(f1.c() - f2.c()));
528 return *(
new Ratio1(f1, f2));
531 Func1& newCompositeFunction(Func1& f1, Func1& f2)
536 return *(
new Const1(0.0));
538 if (isConstant(f1)) {
542 if (isPow(f1) && f1.c() == 1.0) {
546 if (isPow(f1) && f1.c() == 0.0) {
549 return *(
new Const1(1.0));
551 if (isPow(f1) && isPow(f2)) {
552 doublereal c1c2 = f1.
c() * f2.c();
555 return *(
new Pow1(c1c2));
557 return *(
new Composite1(f1, f2));
560 Func1& newTimesConstFunction(Func1& f, doublereal c)
564 return *(
new Const1(0.0));
569 if (f.ID() == TimesConstantFuncType) {
573 return *(
new TimesConstant1(f, c));
576 Func1& newPlusConstFunction(Func1& f, doublereal c)
582 doublereal cc = f.
c() + c;
584 return *(
new Const1(cc));
586 if (f.ID() == PlusConstantFuncType) {
590 return *(
new PlusConstant1(f, c));
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.
bool isIdentical(Func1 &other) const
Routine to determine if two functions are the same.
virtual Func1 & duplicate() const
Duplicate the current function.
doublereal operator()(doublereal t) const
Calls method eval to evaluate the function.
doublereal c() const
accessor function for the stored constant
virtual doublereal eval(doublereal t) const
Evaluate the function.
implements the sin() function
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.
void setC(doublereal c)
Function to set the stored constant.
Base class for 'functor' classes that evaluate a function of one variable.
Func1 & func1() const
accessor function for m_f1
virtual Func1 & derivative() const
Creates a derivative to the current function.
virtual Func1 & derivative() const
Creates a derivative to the current function.
Func1 & func2() const
accessor function for m_f2
virtual int order() const
Return the order of the function, if it makes sense.
Contains declarations for string manipulation functions within Cantera.
Namespace for the Cantera kernel.
virtual Func1 & derivative() const
Creates a derivative to the current function.