9.3. Functions¶
The Cherab function framework is built on the core Raysect 1D, 2D and 3D function framework. For more details on the base functionality refer to the Raysect documentation and the Cherab function tutorials.
Cherab previously provided vector functions which were not present in Raysect. New codes should prefer the Raysect vector functions, but the old aliases are preserved for backwards compatibility.
The Function6D framework in Cherab aims to provide a framework for building six-dimensional distribution functions. It follows closely Raysect’s function framework.
9.3.1. 6D Scalar Functions¶
- class cherab.core.math.function.float.function6d.base.Function6D¶
Cython optimised class for representing an arbitrary 6D function returning a float.
Using __call__() in cython is slow. This class provides an overloadable cython cdef evaluate() method which has much less overhead than a python function call.
For use in cython code only, this class cannot be extended via python.
To create a new function object, inherit this class and implement the evaluate() method. The new function object can then be used with any code that accepts a function object.
- __call__()¶
Evaluate the function f(x, y, z, u, v, w)
- Parameters:
x (float) – function parameter x
y (float) – function parameter y
z (float) – function parameter z
u (float) – function parameter u
v (float) – function parameter v
w (float) – function parameter w
- Return type:
float
- class cherab.core.math.function.float.function6d.constant.Constant6D¶
Bases:
Function6DWraps a scalar constant with a Function6D object.
This class allows a numeric Python scalar, such as a float or an integer, to interact with cython code that requires a Function6D object. The scalar must be convertible to double. The value of the scalar constant will be returned independent of the arguments the function is called with.
This class is intended to be used to transparently wrap python objects that are passed via constructors or methods into cython optimised code. It is not intended that the users should need to directly interact with these wrapping objects. Constructors and methods expecting a Function6D object should be designed to accept a generic python object and then test that object to determine if it is an instance of Function6D. If the object is not a Function6D object it should be wrapped using this class for internal use.
See also: autowrap_function6d()
- Parameters:
value (float) – the constant value to return when called
- class cherab.core.math.function.float.function6d.arg.Arg6D¶
Bases:
Function6DReturns one of the arguments the function is passed, unmodified
This is used to pass coordinates through to other functions in the function framework which expect a Function6D object.
Valid options for argument are “x”, “y”, “z”, “u”, “v”, or “w”.
>>> argx = Arg6D("x") >>> argx(2, 3, 5, 7, 11, 13) 2.0 >>> argy = Arg6D("y") >>> argy(2, 3, 5, 7, 11, 13) 3.0 >>> argz = Arg6D("z") >>> argz(2, 3, 5, 7, 11, 13) 5.0 >>> argu = Arg6D("u") >>> argu(2, 3, 5, 7, 11, 13) 7.0 >>> argv = Arg6D("v") >>> argv(2, 3, 5, 7, 11, 13) 11.0 >>> argw = Arg6D("w") >>> argw(2, 3, 5, 7, 11, 13) 13.0
- Parameters:
argument (str) – either “x”, “y”, “z”, “u”, “v”, or “w”, the argument to return
- class cherab.core.math.function.float.function6d.cmath.Exp6D¶
Bases:
Function6DA Function6D class that implements the exponential of the result of a Function6D object: exp(f())
- Parameters:
function (Function6D) – A Function6D object.
- class cherab.core.math.function.float.function6d.cmath.Sin6D¶
Bases:
Function6DA Function6D class that implements the sine of the result of a Function6D object: sin(f())
- Parameters:
function (Function6D) – A Function6D object.
- class cherab.core.math.function.float.function6d.cmath.Cos6D¶
Bases:
Function6DA Function6D class that implements the cosine of the result of a Function6D object: cos(f())
- Parameters:
function (Function6D) – A Function6D object.
- class cherab.core.math.function.float.function6d.cmath.Tan6D¶
Bases:
Function6DA Function6D class that implements the tangent of the result of a Function6D object: tan(f())
- Parameters:
function (Function6D) – A Function6D object.
- class cherab.core.math.function.float.function6d.cmath.Asin6D¶
Bases:
Function6DA Function6D class that implements the arcsine of the result of a Function6D object: asin(f())
- Parameters:
function (Function6D) – A Function6D object.
- class cherab.core.math.function.float.function6d.cmath.Acos6D¶
Bases:
Function6DA Function6D class that implements the arccosine of the result of a Function6D object: acos(f())
- Parameters:
function (Function6D) – A Function6D object.
- class cherab.core.math.function.float.function6d.cmath.Atan6D¶
Bases:
Function6DA Function6D class that implements the arctangent of the result of a Function6D object: atan(f())
- Parameters:
function (Function6D) – A Function6D object.
- class cherab.core.math.function.float.function6d.cmath.Atan4Q6D¶
Bases:
Function6DA Function6D class that implements the arctangent of the result of 2 Function6D objects: atan2(f1(), f2())
This differs from Atan6D in that it takes separate functions for the numerator and denominator, in order to get the quadrant correct.
- Parameters:
numerator (Function6D) – A Function6D object representing the numerator
denominator (Function6D) – A Function6D object representing the denominator
- class cherab.core.math.function.float.function6d.cmath.Sqrt6D¶
Bases:
Function6DA Function6D class that implements the square root of the result of a Function6D object: sqrt(f())
- Parameters:
function (Function6D) – A Function6D object.
- class cherab.core.math.function.float.function6d.cmath.Erf6D¶
Bases:
Function6DA Function6D class that implements the error function of the result of a Function6D object: erf(f())
- Parameters:
function (Function6D) – A Function6D object.
- class cherab.core.math.function.float.function6d.blend.Blend6D¶
Bases:
Function6DPerforms a linear interpolation between two scalar functions, modulated by a 3rd scalar function.
The value of the scalar mask function is used to interpolated between the values returned by the two functions. Mathematically the value returned by this function is as follows:
\[v = (1 - f_m(x, y, z, u, v, w)) f_1(x, y, z, u, v, w) + f_m(x, y, z, u, v, w) f_2(x, y, z, u, v, w)\]The value of the mask function is clamped to the range [0, 1] if the sampled value exceeds the required range.
9.3.2. 2D Vector Functions¶
- cherab.core.math.function.VectorFunction2D¶
alias of
Function2D
- cherab.core.math.function.ScalarToVectorFunction2D¶
alias of
FloatToVector3DFunction2D
9.3.3. 3D Vector Functions¶
- cherab.core.math.function.VectorFunction3D¶
alias of
Function3D
- cherab.core.math.function.ScalarToVectorFunction3D¶
alias of
FloatToVector3DFunction3D