Cantera  4.0.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(span<const 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(span<const 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(span<const 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(span<const 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(span<const 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(span<const 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(span<const 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(span<const 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(span<const 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(span<const 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(span<const double> tvals, span<const double> fvals,
314 const string& method)
315{
316 if (tvals.size() != fvals.size()) {
317 throw CanteraError("Tabulated1::Tabulated1",
318 "Expected matching time/value lengths, got {} and {}.",
319 tvals.size(), fvals.size());
320 }
321 m_tvec.assign(tvals.begin(), tvals.end());
322 for (auto it = std::begin(m_tvec) + 1; it != std::end(m_tvec); it++) {
323 if (*(it - 1) > *it) {
324 throw CanteraError("Tabulated1::Tabulated1",
325 "time values are not increasing monotonically.");
326 }
327 }
328 m_fvec.assign(fvals.begin(), fvals.end());
329 setMethod(method);
330}
331
332Tabulated1::Tabulated1(span<const double> params) : m_isLinear(true)
333{
334 if (params.size() < 4) {
335 throw CanteraError("Tabulated1::Tabulated1",
336 "Constructor needs an array with at least 4 entries.");
337 }
338 if (params.size() % 2 != 0) {
339 throw CanteraError("Tabulated1::Tabulated1",
340 "Constructor needs an array with an even number of entries.");
341 }
342 size_t n = params.size() / 2;
343 m_tvec.assign(params.data(), params.data() + n);
344 for (auto it = std::begin(m_tvec) + 1; it != std::end(m_tvec); it++) {
345 if (*(it - 1) > *it) {
346 throw CanteraError("Tabulated1::Tabulated1",
347 "Time values are not monotonically increasing.");
348 }
349 }
350 m_fvec.assign(params.data() + n, params.data() + 2 * n);
351}
352
353void Tabulated1::setMethod(const string& method)
354{
355 if (method == "linear") {
356 m_isLinear = true;
357 } else if (method == "previous") {
358 m_isLinear = false;
359 } else {
360 throw NotImplementedError("Tabulated1::setMethod",
361 "Interpolation method '{}' is not implemented.", method);
362 }
363}
364
365double Tabulated1::eval(double t) const {
366 size_t siz = m_tvec.size();
367 // constructor ensures that siz > 0
368 if (t <= m_tvec[0]) {
369 return m_fvec[0];
370 } else if (t >= m_tvec[siz-1]) {
371 return m_fvec[siz-1];
372 } else {
373 size_t ix = 0;
374 while (t > m_tvec[ix+1]) {
375 ix++;
376 }
377 if (m_isLinear) {
378 double df = m_fvec[ix+1] - m_fvec[ix];
379 df /= m_tvec[ix+1] - m_tvec[ix];
380 df *= t - m_tvec[ix];
381 return m_fvec[ix] + df;
382 } else {
383 return m_fvec[ix];
384 }
385 }
386}
387
388shared_ptr<Func1> Tabulated1::derivative() const {
389 vector<double> tvec;
390 vector<double> dvec;
391 size_t siz = m_tvec.size();
392 if (m_isLinear) {
393 // piece-wise continuous derivative
394 if (siz>1) {
395 for (size_t i=1; i<siz; i++) {
396 double d = (m_fvec[i] - m_fvec[i-1]) /
397 (m_tvec[i] - m_tvec[i-1]);
398 tvec.push_back(m_tvec[i-1]);
399 dvec.push_back(d);
400 }
401 }
402 tvec.push_back(m_tvec[siz-1]);
403 dvec.push_back(0.);
404 } else {
405 // derivative is zero (ignoring discontinuities)
406 tvec.push_back(m_tvec[0]);
407 tvec.push_back(m_tvec[siz-1]);
408 dvec.push_back(0.);
409 dvec.push_back(0.);
410 }
411 return make_shared<Tabulated1>(tvec, dvec, "previous");
412}
413
414/******************************************************************************/
415
416string Func1::write(const string& arg) const
417{
418 return fmt::format("\\mathrm{{{}}}({})", type(), arg);
419}
420
421string Pow1::write(const string& arg) const
422{
423 if (m_c == 0.5) {
424 return "\\sqrt{" + arg + "}";
425 }
426 if (m_c == -0.5) {
427 return "\\frac{1}{\\sqrt{" + arg + "}}";
428 }
429 if (m_c != 1.0) {
430 return fmt::format("\\left({}\\right)^{{{}}}", arg, m_c);
431 } else {
432 return arg;
433 }
434}
435
436string Tabulated1::write(const string& arg) const
437{
438 return fmt::format("\\mathrm{{Tabulated}}({})", arg);
439}
440
441string Const1::write(const string& arg) const
442{
443 return fmt::format("{}", m_c);
444}
445
446string Ratio1::write(const string& arg) const
447{
448 return "\\frac{" + m_f1->write(arg) + "}{" + m_f2->write(arg) + "}";
449}
450
451shared_ptr<Func1> Ratio1::derivative() const {
452 auto a1 = newProdFunction(m_f1->derivative(), m_f2);
453 auto a2 = newProdFunction(m_f1, m_f2->derivative());
454 auto s = newDiffFunction(a1, a2);
455 auto p = newProdFunction(m_f2, m_f2);
456 return newRatioFunction(s, p);
457}
458
459string Product1::write(const string& arg) const
460{
461 string s = m_f1->write(arg);
462 if (m_f1->order() < order()) {
463 s = "\\left(" + s + "\\right)";
464 }
465 string s2 = m_f2->write(arg);
466 if (m_f2->order() < order()) {
467 s2 = "\\left(" + s2 + "\\right)";
468 }
469 return s + " " + s2;
470}
471
472shared_ptr<Func1> Product1::derivative() const {
473 auto a1 = newProdFunction(m_f1, m_f2->derivative());
474 auto a2 = newProdFunction(m_f2, m_f1->derivative());
475 return newSumFunction(a1, a2);
476}
477
478string Sum1::write(const string& arg) const
479{
480 string s1 = m_f1->write(arg);
481 string s2 = m_f2->write(arg);
482 if (s2[0] == '-') {
483 return s1 + " - " + s2.substr(1,s2.size());
484 } else {
485 return s1 + " + " + s2;
486 }
487}
488
489string Diff1::write(const string& arg) const
490{
491 string s1 = m_f1->write(arg);
492 string s2 = m_f2->write(arg);
493 if (s2[0] == '-') {
494 return s1 + " + " + s2.substr(1,s2.size());
495 } else {
496 return s1 + " - " + s2;
497 }
498}
499
500string Composite1::write(const string& arg) const
501{
502 string g = m_f2->write(arg);
503 return m_f1->write(g);
504}
505
506shared_ptr<Func1> Composite1::derivative() const {
507 auto d1 = m_f1->derivative();
508 auto d2 = m_f2->derivative();
509 auto d3 = newCompositeFunction(d1, m_f2);
510 return newProdFunction(d3, d2);
511}
512
513string TimesConstant1::write(const string& arg) const
514{
515 string s = m_f1->write(arg);
516 if (m_f1->order() < order()) {
517 s = "\\left(" + s + "\\right)";
518 }
519 if (m_c == 1.0) {
520 return s;
521 }
522 if (m_c == -1.0) {
523 return "-"+s;
524 }
525 char n = s[0];
526 if (n >= '0' && n <= '9') {
527 s = "\\left(" + s + "\\right)";
528 }
529 return fmt::format("{}{}", m_c, s);
530}
531
532string PlusConstant1::write(const string& arg) const
533{
534 if (m_c == 0.0) {
535 return m_f1->write(arg);
536 }
537 return fmt::format("{} + {}", m_f1->write(arg), m_c);
538}
539
540namespace { // restrict scope of helper functions to local translation unit
541
542bool isConstant(const shared_ptr<Func1>& f)
543{
544 return f->type() == "constant";
545}
546
547bool isZero(const shared_ptr<Func1>& f)
548{
549 return f->type() == "constant" && f->c() == 0.0;
550}
551
552bool isOne(const shared_ptr<Func1>& f)
553{
554 return f->type() == "constant" && f->c() == 1.0;
555}
556
557bool isTimesConst(const shared_ptr<Func1>& f)
558{
559 return f->type() == "times-constant";
560}
561
562bool isExp(const shared_ptr<Func1>& f)
563{
564 return f->type() == "exp";
565}
566
567bool isPow(const shared_ptr<Func1>& f)
568{
569 return f->type() == "pow";
570}
571
572pair<bool, double> isProportional(
573 const shared_ptr<Func1>&f1, const shared_ptr<Func1>&f2)
574{
575 bool tc1 = isTimesConst(f1);
576 bool tc2 = isTimesConst(f2);
577 if (!tc1 && !tc2) {
578 if (f1->isIdentical(f2)) {
579 return {true, 1.0};
580 }
581 return {false, 0.};
582 }
583 if (!tc1 && tc2) {
584 if (f1->isIdentical((f2->func1_shared()))) {
585 return {true, f2->c()};
586 }
587 return {false, 0.};
588 }
589 if (tc1 && !tc2) {
590 if (f2->isIdentical((f1->func1_shared()))) {
591 return {true, 1. / f1->c()};
592 }
593 return {false, 0.};
594 }
595 if (f2->func1_shared()->isIdentical((f1->func1_shared()))) {
596 return {true, f2->c() / f1->c()};
597 }
598 return {false, 0.};
599}
600
601} // end unnamed namespace
602
603shared_ptr<Func1> newSumFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
604{
605 if (f1->isIdentical(f2)) {
606 return newTimesConstFunction(f1, 2.);
607 }
608 if (isZero(f1)) {
609 return f2;
610 }
611 if (isZero(f2)) {
612 return f1;
613 }
614 if (isConstant(f2)) {
615 return newPlusConstFunction(f1, f2->c());
616 }
617 if (isConstant(f1)) {
618 return newPlusConstFunction(f2, f1->c());
619 }
620 auto [prop, c] = isProportional(f1, f2);
621 if (prop) {
622 if (c == -1.) {
623 return make_shared<Const1>(0.);
624 }
625 return newTimesConstFunction(f1, c + 1.);
626 }
627 return make_shared<Sum1>(f1, f2);
628}
629
630shared_ptr<Func1> newDiffFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
631{
632 if (isZero(f2)) {
633 return f1;
634 }
635 if (isZero(f1)) {
636 return newTimesConstFunction(f2, -1.);
637 }
638 if (f1->isIdentical(f2)) {
639 return make_shared<Const1>(0.);
640 }
641 if (isConstant(f2)) {
642 return newPlusConstFunction(f1, -f2->c());
643 }
644 auto [prop, c] = isProportional(f1, f2);
645 if (prop) {
646 if (c == 1.0) {
647 return make_shared<Const1>(0.);
648 }
649 return newTimesConstFunction(f1, 1. - c);
650 }
651 return make_shared<Diff1>(f1, f2);
652}
653
654shared_ptr<Func1> newProdFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
655{
656 if (isOne(f1)) {
657 return f2;
658 }
659 if (isOne(f2)) {
660 return f1;
661 }
662 if (isZero(f1) || isZero(f2)) {
663 return make_shared<Const1>(0.);
664 }
665 if (isConstant(f1) && isConstant(f2)) {
666 return make_shared<Const1>(f1->c() * f2->c());
667 }
668 if (isConstant(f1)) {
669 return newTimesConstFunction(f2, f1->c());
670 }
671 if (isConstant(f2)) {
672 return newTimesConstFunction(f1, f2->c());
673 }
674 if (isPow(f1) && isPow(f2)) {
675 return make_shared<Pow1>(f1->c() + f2->c());
676 }
677 if (isExp(f1) && isExp(f2)) {
678 return make_shared<Exp1>(f1->c() + f2->c());
679 }
680
681 bool tc1 = isTimesConst(f1);
682 bool tc2 = isTimesConst(f2);
683
684 if (tc1 || tc2) {
685 double c1 = 1.0;
686 auto ff1 = f1;
687 if (tc1) {
688 c1 = f1->c();
689 ff1 = f1->func1_shared();
690 }
691 double c2 = 1.0;
692 auto ff2 = f2;
693 if (tc2) {
694 c2 = f2->c();
695 ff2 = f2->func1_shared();
696 }
697 auto p = newProdFunction(ff1, ff2);
698
699 if (c1 * c2 != 1.0) {
700 return newTimesConstFunction(p, c1 * c2);
701 }
702 return p;
703 }
704 return make_shared<Product1>(f1, f2);
705}
706
707shared_ptr<Func1> newRatioFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
708{
709 if (isOne(f2)) {
710 return f1;
711 }
712 if (isZero(f1)) {
713 return make_shared<Const1>(0.);
714 }
715 if (isZero(f2)) {
716 throw CanteraError("newRatioFunction", "Division by zero.");
717 }
718 if (f1->isIdentical(f2)) {
719 return make_shared<Const1>(1.);
720 }
721 if (isConstant(f2)) {
722 return newTimesConstFunction(f1, 1. / f2->c());
723 }
724 if (isPow(f1) && isPow(f2)) {
725 return make_shared<Pow1>(f1->c() - f2->c());
726 }
727 if (isExp(f1) && isExp(f2)) {
728 return make_shared<Exp1>(f1->c() - f2->c());
729 }
730 return make_shared<Ratio1>(f1, f2);
731}
732
733shared_ptr<Func1> newCompositeFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2)
734{
735 if (isZero(f1)) {
736 return make_shared<Const1>(0.0);
737 }
738 if (isConstant(f1)) {
739 return f1;
740 }
741 if (isPow(f1) && f1->c() == 1.0) {
742 return f2;
743 }
744 if (isPow(f1) && f1->c() == 0.0) {
745 return make_shared<Const1>(1.);
746 }
747 if (isPow(f1) && isPow(f2)) {
748 return make_shared<Pow1>(f1->c() * f2->c());
749 }
750 return make_shared<Composite1>(f1, f2);
751}
752
753shared_ptr<Func1> newTimesConstFunction(shared_ptr<Func1> f, double c)
754{
755 if (c == 0.0) {
756 return make_shared<Const1>(0.0);
757 }
758 if (c == 1.0) {
759 return f;
760 }
761 if (f->type() == "times-constant") {
762 return make_shared<TimesConstant1>(f->func1_shared(), f->c() * c);
763 }
764 return make_shared<TimesConstant1>(f, c);
765}
766
767shared_ptr<Func1> newPlusConstFunction(shared_ptr<Func1> f, double c)
768{
769 if (c == 0.0) {
770 return f;
771 }
772 if (isConstant(f)) {
773 return make_shared<Const1>(f->c() + c);
774 }
775 if (f->type() == "plus-constant") {
776 return make_shared<PlusConstant1>(f->func1_shared(), f->c() + c);
777 }
778 return make_shared<PlusConstant1>(f, c);
779}
780
781}
Arrhenius1(span< const double > params)
Constructor uses parameters in the following order: .
Definition Func1.cpp:291
Base class for exceptions thrown by Cantera classes.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:506
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:500
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:441
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:489
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:416
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:532
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:226
Poly1(span< const double > params)
Constructor uses parameters in the following order: .
Definition Func1.cpp:215
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:421
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:472
int order() const override
Return the order of the function, if it makes sense.
Definition Func1.h:499
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:459
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:451
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:446
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:478
double eval(double t) const override
Evaluate the function.
Definition Func1.cpp:365
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:388
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:436
void setMethod(const string &method)
Set the interpolation method.
Definition Func1.cpp:353
vector< double > m_tvec
Vector of time values.
Definition Func1.h:375
bool m_isLinear
Boolean indicating interpolation method.
Definition Func1.h:377
vector< double > m_fvec
Vector of function values.
Definition Func1.h:376
Tabulated1(span< const double > tvals, span< 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:530
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:513
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:733
shared_ptr< Func1 > newProdFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Product of two functions.
Definition Func1.cpp:654
shared_ptr< Func1 > newDiffFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Difference of two functions.
Definition Func1.cpp:630
shared_ptr< Func1 > newTimesConstFunction(shared_ptr< Func1 > f, double c)
Product of function and constant.
Definition Func1.cpp:753
shared_ptr< Func1 > newSumFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Sum of two functions.
Definition Func1.cpp:603
shared_ptr< Func1 > newRatioFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Ratio of two functions.
Definition Func1.cpp:707
shared_ptr< Func1 > newPlusConstFunction(shared_ptr< Func1 > f, double c)
Sum of function and constant.
Definition Func1.cpp:767
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.