Cantera  3.2.0a1
Loading...
Searching...
No Matches
Func1.cpp
Go to the documentation of this file.
1//! @file Func1.cpp
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
10
11using namespace std;
12
13namespace Cantera
14{
15
16string Func1::typeName() const
17{
18 return demangle(typeid(*this));
19}
20
21// Calls method eval to evaluate the function
22double Func1::operator()(double t) const
23{
24 return eval(t);
25}
26
27// Evaluate the function.
28double Func1::eval(double t) const
29{
30 return 0.0;
31}
32
33shared_ptr<Func1> Func1::derivative() const
34{
35 throw CanteraError("Func1::derivative",
36 "Needs to be overloaded by Func1 specialization.");
37}
38
39bool Func1::isIdentical(shared_ptr<Func1> other) const
40{
41 if (type() == "functor" || type() != other->type() || m_c != other->m_c) {
42 return false;
43 }
44 if (m_f1) {
45 if (!other->m_f1) {
46 return false;
47 }
48 if (!m_f1->isIdentical(other->m_f1)) {
49 return false;
50 }
51 }
52 if (m_f2) {
53 if (!other->m_f2) {
54 return false;
55 }
56 if (!m_f2->isIdentical(other->m_f2)) {
57 return false;
58 }
59 }
60 return true;
61}
62
63//! accessor function for the returned constant
64double Func1::c() const
65{
66 return m_c;
67}
68
69int Func1::order() const
70{
71 return 3;
72}
73
74/*****************************************************************************/
75
76Sin1::Sin1(const vector<double>& params)
77{
78 if (params.size() != 1) {
79 throw CanteraError("Sin1::Sin1",
80 "Constructor needs exactly one parameter (frequency).");
81 }
82 m_c = params[0];
83}
84
85string Sin1::write(const string& arg) const
86{
87 if (m_c == 1.0) {
88 return fmt::format("\\sin({})", arg);
89 } else {
90 return fmt::format("\\sin({}{})", m_c, arg);
91 }
92}
93
94shared_ptr<Func1> Sin1::derivative() const
95{
96 auto c = make_shared<Cos1>(m_c);
97 return newTimesConstFunction(c, m_c);
98}
99
100/*****************************************************************************/
101
102Cos1::Cos1(const vector<double>& params)
103{
104 if (params.size() != 1) {
105 throw CanteraError("Cos1::Cos1",
106 "Constructor needs exactly one parameter (frequency).");
107 }
108 m_c = params[0];
109}
110
111shared_ptr<Func1> Cos1::derivative() const
112{
113 auto s = make_shared<Sin1>(m_c);
114 return newTimesConstFunction(s, -m_c);
115}
116
117string Cos1::write(const string& arg) const
118{
119 if (m_c == 1.0) {
120 return fmt::format("\\cos({})", arg);
121 } else {
122 return fmt::format("\\cos({}{})", m_c, arg);
123 }
124}
125
126/**************************************************************************/
127
128Exp1::Exp1(const vector<double>& params)
129{
130 if (params.size() != 1) {
131 throw CanteraError("Exp1::Exp1",
132 "Constructor needs exactly one parameter (exponent factor).");
133 }
134 m_c = params[0];
135}
136
137shared_ptr<Func1> Exp1::derivative() const
138{
139 auto f = make_shared<Exp1>(m_c);
140 if (m_c != 1.0) {
141 return newTimesConstFunction(f, m_c);
142 }
143 return f;
144}
145
146string Exp1::write(const string& arg) const
147{
148 if (m_c == 1.0) {
149 return fmt::format("\\exp({})", arg);
150 } else {
151 return fmt::format("\\exp({}{})", m_c, arg);
152 }
153}
154
155Log1::Log1(const vector<double>& params)
156{
157 if (params.size() != 1) {
158 throw CanteraError("Log1::Log1",
159 "Constructor needs exactly one parameter (factor).");
160 }
161 m_c = params[0];
162}
163
164shared_ptr<Func1> Log1::derivative() const
165{
166 auto f = make_shared<Pow1>(-1.);
167 if (m_c != 1.0) {
168 return newTimesConstFunction(f, m_c);
169 }
170 return f;
171}
172
173string Log1::write(const string& arg) const
174{
175 if (m_c == 1.0) {
176 return fmt::format("\\log({})", arg);
177 }
178 return fmt::format("\\log({}{})", m_c, arg);
179}
180
181/******************************************************************************/
182
183Pow1::Pow1(const vector<double>& params)
184{
185 if (params.size() != 1) {
186 throw CanteraError("Pow1::Pow1",
187 "Constructor needs exactly one parameter (exponent).");
188 }
189 m_c = params[0];
190}
191
192shared_ptr<Func1> Pow1::derivative() const
193{
194 if (m_c == 0.0) {
195 return make_shared<Const1>(0.0);
196 }
197 if (m_c == 1.0) {
198 return make_shared<Const1>(1.0);
199 }
200 auto f = make_shared<Pow1>(m_c - 1.);
201 return newTimesConstFunction(f, m_c);
202}
203
204/******************************************************************************/
205
206Const1::Const1(const vector<double>& params)
207{
208 if (params.size() != 1) {
209 throw CanteraError("Const1::Const1",
210 "Constructor needs exactly one parameter (constant).");
211 }
212 m_c = params[0];
213}
214
215Poly1::Poly1(const vector<double>& params)
216{
217 if (params.size() == 0) {
218 throw CanteraError("Poly1::Poly1",
219 "Constructor needs an array that is not empty.");
220 }
221 size_t n = params.size() - 1;
222 m_cpoly.resize(n + 1);
223 copy(params.data(), params.data() + m_cpoly.size(), m_cpoly.begin());
224}
225
226string Poly1::write(const string& arg) const
227{
228 // write terms in reverse order
229 string out = "";
230 if (m_cpoly[m_cpoly.size()-1] != 0.) {
231 out = fmt::format("{}", m_cpoly[m_cpoly.size()-1]);
232 }
233 for (size_t n=1; n<m_cpoly.size(); n++) {
234 if (m_cpoly[m_cpoly.size()-1-n] == 0.) {
235 continue;
236 }
237 string term;
238 if (m_cpoly[m_cpoly.size()-1-n] == 1.) {
239 term = fmt::format("{}", arg);
240 } else if (m_cpoly[m_cpoly.size()-1-n] == -1.) {
241 term = fmt::format("-{}", arg);
242 } else {
243 term = fmt::format("{}{}", m_cpoly[m_cpoly.size()-1-n], arg);
244 }
245 if (n > 9) {
246 term = fmt::format("{}^{{{}}}", term, n);
247 } else if (n > 1) {
248 term = fmt::format("{}^{}", term, n);
249 }
250 if (!out.size()) {
251 out = term;
252 } else if (out[0] == '-') {
253 out = fmt::format("{} - {}", term, out.substr(1));
254 } else {
255 out = fmt::format("{} + {}", term, out);
256 }
257 }
258 return out;
259}
260
261Fourier1::Fourier1(const vector<double>& params)
262{
263 if (params.size() < 4) {
264 throw CanteraError("Fourier1::Fourier1",
265 "Constructor needs an array with at least 4 entries.");
266 }
267 if (params.size() % 2 != 0) {
268 throw CanteraError("Fourier1::Fourier1",
269 "Constructor needs an array with an even number of entries.");
270 }
271 size_t n = params.size() / 2 - 1;
272 m_omega = params[n + 1];
273 m_a0_2 = 0.5 * params[0];
274 m_ccos.resize(n);
275 m_csin.resize(n);
276 copy(params.data() + 1, params.data() + n + 1, m_ccos.begin());
277 copy(params.data() + n + 2, params.data() + 2 * n + 2, m_csin.begin());
278}
279
280Gaussian1::Gaussian1(const vector<double>& params)
281{
282 if (params.size() != 3) {
283 throw CanteraError("Gaussian1::Gaussian1",
284 "Constructor needs exactly 3 parameters (amplitude, center, width).");
285 }
286 m_A = params[0];
287 m_t0 = params[1];
288 m_tau = params[2] / (2. * sqrt(log(2.)));
289}
290
291Arrhenius1::Arrhenius1(const vector<double>& params)
292{
293 if (params.size() < 3) {
294 throw CanteraError("Arrhenius1::Arrhenius1",
295 "Constructor needs an array with at least 3 entries.");
296 }
297 if (params.size() % 3 != 0) {
298 throw CanteraError("Arrhenius1::Arrhenius1",
299 "Constructor needs an array with multiples of 3 entries.");
300 }
301 size_t n = params.size() / 3;
302 m_A.resize(n);
303 m_b.resize(n);
304 m_E.resize(n);
305 for (size_t i = 0; i < n; i++) {
306 size_t loc = 3 * i;
307 m_A[i] = params[loc];
308 m_b[i] = params[loc + 1];
309 m_E[i] = params[loc + 2];
310 }
311}
312
313Tabulated1::Tabulated1(size_t n, const double* tvals, const double* fvals,
314 const string& method)
315{
316 m_tvec.resize(n);
317 std::copy(tvals, tvals + n, m_tvec.begin());
318 for (auto it = std::begin(m_tvec) + 1; it != std::end(m_tvec); it++) {
319 if (*(it - 1) > *it) {
320 throw CanteraError("Tabulated1::Tabulated1",
321 "time values are not increasing monotonically.");
322 }
323 }
324 m_fvec.resize(n);
325 std::copy(fvals, fvals + n, m_fvec.begin());
326 setMethod(method);
327}
328
329Tabulated1::Tabulated1(const vector<double>& params) : m_isLinear(true)
330{
331 if (params.size() < 4) {
332 throw CanteraError("Tabulated1::Tabulated1",
333 "Constructor needs an array with at least 4 entries.");
334 }
335 if (params.size() % 2 != 0) {
336 throw CanteraError("Tabulated1::Tabulated1",
337 "Constructor needs an array with an even number of entries.");
338 }
339 size_t n = params.size() / 2;
340 m_tvec.resize(n);
341 copy(params.data(), params.data() + n, m_tvec.begin());
342 for (auto it = std::begin(m_tvec) + 1; it != std::end(m_tvec); it++) {
343 if (*(it - 1) > *it) {
344 throw CanteraError("Tabulated1::Tabulated1",
345 "Time values are not monotonically increasing.");
346 }
347 }
348 m_fvec.resize(n);
349 copy(params.data() + n, params.data() + 2 * n, m_fvec.begin());
350}
351
352void Tabulated1::setMethod(const string& method)
353{
354 if (method == "linear") {
355 m_isLinear = true;
356 } else if (method == "previous") {
357 m_isLinear = false;
358 } else {
359 throw NotImplementedError("Tabulated1::setMethod",
360 "Interpolation method '{}' is not implemented.", method);
361 }
362}
363
364double Tabulated1::eval(double t) const {
365 size_t siz = m_tvec.size();
366 // constructor ensures that siz > 0
367 if (t <= m_tvec[0]) {
368 return m_fvec[0];
369 } else if (t >= m_tvec[siz-1]) {
370 return m_fvec[siz-1];
371 } else {
372 size_t ix = 0;
373 while (t > m_tvec[ix+1]) {
374 ix++;
375 }
376 if (m_isLinear) {
377 double df = m_fvec[ix+1] - m_fvec[ix];
378 df /= m_tvec[ix+1] - m_tvec[ix];
379 df *= t - m_tvec[ix];
380 return m_fvec[ix] + df;
381 } else {
382 return m_fvec[ix];
383 }
384 }
385}
386
387shared_ptr<Func1> Tabulated1::derivative() const {
388 vector<double> tvec;
389 vector<double> dvec;
390 size_t siz = m_tvec.size();
391 if (m_isLinear) {
392 // piece-wise continuous derivative
393 if (siz>1) {
394 for (size_t i=1; i<siz; i++) {
395 double d = (m_fvec[i] - m_fvec[i-1]) /
396 (m_tvec[i] - m_tvec[i-1]);
397 tvec.push_back(m_tvec[i-1]);
398 dvec.push_back(d);
399 }
400 }
401 tvec.push_back(m_tvec[siz-1]);
402 dvec.push_back(0.);
403 } else {
404 // derivative is zero (ignoring discontinuities)
405 tvec.push_back(m_tvec[0]);
406 tvec.push_back(m_tvec[siz-1]);
407 dvec.push_back(0.);
408 dvec.push_back(0.);
409 }
410 return make_shared<Tabulated1>(tvec.size(), &tvec[0], &dvec[0], "previous");
411}
412
413/******************************************************************************/
414
415string Func1::write(const string& arg) const
416{
417 return fmt::format("\\mathrm{{{}}}({})", type(), arg);
418}
419
420string Pow1::write(const string& arg) const
421{
422 if (m_c == 0.5) {
423 return "\\sqrt{" + arg + "}";
424 }
425 if (m_c == -0.5) {
426 return "\\frac{1}{\\sqrt{" + arg + "}}";
427 }
428 if (m_c != 1.0) {
429 return fmt::format("\\left({}\\right)^{{{}}}", arg, m_c);
430 } else {
431 return arg;
432 }
433}
434
435string Tabulated1::write(const string& arg) const
436{
437 return fmt::format("\\mathrm{{Tabulated}}({})", arg);
438}
439
440string Const1::write(const string& arg) const
441{
442 return fmt::format("{}", m_c);
443}
444
445string Ratio1::write(const string& arg) const
446{
447 return "\\frac{" + m_f1->write(arg) + "}{" + m_f2->write(arg) + "}";
448}
449
450shared_ptr<Func1> Ratio1::derivative() const {
451 auto a1 = newProdFunction(m_f1->derivative(), m_f2);
452 auto a2 = newProdFunction(m_f1, m_f2->derivative());
453 auto s = newDiffFunction(a1, a2);
454 auto p = newProdFunction(m_f2, m_f2);
455 return newRatioFunction(s, p);
456}
457
458string Product1::write(const string& arg) const
459{
460 string s = m_f1->write(arg);
461 if (m_f1->order() < order()) {
462 s = "\\left(" + s + "\\right)";
463 }
464 string s2 = m_f2->write(arg);
465 if (m_f2->order() < order()) {
466 s2 = "\\left(" + s2 + "\\right)";
467 }
468 return s + " " + s2;
469}
470
471shared_ptr<Func1> Product1::derivative() const {
472 auto a1 = newProdFunction(m_f1, m_f2->derivative());
473 auto a2 = newProdFunction(m_f2, m_f1->derivative());
474 return newSumFunction(a1, a2);
475}
476
477string Sum1::write(const string& arg) const
478{
479 string s1 = m_f1->write(arg);
480 string s2 = m_f2->write(arg);
481 if (s2[0] == '-') {
482 return s1 + " - " + s2.substr(1,s2.size());
483 } else {
484 return s1 + " + " + s2;
485 }
486}
487
488string Diff1::write(const string& arg) const
489{
490 string s1 = m_f1->write(arg);
491 string s2 = m_f2->write(arg);
492 if (s2[0] == '-') {
493 return s1 + " + " + s2.substr(1,s2.size());
494 } else {
495 return s1 + " - " + s2;
496 }
497}
498
499string Composite1::write(const string& arg) const
500{
501 string g = m_f2->write(arg);
502 return m_f1->write(g);
503}
504
505shared_ptr<Func1> Composite1::derivative() const {
506 auto d1 = m_f1->derivative();
507 auto d2 = m_f2->derivative();
508 auto d3 = newCompositeFunction(d1, m_f2);
509 return newProdFunction(d3, d2);
510}
511
512string TimesConstant1::write(const string& arg) const
513{
514 string s = m_f1->write(arg);
515 if (m_f1->order() < order()) {
516 s = "\\left(" + s + "\\right)";
517 }
518 if (m_c == 1.0) {
519 return s;
520 }
521 if (m_c == -1.0) {
522 return "-"+s;
523 }
524 char n = s[0];
525 if (n >= '0' && n <= '9') {
526 s = "\\left(" + s + "\\right)";
527 }
528 return fmt::format("{}{}", m_c, s);
529}
530
531string PlusConstant1::write(const string& arg) const
532{
533 if (m_c == 0.0) {
534 return m_f1->write(arg);
535 }
536 return fmt::format("{} + {}", m_f1->write(arg), m_c);
537}
538
539namespace { // restrict scope of helper functions to local translation unit
540
541bool isConstant(const shared_ptr<Func1>& f)
542{
543 return f->type() == "constant";
544}
545
546bool isZero(const shared_ptr<Func1>& f)
547{
548 return f->type() == "constant" && f->c() == 0.0;
549}
550
551bool isOne(const shared_ptr<Func1>& f)
552{
553 return f->type() == "constant" && f->c() == 1.0;
554}
555
556bool isTimesConst(const shared_ptr<Func1>& f)
557{
558 return f->type() == "times-constant";
559}
560
561bool isExp(const shared_ptr<Func1>& f)
562{
563 return f->type() == "exp";
564}
565
566bool isPow(const shared_ptr<Func1>& f)
567{
568 return f->type() == "pow";
569}
570
571pair<bool, double> isProportional(
572 const shared_ptr<Func1>&f1, const shared_ptr<Func1>&f2)
573{
574 bool tc1 = isTimesConst(f1);
575 bool tc2 = isTimesConst(f2);
576 if (!tc1 && !tc2) {
577 if (f1->isIdentical(f2)) {
578 return {true, 1.0};
579 }
580 return {false, 0.};
581 }
582 if (!tc1 && tc2) {
583 if (f1->isIdentical((f2->func1_shared()))) {
584 return {true, f2->c()};
585 }
586 return {false, 0.};
587 }
588 if (tc1 && !tc2) {
589 if (f2->isIdentical((f1->func1_shared()))) {
590 return {true, 1. / f1->c()};
591 }
592 return {false, 0.};
593 }
594 if (f2->func1_shared()->isIdentical((f1->func1_shared()))) {
595 return {true, f2->c() / f1->c()};
596 }
597 return {false, 0.};
598}
599
600} // end unnamed namespace
601
602shared_ptr<Func1> newSumFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
603{
604 if (f1->isIdentical(f2)) {
605 return newTimesConstFunction(f1, 2.);
606 }
607 if (isZero(f1)) {
608 return f2;
609 }
610 if (isZero(f2)) {
611 return f1;
612 }
613 if (isConstant(f2)) {
614 return newPlusConstFunction(f1, f2->c());
615 }
616 if (isConstant(f1)) {
617 return newPlusConstFunction(f2, f1->c());
618 }
619 auto [prop, c] = isProportional(f1, f2);
620 if (prop) {
621 if (c == -1.) {
622 return make_shared<Const1>(0.);
623 }
624 return newTimesConstFunction(f1, c + 1.);
625 }
626 return make_shared<Sum1>(f1, f2);
627}
628
629shared_ptr<Func1> newDiffFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
630{
631 if (isZero(f2)) {
632 return f1;
633 }
634 if (isZero(f1)) {
635 return newTimesConstFunction(f2, -1.);
636 }
637 if (f1->isIdentical(f2)) {
638 return make_shared<Const1>(0.);
639 }
640 if (isConstant(f2)) {
641 return newPlusConstFunction(f1, -f2->c());
642 }
643 auto [prop, c] = isProportional(f1, f2);
644 if (prop) {
645 if (c == 1.0) {
646 return make_shared<Const1>(0.);
647 }
648 return newTimesConstFunction(f1, 1. - c);
649 }
650 return make_shared<Diff1>(f1, f2);
651}
652
653shared_ptr<Func1> newProdFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
654{
655 if (isOne(f1)) {
656 return f2;
657 }
658 if (isOne(f2)) {
659 return f1;
660 }
661 if (isZero(f1) || isZero(f2)) {
662 return make_shared<Const1>(0.);
663 }
664 if (isConstant(f1) && isConstant(f2)) {
665 return make_shared<Const1>(f1->c() * f2->c());
666 }
667 if (isConstant(f1)) {
668 return newTimesConstFunction(f2, f1->c());
669 }
670 if (isConstant(f2)) {
671 return newTimesConstFunction(f1, f2->c());
672 }
673 if (isPow(f1) && isPow(f2)) {
674 return make_shared<Pow1>(f1->c() + f2->c());
675 }
676 if (isExp(f1) && isExp(f2)) {
677 return make_shared<Exp1>(f1->c() + f2->c());
678 }
679
680 bool tc1 = isTimesConst(f1);
681 bool tc2 = isTimesConst(f2);
682
683 if (tc1 || tc2) {
684 double c1 = 1.0;
685 auto ff1 = f1;
686 if (tc1) {
687 c1 = f1->c();
688 ff1 = f1->func1_shared();
689 }
690 double c2 = 1.0;
691 auto ff2 = f2;
692 if (tc2) {
693 c2 = f2->c();
694 ff2 = f2->func1_shared();
695 }
696 auto p = newProdFunction(ff1, ff2);
697
698 if (c1 * c2 != 1.0) {
699 return newTimesConstFunction(p, c1 * c2);
700 }
701 return p;
702 }
703 return make_shared<Product1>(f1, f2);
704}
705
706shared_ptr<Func1> newRatioFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
707{
708 if (isOne(f2)) {
709 return f1;
710 }
711 if (isZero(f1)) {
712 return make_shared<Const1>(0.);
713 }
714 if (isZero(f2)) {
715 throw CanteraError("newRatioFunction", "Division by zero.");
716 }
717 if (f1->isIdentical(f2)) {
718 return make_shared<Const1>(1.);
719 }
720 if (isConstant(f2)) {
721 return newTimesConstFunction(f1, 1. / f2->c());
722 }
723 if (isPow(f1) && isPow(f2)) {
724 return make_shared<Pow1>(f1->c() - f2->c());
725 }
726 if (isExp(f1) && isExp(f2)) {
727 return make_shared<Exp1>(f1->c() - f2->c());
728 }
729 return make_shared<Ratio1>(f1, f2);
730}
731
732shared_ptr<Func1> newCompositeFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
733{
734 if (isZero(f1)) {
735 return make_shared<Const1>(0.0);
736 }
737 if (isConstant(f1)) {
738 return f1;
739 }
740 if (isPow(f1) && f1->c() == 1.0) {
741 return f2;
742 }
743 if (isPow(f1) && f1->c() == 0.0) {
744 return make_shared<Const1>(1.);
745 }
746 if (isPow(f1) && isPow(f2)) {
747 return make_shared<Pow1>(f1->c() * f2->c());
748 }
749 return make_shared<Composite1>(f1, f2);
750}
751
752shared_ptr<Func1> newTimesConstFunction(shared_ptr<Func1> f, double c)
753{
754 if (c == 0.0) {
755 return make_shared<Const1>(0.0);
756 }
757 if (c == 1.0) {
758 return f;
759 }
760 if (f->type() == "times-constant") {
761 return make_shared<TimesConstant1>(f->func1_shared(), f->c() * c);
762 }
763 return make_shared<TimesConstant1>(f, c);
764}
765
766shared_ptr<Func1> newPlusConstFunction(shared_ptr<Func1> f, double c)
767{
768 if (c == 0.0) {
769 return f;
770 }
771 if (isConstant(f)) {
772 return make_shared<Const1>(f->c() + c);
773 }
774 if (f->type() == "plus-constant") {
775 return make_shared<PlusConstant1>(f->func1_shared(), f->c() + c);
776 }
777 return make_shared<PlusConstant1>(f, c);
778}
779
780}
Base class for exceptions thrown by Cantera classes.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:505
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:499
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:440
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:111
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:117
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:488
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:137
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:146
string typeName() const
Returns a string with the class name of the functor.
Definition Func1.cpp:16
virtual shared_ptr< Func1 > derivative() const
Creates a derivative to the current function.
Definition Func1.cpp:33
virtual string type() const
Returns a string describing the type of the function.
Definition Func1.h:90
virtual double eval(double t) const
Evaluate the function.
Definition Func1.cpp:28
virtual string write(const string &arg) const
Write LaTeX string describing function.
Definition Func1.cpp:415
double operator()(double t) const
Calls method eval to evaluate the function.
Definition Func1.cpp:22
virtual bool isIdentical(shared_ptr< Func1 > other) const
Routine to determine if two functions are the same.
Definition Func1.cpp:39
virtual int order() const
Return the order of the function, if it makes sense.
Definition Func1.cpp:69
double c() const
Accessor function for the stored constant m_c.
Definition Func1.cpp:64
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:164
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:173
An error indicating that an unimplemented function has been called.
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:531
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:226
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:192
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:420
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:471
int order() const override
Return the order of the function, if it makes sense.
Definition Func1.h:500
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:458
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:450
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:445
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:94
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:85
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:477
double eval(double t) const override
Evaluate the function.
Definition Func1.cpp:364
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:387
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:435
void setMethod(const string &method)
Set the interpolation method.
Definition Func1.cpp:352
vector< double > m_tvec
Vector of time values.
Definition Func1.h:376
bool m_isLinear
Boolean indicating interpolation method.
Definition Func1.h:378
vector< double > m_fvec
Vector of function values.
Definition Func1.h:377
Tabulated1(size_t n, const double *tvals, const double *fvals, const string &method="linear")
Constructor.
Definition Func1.cpp:313
int order() const override
Return the order of the function, if it makes sense.
Definition Func1.h:531
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:512
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
shared_ptr< Func1 > newCompositeFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Composite of two functions.
Definition Func1.cpp:732
shared_ptr< Func1 > newProdFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Product of two functions.
Definition Func1.cpp:653
shared_ptr< Func1 > newDiffFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Difference of two functions.
Definition Func1.cpp:629
shared_ptr< Func1 > newTimesConstFunction(shared_ptr< Func1 > f, double c)
Product of function and constant.
Definition Func1.cpp:752
shared_ptr< Func1 > newSumFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Sum of two functions.
Definition Func1.cpp:602
shared_ptr< Func1 > newRatioFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Ratio of two functions.
Definition Func1.cpp:706
shared_ptr< Func1 > newPlusConstFunction(shared_ptr< Func1 > f, double c)
Sum of function and constant.
Definition Func1.cpp:766
string demangle(const std::type_info &type)
Convert a type name to a human readable string, using boost::core::demangle if available.
Definition global.cpp:213
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
Contains declarations for string manipulation functions within Cantera.