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.bibof the sample. If this file does not exist, it will be created.- Parameters
- sample
AbstractSample Sample object at hand.
- entries_for{‘eigenmodes1d’, ‘eigenmodes2d’, ‘absorption’, ‘tetrax’}
Can be in
- sample
- tetrax.helpers.io.check_mesh_shape(mesh: meshio._mesh.Mesh, dim: int) bool#
Check if mesh is properly shaped.
dim == 3: always Truedim == 2: True if mesh is in xy plane.dim == 1: True if mesh is on y axis.
- tetrax.helpers.io.get_ids(db)#
Get the a 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
- mesh
meshio.Mesh Mesh object.
- mesh
- Returns
intDimension 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
- Returns
MeshVectororFlattenedMeshVectorMode 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) to a file using meshio.
- Parameters
- field
MeshScalar,MeshVectoror array_like Input scalar- or vector field to be saved to the file. If input is not MeshScalar or MeshVector, a shape check will be performed to infer the data type.
- sample
AbstractSample The sample on which the scalar- or vector field is defined. Necessary to save mesh with vtk.
- fname
str Name of the file, has to contain a file ending from which the format can be inferred (Default is “field.vtk”)
- qname
Name of the scalar or vector quantity to appear in the file (default is None). If qname is None, then the name will be set to scalar or vector, depending on the input field.
- 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_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
- vec
FlattenedMeshVector Flattened mesh vector of shape (3*N,).
- vec
- Returns
MeshScalarMesh 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
- vec1
FlattenedMeshVector Flattened mesh vector of shape (3*N,).
- vec2
FlattenedMeshVector Flattened mesh vector of shape (3*N,).
- vec1
- Returns
MeshScalarFlattened 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
- vec1
FlattenedLocalMeshVector Flattened local mesh vector of shape (2*N,).
- vec2
FlattenedLocalMeshVector Flattened local mesh vector of shape (2*N,).
- vec1
- Returns
MeshScalarFlattened 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
- vec1
FlattenedMeshVector Flattened mesh vector of shape (3*N,).
- vec2
FlattenedMeshVector Flattened mesh vector of shape (3*N,).
- vec1
- Returns
scipy.sparse.csr_matrixSparse matrix of shape
(3*N, 3*N)incsrformat.
- 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
- Returns
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
- Returns
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.
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
- Returns
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.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
- i
FlattenedMeshVector Flattened mesh vector of shape (3*N,).
- j
FlattenedMeshVector Flattened mesh vector of shape (3*N,).
- A
scipy.sparse.linalg.LinearOperator LinearOperator of shape (3*N, 3*N).
- dV
MeshScalar Volume elements of the mesh.
- i
- Returns
- tetrax.helpers.math.normalize_single_3d_vec(vec)#
Normalizes a vector field.
- Parameters
- vec
MeshVector Mesh vector of shape (N,3).
- vec
- Returns
- vec_normalized
MeshVector Normalized mesh vector of shape (N,3).
- vec_normalized
- tetrax.helpers.math.sample_average(field, sample)#
Calculates the sample average of a scalar or vector field.
- Parameters
- field
MeshScalarorMeshVector - sample
AbstractSample Sample on which the field is define. Required to obtain the (generalized) volume elments.
- field
- Returns
- averaged_field
floatornumpy.array Returns averaged scalar fields as a
floatand averaged vector fields as a triplet of ``float``s.
- averaged_field
- 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
- theta
MeshScalar Polar angle at each node point.
- phi
MeshScalar Azimuthal angle at each node point.
- as_flattenedbool, optional
Return resulting unit vector as flattened mesh vector (default is False).
- theta
- Returns
MeshVectororFlattenedMeshVectorUnit mesh vector of shape (N, 3) if as_flattened=False or as flattened mesh vector of shape (3*N,) if as_flattened=True.