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