tetrax.helpers package#

Submodules#

tetrax.helpers.io module#

This submodule provides some helper functions for input and output of files, as well as some mesh checkers.

tetrax.helpers.io.add_to_bib(sample, entries_for)#

Adds the references relevant for a certain numerical experiment (depending on the sample geometry) to the bibtex file references.bib of the sample. If this file does not exist, it will be created.

Parameters
sampleAbstractSample

Sample object at hand.

entries_for{‘eigenmodes1d’, ‘eigenmodes2d’, ‘absorption’, ‘tetrax’, ‘linewidth’}

Can be in

tetrax.helpers.io.check_mesh_shape(mesh: meshio._mesh.Mesh, dim: int) bool#

Check if mesh is properly shaped.

  • dim == 3: always True

  • dim == 2: True if mesh is in xy plane.

  • dim == 1: True if mesh is on y axis.

Parameters
meshmeshio.Mesh

Mesh object.

dimint

Dimension of mesh.

Returns
bool
tetrax.helpers.io.get_ids(db)#

Get the list of the bibtex key in a bibtex database.

tetrax.helpers.io.get_mesh_dimension(mesh: meshio._mesh.Mesh) int#

Obtain the dimension of a mesh.

The dimension of the mesh is obtained as the highest topoligical dimension of the different cell types in the mesh.

Parameters
meshmeshio.Mesh

Mesh object.

Returns
int

Dimension of the mesh (0, 1, 2 or 3).

tetrax.helpers.io.get_num_modes_from_dataframe(dataframe) int#

Returns the number of modes from dispersion dataframe.

tetrax.helpers.io.read_mode_from_vtk(fname, as_flattened=False, magnetic_order='FM')#

Reads a complex-valued spatial mode profile from a ´vtk` file.

Parameters
fnamestr

Filename of vtk file.

as_flattenedbool, optional

Return mode profile as flattened mesh vector (default is False).

Returns
MeshVector or FlattenedMeshVector

Mode profile as mesh vector of shape (N, 3) if as_flattened=False or as flattened mesh vector of shape (3*N,) if as_flattened=True.

Notes

Requires that the vtk file contains the data fields “Re(m_x)”, “Im(m_x)” and so forth.

tetrax.helpers.io.write_field_to_file(field, sample, fname='field.vtk', qname=None)#

Writes a scalar or vector field (MeshScalar or MeshVector) or a list of fields to a file using meshio.

Parameters
fieldMeshScalar, MeshVector array_like, or list

Input scalar- or vector field(s) to be saved to the file. If input is not MeshScalar or MeshVector, a shape check will be performed to infer the data type.

sampleAbstractSample

The sample on which the scalar- or vector field is defined. Necessary to save mesh with vtk.

fnamestr

Name of the file, has to contain a file ending from which the format can be inferred (Default is “field.vtk”)

qnamestr or list(str)

Name(s) of the scalar or vector quantity (quantities) to appear in the file (default is None). If qname is None, then the name(s) will be set to scalar or vector, depending on each input field.

tetrax.helpers.math module#

This submodule contains a number of mathematical functions. The import convention

>>> import numpy as np

is used.

tetrax.helpers.math.diag_matrix_from_vec(v)#

Given a vector v (length n), construct a sparse matrix with dimension n x n. The diagonal of the matrix is v.

tetrax.helpers.math.flattened_AFMmesh_vec_scalar_product(vec1, vec2)#

tba

tetrax.helpers.math.flattened_AFMmesh_vec_scalar_product_separate(vec1, vec2)#

Calculates the node-wise inner product of two flattened mesh vectors \(\mathbf{v}\) and \(\mathbf{w}\).

Assumes that the mesh vectors are of shape (3*N,) (with N being the number of nodes in the mesh) and are ordered according to

\[\mathbf{v} = (v_{x_1}, ... , v_{x_N}, v_{y_1}, ... , v_{y_N}, v_{z_1}, ... , v_{z_N})\]

and

\[\mathbf{w} = (w_{x_1}, ... , w_{x_N}, w_{y_1}, ... , w_{y_N}, w_{z_1}, ... , w_{z_N})\]

At each node \(i\), the inner product is defined as

\[\mathbf{v}_i \cdot \mathbf{w}_i = \sum\limits_{j=x,y,z} v_{j_i}w_{j_i}\]
Parameters
vec1FlattenedMeshVector

Flattened mesh vector of shape (3*N,).

vec2FlattenedMeshVector

Flattened mesh vector of shape (3*N,).

Returns
MeshScalar

Flattened mesh scalar of shape (N,).

tetrax.helpers.math.flattened_mesh_vec_abs(vec)#

Calculates the node-wise magnitude of a FlattenedMeshVector \(\mathbf{v}\).

Assumes that the mesh vector is of shape (3*N,) (with N being the number of nodes in the mesh) and is ordered according to

\[\mathbf{v} = (v_{x_1}, ... , v_{x_N}, v_{y_1}, ... , v_{y_N}, v_{z_1}, ... , v_{z_N})\]

At each node \(i\), the magnitude is calculated as

\[\| \mathbf{v}_i \| = \sqrt{v_{x_i}^2 + v_{y_i}^2+ v_{z_i}^2}\]
Parameters
vecFlattenedMeshVector

Flattened mesh vector of shape (3*N,).

Returns
MeshScalar

Mesh scalar of shape (N,).

tetrax.helpers.math.flattened_mesh_vec_scalar_product(vec1, vec2)#

Calculates the node-wise inner product of two flattened mesh vectors \(\mathbf{v}\) and \(\mathbf{w}\).

Assumes that the mesh vectors are of shape (3*N,) (with N being the number of nodes in the mesh) and are ordered according to

\[\mathbf{v} = (v_{x_1}, ... , v_{x_N}, v_{y_1}, ... , v_{y_N}, v_{z_1}, ... , v_{z_N})\]

and

\[\mathbf{w} = (w_{x_1}, ... , w_{x_N}, w_{y_1}, ... , w_{y_N}, w_{z_1}, ... , w_{z_N})\]

At each node \(i\), the inner product is defined as

\[\mathbf{v}_i \cdot \mathbf{w}_i = \sum\limits_{j=x,y,z} v_{j_i}w_{j_i}\]
Parameters
vec1FlattenedMeshVector

Flattened mesh vector of shape (3*N,).

vec2FlattenedMeshVector

Flattened mesh vector of shape (3*N,).

Returns
MeshScalar

Flattened mesh scalar of shape (N,).

tetrax.helpers.math.flattened_mesh_vec_scalar_product2d(vec1, vec2)#

Calculates the node-wise inner product of two flattened mesh vectors \(\mathbf{v}\) and \(\mathbf{w}\) which are define in a 2D vector field.

Assumes that the mesh vectors are of shape (2*N,) (with N being the number of nodes in the mesh) and are ordered according to

\[\mathbf{v} = (v_{x_1}, ... , v_{x_N}, v_{y_1}, ... , v_{y_N})\]

and

\[\mathbf{w} = (w_{x_1}, ... , w_{x_N}, w_{y_1}, ... , w_{y_N})\]

At each node \(i\), the inner product is defined as

\[\mathbf{v}_i \cdot \mathbf{w}_i = \sum\limits_{j=x,y} v_{j_i}w_{j_i}\]
Parameters
vec1FlattenedLocalMeshVector

Flattened local mesh vector of shape (2*N,).

vec2FlattenedLocalMeshVector

Flattened local mesh vector of shape (2*N,).

Returns
MeshScalar

Flattened mesh scalar of shape (N,).

tetrax.helpers.math.flattened_mesh_vec_tensor_product(vec1, vec2)#

Calculates the node-wise tensor product of two flattened mesh vectors \(\mathbf{v}\) and \(\mathbf{w}\).

Assumes that the mesh vectors are of shape (3*N,) (with N being the number of nodes in the mesh) and are ordered according to

\[\mathbf{v} = (v_{x_1}, ... , v_{x_N}, v_{y_1}, ... , v_{y_N}, v_{z_1}, ... , v_{z_N})\]

and

\[\mathbf{w} = (w_{x_1}, ... , w_{x_N}, w_{y_1}, ... , w_{y_N}, w_{z_1}, ... , w_{z_N})\]

At each node \(i\), the tensor product is defined as

\[\begin{split}\mathbf{v}_i \otimes \mathbf{w}_i = \begin{pmatrix} v_{x_i} w_{x_i} & v_{x_i} w_{y_i} & v_{x_i} w_{z_i} \\ v_{y_i} w_{x_i} & v_{y_i} w_{y_i} & v_{y_i} w_{z_i} \\ v_{z_i} w_{x_i} & v_{z_i} w_{y_i} & v_{z_i} w_{z_i} \end{pmatrix}\end{split}\]

The result is returned as a sparse block matrix of shape (3*N, 3*N), where the entries are ordered as

\[\begin{split}\hat{\mathbf{U}} = \begin{pmatrix} \hat{\mathbf{U}}_{xx} & \hat{\mathbf{U}}_{xy} & \hat{\mathbf{U}}_{xz} \\ \hat{\mathbf{U}}_{yx} & \hat{\mathbf{U}}_{yy} & \hat{\mathbf{U}}_{yz} \\ \hat{\mathbf{U}}_{zx} & \hat{\mathbf{U}}_{zy} & \hat{\mathbf{U}}_{zz} \end{pmatrix}\end{split}\]

in the diagonal blocks \(\hat{\mathbf{U}}_{xx} = \mathrm{diag}(v_{x_1} w_{x_1}, ..., v_{x_N} w_{x_N})\) and so forth.

Parameters
vec1FlattenedMeshVector

Flattened mesh vector of shape (3*N,).

vec2FlattenedMeshVector

Flattened mesh vector of shape (3*N,).

Returns
scipy.sparse.csr_matrix

Sparse matrix of shape (3*N, 3*N) in csr format.

tetrax.helpers.math.h_CPW(k, A, L, g, s)#

Fourier transform in z direction of one component of the microwave field distribution of a CPW antenna.

Parameters
kfloat

Wave vector along \(z\) direction.

Afloat

Amplitude of the field.

Lfloat

Width of individual current lines (in \(z\) direction).

gfloat

Gap between individual current lines (in \(z\) direction). Do not confuse with pitch.

sfloat

Distance from the center plane of the antenna.

Returns
float

See also

h_strip

This function is used in h_CPW.

h_U, h_hom

Notes

Assuming an infinitely thin antenna [R69191dc8bea2-1], the wave-vector dependent magnetitude is calculated according to

\[h_\mathrm{CPW}(k)=2A\sin^2\big(k(g+L)/2\big)\,h_\mathrm{strip}(k).\]
tetrax.helpers.math.h_U(k, A, L, g, s)#

Fourier transform in z direction of one component of the microwave-field distribution of a U-shaped antenna.

Parameters
kfloat

Wave vector along \(z\) direction.

Afloat

Amplitude of the field.

Lfloat

Width of individual current lines (in \(z\) direction).

gfloat

Gap between individual current lines (in \(z\) direction). Do not confuse with pitch.

sfloat

Distance from the center plane of the antenna.

Returns
float

See also

h_strip

This function is used in h_CPW.

h_U, h_hom

Notes

Assuming an infinitely thin antenna [1], the wave-vector dependent magnetitude is calculated according to

\[h_\mathrm{CPW}(k)=2iA\sin\big(k(g+L)/2\big)\,h_\mathrm{strip}(k).\]

References

1

M. Sushruth, et al., “Electrical spectroscopy of forward volume spin waves in perpendicularly magnetized materials”, Physical Review Research 2, 043203 (2020).

tetrax.helpers.math.h_hom(k, A)#

Fourier transform in z direction of one component of the of one component of the microwave-field distribution of a CPW antenna.

Parameters
kfloat

Wave vector along \(z\) direction.

Afloat

Amplitude of the field.

Returns
float

See also

h_strip, h_CPW, h_U

Notes

The wave-vector dependent magnetitude is calculated according to

\[h_\mathrm{hom}(k)=A\delta(k).\]

with \(\delta\) being the Dirac distribution.

tetrax.helpers.math.h_strip(k, A, L, s)#

Fourier transform in z direction of one component of the microwave field distribution of a stripline antenna.

Parameters
kfloat

Wave vector along \(z\) direction.

Afloat

Amplitude of the field.

Lfloat

Width of antenna (in \(z\) direction).

sfloat

Distance from the center plane of the antenna.

Returns
float

See also

h_U, h_CPW, h_hom

Notes

Assuming an infinitely thin antenna [1], the wave-vector dependent magnetitude is calculated according to

\[h_\mathrm{strip}(k)=A\frac{\sin(kL/2)}{kL/2} e^{-\vert k\vert s}.\]

References

1

M. Sushruth, et al., “Electrical spectroscopy of forward volume spin waves in perpendicularly magnetized materials”, Physical Review Research 2, 043203 (2020).

tetrax.helpers.math.interpolate_along_curve(xyz, field, curve, num_points=100, return_curve=False, dim=2)#

Interpolate unstructured data along a specified line or curve.

tetrax.helpers.math.matrix_elem(i, j, A, dV)#

Calculates the element of an operator A in the basis with respect to the basis vectors i and j as

\[A_{i,j} = \int\mathrm{d}V \ \mathbf{i}^*\cdot \hat{\mathbf{A}} \cdot \mathbf{j}.\]
Parameters
iFlattenedMeshVector

Flattened mesh vector of shape (3*N,).

jFlattenedMeshVector

Flattened mesh vector of shape (3*N,).

Ascipy.sparse.linalg.LinearOperator

LinearOperator of shape (3*N, 3*N).

dVMeshScalar

Volume elements of the mesh.

Returns
float
tetrax.helpers.math.normalize_single_3d_vec(vec)#

Normalizes a vector field.

Parameters
vecMeshVector

Mesh vector of shape (N,3).

Returns
vec_normalizedMeshVector

Normalized mesh vector of shape (N,3).

tetrax.helpers.math.sample_average(field, sample)#

Calculates the sample average of a scalar or vector field.

Parameters
fieldMeshScalar or MeshVector
sampleAbstractSample

Sample on which the field is define. Required to obtain the (generalized) volume elments.

Returns
averaged_fieldfloat or numpy.array

Returns averaged scalar fields as a float and averaged vector fields as a triplet of ``float``s.

tetrax.helpers.math.spherical_angles_to_mesh_vector(theta, phi, as_flattened=False)#

Node-wise, convert spherical angles to a unit vector.

Assumes that theta and phi are of shape (N,) with N being the number of mesh nodes.

Parameters
thetaMeshScalar

Polar angle at each node point.

phiMeshScalar

Azimuthal angle at each node point.

as_flattenedbool, optional

Return resulting unit vector as flattened mesh vector (default is False).

Returns
MeshVector or FlattenedMeshVector

Unit mesh vector of shape (N, 3) if as_flattened=False or as flattened mesh vector of shape (3*N,) if as_flattened=True.

Module contents#