Warning
This documentation is for an old version of Cantera. You can find docs for newer versions here.
The classes in this module are designed to allow constructing userdefined functions of one variable in Python that can be used with the Cantera C++ kernel. These classes are mostly shadow classes for corresponding classes in the C++ kernel.
Functors of one variable.
A Functor is an object that behaves like a function. Func1 is the base class from which several functor classes derive. These classes are designed to allow specifying functions of time from Python that can be used by the C++ kernel.
Functors can be added, multiplied, and divided to yield new functors.
>>> f1 = Polynomial([1.0, 0.0, 3.0]) # 3*t*t + 1
>>> f1(2.0)
13
>>> f2 = Polynomial([1.0, 2.0]) # 2*t  1
>>> f2(2.0)
5
>>> f3 = f1/f2 # (3*t*t + 1)/(2*t  1)
>>> f3(2.0)
4.3333333
The constructor is meant to be called from constructors of subclasses of Func1: Polynomial, Gaussian, Arrhenius, Fourier, Const, PeriodicFunction.
Internal. Return the integer index used internally to access the kernellevel object.
A polynomial. Instances of class ‘Polynomial’ evaluate
The coefficients are supplied as a list, beginning with \(a_N\) and ending with \(a_0\).
>>> p1 = Polynomial([1.0, 2.0, 3.0]) # 3t^2  2t + 1
>>> p2 = Polynomial([6.0, 8.0]) # 8t + 6
coeffs  polynomial coefficients
A Gaussian pulse. Instances of class ‘Gaussian’ evaluate
where
‘FWHM’ denotes the full width at half maximum.
As an example, here is how to create a Gaussian pulse with peak amplitude 10.0, centered at time 2.0, with fullwidth at half max = 0.2:
>>> f = Gaussian(A = 10.0, t0 = 2.0, FWHM = 0.2)
>>> f(2.0)
10
>>> f(1.9)
5
>>> f(2.1)
5
Fourier series. Instances of class ‘Fourier’ evaluate the Fourier series
where
The function \(f(t)\) is periodic, with period \(T = 2\pi/\omega\).
As an example, a function with Fourier components up to the second harmonic is constructed as follows:
>>> coeffs = [(a0, b0), (a1, b1), (a2, b2)]
>>> f = Fourier(omega, coeffs)
Note that b0 must be specified, but is not used. The value of b0 is arbitrary.
Parameters: 


Sum of modified Arrhenius terms. Instances of class ‘Arrhenius’ evaluate
Example:
>>> f = Arrhenius([(a0, b0, e0), (a1, b1, e1)])
Parameters:  coefficients – sequence of (A, b, E) triplets. 

Constant function. Objects created by function Const act as functions that have a constant value. These are used internally whenever a statement like
>>> f = Gausian(2.0, 1.0, 0.1) + 4.0
is encountered. The addition operator of class Func1 is defined so that this is equivalent to
>>> f = SumFunction(Gaussian(2.0, 1.0, 0.1), Const(4.0))
Function Const returns instances of class Polynomial that have degree zero, with the constant term set to the desired value.
Converts a function into a periodic function with period T.
Parameters: 


Combines two functions. This class is the base class for functors that combine two other functors in a binary operation.
Sum of two functions. Instances of class SumFunction evaluate the sum of two supplied functors. It is not necessary to explicitly create an instance of SumFunction, since the addition operator of the base class is overloaded to return a SumFunction instance.
>>> f1 = Polynomial([2.0, 1.0])
>>> f2 = Polynomial([3.0, 5.0])
>>> f3 = f1 + f2 # functor to evaluate (2t + 1) + (3t  5)
In this example, object ‘f3’ is a functor of class’SumFunction’ that calls f1 and f2 and returns their sum.
Parameters: 


Difference of two functions. Instances of class DiffFunction evaluate the difference of two supplied functors. It is not necessary to explicitly create an instance of DiffFunction, since the subtraction operator of the base class is overloaded to return a DiffFunction instance.
>>> f1 = Polynomial([2.0, 1.0])
>>> f2 = Polynomial([3.0, 5.0])
>>> f3 = f1  f2 # functor to evaluate (2t + 1)  (3t  5)
In this example, object ‘f3’ is a functor of class’DiffFunction’ that calls f1 and f2 and returns their difference.
Parameters: 


Product of two functions. Instances of class ProdFunction evaluate the product of two supplied functors. It is not necessary to explicitly create an instance of ‘ProdFunction’, since the multiplication operator of the base class is overloaded to return a ‘ProdFunction’ instance.
>>> f1 = Polynomial([2.0, 1.0])
>>> f2 = Polynomial([3.0, 5.0])
>>> f3 = f1 * f2 # functor to evaluate (2t + 1)*(3t  5)
In this example, object ‘f3’ is a functor of class’ProdFunction’ that calls f1 and f2 and returns their product.
Parameters: 


Ratio of two functions. Instances of class RatioFunction evaluate the ratio of two supplied functors. It is not necessary to explicitly create an instance of ‘RatioFunction’, since the division operator of the base class is overloaded to return a RatioFunction instance.
>>> f1 = Polynomial([2.0, 1.0])
>>> f2 = Polynomial([3.0, 5.0])
>>> f3 = f1 / f2 # functor to evaluate (2t + 1)/(3t  5)
In this example, object ‘f3’ is a functor of class’RatioFunction’ that calls f1 and f2 and returns their ratio.
Parameters: 


Function of a function. Instances of class CompositeFunction evaluate f(g(t)) for two supplied functors f and g. It is not necessary to explicitly create an instance of ‘CompositeFunction’, since the () operator of the base class is overloaded to return a CompositeFunction when called with a functor argument.
>>> f1 = Polynomial([2.0, 1.0])
>>> f2 = Polynomial([3.0, 5.0])
>>> f3 = f1(f2) # functor to evaluate 2(3t  5) + 1
In this example, object ‘f3’ is a functor of class’CompositeFunction’ that calls f1 and f2 and returns f1(f2(t)).
Parameters: 


Take the derivative of a functor f