FieldRotator#
- class discretisedfield.FieldRotator(field)#
Rotate a field.
This class can be used to rotate a
field
object. During rotation a new region and mesh are constructed andfield
values are interpolated onto the new mesh. Multiple consecutive rotations are possible without additional numerical errors. Rotation always starts from the initial unrotated field.Periodic boundary conditions have no effect.
- Parameters:
field (discretisedfield.Field) – Field to rotate.
Examples
>>> import discretisedfield as df >>> from math import pi
Create a
field
to rotate.>>> region = df.Region(p1=(0, 0, 0), p2=(20, 10, 2)) >>> mesh = df.Mesh(region=region, cell=(1, 1, 1)) >>> field = df.Field(mesh, nvdim=3, value=(0, 0, 1)) >>> field.mesh.n array([20, 10, 2])
Create a
FieldRotator
object for thefield
.>>> field_rotator = df.FieldRotator(field)
Rotate the
field
.>>> field_rotator.rotate('from_euler', seq='x', angles=pi/2)
Access the rotated field.
>>> field_rotator.field Field(...) >>> field_rotator.field.mesh.n array([20, 2, 10])
Apply a second rotation.
>>> field_rotator.rotate('from_euler', seq='z', angles=pi/2) >>> field_rotator.field.mesh.n array([ 2, 20, 10])
Methods
__dir__
Default dir() implementation.
__eq__
Return self==value.
Representation string.
Remove all rotations.
Rotate the field.
Properties
Rotated field.
- __repr__()#
Representation string.
Internally self._repr_html_() is called and all html tags are removed from this string.
- Returns:
Representation string.
- Return type:
str
Example
Getting representation string.
>>> import discretisedfield as df ... >>> p1 = (0, 0, 0) >>> p2 = (2, 2, 1) >>> cell = (1, 1, 1) >>> mesh = df.Mesh(p1=p1, p2=p2, cell=cell) ... >>> field = df.Field(mesh, nvdim=1, value=1) >>> rotator = df.FieldRotator(field) >>> rotator FieldRotator(...)
- clear_rotation()#
Remove all rotations.
- rotate(method, /, *args, n=None, **kwargs)#
Rotate the field.
Rotate the field using the given
method
. The definition of the rotation is based onscipy.spatial.transform.Rotation
. Additional parameters required for the different possible rotation methods must be specified following to thescipy
documentation. These are passed directly to the relevantscipy
function. For a detailed explanation and required arguments of the different methods please refer directly to thescipy
documentation.The only method that differs from
scipy
isalign_vector
. This method expects two keyword argumentsinitial
andfinal
(array-like, 3). This method rotates the vectorinitial
to the vectorfinal
, the cross product is kept fixed, i.e. it defines the rotation vector.The rotation of the field consists of three steps, rotation of the region, remeshing, and rotation + interpolation of the field values. Rotation of the region produces as new, larger region for the new field. If
n
is not specified remeshing is done automatically and the cell volume is kept mostly constant. Interpolation of the field values is done using linear interpolation. For more details on the rotation process please refer to the detailed documentation notebook.- Parameters:
method (str) – Rotation method. One of
'from_quat'
,'from_matrix'
,'from_rotvec'
,'from_mpr'
,'from_euler'
, or'align_vector'
.args – Additional positional arguments for the rotation method.
n (array-like, 3, optional) – Number of cells in the new mesh. If not specified
n
is chosen automatically to keep the cell volume mostly constant. Defaults toNone
.kwargs – Additional keyword arguments for the rotation method.
Examples
>>> import discretisedfield as df >>> from math import pi >>> region = df.Region(p1=(0, 0, 0), p2=(20, 10, 2)) >>> mesh = df.Mesh(region=region, cell=(1, 1, 1)) >>> field = df.Field(mesh, nvdim=3, value=(0, 0, 1)) >>> field_rotator = df.FieldRotator(field) >>> field_rotator.rotate('from_euler', seq='x', angles=pi/2)
- property field#
Rotated field.