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