salvus.mesh.data_structures.unstructured_mesh.unstructured_mesh
The unstructured mesh class for higher order quadrilateral and hexahedral meshes.
Classes
UnstructuredMesh
UnstructuredMeshclass UnstructuredMesh(builtins.object):
def __init__(
self,
points: npt.NDArray,
connectivity: npt.NDArray,
scale: float = 1.0,
global_variables: dict = default,
global_strings: dict = default,
global_arrays: dict = default,
elemental_fields: dict[str, npt.NDArray] = default,
nodal_fields: dict[str, npt.NDArray] = default,
side_sets: dict[str, typing.Tuple[npt.NDArray, npt.NDArray]] = default,
deformations: dict[str, npt.NDArray] = default,
) -> None: ...Salvus’ representation of higher-order unstructured meshes.
pointsnpt.NDArray — Nodes of the mesh, array with shape (number of points, number of dimensions)connectivitynpt.NDArray — Connectivity of the mesh defining the elements in the mesh listing all nodes in tensorized order. Must have shape (number of elements, (shape order + 1) ** (number of dimensions)).scalefloat — A scaling of the mesh that is only applied to the points array upon writing to file.global_variablesdict — Global variables stored in the mesh.global_stringsdict — Global strings stored in the mesh.global_arraysdict — Global arrays stored in the mesh.elemental_fieldsdict[str, npt.NDArray] — Fields defined on the mesh.nodal_fieldsdict[str, npt.NDArray] — Nodal fields.side_setsdict[str, typing.Tuple[npt.NDArray, npt.NDArray]] — The side sets.deformationsdict[str, npt.NDArray] — Collects so far unapplied deformations.
coordinate_system CoordinateSystem
coordinate_system CoordinateSystemThe coordinate system of the mesh.
edges_per_element int
edges_per_element intThe number of edge for one element of the mesh.
We only support quads and hexes currently so it will be either 4 or 12.
element_nodal_fields typing.Dict[str, npt.NDArray]
element_nodal_fields typing.Dict[str, npt.NDArray]Element nodal fields.
element_nodes_shape typing.Tuple[int, ...]
element_nodes_shape typing.Tuple[int, ...]Return the shape of the element nodes array.
Useful for initializing element nodal fields.
Returns: The shape of the element nodes.
elemental_scalar_fields typing.Dict[str, npt.NDArray]
elemental_scalar_fields typing.Dict[str, npt.NDArray]Element scalar fields.
first_order_connectivity npt.NDArray
first_order_connectivity npt.NDArrayFirst order connectivity constructed from the corner points in case the shape mapping order is larger than 1.
max_dist_abc float
max_dist_abc floatMaximum distance of the absorbing damping layer from the edge of the domain.
ndim int
ndim intThe dimensionality of the mesh.
nelem int
nelem intTotal number of spectral elements in the unstructured mesh.
nodes_per_element int
nodes_per_element intThe number of nodes for one element of the mesh.
Will be 4 for first-order 2-D meshes, 9 for second-order 2-D meshes, 8 for first-order 3-D meshes, 125 for fourth-order 3-D meshes and so on.
npoint int
npoint intTotal number of nodes in the unstructured mesh.
number_of_elemental_fields int
number_of_elemental_fields intThe total number of elemental fields in the mesh.
number_of_elements int
number_of_elements intTotal number of spectral elements in the unstructured mesh.
number_of_global_arrays int
number_of_global_arrays intThe total number of global arrays in the mesh.
number_of_global_strings int
number_of_global_strings intThe total number of global strings in the mesh.
number_of_global_variables int
number_of_global_variables intThe total number of global variables in the mesh.
number_of_nodal_fields int
number_of_nodal_fields intThe total number of nodal fields in the mesh.
number_of_nodes int
number_of_nodes intTotal number of nodes in the unstructured mesh.
number_of_side_sets int
number_of_side_sets intThe total number of side sets in the mesh.
shape_order int
shape_order intShape mapping order, i.e. the number of points in each direction in the tensorized elements - 1.
from_exodus()
from_exodus()def from_exodus(
filename: str | pathlib.Path,
attach_element_block_indices: bool = False,
select_element_block_indices: typing.Sequence[int] | None = None,
) -> UnstructuredMesh: ...Read unstructured mesh from exodus file.
Only supports first order quads or hexes.
filenamestr | pathlib.Path — File to open.attach_element_block_indicesbool — If True, attach the element block indices to the mesh.select_element_block_indicestyping.Sequence[int] | None — If given, read only these element blocks. Keep in mind that exodus uses 1-based indexing.
from_h5()
from_h5()def from_h5(
filename: str | pathlib.Path, read_data: bool = True
) -> UnstructuredMesh: ...Read an unstructured mesh from an HDF5 Salvus mesh file.
filenamestr | pathlib.Path — File to open.read_databool — read the elemental and element nodal data
add_dem_2D()
add_dem_2D()def add_dem_2D(
mesh: UnstructuredMesh,
x: npt.NDArray,
deformation: npt.NDArray,
vertical_begin_deformation: float = 0.0,
vertical_end_deformation: float = inf,
vertical_reference: typing.Optional[float] = None,
name: typing.Optional[str] = None,
mode: DeformationMode2D | str = DeformationMode2D.cartesian,
) -> None: ...Queue a 2D deformation for later application.
Please see the compute_deformation_2D function for more information.
meshUnstructuredMesh — The mesh to queue for.xnpt.NDArray — horizontal coordinates of the deformation. Angle in radians for spherical models.deformationnpt.NDArray — The deformation sampled at coordinates x.vertical_begin_deformationfloat — Don’t deform any points with a vertical coordinate smaller than this.vertical_end_deformationfloat — Don’t deform any points with a vertical coordinate larger than this.vertical_referencetyping.Optional[float] — Vertical coordinate, at which the deformation should be applied, e.g. y-coordinate of the surface for surface deformation. Defaults to the max y coordinate / radius in case at least one of y0, y1 are finite.nametyping.Optional[str] — Optionally pass a name for the deformation.modeDeformationMode2D | str — The deformation mode.
add_dem_3D()
add_dem_3D()def add_dem_3D(
mesh: UnstructuredMesh,
x: npt.NDArray,
y: npt.NDArray,
deformation: npt.NDArray,
vertical_begin_deformation: float = 0.0,
vertical_end_deformation: float = inf,
vertical_reference: typing.Optional[float] = None,
interpolation_order: int = 3,
mode: DeformationMode3D | str = DeformationMode3D.cartesian,
name: typing.Optional[str] = None,
) -> None: ...Queue a 3D deformation for later application.
Please see the compute_deformation_3D function for more information.
meshUnstructuredMesh — The mesh to queue for.xnpt.NDArray — first horizontal coordinate of the deformation. Angle in radians for spherical models.ynpt.NDArray — second horizontal coordinate of the deformation. Angle in radians for spherical models.deformationnpt.NDArray — The deformation sampled at coordinates x.vertical_begin_deformationfloat — Don’t deform any points with a vertical coordinate smaller than this.vertical_end_deformationfloat — Don’t deform any points with a vertical coordinate larger than this.vertical_referencetyping.Optional[float] — Vertical coordinate, at which the deformation should be applied, e.g. y-coordinate of the surface for surface deformation. Defaults to the max y coordinate / radius in case at least one of y0, y1 are finite.interpolation_orderint — Horizontal interpolation order.modeDeformationMode3D | str — The deformation mode.nametyping.Optional[str] — Optionally pass a name for the deformation.
add_dem_cylindrical()
add_dem_cylindrical()def add_dem_cylindrical(
mesh: UnstructuredMesh,
phi: npt.NDArray,
z: npt.NDArray,
dem: npt.NDArray,
r0: float = 0.0,
r1: float = inf,
rref: typing.Optional[float] = None,
name: typing.Optional[str] = None,
) -> None: ...Queue cylindrical deformations for later application.
Add deformation for cylindrical meshes where the axis of the cylinder is aligned with the z component. The DEM radially stretches the domain in the region of (x,y)-radii in [r0, r1] - points below r0 are kept fixed, points above r1 are moved as the DEM, points in between are interpolated and the full DEM is applied to points at rref.
Usage: first call add_dem_cylindrical for each boundary that is to be perturbed and finally call apply_dem to add the perturbation to the mesh coordinates.
meshUnstructuredMesh — The mesh.phinpt.NDArray — Angle in the x-y-plane of the DEM in radians.znpt.NDArray — z-coordinates of the DEM.demnpt.NDArray — the DEM sampled at the coordinates (phi,z)r0float — radius in x-y-plane at which the stretching beginsr1float — radius in x-y-plane at which the stretching ends, can be infinityrreftyping.Optional[float] — radius in x-y-plane at which the deformation should be appliednametyping.Optional[str] — name of this deformation to refer to it in UnstructuredMesh.apply_dem()
apply_deformations()
apply_deformations()def apply_deformations(
mesh: UnstructuredMesh, names: typing.Optional[typing.List[str]] = None
) -> None: ...Apply the previously added deformations.
meshUnstructuredMesh — The mesh.namestyping.Optional[typing.List[str]] — Names of the deformations to apply. Defaults to all added ones.
apply_dem()
apply_dem()def apply_dem(
mesh: UnstructuredMesh, names: typing.Optional[typing.List[str]] = None
) -> None: ...Apply the previously added deformations.
meshUnstructuredMesh — The mesh.namestyping.Optional[typing.List[str]] — Names of the deformations to apply. Defaults to all added ones.
apply_element_mask()
apply_element_mask()def apply_element_mask(
mesh: UnstructuredMesh,
mask: npt.NDArray,
return_node_map: bool = False,
side_sets: typing.Optional[typing.Union[str, typing.List[str]]] = None,
) -> typing.Union[
UnstructuredMesh, typing.Tuple[UnstructuredMesh, npt.NDArray]
]: ...Apply an element mask to the mesh returning a new mesh object.
Only retains elements that are set to True in the mask.
meshUnstructuredMesh — The mesh.masknpt.NDArray — The mask as boolean array.return_node_mapbool — Return a node map together with the new mesh object, to be used to map nodal fields to the set of nodes that are retained in the mesh.side_setstyping.Optional[typing.Union[str, typing.List[str]]] — list of side set names to which the mask should be directly connected. All elements not connected to the side sets are retained. Can be used to avoid cavities in the mask.
apply_scale()
apply_scale()def apply_scale(mesh: UnstructuredMesh) -> None: ...Apply the scaling factor to the mesh.
meshUnstructuredMesh — The mesh.
attach_elemental_field()
attach_elemental_field()def attach_elemental_field(self, name: str, value: npt.NDArray) -> None: ...Attach an elemental field to the mesh.
namestr — The name of the elemental field.valuenpt.NDArray — The data array to store.
attach_field()
attach_field()def attach_field(self, name: str, data: npt.NDArray) -> None: ...Attach a field to the mesh.
The shape of the data determines
namestr — name of the fielddatanpt.NDArray — data to store. 1D numpy array, with size of either nelem or npoint.
attach_global_variable()
attach_global_variable()def attach_global_variable(
self, name: str, data: typing.Union[float, str, npt.NDArray]
) -> None: ...Add a global variable to the mesh.
Depending on the type of data it will go to different containers.
namestr — The key to store.datatyping.Union[float, str, npt.NDArray] — The value to store.
attach_nodal_field()
attach_nodal_field()def attach_nodal_field(self, name: str, value: npt.NDArray) -> None: ...Attach a nodal field to the mesh.
namestr — The name of the nodal field.valuenpt.NDArray — The data array to store.
change_tensor_order()
change_tensor_order()def change_tensor_order(
mesh: UnstructuredMesh,
tensor_order: typing.Optional[salvus._core.types.int_] = None,
interpolation_mode: InterpolationMode | str = InterpolationMode.linear,
interpolation_kwargs: typing.Optional[typing.Dict] = None,
make_unique_points: bool = True,
tensor_node_locations: typing.Optional[npt.NDArray] = None,
) -> None: ...Change the tensor order of a mesh’s elements
Usually going from linear to higher order elements.
Please be aware that this will delete any potentially set element nodal fields and nodal fields. Elemental fields and side sets will be retained.
New grid points are created by interpolating the existing corner
points. This function supports a variety of interpolation modes (some
of which require extra kwargs to set as part of the
interpolation_kwargs dictionary):
"linear": The default. Perform a bi/trilinear interpolation. No extra keyword arguments are supported or required for this mode."spherical": Linearly interpolate in radial direction, and apply spherical linear interpolation (slerp) laterally. The center of the sphere is always considered to be at the origin of the coordinate system. Supported additional keywords:
"r1_spherical": Apply slerp only for radii >=r1_spherical, default:0.0."r0_spherical": Apply bi/trilinear interpolation for radii <r0_spherical, default:0.0.
If r1_spherical > r0_spherical intermediate radii will linearly
interpolate between both modes.
"cylindrical": Linearly interpolate radially and along the last dimension. Slerp in the middle dimension. Only defined in 3D, for 2D point symmetry use"spherical". Supported additional keywords:
"r1_cylindrical": Apply slerp only for radii >=r1_cylindrical, default:0.0."r0_cylindrical": Apply bi/trilinear interpolation for radii <r0_cylindrical, default:0.0.
If r1_cylindrical > r0_cylindrical intermediate radii will linearly
interpolate between both modes.
"SmoothieSEM": Special interpolation mode for spherical SmoothieSEM mesh that preserves the cylindrical “inner core”. Supported additional keywords:"r0_spherical","r1_spherical","r0_cylindrical", and"r1_cylindrical"with the same meaning as for the other interpolation modes.
meshUnstructuredMesh — The mesh whose tensor order to change.tensor_ordertyping.Optional[salvus._core.types.int_] — Desired new tensor order of the elements.interpolation_modeInterpolationMode | str — How to interpolate the location of the new grid points. See above description.interpolation_kwargstyping.Optional[typing.Dict] — Extra keyword arguments for the chosen interpolation mode. See above description.make_unique_pointsbool — Remove duplicate points. Make sure to have a reason if you set this toFalse.tensor_node_locationstyping.Optional[npt.NDArray] — Locations of the tensor nodes. Defaults to the GLL locations of the chosen tensor order. In almost all cases you will not have to change this.
clear()
clear()def clear(self) -> None: ...“Clear” the mesh.
This will remove everything that is not related to the geometry, e.g. only the points, connectivity and scale will be kept.
compute_dt()
compute_dt()def compute_dt(
mesh: UnstructuredMesh,
max_velocity: typing.Union[npt.NDArray, float],
courant_number: float = 1.0,
min_gll_point_distance: float = 1.0,
fast: bool = True,
return_hmin_elemnodes: bool = False,
) -> typing.Union[
typing.Tuple[float, npt.NDArray],
typing.Tuple[float, npt.NDArray, npt.NDArray],
]: ...Compute an estimation of the time step set by each element.
meshUnstructuredMesh — The mesh to compute it for.max_velocitytyping.Union[npt.NDArray, float] — Fastest velocity in each element.courant_numberfloat — Courant numbermin_gll_point_distancefloat — min_gll_point_distancefastbool — fastreturn_hmin_elemnodesbool — return_hmin_elemnodes
compute_mesh_quality()
compute_mesh_quality()def compute_mesh_quality(
mesh: UnstructuredMesh, quality_metric: str = "edge_aspect_ratio"
) -> npt.NDArray: ...Compute a few proxies for for mesh quality.
meshUnstructuredMesh — The mesh to compute it for.quality_metricstr — The quality metric to compute.
compute_resolved_frequency()
compute_resolved_frequency()def compute_resolved_frequency(
mesh: UnstructuredMesh,
min_velocity: npt.NDArray,
elements_per_wavelength: float,
) -> typing.Tuple[float, npt.NDArray]: ...Estimate the highest resolved frequency in each element.
meshUnstructuredMesh — The mesh to compute it for.min_velocitynpt.NDArray — Minimum velocity in each element.elements_per_wavelengthfloat — The elements per wavelength.
compute_spatial_gradients()
compute_spatial_gradients()def compute_spatial_gradients(
mesh: UnstructuredMesh,
fields: typing.Optional[typing.Union[str, typing.List[str]]] = None,
) -> None: ...Extract spatial model gradients.
This function takes a mesh object and computes the spatial model gradient of each field contained in the mesh. The function returns the same mesh with additional fields for each component of the gradient.
Model gradients are always computed in Cartesian coordinates. By construction of the Lagrange basis, the gradients are not continuous across elemental boundaries. Hence, the values of the gradient on points shared between elements, depend on which element they are computed in.
meshUnstructuredMesh — Mesh object for which model gradients are to be computed.fieldstyping.Optional[typing.Union[str, typing.List[str]]] — Optional list of fields for which model gradients should be computed. Defaults to all fields contained in the mesh.
copy()
copy()def copy(self) -> UnstructuredMesh: ...Return a deep copy of the object.
create_side_set()
create_side_set()def create_side_set(
mesh: UnstructuredMesh,
side_set_name: str,
side_set: typing.Optional[
typing.Union[
typing.Tuple[npt.NDArray, npt.NDArray],
typing.Set[typing.Tuple[int, int]],
]
] = None,
element_indices: typing.Optional[npt.NDArray] = None,
side_indices: typing.Optional[npt.NDArray] = None,
) -> None: ...Create a new side set on the mesh.
There are a two options here:
- Provide the element and side indices.
- Directly provide the side set set as provided by UnstructuredMesh.get_side_set().
meshUnstructuredMesh — The mesh.side_set_namestr — The name of the to be create side set.side_settyping.Optional[typing.Union[typing.Tuple[npt.NDArray, npt.NDArray], typing.Set[typing.Tuple[int, int]]]] — Directly provide the side set.element_indicestyping.Optional[npt.NDArray] — The global element indices for the new side set.side_indicestyping.Optional[npt.NDArray] — The side ids to use for each element.
estimate_resolved_frequency()
estimate_resolved_frequency()def estimate_resolved_frequency(
mesh: UnstructuredMesh,
min_velocity: npt.NDArray,
elements_per_wavelength: float,
) -> typing.Tuple[float, npt.NDArray]: ...Estimate the highest resolved frequency in each element.
meshUnstructuredMesh — The mesh to compute it for.min_velocitynpt.NDArray — Minimum velocity in each element.elements_per_wavelengthfloat — The elements per wavelength.
estimate_time_step()
estimate_time_step()def estimate_time_step(
mesh: UnstructuredMesh,
max_velocity: typing.Union[npt.NDArray, float],
courant_number: float = 1.0,
min_gll_point_distance: float = 1.0,
fast: bool = True,
return_hmin_elemnodes: bool = False,
) -> typing.Union[
typing.Tuple[float, npt.NDArray],
typing.Tuple[float, npt.NDArray, npt.NDArray],
]: ...Compute an estimation of the time step set by each element.
meshUnstructuredMesh — The mesh to compute it for.max_velocitytyping.Union[npt.NDArray, float] — Fastest velocity in each element.courant_numberfloat — Courant numbermin_gll_point_distancefloat — min_gll_point_distancefastbool — fastreturn_hmin_elemnodesbool — return_hmin_elemnodes
extrude()
extrude()def extrude(
mesh: UnstructuredMesh,
offsets: npt.NDArray,
scale: typing.Optional[npt.NDArray] = None,
rotation: typing.Optional[npt.NDArray] = None,
center: typing.Optional[npt.NDArray] = None,
) -> UnstructuredMesh: ...Extrude a 2D mesh to create a 3D mesh.
Each extruded 2D mesh can be offset, scaled and rotated copies of the original.
meshUnstructuredMesh — The mesh to extrude.offsetsnpt.NDArray — offsets, either in the new dimension or all 3 dimension, shape is (nextrude, ) or (nextrude, 3)scaletyping.Optional[npt.NDArray] — scaling factor for each extruded copy, relative to the center, shape is (nextrude,)rotationtyping.Optional[npt.NDArray] — rotation of each extruded copy in terms of euler angles relative to the center, shape is (nextrude, 3)centertyping.Optional[npt.NDArray] — center coordinates for rotation, defaults to the center of mass of the original 2D mesh, shape is (3,)
extrude_side_set()
extrude_side_set()def extrude_side_set(
mesh: UnstructuredMesh,
side_set: str,
offsets: npt.NDArray,
scale: typing.Optional[npt.NDArray] = None,
rotation: typing.Optional[npt.NDArray] = None,
center: typing.Optional[npt.NDArray] = None,
) -> UnstructuredMesh: ...Extrude a side set to add new elements to the mesh.
meshUnstructuredMesh — The mesh to extrude.side_setstr — name of the side setoffsetsnpt.NDArray — offsets, either in the new dimension or all 3 dimension, shape is (nextrude, ) or (nextrude, 3)scaletyping.Optional[npt.NDArray] — scaling factor for each extruded copy, relative to the center, shape is (nextrude,)rotationtyping.Optional[npt.NDArray] — rotation of each extruded copy in terms of euler angles relative to the center, shape is (nextrude, 3)centertyping.Optional[npt.NDArray] — center coordinates for rotation, defaults to the center of mass of the original 2D mesh, shape is (3,)
extrude_side_set_2D()
extrude_side_set_2D()def extrude_side_set_2D(
mesh: UnstructuredMesh,
side_set: str,
offsets: npt.NDArray,
direction: typing.Optional[str] = None,
) -> UnstructuredMesh: ...Extrude a side set of a 2D mesh and append new elements.
Currently, the functionality is limited to cartesian meshes with side sets that are aligned with the coordinate axis.
meshUnstructuredMesh — The mesh to extrude.side_setstr — name of the side setoffsetsnpt.NDArray — offsets, either in the new dimension or all 3 dimension, shape is (nextrude, ) or (nextrude, 3)directiontyping.Optional[str] — Optional axis of extrusion ifoffsetsis a one-dimensional array. Must bexory.
find_side_sets()
find_side_sets()def find_side_sets(
mesh: UnstructuredMesh, mode: str = "cartesian", tolerance: float = 1e-08
) -> None: ...Find surfaces of simple box or spherical meshes in 2 or 3 dimension.
Use UnstructuredMesh.find_surface() for more complex shapes.
meshUnstructuredMesh — The unstructured mesh.modestr — the side sets to be found depend on the shape of the mesh, should be one of “cartesian”, “cylindrical”, “spherical_full”, “spherical_chunk”, “spherical_chunk_z”, or “spherical_SmoothieSEM”.tolerancefloat — Floating point tolerance to assume a node is on a given side.
find_side_sets_enclosing()
find_side_sets_enclosing()def find_side_sets_enclosing(
mesh: UnstructuredMesh, mode: str = "cartesian", tolerance: float = 1e-08
) -> None: ...Find surfaces of simple box or spherical meshes in 2 or 3 dimension, augmented by a catch-all surface for unidentified portions of the surface, named “remainder_side_set”.
Runs find_side_sets followed by find_surface to find the remainder
side-sets of any non-found facets. Uniquefies side-sets, which will alter
existing side-sets.
meshUnstructuredMesh — The unstructured mesh.modestr — the side sets to be found depend on the shape of the mesh, should be one of “cartesian”, “cylindrical”, “spherical_full”, “spherical_chunk”, “spherical_chunk_z”, or “spherical_SmoothieSEM”.tolerancefloat — Floating point tolerance to assume a node is on a given side.
find_side_sets_generic()
find_side_sets_generic()def find_side_sets_generic(
mesh: UnstructuredMesh,
name: str,
distance: typing.Union[
typing.Callable[[npt.NDArray], npt.NDArray], npt.NDArray
],
tolerance: float = 1e-08,
attach_side_set: bool = True,
) -> typing.Optional[typing.Tuple[npt.NDArray, npt.NDArray]]: ...Find side sets based on a distance function.
meshUnstructuredMesh — The mesh.namestr — Name of the new side set.distancetyping.Union[typing.Callable[[npt.NDArray], npt.NDArray], npt.NDArray] — Callback function taking in points and returning a distance.tolerancefloat — Point with a distance beneath this are part of the side set.attach_side_setbool — If true, add the side set to the mesh, othewise return the side set elements and sides.
find_surface()
find_surface()def find_surface(
mesh: UnstructuredMesh, side_set_name: str = "surface"
) -> None: ...Mark all surface faces as a side set.
meshUnstructuredMesh — The mesh to use.side_set_namestr — Name to give to the found surface.
get_element_centroid()
get_element_centroid()def get_element_centroid(
mesh: UnstructuredMesh, spherical: bool = False
) -> npt.NDArray: ...For each element, compute its centroid.
meshUnstructuredMesh — The mesh.sphericalbool — Assume a spherical mesh to perform a spherical computation.
get_element_centroid_radius()
get_element_centroid_radius()def get_element_centroid_radius(mesh: UnstructuredMesh) -> npt.NDArray: ...Get the radius of the centroid of each element for spherical meshes.
Compute the centroids of all elements on the fly from the nodes of the mesh. Useful to determine which domain in a layered medium an element belongs to or to compute elemental properties from the model. This function computes the spherical radius directly and is hence more memory efficient than UnstructuredMesh.get_element_centroid()
meshUnstructuredMesh — The mesh.
get_element_nodes()
get_element_nodes()def get_element_nodes(
mesh: UnstructuredMesh,
mask: typing.Union[typing.Tuple, npt.NDArray] = (slice(None, None, None),),
) -> npt.NDArray: ...Get the nodes for each element in the mesh.
Get duplicated nodes, i.e. an array with shape (nelem, nodes_per_element, ndim) containing the node locations for all elements for all nodes. This can be significant in terms of memory requirements.
meshUnstructuredMesh — The mesh.masktyping.Union[typing.Tuple, npt.NDArray] — An optional mask to apply to the connectivity before returning the points.
get_side_set()
get_side_set()def get_side_set(
mesh: UnstructuredMesh, name: str
) -> typing.Set[typing.Tuple[int, int]]: ...Get one side set as a set.
Useful for logical operations on side sets.
meshUnstructuredMesh — The mesh.namestr — Name of the side set.
get_side_set_facet_nodes()
get_side_set_facet_nodes()def get_side_set_facet_nodes(
mesh: UnstructuredMesh, name: str
) -> typing.Tuple[npt.NDArray[np.float_], npt.NDArray[np.int_]]: ...Get the tensorized nodes along a side set.
Note that this function respects the tensor order of the mesh, and will therefore return nodes equivalent to a tensorized quad in 3-D and all the nodes along an edge in 2-D.
meshUnstructuredMesh — The mesh.namestr — The name of the side set.
get_side_set_nodes()
get_side_set_nodes()def get_side_set_nodes(mesh: UnstructuredMesh, name: str) -> npt.NDArray: ...Return side set node ids as an array.
meshUnstructuredMesh — The mesh.namestr — Name of the side set.
jacobian_at_nodes()
jacobian_at_nodes()def jacobian_at_nodes(mesh: UnstructuredMesh) -> npt.NDArray: ...Compute the Jacobian at each element and each node.
meshUnstructuredMesh — The mesh.
map_nodal_fields_to_element_nodal()
map_nodal_fields_to_element_nodal()def map_nodal_fields_to_element_nodal(self) -> None: ...Map all nodal fields to element nodal and reset the nodal fields dictionary. To be used to store such data using UnstructuredMesh.write_h5
queue_mesh_deformations_2D()
queue_mesh_deformations_2D()def queue_mesh_deformations_2D(
mesh: UnstructuredMesh,
x: npt.NDArray,
deformation: npt.NDArray,
vertical_begin_deformation: float = 0.0,
vertical_end_deformation: float = inf,
vertical_reference: typing.Optional[float] = None,
name: typing.Optional[str] = None,
mode: DeformationMode2D | str = DeformationMode2D.cartesian,
) -> None: ...Queue a 2D deformation for later application.
Please see the compute_deformation_2D function for more information.
meshUnstructuredMesh — The mesh to queue for.xnpt.NDArray — horizontal coordinates of the deformation. Angle in radians for spherical models.deformationnpt.NDArray — The deformation sampled at coordinates x.vertical_begin_deformationfloat — Don’t deform any points with a vertical coordinate smaller than this.vertical_end_deformationfloat — Don’t deform any points with a vertical coordinate larger than this.vertical_referencetyping.Optional[float] — Vertical coordinate, at which the deformation should be applied, e.g. y-coordinate of the surface for surface deformation. Defaults to the max y coordinate / radius in case at least one of y0, y1 are finite.nametyping.Optional[str] — Optionally pass a name for the deformation.modeDeformationMode2D | str — The deformation mode.
queue_mesh_deformations_3D()
queue_mesh_deformations_3D()def queue_mesh_deformations_3D(
mesh: UnstructuredMesh,
x: npt.NDArray,
y: npt.NDArray,
deformation: npt.NDArray,
vertical_begin_deformation: float = 0.0,
vertical_end_deformation: float = inf,
vertical_reference: typing.Optional[float] = None,
interpolation_order: int = 3,
mode: DeformationMode3D | str = DeformationMode3D.cartesian,
name: typing.Optional[str] = None,
) -> None: ...Queue a 3D deformation for later application.
Please see the compute_deformation_3D function for more information.
meshUnstructuredMesh — The mesh to queue for.xnpt.NDArray — first horizontal coordinate of the deformation. Angle in radians for spherical models.ynpt.NDArray — second horizontal coordinate of the deformation. Angle in radians for spherical models.deformationnpt.NDArray — The deformation sampled at coordinates x.vertical_begin_deformationfloat — Don’t deform any points with a vertical coordinate smaller than this.vertical_end_deformationfloat — Don’t deform any points with a vertical coordinate larger than this.vertical_referencetyping.Optional[float] — Vertical coordinate, at which the deformation should be applied, e.g. y-coordinate of the surface for surface deformation. Defaults to the max y coordinate / radius in case at least one of y0, y1 are finite.interpolation_orderint — Horizontal interpolation order.modeDeformationMode3D | str — The deformation mode.nametyping.Optional[str] — Optionally pass a name for the deformation.
queue_mesh_deformations_cylindrical()
queue_mesh_deformations_cylindrical()def queue_mesh_deformations_cylindrical(
mesh: UnstructuredMesh,
phi: npt.NDArray,
z: npt.NDArray,
dem: npt.NDArray,
r0: float = 0.0,
r1: float = inf,
rref: typing.Optional[float] = None,
name: typing.Optional[str] = None,
) -> None: ...Queue cylindrical deformations for later application.
Add deformation for cylindrical meshes where the axis of the cylinder is aligned with the z component. The DEM radially stretches the domain in the region of (x,y)-radii in [r0, r1] - points below r0 are kept fixed, points above r1 are moved as the DEM, points in between are interpolated and the full DEM is applied to points at rref.
Usage: first call add_dem_cylindrical for each boundary that is to be perturbed and finally call apply_dem to add the perturbation to the mesh coordinates.
meshUnstructuredMesh — The mesh.phinpt.NDArray — Angle in the x-y-plane of the DEM in radians.znpt.NDArray — z-coordinates of the DEM.demnpt.NDArray — the DEM sampled at the coordinates (phi,z)r0float — radius in x-y-plane at which the stretching beginsr1float — radius in x-y-plane at which the stretching ends, can be infinityrreftyping.Optional[float] — radius in x-y-plane at which the deformation should be appliednametyping.Optional[str] — name of this deformation to refer to it in UnstructuredMesh.apply_dem()
refine_locally()
refine_locally()def refine_locally(
mesh: UnstructuredMesh,
mask: npt.NDArray,
refinement_level: int = 1,
hierarchical_map: typing.Optional[npt.NDArray] = None,
refinement_type: RefinementType | str = RefinementType.unstable,
interpolation_mode: InterpolationMode | str = InterpolationMode.linear,
interpolation_kwargs: typing.Optional[typing.Dict] = None,
reinterpolate_nodal_fields: bool = False,
unique_points_tolerance: int = 12,
) -> typing.Optional[npt.NDArray]: ...Refine the mesh locally using various refinement templates.
Please not that this will modify the mesh. Create a copy if you don’t desire this behavior.
New grid points are created by interpolating the existing corner
points. This function supports a variety of interpolation modes (some
of which require extra kwargs to set as part of the
interpolation_kwargs dictionary):
"linear": The default. Perform a bi/trilinear interpolation. No extra keyword arguments are supported or required for this mode."spherical": Linearly interpolate radially, slerp laterally. The center of the sphere is always considered to be at the origin of the coordinate system. Supported additional keywords:"r0_spherical"and"r1_spherical". Don’t slerp <r0, slerp =>r0, and linearly interpolate between both modes in between."cylindrical": Linearly interpolate radially and along the last dimension. Slerp in the middle dimension. Only makes sense in 3D, for 2D point symmetry use"spherical"Supported additional keywords:"r0_cylindrical"and"r1_cylindrical". Don’t slerp <r0, slerp =>r0, and linearly interpolate between both modes in between."SmoothieSEM": Special for SmoothieSEM, only for expert usage.
meshUnstructuredMesh — The unstructured mesh to refine.masknpt.NDArray — Mark either elements, nodes or edges to refine, boolean array with shape (nelem,), (npoint,) or (nelem, edges_per_element)refinement_levelint — Refinement level, can only be larger than 1 for stable schemes and an elemental mask.hierarchical_maptyping.Optional[npt.NDArray] — Pass a hierarchical map to keep track of which element in a coarser mesh the newly created elements belongs to.refinement_typeRefinementType | str — Choose the refinement style, currently available in 2D are ‘stable’, ‘unstable’, ‘stable_convex’ and ‘unstable_convex’, in 3D ‘unstable_unidir’, ‘unstable’, ‘stable_convex’, ‘unstable_convex’, ‘unstable_convex_dir’, ‘unstable_dir’. Here stable refers to maintaining the angles in multilevel refinements, convexity refers to the region in the mesh in terms of its connectivity (which may be different to its geometric shape for non-rectilinar meshes) and directionality refers to isotropic or anisotropic refinements (where the latter need an edge based refinement mask).interpolation_modeInterpolationMode | str — How to interpolate the location of the new grid points. See above description.interpolation_kwargstyping.Optional[typing.Dict] — Extra keyword arguments for the chosen interpolation mode. See above description.reinterpolate_nodal_fieldsbool — map nodal fields to the newly created nodes using linear interpolationunique_points_toleranceint — The number of decimal digits used to determine unique points in the refined mesh.
rotate_coordinates()
rotate_coordinates()def rotate_coordinates(
mesh: UnstructuredMesh, euler_angles: npt.NDArray
) -> None: ...Rotate the nodes coordinates around the origin.
meshUnstructuredMesh — The mesh.euler_anglesnpt.NDArray — Euler-angles to rotate around.
to_material()
to_material()def to_material(mesh: UnstructuredMesh) -> material.Material: ...Create a material from the mesh, without encoding geometrical information.
meshUnstructuredMesh — The mesh.
transform_material()
transform_material()def transform_material(
mesh: UnstructuredMesh,
m: typing.Type[material.Material],
reduction_method: (
typing.Literal["remove-components", "force"] | None
) = None,
) -> UnstructuredMesh: ...Transform the material of a mesh to another compatible material.
meshUnstructuredMesh — The mesh.mtyping.Type[material.Material] — The desired material.reduction_methodtyping.Literal['remove-components', 'force'] | None — Method to move between incompatible symmetry classes. None will only move to symmetries that are equal or more permissive, whileremove-componentswill drop components that are found to match the new material’s constraints as necessary, and thus leading to loss of free parameters but not of information. The option “force” will take all information necessary to construct the new parameter set without verification, leading to loss of information.
write_binary_vtk()
write_binary_vtk()def write_binary_vtk(
mesh: UnstructuredMesh, filename: typing.Union[str, pathlib.Path]
) -> None: ...Write a binary VTK file.
Please note that this method currently writes the mesh without any attached material parameters. The advantage of using this output format is that ParaView can visualize high-order shapes (e.g. curved elements) in that format.
meshUnstructuredMesh — The mesh to write.filenametyping.Union[str, pathlib.Path] — Filename. Make sure it uses a.vtuextension so ParaView recognizes it.
write_h5()
write_h5()def write_h5(
mesh: UnstructuredMesh,
filename: typing.Union[str, pathlib.Path],
datatype: typing.Type[np.number] = numpy.float64,
compression: typing.Optional[typing.Tuple[str, int]] = None,
mode: str = "model",
write_chunk_size: int = 10000,
overwrite: bool = True,
periodic_bcs: typing.Optional[typing.List[typing.Tuple[str, str]]] = None,
) -> None: ...Write the mesh to an h5 file with xdmf descriptor.
meshUnstructuredMesh — The mesh to write.filenametyping.Union[str, pathlib.Path] — Filename.datatypetyping.Type[np.number] — Datatype to write.compressiontyping.Optional[typing.Tuple[str, int]] — Turn on compression. Pass a tuple of(method, option), e.g.("gzip", 2). Slows down writing a lot but the resulting files are potentially much smaller.modestr — one of"all","model","skeleton"or"minimal". Controls the content of the mesh file and whether an xdmf file is added. ‘all’: largest file size, multiple block xdmf file and faster reading from file with UnstructuredMesh.from_h5() ‘model’: all data to view the model, single block xdmf file for easy opening in paraview ‘skeleton’: only the first order connectivity can be viewed ‘minimal’: smallest file size, no xdmf.write_chunk_sizeint — HDF5 chunk size in bytes.overwritebool — Potentially overwrite an existing file.periodic_bcstyping.Optional[typing.List[typing.Tuple[str, str]]] — Pass a tuple of side sets that you would like to make periodic. For example:[("x0", "x1"), ("z0", "z1)]. This option will only work if the mesh has been derived from theStructuredGrid3D.cube()class.
write_vtp()
write_vtp()def write_vtp(
mesh: UnstructuredMesh,
filename: typing.Union[str, pathlib.Path],
side_sets: typing.List[str] = ["x0", "x1", "y0", "y1", "z0", "z1"],
) -> None: ...Write the mesh to a vtp file, meant for visualization with the GUI.
In 3D, it only writes the hull.
meshUnstructuredMesh — The mesh to write.filenametyping.Union[str, pathlib.Path] — filenameside_setstyping.List[str] — Side sets to write.