Data types
The data types module contains class definition to hold SEM data.
The main classes are:
Some functions using these classes are in the utils module. Here we show them:
Module for utility functions for the datatypes module
- pysemtools.datatypes.utils.extrude_2d_sem_mesh(comm, lz: int = 1, msh: Mesh | None = None, fld: Field | FieldRegistry | None = None, point_dist: ndarray | None = None)
Extrude a 2D SEM mesh to 3D.
Extrude a 2D SEM mesh to 3D by replicating the mesh and fields in the z direction.
- Parameters:
- commComm
A communicator object.
- lzint
Number of layers in the z direction.
- mshMesh
A mesh object.
- fldField or FieldRegistry
A field object.
- point_distndarray
Array with the z coordinates of the new mesh. Defaults to GLL points from -1 to 1.
- Returns:
- Mesh
A 3D mesh object.
- FieldRegistry
A 3D field object.
- pysemtools.datatypes.utils.get_angular_rotation_tensor(grad_u, msh)
Calculate the antisymetric part of the gradient.
Calculate the antisymetric part of the gradient tensor, defined as:
\[1/2 (G(u) - G(u)^T).\]Typically known in fluids as the angular rotation tensor.
Another notation is: \(1/2 (\partial{u_i}/\partial{x}_j - \partial{u}_j/\partial{x}_i)\).
- Parameters:
- grad_undarray
Gradient of a field. A 6D ndarray with the shape (nelv, lz, ly, lx, 3, 3) for 3d data.
- mshMesh
A mesh object.
- Returns:
- ndarray
A 6D ndarrays with the shape (nelv, lz, ly, lx, 3, 3).
Examples
For grad
>>> aij = get_angular_rotation_tensor(grad, msh)
Useful for postprocessing
- pysemtools.datatypes.utils.get_gradient(msh, coef, field_list=None)
Get gradient from a 3D field vector field wrt x, y, z directions.
The gradient of a vector field is a tensor. The gradient of a scalar field is a vector field.
For each point in a vector field \(u_i = [u_1, u_2, u_3]\) in space with coordinates \(x_j = [x, y, z]\), the gradient is a 3x3 tensor \(G(u)_{i,j}\) with:
\[G(u)_{i,j} = \partial{u_i}/\partial{x_j}.\]whith \(i\) and \(j\) being the rows and columns of the matrix, respectively.
- Parameters:
- mshMesh
A mesh object.
- coefCoef
A coef object.
- field_listlist
A list of the vector/scalar fields to calcule the 3D gradient to. Each entry in the list should be a 4D ndarray with the shape (nelv, lz, ly, lx). (Default value = None).
- Returns:
- ndarray
A 6D ndarray with the shape (nelv, lz, ly, lx, number_of_fields, 3).
Notes
Each point in a vector field u(x,y,z), v(x,y,z), w(x,y,z) has a gradient (jacobian) that is a 3x3 tensor.
Each point in a scalar field s(x,y,z) has a gradient (jacobian) that is a 1x3 tensor.
The resulting gradient is a 6D tensor with the shape (nelv, lz, ly, lx, number_of_fields, 3).
Examples
For fields grad_u
>>> grad = get_gradient(msh, coef, [u, v, w])
- pysemtools.datatypes.utils.get_strain_tensor(grad_u, msh)
Calculate the symetric part of the gradient.
Calculate the symetric part of the gradient tensor, defined as:
\[1/2 (G(u) + G(u)^T).\]Typically known in fluids as the strain tensor.
Another notation is: \(1/2 (\partial{u_i}/\partial{x}_j + \partial{u}_j/\partial{x}_i)\).
- Parameters:
- grad_undarray
Gradient of a field. A 6D ndarray with the shape (nelv, lz, ly, lx, 3, 3) for 3d data.
- mshMesh
A mesh object.
- Returns:
- ndarray
A 6D ndarrays with the shape (nelv, lz, ly, lx, 3, 3).
Examples
For grad
>>> sij = get_strain_tensor(grad, msh)
Useful for postprocessing
- pysemtools.datatypes.utils.write_fld_file_from_list(fname, comm, msh, field_list=None)
Write fld file from a field list, each field written as a scalar.
This function writes a fld from a field list in the scalar positions.
- Parameters:
- fnamestr
Name of the file to be written.
- commComm
A communicator object.
- mshMesh
A mesh object.
- field_listlist
- A list of the fields to be written to the file.
(Default value = None).
Examples
Having defined ndarrays u, v, w of shape (nelv, lz, ly, lx). To write them as scalars in the file:
>>> write_fld_file_from_list("field0.f00001", comm, msh, [u, v, w])
To write them in positions 0, 1, 2 of the vel keyword in the file, you should not use this function, and instead create a empty field object and update its metadata with the correct positions.
>>> out_fld = Field(comm) >>> out_fld.fields["vel"].append(u) >>> out_fld.fields["vel"].append(v) >>> out_fld.fields["vel"].append(w) >>> out_fld.update_vars() >>> out_data = create_hexadata_from_msh_fld(msh=msh, fld=out_fld) >>> pwritenek("field0.f00001", out_data, comm)
This function just wraps these commands and assumes they will be in the scalar keyword.
- pysemtools.datatypes.utils.write_fld_subdomain_from_list(fname, comm, msh, field_list=None, subdomain=[], p=None)
Write a subdomain and p-refine of the sem mesh into an fld file from a field list.
This function writes a fld from a field list in the scalar positions. In a subdomain specified by the list of list subdomain.
If p is not None, the mesh is refined/coarsened.
- Parameters:
- fnamestr
Name of the file to be written.
- commComm
A communicator object.
- mshMesh
A mesh object.
- field_listlist
A list of the fields to be written to the file. (Default value = None).
- subdomainlist
A list of lists with the subdomain to be written. the format is: subdomain = [[x_min, x_max],[y_min, y_max],[z_min, z_max]]. (Default value = []).
- pint, optional
Polynomial degree of the new mesh. If None, the mesh is not refined/coarsened. (Default value = None).