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