salvus.mesh.algorithms.unstructured_mesh.basic
salvus.mesh.algorithms.unstructured_mesh.basic salvus mesh algorithms unstructured_mesh basic Basic operations.
Functions
add_two_meshes()
add_two_meshes()def add_two_meshes(
mesh_a: UnstructuredMesh,
mesh_b: UnstructuredMesh,
make_unique_points: bool = True,
) -> UnstructuredMesh: ...Add two meshes together.
Only fields that exist in both meshes, will be in the combined mesh, others will be discarded.
mesh_aUnstructuredMesh — First mesh.mesh_bUnstructuredMesh — Second mesh.make_unique_pointsbool — If True, duplicate points in both meshes will be discarded. This should be True in most cases, only set this to False for performance reasons if you know what you are doing.
apply_element_mask()
apply_element_mask()def apply_element_mask(
mesh: UnstructuredMesh,
mask: npt.NDArray,
return_node_map: bool = False,
side_sets: str | list[str] | None = None,
) -> UnstructuredMesh | 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_setsstr | list[str] | None — 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.
assert_meshes_are_compatible()
assert_meshes_are_compatible()def assert_meshes_are_compatible(
mesh_a: UnstructuredMesh, mesh_b: UnstructuredMesh
) -> None: ...Asserts that two meshes are compatible.
Compatibility is defined as having the same dimensionality, scale, and shape order.
Will raise a descriptive AssertionError if that is not the case.
mesh_aUnstructuredMesh — The first mesh.mesh_bUnstructuredMesh — The second mesh.
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: 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.masktuple | npt.NDArray — An optional mask to apply to the connectivity before returning the points.
get_mass_matrix()
get_mass_matrix()def get_mass_matrix(mesh: UnstructuredMesh) -> npt.NDArray: ...Compute the mass matrix of a mesh.
This function computes the mass matrix of a mesh using the GLL quadrature points and weights. The mass matrix is computed as the integral of the product of the shape functions over the element volume.
meshUnstructuredMesh — The mesh for which to compute the mass matrix.
get_valence()
get_valence()def get_valence(mesh: UnstructuredMesh) -> npt.NDArray: ...Get the valence of each node in the mesh ordered per element.
meshUnstructuredMesh — The mesh.
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.
meshes_are_equal()
meshes_are_equal()def meshes_are_equal(
mesh_a: UnstructuredMesh,
mesh_b: typing.Any,
raise_with_error_if_not_equal: bool = False,
) -> bool: ...Compare two meshes for equality.
mesh_aUnstructuredMesh — Mesh a.mesh_btyping.Any — The other mesh.raise_with_error_if_not_equalbool — Raise in case both are not equal.
rotate_coordinates()
rotate_coordinates()def rotate_coordinates(
mesh: UnstructuredMesh, euler_angles: npt.NDArray
) -> None: ...Rotate the mesh coordinates in-place using Z-Y-Z extrinsic Euler angles.
This function rotates the mesh node coordinates around the origin by applying three right-handed, global-axis-fixed rotations in the following sequence:
1. Rotate around the global Z-axis by `euler_angles[0]` degrees.
2. Rotate around the global Y-axis by `euler_angles[1]` degrees.
3. Rotate around the global Z-axis by `euler_angles[2]` degrees.meshUnstructuredMesh — The mesh.euler_anglesnpt.NDArray — Euler-angles in degrees to rotate around.