9.5. Mappers¶

class cherab.core.math.mappers.AxisymmetricMapper

Performs an 360 degree rotation of a 2D function (defined on the xz plane) around the z-axis.

Due to the nature of this mapping, only the positive region of the x range of the supplied function is mapped.

Parameters

function2d (Function2D) – The function to be mapped.

>>> from numpy import sqrt
>>> from cherab.core.math import AxisymmetricMapper
>>>
>>> def f1(r, z):
>>>     return r
>>>
>>> f2 = AxisymmetricMapper(f1)
>>>
>>> f2(1, 0, 0)
1.0
>>> f2(1/sqrt(2), 1/sqrt(2), 0)
0.99999999
class cherab.core.math.mappers.IsoMapper2D

Applies a 1D function to modify the value of a 2D scalar field.

For a given 2D scalar field f(x,y) and 1D function g(x) this object returns g(f(x,y)).

Parameters
• function2d (Function2D) – the 2D scalar field

• function1d (Function1D) – the 1D function

>>> from raysect.core.math.function.float import Interpolator1DArray
>>> from cherab.core.math import IsoMapper2D
>>> from cherab.tools.equilibrium import example_equilibrium
>>>
>>> equilibrium = example_equilibrium()
>>>
>>> # extract the 2D psi function
>>> psi_n = equilibrium.psi_normalised
>>> # make a 1D psi profile
>>> profile = Interpolator1DArray([0, 0.5, 0.9, 1.0], [2500, 2000, 1000, 0], 'cubic', 'none', 0)
>>> # perform the flux function mapping
>>> f = IsoMapper2D(psi_n, profile)
>>>
>>> f(2, 0)
2499.97177
>>> f(2.2, 0.5)
1990.03783
class cherab.core.math.mappers.IsoMapper3D

Applies a 1D function to modify the value of a 3D scalar field.

For a given 3D scalar field f(x,y,z) and 1D function g(x) this object returns g(f(x,y,z)).

Parameters
• function3d (Function3D) – the 3D scalar field

• function1d (Function1D) – the 1D function

>>> from raysect.core.math.function.float import Interpolator1DArray
>>> from cherab.core.math import IsoMapper2D, AxisymmetricMapper
>>> from cherab.tools.equilibrium import example_equilibrium
>>>
>>> equilibrium = example_equilibrium()
>>>
>>> # extract the 3D psi function
>>> psi_n = equilibrium.psi_normalised
>>> psi_n_3d = AxisymmetricMapper(psi_n)
>>> # make a 1D psi profile
>>> profile = Interpolator1DArray([0, 0.5, 0.9, 1.0], [2500, 2000, 1000, 0], 'cubic', 'none', 0)
>>> # perform the flux function mapping
>>> f = IsoMapper3D(psi_n_3d, profile)
>>>
>>> f(2, 0, 0)
2499.97177
>>> f(0, 2, 0)
2499.97177
class cherab.core.math.mappers.Swizzle2D

Inverts the argument order of the specified function.

Parameters

function2d (Function2D) – The 2D function you want to inverse the arguments.

>>> from cherab.core.math import Swizzle2D
>>>
>>> def f1(r, z):
>>>     return r**2 + z
>>>
>>> f2 = Swizzle2D(f1)
>>>
>>> f2(3, 0)
3.0
class cherab.core.math.mappers.Swizzle3D

Rearranges the order of a 3D functions arguments.

For instance, a 90 degree rotation of function coordinates can be performed by swapping arguments: xyz -> xzy

Shape is a tuple of 3 integers from 0,1,2 imposing the order of arguments. 0, 1 and 2 correspond respectively to x, y and z where ( x,y,z) are the initial arguments. For instance: shape = (0,2,1) transforms f(x,y,z) in f(x,z,y) shape = (1,0,1) transforms f(x,y,z) in f(y,x,y)

Parameters
• function3d (Function3D) – the 3D function you want to reorder the arguments.

• shape (tuple) – a tuple of integers imposing the order of the arguments.

>>> from cherab.core.math import Swizzle3D
>>>
>>> def f1(x, y, z):
>>>     return x**3 + y**2 + z
>>>
>>> f2 = Swizzle3D(f1, (0, 2, 1))
>>>
>>> f2(3, 2, 1)
30.0
class cherab.core.math.mappers.VectorAxisymmetricMapper

Performs an 360 degree rotation of a 2D vector function (defined on the xz plane) around the z-axis.

Due to the nature of this mapping, only the positive region of the x range of the supplied function is mapped.

Parameters

vectorfunction2d (VectorFunction2D) – The vector function to be mapped.

>>> from cherab.core.math import VectorAxisymmetricMapper
>>>
>>> def my_func(r, z):
>>>     v = Vector3D(1, 0, 0)
>>>     v.length = r
>>>     return v
>>>
>>> f = VectorAxisymmetricMapper(my_func)
>>>
>>> f(1, 0, 0)
Vector3D(1.0, 0.0, 0.0)
>>> f(1/sqrt(2), 1/sqrt(2), 0)
Vector3D(0.70710678, 0.70710678, 0.0)