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.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_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.read_mode_from_vtk(fname, as_flattened=False)#
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
- numpy.array
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.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_mesh_vec_abs(vec)#
Calculates the node-wise magnitude of a flattened mesh vector \(\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
- vecnp.array
Flattened mesh vector of shape (3*N,).
- Returns
- np.array
Flattened 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
- vec1np.array
Flattened mesh vector of shape (3*N,).
- vec2np.array
Flattened mesh vector of shape (3*N,).
- Returns
- np.array
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
- vec1np.array
Flattened mesh vector of shape (2*N,).
- vec2np.array
Flattened mesh vector of shape (2*N,).
- Returns
- np.array
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
- vec1np.array
Flattened mesh vector of shape (3*N,).
- vec2np.array
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
Notes
Assuming an infinitely thin antenna [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).\]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_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
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
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
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.normalize_single_3d_vec(vec)#
- 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
- thetanp.array
Polar angle at each node point.
- phinp.array
Azimuthal angle at each node point.
- as_flattenedbool, optional
Return resulting unit vector as flattened mesh vector (default is False).
- Returns
- np.array
Unit mesh vector of shape (N, 3) if as_flattened=False or as flattened mesh vector of shape (3*N,) if as_flattened=True.