Mondaic

salvus.mesh.algorithms.unstructured_mesh.basic

salvus.mesh.algorithms.unstructured_mesh.basic salvus mesh algorithms unstructured_mesh basic

Basic operations.

Functions

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.

Parameters
  • mesh_a UnstructuredMesh — First mesh.
  • mesh_b UnstructuredMesh — Second mesh.
  • make_unique_points bool — 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.
Returns UnstructuredMesh

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.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • mask npt.NDArray — The mask as boolean array.
  • return_node_map bool — 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_sets str | 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.
Returns UnstructuredMesh | tuple[UnstructuredMesh, npt.NDArray]

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.

Parameters
  • mesh_a UnstructuredMesh — The first mesh.
  • mesh_b UnstructuredMesh — The second mesh.
Returns None

get_element_centroid()

def get_element_centroid(
    mesh: UnstructuredMesh, spherical: bool = False
) -> npt.NDArray: ...

For each element, compute its centroid.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • spherical bool — Assume a spherical mesh to perform a spherical computation.
Returns npt.NDArray

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()

Parameters
  • mesh UnstructuredMesh — The mesh.
Returns npt.NDArray

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.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • mask tuple | npt.NDArray — An optional mask to apply to the connectivity before returning the points.
Returns npt.NDArray

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.

Parameters
  • mesh UnstructuredMesh — The mesh for which to compute the mass matrix.
Returns npt.NDArray — The mass matrix of the mesh as a 2D numpy array of shape (n_elem, n_nodes_per_element).

get_valence()

def get_valence(mesh: UnstructuredMesh) -> npt.NDArray: ...

Get the valence of each node in the mesh ordered per element.

Parameters
  • mesh UnstructuredMesh — The mesh.
Returns npt.NDArray — The valence of each node in the mesh.

jacobian_at_nodes()

def jacobian_at_nodes(mesh: UnstructuredMesh) -> npt.NDArray: ...

Compute the Jacobian at each element and each node.

Parameters
  • mesh UnstructuredMesh — The mesh.
Returns npt.NDArray — The Jacobian: [n_elm, n_node, n_dim, n_dim].

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.

Parameters
  • mesh_a UnstructuredMesh — Mesh a.
  • mesh_b typing.Any — The other mesh.
  • raise_with_error_if_not_equal bool — Raise in case both are not equal.
Returns bool

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.
Parameters
  • mesh UnstructuredMesh — The mesh.
  • euler_angles npt.NDArray — Euler-angles in degrees to rotate around.
Returns None