Cantera  2.3.0
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 http://www.cantera.org/license.txt for license and copyright information.
7 
8 #ifndef CT_FUNC1_H
9 #define CT_FUNC1_H
10 
11 #include "cantera/base/ct_defs.h"
12 
13 #include <iostream>
14 
15 namespace Cantera
16 {
17 
18 const int FourierFuncType = 1;
19 const int PolyFuncType = 2;
20 const int ArrheniusFuncType = 3;
21 const int GaussianFuncType = 4;
22 const int SumFuncType = 20;
23 const int DiffFuncType = 25;
24 const int ProdFuncType = 30;
25 const int RatioFuncType = 40;
26 const int PeriodicFuncType = 50;
27 const int CompositeFuncType = 60;
28 const int TimesConstantFuncType = 70;
29 const int PlusConstantFuncType = 80;
30 const int SinFuncType = 100;
31 const int CosFuncType = 102;
32 const int ExpFuncType = 104;
33 const int PowFuncType = 106;
34 const int ConstFuncType = 110;
35 
36 class TimesConstant1;
37 
38 /**
39  * Base class for 'functor' classes that evaluate a function of one variable.
40  */
41 class Func1
42 {
43 public:
44  Func1();
45 
46  virtual ~Func1() {}
47 
48  Func1(const Func1& right);
49 
50  Func1& operator=(const Func1& right);
51 
52  //! Duplicate the current function.
53  /*!
54  * This duplicates the current function, returning a reference to the newly
55  * created function.
56  */
57  virtual Func1& duplicate() const;
58 
59  virtual int ID() const;
60 
61  //! Calls method eval to evaluate the function
62  doublereal operator()(doublereal t) const;
63 
64  /// Evaluate the function.
65  virtual doublereal eval(doublereal t) const;
66 
67  //! Creates a derivative to the current function
68  /*!
69  * This will create a new derivative function and return a reference to the
70  * function.
71  */
72  virtual Func1& derivative() const;
73 
74  //! Routine to determine if two functions are the same.
75  /*!
76  * Two functions are the same if they are the same function. This means
77  * that the ID and stored constant is the same. This means that the m_f1
78  * and m_f2 are identical if they are non-null.
79  */
80  bool isIdentical(Func1& other) const;
81 
82  virtual doublereal isProportional(TimesConstant1& other);
83  virtual doublereal isProportional(Func1& other);
84 
85  virtual std::string write(const std::string& arg) const;
86 
87  //! accessor function for the stored constant
88  doublereal c() const;
89 
90  //! Function to set the stored constant
91  void setC(doublereal c);
92 
93  //! accessor function for m_f1
94  Func1& func1() const;
95 
96  //! accessor function for m_f2
97  Func1& func2() const;
98 
99  //! Return the order of the function, if it makes sense
100  virtual int order() const;
101 
102  Func1& func1_dup() const;
103 
104  Func1& func2_dup() const;
105 
106  Func1* parent() const;
107 
108  void setParent(Func1* p);
109 
110 protected:
111  doublereal m_c;
112  Func1* m_f1;
113  Func1* m_f2;
114  Func1* m_parent;
115 };
116 
117 
118 Func1& newSumFunction(Func1& f1, Func1& f2);
119 Func1& newDiffFunction(Func1& f1, Func1& f2);
120 Func1& newProdFunction(Func1& f1, Func1& f2);
121 Func1& newRatioFunction(Func1& f1, Func1& f2);
122 Func1& newCompositeFunction(Func1& f1, Func1& f2);
123 Func1& newTimesConstFunction(Func1& f1, doublereal c);
124 Func1& newPlusConstFunction(Func1& f1, doublereal c);
125 
126 //! implements the sin() function
127 /*!
128  * The argument to sin() is in radians
129  */
130 class Sin1 : public Func1
131 {
132 public:
133  Sin1(doublereal omega = 1.0) :
134  Func1() {
135  m_c = omega;
136  }
137 
138  Sin1(const Sin1& b) :
139  Func1(b) {
140  }
141 
142  Sin1& operator=(const Sin1& right) {
143  if (&right == this) {
144  return *this;
145  }
146  Func1::operator=(right);
147  return *this;
148  }
149 
150  virtual Func1& duplicate() const {
151  Sin1* nfunc = new Sin1(*this);
152  return (Func1&) *nfunc;
153  }
154 
155  virtual std::string write(const std::string& arg) const;
156 
157  virtual int ID() const {
158  return SinFuncType;
159  }
160 
161  virtual doublereal eval(doublereal t) const {
162  return sin(m_c*t);
163  }
164 
165  virtual Func1& derivative() const;
166 };
167 
168 /// cos
169 class Cos1 : public Func1
170 {
171 public:
172  Cos1(doublereal omega = 1.0) :
173  Func1() {
174  m_c = omega;
175  }
176 
177  Cos1(const Cos1& b) :
178  Func1(b) {
179  }
180 
181  Cos1& operator=(const Cos1& right) {
182  if (&right == this) {
183  return *this;
184  }
185  Func1::operator=(right);
186  return *this;
187  }
188 
189  virtual Func1& duplicate() const {
190  Cos1* nfunc = new Cos1(*this);
191  return (Func1&) *nfunc;
192  }
193  virtual std::string write(const std::string& arg) const;
194  virtual int ID() const {
195  return CosFuncType;
196  }
197  virtual doublereal eval(doublereal t) const {
198  return cos(m_c * t);
199  }
200  virtual Func1& derivative() const;
201 };
202 
203 /// exp
204 class Exp1 : public Func1
205 {
206 public:
207  Exp1(doublereal A = 1.0) :
208  Func1() {
209  m_c = A;
210  }
211 
212  Exp1(const Exp1& b) :
213  Func1(b) {
214  }
215  Exp1& operator=(const Exp1& right) {
216  if (&right == this) {
217  return *this;
218  }
219  Func1::operator=(right);
220  return *this;
221  }
222  virtual std::string write(const std::string& arg) const;
223  virtual int ID() const {
224  return ExpFuncType;
225  }
226  virtual Func1& duplicate() const {
227  return *(new Exp1(m_c));
228  }
229  virtual doublereal eval(doublereal t) const {
230  return exp(m_c*t);
231  }
232 
233  virtual Func1& derivative() const;
234 };
235 
236 /// pow
237 class Pow1 : public Func1
238 {
239 public:
240  Pow1(doublereal n) :
241  Func1() {
242  m_c = n;
243  }
244 
245  Pow1(const Pow1& b) :
246  Func1(b) {
247  }
248  Pow1& operator=(const Pow1& right) {
249  if (&right == this) {
250  return *this;
251  }
252  Func1::operator=(right);
253  return *this;
254  }
255  virtual std::string write(const std::string& arg) const;
256  virtual int ID() const {
257  return PowFuncType;
258  }
259  virtual Func1& duplicate() const {
260  return *(new Pow1(m_c));
261  }
262  virtual doublereal eval(doublereal t) const {
263  return pow(t, m_c);
264  }
265  virtual Func1& derivative() const;
266 };
267 
268 /**
269  * Constant.
270  */
271 class Const1 : public Func1
272 {
273 public:
274  Const1(doublereal A) :
275  Func1() {
276  m_c = A;
277  }
278 
279  Const1(const Const1& b) :
280  Func1(b) {
281  }
282 
283  Const1& operator=(const Const1& right) {
284  if (&right == this) {
285  return *this;
286  }
287  Func1::operator=(right);
288  return *this;
289  }
290 
291  virtual std::string write(const std::string& arg) const;
292  virtual int ID() const {
293  return ConstFuncType;
294  }
295  virtual doublereal eval(doublereal t) const {
296  return m_c;
297  }
298  virtual Func1& duplicate() const {
299  return *(new Const1(m_c));
300  }
301 
302  virtual Func1& derivative() const {
303  Func1* z = new Const1(0.0);
304  return *z;
305  }
306 };
307 
308 
309 /**
310  * Sum of two functions.
311  */
312 class Sum1 : public Func1
313 {
314 public:
315  Sum1(Func1& f1, Func1& f2) :
316  Func1() {
317  m_f1 = &f1;
318  m_f2 = &f2;
319  m_f1->setParent(this);
320  m_f2->setParent(this);
321  }
322 
323  virtual ~Sum1() {
324  delete m_f1;
325  delete m_f2;
326  }
327 
328  Sum1(const Sum1& b) :
329  Func1(b) {
330  *this = Sum1::operator=(b);
331  }
332 
333  Sum1& operator=(const Sum1& right) {
334  if (&right == this) {
335  return *this;
336  }
337  Func1::operator=(right);
338  m_f1 = &m_f1->duplicate();
339  m_f2 = &m_f2->duplicate();
340  m_f1->setParent(this);
341  m_f2->setParent(this);
342  m_parent = 0;
343  return *this;
344  }
345 
346  virtual int ID() const {
347  return SumFuncType;
348  }
349 
350  virtual doublereal eval(doublereal t) const {
351  return m_f1->eval(t) + m_f2->eval(t);
352  }
353 
354  virtual Func1& duplicate() const {
355  Func1& f1d = m_f1->duplicate();
356  Func1& f2d = m_f2->duplicate();
357  return newSumFunction(f1d, f2d);
358  }
359 
360  virtual Func1& derivative() const {
361  Func1& d1 = m_f1->derivative();
362  Func1& d2 = m_f2->derivative();
363  return newSumFunction(d1, d2);
364  }
365  virtual int order() const {
366  return 0;
367  }
368 
369  virtual std::string write(const std::string& arg) const;
370 };
371 
372 
373 /**
374  * Difference of two functions.
375  */
376 class Diff1 : public Func1
377 {
378 public:
379  Diff1(Func1& f1, Func1& f2) {
380  m_f1 = &f1;
381  m_f2 = &f2;
382  m_f1->setParent(this);
383  m_f2->setParent(this);
384  }
385 
386  virtual ~Diff1() {
387  delete m_f1;
388  delete m_f2;
389  }
390 
391  Diff1(const Diff1& b) :
392  Func1(b) {
393  *this = Diff1::operator=(b);
394  }
395 
396  Diff1& operator=(const Diff1& right) {
397  if (&right == this) {
398  return *this;
399  }
400  Func1::operator=(right);
401  m_f1 = &m_f1->duplicate();
402  m_f2 = &m_f2->duplicate();
403  m_f1->setParent(this);
404  m_f2->setParent(this);
405  m_parent = 0;
406  return *this;
407  }
408 
409  virtual int ID() const {
410  return DiffFuncType;
411  }
412 
413  virtual doublereal eval(doublereal t) const {
414  return m_f1->eval(t) - m_f2->eval(t);
415  }
416 
417  virtual Func1& duplicate() const {
418  Func1& f1d = m_f1->duplicate();
419  Func1& f2d = m_f2->duplicate();
420  return newDiffFunction(f1d, f2d);
421  }
422  virtual Func1& derivative() const {
423  return newDiffFunction(m_f1->derivative(), m_f2->derivative());
424  }
425  virtual int order() const {
426  return 0;
427  }
428 
429  virtual std::string write(const std::string& arg) const;
430 };
431 
432 
433 /**
434  * Product of two functions.
435  */
436 class Product1 : public Func1
437 {
438 public:
439  Product1(Func1& f1, Func1& f2) :
440  Func1() {
441  m_f1 = &f1;
442  m_f2 = &f2;
443  m_f1->setParent(this);
444  m_f2->setParent(this);
445  }
446 
447  virtual ~Product1() {
448  delete m_f1;
449  delete m_f2;
450  }
451 
452  Product1(const Product1& b) :
453  Func1(b) {
454  *this = Product1::operator=(b);
455  }
456 
457  Product1& operator=(const Product1& right) {
458  if (&right == this) {
459  return *this;
460  }
461  Func1::operator=(right);
462  m_f1 = &m_f1->duplicate();
463  m_f2 = &m_f2->duplicate();
464  m_f1->setParent(this);
465  m_f2->setParent(this);
466  m_parent = 0;
467  return *this;
468  }
469 
470  virtual int ID() const {
471  return ProdFuncType;
472  }
473 
474  virtual Func1& duplicate() const {
475  Func1& f1d = m_f1->duplicate();
476  Func1& f2d = m_f2->duplicate();
477  return newProdFunction(f1d, f2d);
478  }
479 
480  virtual std::string write(const std::string& arg) const;
481 
482  virtual doublereal eval(doublereal t) const {
483  return m_f1->eval(t) * m_f2->eval(t);
484  }
485 
486  virtual Func1& derivative() const {
487  Func1& a1 = newProdFunction(m_f1->duplicate(), m_f2->derivative());
488  Func1& a2 = newProdFunction(m_f2->duplicate(), m_f1->derivative());
489  return newSumFunction(a1, a2);
490  }
491  virtual int order() const {
492  return 1;
493  }
494 };
495 
496 /**
497  * Product of two functions.
498  */
499 class TimesConstant1 : public Func1
500 {
501 public:
502  TimesConstant1(Func1& f1, doublereal A) :
503  Func1() {
504  m_f1 = &f1;
505  m_c = A;
506  m_f1->setParent(this);
507  }
508 
509  virtual ~TimesConstant1() {
510  delete m_f1;
511  }
512 
513  TimesConstant1(const TimesConstant1& b) :
514  Func1(b) {
515  *this = TimesConstant1::operator=(b);
516  }
517 
518  TimesConstant1& operator=(const TimesConstant1& right) {
519  if (&right == this) {
520  return *this;
521  }
522  Func1::operator=(right);
523  m_f1 = &m_f1->duplicate();
524  m_f1->setParent(this);
525  m_parent = 0;
526  return *this;
527  }
528  virtual int ID() const {
529  return TimesConstantFuncType;
530  }
531 
532  virtual Func1& duplicate() const {
533  Func1& f1 = m_f1->duplicate();
534  Func1* dup = new TimesConstant1(f1, m_c);
535  return *dup;
536  }
537 
538  virtual doublereal isProportional(TimesConstant1& other) {
539  if (func1().isIdentical(other.func1())) {
540  return (other.c()/c());
541  } else {
542  return 0.0;
543  }
544  }
545 
546  virtual doublereal isProportional(Func1& other) {
547  if (func1().isIdentical(other)) {
548  return 1.0/c();
549  } else {
550  return 0.0;
551  }
552  }
553 
554  virtual doublereal eval(doublereal t) const {
555  return m_f1->eval(t) * m_c;
556  }
557 
558  virtual Func1& derivative() const {
559  Func1& f1d = m_f1->derivative();
560  Func1* d = &newTimesConstFunction(f1d, m_c);
561  return *d;
562  }
563 
564  virtual std::string write(const std::string& arg) const;
565 
566  virtual int order() const {
567  return 0;
568  }
569 };
570 
571 /**
572  * A function plus a constant.
573  */
574 class PlusConstant1 : public Func1
575 {
576 public:
577  PlusConstant1(Func1& f1, doublereal A) :
578  Func1() {
579  m_f1 = &f1;
580  m_c = A;
581  m_f1->setParent(this);
582  }
583 
584  virtual ~PlusConstant1() {
585  delete m_f1;
586  }
587 
588  PlusConstant1(const PlusConstant1& b) :
589  Func1(b) {
590  *this = PlusConstant1::operator=(b);
591  }
592 
593  PlusConstant1& operator=(const PlusConstant1& right) {
594  if (&right == this) {
595  return *this;
596  }
597  Func1::operator=(right);
598  m_f1 = &m_f1->duplicate();
599  m_f1->setParent(this);
600  m_parent = 0;
601  return *this;
602  }
603 
604  virtual int ID() const {
605  return PlusConstantFuncType;
606  }
607 
608  virtual Func1& duplicate() const {
609  Func1& f1 = m_f1->duplicate();
610  Func1* dup = new PlusConstant1(f1, m_c);
611  return *dup;
612  }
613 
614  virtual doublereal eval(doublereal t) const {
615  return m_f1->eval(t) + m_c;
616  }
617  virtual Func1& derivative() const {
618  return m_f1->derivative();
619  }
620  virtual std::string write(const std::string& arg) const;
621 
622  virtual int order() const {
623  return 0;
624  }
625 };
626 
627 
628 /**
629  * Ratio of two functions.
630  */
631 class Ratio1 : public Func1
632 {
633 public:
634  Ratio1(Func1& f1, Func1& f2) :
635  Func1() {
636  m_f1 = &f1;
637  m_f2 = &f2;
638  m_f1->setParent(this);
639  m_f2->setParent(this);
640  }
641 
642  virtual ~Ratio1() {
643  delete m_f1;
644  delete m_f2;
645  }
646 
647  Ratio1(const Ratio1& b) :
648  Func1(b) {
649  *this = Ratio1::operator=(b);
650  }
651 
652  Ratio1& operator=(const Ratio1& right) {
653  if (&right == this) {
654  return *this;
655  }
656  Func1::operator=(right);
657  m_f1 = &m_f1->duplicate();
658  m_f2 = &m_f2->duplicate();
659  m_f1->setParent(this);
660  m_f2->setParent(this);
661  m_parent = 0;
662  return *this;
663  }
664 
665  virtual int ID() const {
666  return RatioFuncType;
667  }
668 
669  virtual doublereal eval(doublereal t) const {
670  return m_f1->eval(t) / m_f2->eval(t);
671  }
672 
673  virtual Func1& duplicate() const {
674  Func1& f1d = m_f1->duplicate();
675  Func1& f2d = m_f2->duplicate();
676  return newRatioFunction(f1d, f2d);
677  }
678 
679  virtual Func1& derivative() const {
680  Func1& a1 = newProdFunction(m_f1->derivative(), m_f2->duplicate());
681  Func1& a2 = newProdFunction(m_f1->duplicate(), m_f2->derivative());
682  Func1& s = newDiffFunction(a1, a2);
683  Func1& p = newProdFunction(m_f2->duplicate(), m_f2->duplicate());
684  return newRatioFunction(s, p);
685  }
686 
687  virtual std::string write(const std::string& arg) const;
688 
689  virtual int order() const {
690  return 1;
691  }
692 };
693 
694 /**
695  * Composite function.
696  */
697 class Composite1 : public Func1
698 {
699 public:
700  Composite1(Func1& f1, Func1& f2) :
701  Func1() {
702  m_f1 = &f1;
703  m_f2 = &f2;
704  m_f1->setParent(this);
705  m_f2->setParent(this);
706  }
707 
708  virtual ~Composite1() {
709  delete m_f1;
710  delete m_f2;
711  }
712 
713  Composite1(const Composite1& b) :
714  Func1(b) {
715  *this = Composite1::operator=(b);
716  }
717 
718  Composite1& operator=(const Composite1& right) {
719  if (&right == this) {
720  return *this;
721  }
722  Func1::operator=(right);
723  m_f1 = &m_f1->duplicate();
724  m_f2 = &m_f2->duplicate();
725  m_f1->setParent(this);
726  m_f2->setParent(this);
727  m_parent = 0;
728  return *this;
729  }
730 
731  virtual int ID() const {
732  return CompositeFuncType;
733  }
734 
735  virtual doublereal eval(doublereal t) const {
736  return m_f1->eval(m_f2->eval(t));
737  }
738 
739  virtual Func1& duplicate() const {
740  Func1& f1d = m_f1->duplicate();
741  Func1& f2d = m_f2->duplicate();
742  return newCompositeFunction(f1d, f2d);
743  }
744 
745  virtual Func1& derivative() const {
746  Func1* d1 = &m_f1->derivative();
747 
748  Func1* d3 = &newCompositeFunction(*d1, m_f2->duplicate());
749  Func1* d2 = &m_f2->derivative();
750  Func1* p = &newProdFunction(*d3, *d2);
751  return *p;
752  }
753 
754  virtual std::string write(const std::string& arg) const;
755 
756  virtual int order() const {
757  return 2;
758  }
759 };
760 
761 // The functors below are the old-style ones. They still work,
762 // but can't do derivatives.
763 
764 /**
765  * A Gaussian.
766  * \f[
767  * f(t) = A e^{-[(t - t_0)/\tau]^2}
768  * \f]
769  * where \f[ \tau = \frac{fwhm}{2\sqrt{\ln 2}} \f]
770  * @param A peak value
771  * @param t0 offset
772  * @param fwhm full width at half max
773  */
774 class Gaussian : public Func1
775 {
776 public:
777  Gaussian(double A, double t0, double fwhm) :
778  Func1() {
779  m_A = A;
780  m_t0 = t0;
781  m_tau = fwhm/(2.0*std::sqrt(std::log(2.0)));
782  }
783 
784  Gaussian(const Gaussian& b) :
785  Func1(b) {
786  *this = Gaussian::operator=(b);
787  }
788 
789  Gaussian& operator=(const Gaussian& right) {
790  if (&right == this) {
791  return *this;
792  }
793  Func1::operator=(right);
794  m_A = right.m_A;
795  m_t0 = right.m_t0;
796  m_tau = right.m_tau;
797  m_parent = 0;
798  return *this;
799  }
800 
801  virtual Func1& duplicate() const {
802  Gaussian* np = new Gaussian(*this);
803  return *((Func1*)np);
804  }
805 
806  virtual doublereal eval(doublereal t) const {
807  doublereal x = (t - m_t0)/m_tau;
808  return m_A * std::exp(-x*x);
809  }
810 
811 protected:
812  doublereal m_A, m_t0, m_tau;
813 };
814 
815 
816 /**
817  * Polynomial of degree n.
818  */
819 class Poly1 : public Func1
820 {
821 public:
822  Poly1(size_t n, const double* c) :
823  Func1() {
824  m_cpoly.resize(n+1);
825  std::copy(c, c+m_cpoly.size(), m_cpoly.begin());
826  }
827 
828  Poly1(const Poly1& b) :
829  Func1(b) {
830  *this = Poly1::operator=(b);
831  }
832 
833  Poly1& operator=(const Poly1& right) {
834  if (&right == this) {
835  return *this;
836  }
837  Func1::operator=(right);
838  m_cpoly = right.m_cpoly;
839  m_parent = 0;
840  return *this;
841  }
842 
843  virtual Func1& duplicate() const {
844  Poly1* np = new Poly1(*this);
845  return *((Func1*)np);
846  }
847 
848  virtual doublereal eval(doublereal t) const {
849  doublereal r = m_cpoly[m_cpoly.size()-1];
850  for (size_t n = 1; n < m_cpoly.size(); n++) {
851  r *= t;
852  r += m_cpoly[m_cpoly.size() - n - 1];
853  }
854  return r;
855  }
856 
857 protected:
858  vector_fp m_cpoly;
859 };
860 
861 
862 /**
863  * Fourier cosine/sine series.
864  *
865  * \f[
866  * f(t) = \frac{A_0}{2} +
867  * \sum_{n=1}^N A_n \cos (n \omega t) + B_n \sin (n \omega t)
868  * \f]
869  */
870 class Fourier1 : public Func1
871 {
872 public:
873  Fourier1(size_t n, double omega, double a0,
874  const double* a, const double* b) :
875  Func1() {
876  m_omega = omega;
877  m_a0_2 = 0.5*a0;
878  m_ccos.resize(n);
879  m_csin.resize(n);
880  std::copy(a, a+n, m_ccos.begin());
881  std::copy(b, b+n, m_csin.begin());
882  }
883 
884  Fourier1(const Fourier1& b) :
885  Func1(b) {
886  *this = Fourier1::operator=(b);
887  }
888 
889  Fourier1& operator=(const Fourier1& right) {
890  if (&right == this) {
891  return *this;
892  }
893  Func1::operator=(right);
894  m_omega = right.m_omega;
895  m_a0_2 = right.m_a0_2;
896  m_ccos = right.m_ccos;
897  m_csin = right.m_csin;
898  m_parent = 0;
899  return *this;
900  }
901 
902  virtual Func1& duplicate() const {
903  Fourier1* np = new Fourier1(*this);
904  return *((Func1*)np);
905  }
906 
907  virtual doublereal eval(doublereal t) const {
908  size_t n, nn;
909  doublereal sum = m_a0_2;
910  for (n = 0; n < m_ccos.size(); n++) {
911  nn = n + 1;
912  sum += m_ccos[n]*std::cos(m_omega*nn*t)
913  + m_csin[n]*std::sin(m_omega*nn*t);
914  }
915  return sum;
916  }
917 
918 protected:
919  doublereal m_omega, m_a0_2;
920  vector_fp m_ccos, m_csin;
921 };
922 
923 
924 /**
925  * Sum of Arrhenius terms.
926  * \f[
927  * f(T) = \sum_{n=1}^N A_n T^b_n \exp(-E_n/T)
928  * \f]
929  */
930 class Arrhenius1 : public Func1
931 {
932 public:
933  Arrhenius1(size_t n, const double* c) :
934  Func1() {
935  m_A.resize(n);
936  m_b.resize(n);
937  m_E.resize(n);
938  for (size_t i = 0; i < n; i++) {
939  size_t loc = 3*i;
940  m_A[i] = c[loc];
941  m_b[i] = c[loc+1];
942  m_E[i] = c[loc+2];
943  }
944  }
945 
946  Arrhenius1(const Arrhenius1& b) :
947  Func1() {
948  *this = Arrhenius1::operator=(b);
949  }
950 
951  Arrhenius1& operator=(const Arrhenius1& right) {
952  if (&right == this) {
953  return *this;
954  }
955  Func1::operator=(right);
956  m_A = right.m_A;
957  m_b = right.m_b;
958  m_E = right.m_E;
959  m_parent = 0;
960  return *this;
961  }
962 
963  virtual Func1& duplicate() const {
964  Arrhenius1* np = new Arrhenius1(*this);
965  return *((Func1*)np);
966  }
967 
968  virtual doublereal eval(doublereal t) const {
969  doublereal sum = 0.0;
970  for (size_t n = 0; n < m_A.size(); n++) {
971  sum += m_A[n]*std::pow(t,m_b[n])*std::exp(-m_E[n]/t);
972  }
973  return sum;
974  }
975 
976 protected:
977  vector_fp m_A, m_b, m_E;
978 };
979 
980 /**
981  * Periodic function. Takes any function and makes it periodic with period T.
982  */
983 class Periodic1 : public Func1
984 {
985 public:
986  Periodic1(Func1& f, doublereal T) :
987  Func1() {
988  m_func = &f;
989  m_c = T;
990  }
991 
992  Periodic1(const Periodic1& b) :
993  Func1() {
994  *this = Periodic1::operator=(b);
995  }
996 
997  Periodic1& operator=(const Periodic1& right) {
998  if (&right == this) {
999  return *this;
1000  }
1001  Func1::operator=(right);
1002  m_func = &right.m_func->duplicate();
1003  return *this;
1004  }
1005 
1006  virtual Func1& duplicate() const {
1007  Periodic1* np = new Periodic1(*this);
1008  return *((Func1*)np);
1009  }
1010 
1011  virtual ~Periodic1() {
1012  delete m_func;
1013  }
1014 
1015  virtual doublereal eval(doublereal t) const {
1016  int np = int(t/m_c);
1017  doublereal time = t - np*m_c;
1018  return m_func->eval(time);
1019  }
1020 
1021 protected:
1022  Func1* m_func;
1023 };
1024 
1025 }
1026 
1027 #endif
A function plus a constant.
Definition: Func1.h:574
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:963
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:806
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:673
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.h:617
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.cpp:202
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:482
Product of two functions.
Definition: Func1.h:436
virtual int order() const
Return the order of the function, if it makes sense.
Definition: Func1.cpp:119
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.h:679
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:907
exp
Definition: Func1.h:204
bool isIdentical(Func1 &other) const
Routine to determine if two functions are the same.
Definition: Func1.cpp:72
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.cpp:42
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.h:558
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:295
doublereal operator()(doublereal t) const
Calls method eval to evaluate the function.
Definition: Func1.cpp:54
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:614
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:413
Fourier cosine/sine series.
Definition: Func1.h:870
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:354
pow
Definition: Func1.h:237
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:843
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.h:745
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
doublereal c() const
accessor function for the stored constant
Definition: Func1.cpp:97
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:669
virtual int order() const
Return the order of the function, if it makes sense.
Definition: Func1.h:622
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.cpp:60
implements the sin() function
Definition: Func1.h:130
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:417
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.h:302
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:532
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:554
Difference of two functions.
Definition: Func1.h:376
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:801
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.h:486
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:262
Ratio of two functions.
Definition: Func1.h:631
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:226
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:968
virtual int order() const
Return the order of the function, if it makes sense.
Definition: Func1.h:566
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.cpp:65
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.h:422
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.h:360
cos
Definition: Func1.h:169
virtual int order() const
Return the order of the function, if it makes sense.
Definition: Func1.h:756
void setC(doublereal c)
Function to set the stored constant.
Definition: Func1.cpp:103
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:350
Composite function.
Definition: Func1.h:697
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:298
Periodic function.
Definition: Func1.h:983
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:1015
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:229
virtual int order() const
Return the order of the function, if it makes sense.
Definition: Func1.h:365
Base class for &#39;functor&#39; classes that evaluate a function of one variable.
Definition: Func1.h:41
A Gaussian.
Definition: Func1.h:774
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:150
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:474
Func1 & func1() const
accessor function for m_f1
Definition: Func1.cpp:109
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.cpp:155
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:735
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.cpp:181
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:259
Func1 & func2() const
accessor function for m_f2
Definition: Func1.cpp:114
virtual int order() const
Return the order of the function, if it makes sense.
Definition: Func1.h:491
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
virtual int order() const
Return the order of the function, if it makes sense.
Definition: Func1.h:425
Sum of two functions.
Definition: Func1.h:312
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:608
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:1006
Product of two functions.
Definition: Func1.h:499
Polynomial of degree n.
Definition: Func1.h:819
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:197
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:848
Sum of Arrhenius terms.
Definition: Func1.h:930
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:189
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.h:161
Constant.
Definition: Func1.h:271
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:902
virtual Func1 & derivative() const
Creates a derivative to the current function.
Definition: Func1.cpp:163
virtual Func1 & duplicate() const
Duplicate the current function.
Definition: Func1.h:739
virtual int order() const
Return the order of the function, if it makes sense.
Definition: Func1.h:689