Cantera  3.2.0a1
Loading...
Searching...
No Matches
Func1.h
Go to the documentation of this file.
1/**
2 * @file Func1.h
3 */
4
5// This file is part of Cantera. See License.txt in the top-level directory or
6// at https://cantera.org/license.txt for license and copyright information.
7
8#ifndef CT_FUNC1_H
9#define CT_FUNC1_H
10
13
14#include <iostream>
15
16namespace Cantera
17{
18
19class TimesConstant1;
20
21//! @defgroup func1 Functor Objects
22//! Functors implement functions of a single variable @f$ f(x) @f$.
23//! Functor objects can be combined to form compound expressions, which allows for
24//! the implementation of generic mathematical expressions.
25//! @ingroup numerics
26
27//! @defgroup func1basic Basic Functors
28//! Basic functors implement standard mathematical expressions with a single
29//! parameter.
30//! The following simple functor types are implemented:
31//! - @c "sin" (class Sin1), @c "cos" (class Cos1),
32//! - @c "exp" (class Exp1), @c "log" (class Log1),
33//! - @c "pow" (class Pow1),
34//! - @c "constant" (class Const1).
35//! @ingroup func1
36
37//! @defgroup func1advanced Advanced Functors
38//! Advanced functors implement expressions that require multiple parameters.
39//! The following advanced functor types are implemented:
40//! - @c "tabulated-linear" and @c "tabulated-previous" (class Tabulated1),
41//! - @c "polynomial3" (class Poly1),
42//! - @c "Fourier" (class Fourier1),
43//! - @c "Gaussian" (class Gaussian1),
44//! - @c "Arrhenius" (class Arrhenius1).
45//! @ingroup func1
46
47//! @defgroup func1compound Compound Functors
48//! Compound functors implement expressions that are composed of other functors.
49//! The following compound functor types are implemented:
50//! - @c "sum" (class Sum1),
51//! - @c "diff" (class Diff1),
52//! - @c "product" (class Product1),
53//! - @c "ratio" (class Ratio1),
54//! - @c "composite" (class Composite1),
55//! @ingroup func1
56
57//! @defgroup func1modified Modified Functors
58//! Modified functors implement expressions that involve one functor and
59//! a single parameter.
60//! The following modified functor types are implemented:
61//! - @c "times-constant" (class TimesConstant1),
62//! - @c "plus-constant" (class PlusConstant1),
63//! - @c "periodic" (class Periodic1).
64//! @ingroup func1
65
66//! @defgroup func1helper Helper Functions
67//! Helper functions detect simplifications that can be made to compound expressions.
68//! @ingroup func1
69
70/**
71 * Base class for 'functor' classes that evaluate a function of one variable.
72 * @ingroup func1
73 */
74class Func1
75{
76public:
77 Func1() = default;
78
79 Func1(shared_ptr<Func1> f1, shared_ptr<Func1> f2) : m_f1(f1), m_f2(f2) {}
80
81 Func1(shared_ptr<Func1> f1, double A) : m_c(A), m_f1(f1) {}
82
83 virtual ~Func1() = default;
84
85 Func1(const Func1& right) = delete;
86 Func1& operator=(const Func1& right) = delete;
87
88 //! Returns a string describing the type of the function
89 //! @since New in %Cantera 3.0.
90 virtual string type() const {
91 return "functor";
92 }
93
94 //! Returns a string with the class name of the functor
95 //! @since New in %Cantera 3.0.
96 string typeName() const;
97
98 //! Calls method eval to evaluate the function
99 double operator()(double t) const;
100
101 //! Evaluate the function.
102 virtual double eval(double t) const;
103
104 //! Creates a derivative to the current function
105 /*!
106 * @return shared pointer to new derivative function.
107 * @since Starting in %Cantera 3.1, the return type is a `shared_ptr`.
108 */
109 virtual shared_ptr<Func1> derivative() const;
110
111 //! Routine to determine if two functions are the same.
112 /*!
113 * Two functions are the same if they are the same function. For example, either
114 * ID and stored constant are the same, or the #m_f1 and #m_f2 are identical if they
115 * are non-null. Functors of the base class Func1 are by default not identical, as
116 * they are used by callback functions that cannot be differentiated. In instances
117 * where exact comparisons are not implemented, `false` is returned to prevent false
118 * positives that could lead to incorrect simplifications of compound functors.
119 */
120 virtual bool isIdentical(shared_ptr<Func1> other) const;
121
122 //! Write LaTeX string describing function.
123 virtual string write(const string& arg) const;
124
125 //! Accessor function for the stored constant #m_c.
126 double c() const;
127
128 //! Accessor function for #m_f1.
129 //! @since New in %Cantera 3.0.
130 shared_ptr<Func1> func1_shared() const {
131 return m_f1;
132 }
133
134 //! Accessor function for #m_f2.
135 //! @since New in %Cantera 3.0.
136 shared_ptr<Func1> func2_shared() const {
137 return m_f2;
138 }
139
140 //! Return the order of the function, if it makes sense
141 virtual int order() const;
142
143protected:
144 double m_c = 0.0;
145 shared_ptr<Func1> m_f1;
146 shared_ptr<Func1> m_f2;
147};
148
149//! Sum of two functions.
150//! @ingroup func1helper
151shared_ptr<Func1> newSumFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2);
152
153//! Difference of two functions.
154//! @ingroup func1helper
155shared_ptr<Func1> newDiffFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2);
156
157//! Product of two functions.
158//! @ingroup func1helper
159shared_ptr<Func1> newProdFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2);
160
161//! Ratio of two functions.
162//! @ingroup func1helper
163shared_ptr<Func1> newRatioFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2);
164
165//! Composite of two functions.
166//! @ingroup func1helper
167shared_ptr<Func1> newCompositeFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2);
168
169//! Product of function and constant.
170//! @ingroup func1helper
171shared_ptr<Func1> newTimesConstFunction(shared_ptr<Func1> f1, double c);
172
173//! Sum of function and constant.
174//! @ingroup func1helper
175shared_ptr<Func1> newPlusConstFunction(shared_ptr<Func1> f1, double c);
176
177//! Implements the @c sin() function.
178/*!
179 * The functor class with type @c "sin" returns @f$ f(x) = \sin(\omega x) @f$,
180 * where the argument @f$ x @f$ is in radians.
181 * @param omega Frequency @f$ \omega @f$ (default=1.0)
182 * @ingroup func1basic
183 */
184class Sin1 : public Func1
185{
186public:
187 Sin1(double omega=1.0) {
188 m_c = omega;
189 }
190
191 //! Constructor uses single parameter (frequency)
192 Sin1(const vector<double>& params);
193
194 string write(const string& arg) const override;
195
196 string type() const override {
197 return "sin";
198 }
199
200 double eval(double t) const override{
201 return sin(m_c*t);
202 }
203
204 shared_ptr<Func1> derivative() const override;
205};
206
207
208//! Implements the @c cos() function.
209/*!
210 * The functor class with type @c "cos" returns @f$ f(x) = \cos(\omega x) @f$,
211 * where the argument @f$ x @f$ is in radians.
212 * @param omega Frequency @f$ \omega @f$ (default=1.0)
213 * @ingroup func1basic
214 */
215class Cos1 : public Func1
216{
217public:
218 Cos1(double omega=1.0) {
219 m_c = omega;
220 }
221
222 //! Constructor uses single parameter (frequency)
223 Cos1(const vector<double>& params);
224
225 string write(const string& arg) const override;
226
227 string type() const override {
228 return "cos";
229 }
230
231 double eval(double t) const override {
232 return cos(m_c * t);
233 }
234 shared_ptr<Func1> derivative() const override;
235};
236
237
238//! Implements the @c exp() (exponential) function.
239/*!
240 * The functor class with type @c "exp" returns @f$ f(x) = \exp(a x) @f$.
241 * @param a Factor (default=1.0)
242 * @ingroup func1basic
243 */
244class Exp1 : public Func1
245{
246public:
247 Exp1(double a=1.0) {
248 m_c = a;
249 }
250
251 //! Constructor uses single parameter (exponent factor)
252 Exp1(const vector<double>& params);
253
254 string write(const string& arg) const override;
255
256 string type() const override {
257 return "exp";
258 }
259
260 double eval(double t) const override {
261 return exp(m_c*t);
262 }
263
264 shared_ptr<Func1> derivative() const override;
265};
266
267
268//! Implements the @c log() (natural logarithm) function.
269/*!
270 * The functor class with type @c "log" returns @f$ f(x) = \ln(a x) @f$.
271 * @param a Factor (default=1.0)
272 * @ingroup func1basic
273 * @since New in %Cantera 3.0
274 */
275class Log1 : public Func1
276{
277public:
278 Log1(double a=1.0) {
279 m_c = a;
280 }
281
282 //! Constructor uses single parameter (factor)
283 Log1(const vector<double>& params);
284
285 string type() const override {
286 return "log";
287 }
288
289 double eval(double t) const override {
290 return log(m_c * t);
291 }
292
293 shared_ptr<Func1> derivative() const override;
294
295 string write(const string& arg) const override;
296};
297
298//! Implements the @c pow() (power) function.
299/*!
300 * The functor class with type @c "pow" returns @f$ f(x) = x^n @f$.
301 * @param n Exponent
302 * @ingroup func1basic
303 */
304class Pow1 : public Func1
305{
306public:
307 Pow1(double n) {
308 m_c = n;
309 }
310
311 //! Constructor uses single parameter (exponent)
312 Pow1(const vector<double>& params);
313
314 string write(const string& arg) const override;
315
316 string type() const override {
317 return "pow";
318 }
319
320 double eval(double t) const override {
321 return pow(t, m_c);
322 }
323 shared_ptr<Func1> derivative() const override;
324};
325
326//! Implements a tabulated function.
327/*!
328 * The functor class is based on tabulated arrays @c tvals and @c fvals, where
329 * @c tvals contain independent variables and @c fvals are corresponding function
330 * values. Depending on configuration, the function is either interpolated linearly
331 * between the tabulated points (type @c "tabulated-linear" ; default), or yields
332 * the last tabulated value until a new tabulated time value is reached (type
333 * @c "tabulated-previous" ).
334 * @ingroup func1advanced
335 */
336class Tabulated1 : public Func1
337{
338public:
339 //! Constructor.
340 /*!
341 * @param n Size of tabulated value arrays
342 * @param tvals Pointer to time value array
343 * @param fvals Pointer to function value array
344 * @param method Interpolation method ('linear' or 'previous')
345 */
346 Tabulated1(size_t n, const double* tvals, const double* fvals,
347 const string& method="linear");
348
349 //! Constructor uses @f$ 2 n @f$ parameters in the following order:
350 //! @f$ [t_0, t_1, \dots, t_{n-1}, f_0, f_1, \dots, f_{n-1}] @f$
351 Tabulated1(const vector<double>& params);
352
353 //! Set the interpolation method
354 //! @param method Evaluation method. If @c "linear" (default), a linear
355 //! interpolation between tabulated values is used; if @c "previous", the
356 //! last tabulated value is held until a new tabulated time value is reached.
357 //! @since New in %Cantera 3.0
358 void setMethod(const string& method);
359
360 bool isIdentical(shared_ptr<Func1> other) const override {
361 return false; // base class check is insufficient
362 }
363
364 string write(const string& arg) const override;
365
366 string type() const override {
367 if (m_isLinear) {
368 return "tabulated-linear";
369 }
370 return "tabulated-previous";
371 }
372
373 double eval(double t) const override;
374 shared_ptr<Func1> derivative() const override;
375private:
376 vector<double> m_tvec; //!< Vector of time values
377 vector<double> m_fvec; //!< Vector of function values
378 bool m_isLinear; //!< Boolean indicating interpolation method
379};
380
381
382//! Implements a constant.
383/*!
384 * The functor class with type @c "constant" returns @f$ f(x) = a @f$.
385 * @param a Constant
386 * @ingroup func1basic
387 */
388class Const1 : public Func1
389{
390public:
391 Const1(double a) {
392 m_c = a;
393 }
394
395 //! Constructor uses single parameter (constant)
396 Const1(const vector<double>& params);
397
398 string write(const string& arg) const override;
399
400 string type() const override {
401 return "constant";
402 }
403
404 double eval(double t) const override {
405 return m_c;
406 }
407 shared_ptr<Func1> derivative() const override {
408 return make_shared<Const1>(0.0);
409 }
410};
411
412
413/**
414 * Implements the sum of two functions.
415 * The functor class with type @c "sum" returns @f$ f(x) = f_1(x) + f_2(x) @f$.
416 * @param f1 Functor @f$ f_1(x) @f$
417 * @param f2 Functor @f$ f_2(x) @f$
418 * @ingroup func1compound
419 */
420class Sum1 : public Func1
421{
422public:
423 Sum1(shared_ptr<Func1> f1, shared_ptr<Func1> f2) : Func1(f1, f2) {}
424
425 string type() const override {
426 return "sum";
427 }
428
429 double eval(double t) const override {
430 return m_f1->eval(t) + m_f2->eval(t);
431 }
432
433 shared_ptr<Func1> derivative() const override {
434 return newSumFunction(m_f1->derivative(), m_f2->derivative());
435 }
436
437 int order() const override {
438 return 0;
439 }
440
441 string write(const string& arg) const override;
442};
443
444/**
445 * Implements the difference of two functions.
446 * The functor class with type @c "diff" returns @f$ f(x) = f_1(x) - f_2(x) @f$.
447 * @param f1 Functor @f$ f_1(x) @f$
448 * @param f2 Functor @f$ f_2(x) @f$
449 * @ingroup func1compound
450 */
451class Diff1 : public Func1
452{
453public:
454 Diff1(shared_ptr<Func1> f1, shared_ptr<Func1> f2) : Func1(f1, f2) {}
455
456 string type() const override {
457 return "diff";
458 }
459
460 double eval(double t) const override {
461 return m_f1->eval(t) - m_f2->eval(t);
462 }
463
464 shared_ptr<Func1> derivative() const override {
465 return newDiffFunction(m_f1->derivative(), m_f2->derivative());
466 }
467
468 int order() const override {
469 return 0;
470 }
471
472 string write(const string& arg) const override;
473};
474
475
476/**
477 * Implements the product of two functions.
478 * The functor class with type @c "product" returns @f$ f(x) = f_1(x) f_2(x) @f$.
479 * @param f1 Functor @f$ f_1(x) @f$
480 * @param f2 Functor @f$ f_2(x) @f$
481 * @ingroup func1compound
482 */
483class Product1 : public Func1
484{
485public:
486 Product1(shared_ptr<Func1> f1, shared_ptr<Func1> f2) : Func1(f1, f2) {}
487
488 string type() const override {
489 return "product";
490 }
491
492 string write(const string& arg) const override;
493
494 double eval(double t) const override {
495 return m_f1->eval(t) * m_f2->eval(t);
496 }
497
498 shared_ptr<Func1> derivative() const override;
499
500 int order() const override {
501 return 1;
502 }
503};
504
505/**
506 * Implements the product of a function and a constant.
507 * The functor class with type @c "times-constant" returns @f$ f(x) = a f_1(x) @f$.
508 * @param f1 Functor @f$ f_1(x) @f$
509 * @param a Constant @f$ a @f$
510 * @ingroup func1modified
511 */
512class TimesConstant1 : public Func1
513{
514public:
515 TimesConstant1(shared_ptr<Func1> f1, double a) : Func1(f1, a) {}
516
517 string type() const override {
518 return "times-constant";
519 }
520
521 double eval(double t) const override {
522 return m_f1->eval(t) * m_c;
523 }
524
525 shared_ptr<Func1> derivative() const override {
526 return newTimesConstFunction(m_f1->derivative(), m_c);
527 }
528
529 string write(const string& arg) const override;
530
531 int order() const override {
532 return 0;
533 }
534};
535
536/**
537 * Implements the sum of a function and a constant.
538 * The functor class with type @c "plus-constant" returns @f$ f(x) = f_1(x) + a @f$.
539 * @param f1 Functor @f$ f_1(x) @f$
540 * @param a Constant @f$ a @f$
541 * @ingroup func1modified
542 */
543class PlusConstant1 : public Func1
544{
545public:
546 PlusConstant1(shared_ptr<Func1> f1, double a) : Func1(f1, a) {}
547
548 string type() const override {
549 return "plus-constant";
550 }
551
552 double eval(double t) const override {
553 return m_f1->eval(t) + m_c;
554 }
555
556 shared_ptr<Func1> derivative() const override {
557 return m_f1->derivative();
558 }
559
560 string write(const string& arg) const override;
561
562 int order() const override {
563 return 0;
564 }
565};
566
567
568/**
569 * Implements the ratio of two functions.
570 * The functor class with type @c "ratio" returns @f$ f(x) = f_1(x) / f_2(x) @f$.
571 * @param f1 Functor @f$ f_1(x) @f$
572 * @param f2 Functor @f$ f_2(x) @f$
573 * @ingroup func1compound
574 */
575class Ratio1 : public Func1
576{
577public:
578 Ratio1(shared_ptr<Func1> f1, shared_ptr<Func1> f2) : Func1(f1, f2) {}
579
580 string type() const override {
581 return "ratio";
582 }
583
584 double eval(double t) const override {
585 return m_f1->eval(t) / m_f2->eval(t);
586 }
587
588 shared_ptr<Func1> derivative() const override;
589
590 string write(const string& arg) const override;
591
592 int order() const override {
593 return 1;
594 }
595};
596
597/**
598 * Implements a composite function.
599 * The functor class with type @c "composite" returns @f$ f(x) = f_1\left(f_2(x)\right) @f$.
600 * @param f1 Functor @f$ f_1(x) @f$
601 * @param f2 Functor @f$ f_2(x) @f$
602 * @ingroup func1compound
603 */
604class Composite1 : public Func1
605{
606public:
607 Composite1(shared_ptr<Func1> f1, shared_ptr<Func1> f2) : Func1(f1, f2) {}
608
609 string type() const override {
610 return "composite";
611 }
612
613 double eval(double t) const override {
614 return m_f1->eval(m_f2->eval(t));
615 }
616
617 shared_ptr<Func1> derivative() const override;
618
619 string write(const string& arg) const override;
620
621 int order() const override {
622 return 2;
623 }
624};
625
626// The functors below are the old-style ones. They still work,
627// but can't do derivatives.
628
629/**
630 * Implements a Gaussian function.
631 * The functor class with type @c "Gaussian" returns
632 * @f[
633 * f(t) = A e^{-[(t - t_0)/\tau]^2}
634 * @f]
635 * where @f$ \tau = \mathrm{fwhm} / (2 \sqrt{\ln 2}) @f$.
636 * @param A peak value
637 * @param t0 offset
638 * @param fwhm full width at half max
639 * @ingroup func1advanced
640 * @since New in %Cantera 3.0.
641 */
642class Gaussian1 : public Func1
643{
644public:
645 Gaussian1(double A, double t0, double fwhm) {
646 m_A = A;
647 m_t0 = t0;
648 m_tau = fwhm/(2.0*std::sqrt(std::log(2.0)));
649 }
650
651 //! Constructor uses 3 parameters in the following order:
652 //! @f$ [A, t_0, \mathrm{fwhm}] @f$
653 Gaussian1(const vector<double>& params);
654
655 string type() const override {
656 return "Gaussian";
657 }
658
659 bool isIdentical(shared_ptr<Func1> other) const override {
660 return false; // base class check is insufficient
661 }
662
663 double eval(double t) const override {
664 double x = (t - m_t0)/m_tau;
665 return m_A * std::exp(-x*x);
666 }
667
668protected:
669 double m_A, m_t0, m_tau;
670};
671
672
673/**
674 * Implements a polynomial of degree @e n.
675 * The functor class with type @c "polynomial3" returns
676 * @f[
677 * f(x) = a_n x^n + \dots + a_1 x + a_0
678 * @f]
679 * with coefficients provided in the order @f$ [a_n, \dots, a_1, a_0] @f$ (consistent
680 * with MATLAB and NumPy conventions). Note that %Cantera 3.1 reversed the coefficient
681 * order with respect to its earlier definition.
682 * @since Changed in %Cantera 3.1.
683 * @ingroup func1advanced
684 */
685class Poly1 : public Func1
686{
687public:
688 Poly1(size_t n, const double* c) {
689 m_cpoly.resize(n+1);
690 std::copy(c, c+m_cpoly.size(), m_cpoly.begin());
691 }
692
693 //! Constructor uses @f$ n + 1 @f$ parameters in the following order:
694 //! @f$ [a_n, \dots, a_1, a_0] @f$
695 Poly1(const vector<double>& params);
696
697 string type() const override {
698 return "polynomial3";
699 }
700
701 bool isIdentical(shared_ptr<Func1> other) const override {
702 return false; // base class check is insufficient
703 }
704
705 double eval(double t) const override {
706 double r = m_cpoly[0];
707 for (size_t n = 1; n < m_cpoly.size(); n++) {
708 r *= t;
709 r += m_cpoly[n];
710 }
711 return r;
712 }
713
714 string write(const string& arg) const override;
715
716protected:
717 vector<double> m_cpoly;
718};
719
720
721/**
722 * Implements a Fourier cosine/sine series.
723 * The functor class with type @c "Fourier" returns
724 * @f[
725 * f(t) = \frac{a_0}{2} + \sum_{n=1}^N a_n \cos (n \omega t) + b_n \sin (n \omega t)
726 * @f]
727 * @ingroup func1advanced
728 */
729class Fourier1 : public Func1
730{
731public:
732 Fourier1(size_t n, double omega, double a0, const double* a, const double* b) {
733 m_omega = omega;
734 m_a0_2 = 0.5*a0;
735 m_ccos.resize(n);
736 m_csin.resize(n);
737 std::copy(a, a+n, m_ccos.begin());
738 std::copy(b, b+n, m_csin.begin());
739 }
740
741 //! Constructor uses @f$ 2 n + 2 @f$ parameters in the following order:
742 //! @f$ [a_0, a_1, \dots, a_n, \omega, b_1, \dots, b_n] @f$
743 Fourier1(const vector<double>& params);
744
745 string type() const override {
746 return "Fourier";
747 }
748
749 bool isIdentical(shared_ptr<Func1> other) const override {
750 return false; // base class check is insufficient
751 }
752
753 double eval(double t) const override {
754 size_t n, nn;
755 double sum = m_a0_2;
756 for (n = 0; n < m_ccos.size(); n++) {
757 nn = n + 1;
758 sum += m_ccos[n]*std::cos(m_omega*nn*t)
759 + m_csin[n]*std::sin(m_omega*nn*t);
760 }
761 return sum;
762 }
763
764protected:
765 double m_omega, m_a0_2;
766 vector<double> m_ccos, m_csin;
767};
768
769
770/**
771 * Implements a sum of Arrhenius terms.
772 * The functor class with type @c "Arrhenius" returns
773 * @f[
774 * f(T) = \sum_{n=1}^N A_n T^b_n \exp(-E_n/T)
775 * @f]
776 * @ingroup func1advanced
777 */
778class Arrhenius1 : public Func1
779{
780public:
781 Arrhenius1(size_t n, const double* c) {
782 m_A.resize(n);
783 m_b.resize(n);
784 m_E.resize(n);
785 for (size_t i = 0; i < n; i++) {
786 size_t loc = 3*i;
787 m_A[i] = c[loc];
788 m_b[i] = c[loc+1];
789 m_E[i] = c[loc+2];
790 }
791 }
792
793 //! Constructor uses @f$ 3 n @f$ parameters in the following order:
794 //! @f$ [A_1, b_1, E_1, A_2, b_2, E_2, \dots, A_n, b_n, E_n] @f$
795 Arrhenius1(const vector<double>& params);
796
797 string type() const override {
798 return "Arrhenius";
799 }
800
801 bool isIdentical(shared_ptr<Func1> other) const override {
802 return false; // base class check is insufficient
803 }
804
805 double eval(double t) const override {
806 double sum = 0.0;
807 for (size_t n = 0; n < m_A.size(); n++) {
808 sum += m_A[n]*std::pow(t,m_b[n])*std::exp(-m_E[n]/t);
809 }
810 return sum;
811 }
812
813protected:
814 vector<double> m_A, m_b, m_E;
815};
816
817/**
818 * Implements a periodic function.
819 * Takes any function and makes it periodic with period @f$ T @f$.
820 * @param f Functor to be made periodic
821 * @param T Period
822 * @ingroup func1modified
823 */
824class Periodic1 : public Func1
825{
826public:
827 Periodic1(shared_ptr<Func1> f, double A) : Func1(f, A) {}
828
829 string type() const override {
830 return "periodic";
831 }
832
833 double eval(double t) const override {
834 int np = int(t/m_c);
835 double time = t - np*m_c;
836 return m_f1->eval(time);
837 }
838};
839
840}
841
842#endif
Implements a sum of Arrhenius terms.
Definition Func1.h:779
double eval(double t) const override
Evaluate the function.
Definition Func1.h:805
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:797
bool isIdentical(shared_ptr< Func1 > other) const override
Routine to determine if two functions are the same.
Definition Func1.h:801
Implements a composite function.
Definition Func1.h:605
double eval(double t) const override
Evaluate the function.
Definition Func1.h:613
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:505
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:609
int order() const override
Return the order of the function, if it makes sense.
Definition Func1.h:621
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:499
Implements a constant.
Definition Func1.h:389
double eval(double t) const override
Evaluate the function.
Definition Func1.h:404
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.h:407
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:400
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:440
Implements the cos() function.
Definition Func1.h:216
double eval(double t) const override
Evaluate the function.
Definition Func1.h:231
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:111
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:227
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:117
Implements the difference of two functions.
Definition Func1.h:452
double eval(double t) const override
Evaluate the function.
Definition Func1.h:460
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.h:464
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:456
int order() const override
Return the order of the function, if it makes sense.
Definition Func1.h:468
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:488
Implements the exp() (exponential) function.
Definition Func1.h:245
double eval(double t) const override
Evaluate the function.
Definition Func1.h:260
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:137
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:256
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:146
Implements a Fourier cosine/sine series.
Definition Func1.h:730
double eval(double t) const override
Evaluate the function.
Definition Func1.h:753
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:745
bool isIdentical(shared_ptr< Func1 > other) const override
Routine to determine if two functions are the same.
Definition Func1.h:749
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:130
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
shared_ptr< Func1 > func2_shared() const
Accessor function for m_f2.
Definition Func1.h:136
double c() const
Accessor function for the stored constant m_c.
Definition Func1.cpp:64
Implements a Gaussian function.
Definition Func1.h:643
double eval(double t) const override
Evaluate the function.
Definition Func1.h:663
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:655
bool isIdentical(shared_ptr< Func1 > other) const override
Routine to determine if two functions are the same.
Definition Func1.h:659
Implements the log() (natural logarithm) function.
Definition Func1.h:276
double eval(double t) const override
Evaluate the function.
Definition Func1.h:289
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:164
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:285
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:173
Implements a periodic function.
Definition Func1.h:825
double eval(double t) const override
Evaluate the function.
Definition Func1.h:833
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:829
Implements the sum of a function and a constant.
Definition Func1.h:544
double eval(double t) const override
Evaluate the function.
Definition Func1.h:552
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.h:556
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:548
int order() const override
Return the order of the function, if it makes sense.
Definition Func1.h:562
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:531
Implements a polynomial of degree n.
Definition Func1.h:686
double eval(double t) const override
Evaluate the function.
Definition Func1.h:705
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:697
bool isIdentical(shared_ptr< Func1 > other) const override
Routine to determine if two functions are the same.
Definition Func1.h:701
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:226
Implements the pow() (power) function.
Definition Func1.h:305
double eval(double t) const override
Evaluate the function.
Definition Func1.h:320
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:192
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:316
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:420
Implements the product of two functions.
Definition Func1.h:484
double eval(double t) const override
Evaluate the function.
Definition Func1.h:494
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:471
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:488
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
Implements the ratio of two functions.
Definition Func1.h:576
double eval(double t) const override
Evaluate the function.
Definition Func1.h:584
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:450
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:580
int order() const override
Return the order of the function, if it makes sense.
Definition Func1.h:592
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:445
Implements the sin() function.
Definition Func1.h:185
double eval(double t) const override
Evaluate the function.
Definition Func1.h:200
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.cpp:94
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:196
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:85
Implements the sum of two functions.
Definition Func1.h:421
double eval(double t) const override
Evaluate the function.
Definition Func1.h:429
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.h:433
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:425
int order() const override
Return the order of the function, if it makes sense.
Definition Func1.h:437
string write(const string &arg) const override
Write LaTeX string describing function.
Definition Func1.cpp:477
Implements a tabulated function.
Definition Func1.h:337
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 type() const override
Returns a string describing the type of the function.
Definition Func1.h:366
bool isIdentical(shared_ptr< Func1 > other) const override
Routine to determine if two functions are the same.
Definition Func1.h:360
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
Implements the product of a function and a constant.
Definition Func1.h:513
double eval(double t) const override
Evaluate the function.
Definition Func1.h:521
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
Definition Func1.h:525
string type() const override
Returns a string describing the type of the function.
Definition Func1.h:517
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
This file contains definitions of constants, types and terms that are used in internal routines and a...
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
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
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595