Mondaic

salvus.mesh.algorithms.unstructured_mesh.side_sets

salvus.mesh.algorithms.unstructured_mesh.side_sets salvus mesh algorithms unstructured_mesh side_sets

Side set related algorithms.

Functions

analyze_masks()

def analyze_masks(masks: list[npt.NDArray]) -> tuple[bool, bool]: ...

Analyze boolean masks to check for overlaps and coverage.

Parameters
  • masks list[npt.NDArray] — List of boolean masks (same shape).
Returns tuple[bool, bool] — A tuple of two booleans indicating whether the masks overlap and provide full coverage.

compute_normal_vectors_towards_side_set()

def compute_normal_vectors_towards_side_set(
    mesh: UnstructuredMesh,
    side_set_to_mask_map: dict[str, npt.NDArray],
    outward_pointing: bool = True,
    split_per_mask: bool = True,
) -> npt.NDArray | dict[str, npt.NDArray]: ...

Compute the normal vectors over the entire mesh for side set-mask combinations.

Only active elements in a mask that are attached to the associated side set will be considered. Any element in a mask that is not attached to the associated side set is excluded.

Also requires the masks to not have overlap. If multiple normal vectors for one element are desired (e.g. to different side sets), run this routine separately per side set.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • side_set_to_mask_map dict[str, npt.NDArray] — A dictionary which maps a side set (string) to a boolean element mask.
  • outward_pointing bool — Whether to have the normal vectors outward (True) or inward (False) w.r.t to the side set. Outwards is defined as the direction from the elements in the mask towards the side-set.
  • split_per_mask bool — If set to True, will instead return a dictionary mapping every side set to the original element indices as appearing in order of the mask.
Returns npt.NDArray | dict[str, npt.NDArray] — The normal vectors per element per GLL point, shaped like (mesh.nelem, mesh.points_per_element, mesh.ndim). If split_per_mask is True, will return a dictionary with the same keys as side_set_to_mask_map, with entries the normal vectors shaped as (nelem_in_mask, mesh.points_per_element, mesh.ndim). Points for which the normal vector computation failed are set to zero.

create_side_set()

def create_side_set(
    mesh: UnstructuredMesh,
    side_set_name: str,
    side_set: (
        tuple[npt.NDArray, npt.NDArray] | set[tuple[int, int]] | None
    ) = None,
    element_indices: npt.NDArray | None = None,
    side_indices: npt.NDArray | None = 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().
Parameters
  • mesh UnstructuredMesh — The mesh.
  • side_set_name str — The name of the to be create side set.
  • side_set tuple[npt.NDArray, npt.NDArray] | set[tuple[int, int]] | None — Directly provide the side set.
  • element_indices npt.NDArray | None — The global element indices for the new side set.
  • side_indices npt.NDArray | None — The side ids to use for each element.
Returns None

create_side_set_between_masks()

def create_side_set_between_masks(
    mesh: UnstructuredMesh,
    mask_A: npt.NDArray,
    mask_B: npt.NDArray | None = None,
    only_add_side_A: bool = True,
) -> tuple[npt.NDArray, npt.NDArray]: ...

Create a side set between two masks or a mask and its inverse.

Ideal when creating internal side sets easily without a distance metric. Needs to be manually added to the mesh afterwards.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • mask_A npt.NDArray — The first mask.
  • mask_B npt.NDArray | None — The second mask. If None, the inverse of mask_A is taken.
  • only_add_side_A bool — Whether or not to only add the elements and facets relating to one side of the boundary. Functionally no different but setting to False will double surface data output size.
Returns tuple[npt.NDArray, npt.NDArray] — The elements and sides of the mesh that are part of the internal side set. By default, will contain entries for elements in just mask A.

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.

Parameters
  • mesh UnstructuredMesh — The unstructured mesh.
  • mode str — 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”.
  • tolerance float — Floating point tolerance to assume a node is on a given side.
Returns None

find_side_sets_cartesian()

def find_side_sets_cartesian(
    mesh: UnstructuredMesh, tolerance: float = 1e-08
) -> None: ...

Find cartesian side sets.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • tolerance float — Distance tolerance.
Returns None

find_side_sets_cylindrical()

def find_side_sets_cylindrical(
    mesh: UnstructuredMesh, tolerance: float = 1e-08
) -> None: ...

Find cylindrical side sets.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • tolerance float — Distance tolerance.
Returns None

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.

Parameters
  • mesh UnstructuredMesh — The unstructured mesh.
  • mode str — 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”.
  • tolerance float — Floating point tolerance to assume a node is on a given side.
Returns None

find_side_sets_generic()

def find_side_sets_generic(
    mesh: UnstructuredMesh,
    name: str,
    distance: typing.Callable[[npt.NDArray], npt.NDArray] | npt.NDArray,
    tolerance: float = 1e-08,
    attach_side_set: bool = True,
) -> tuple[npt.NDArray, npt.NDArray] | None: ...

Find side sets based on a distance function.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • name str — Name of the new side set.
  • distance typing.Callable[[npt.NDArray], npt.NDArray] | npt.NDArray — Callback function taking in points and returning a distance.
  • tolerance float — Point with a distance beneath this are part of the side set.
  • attach_side_set bool — If true, add the side set to the mesh, othewise return the side set elements and sides.
Returns tuple[npt.NDArray, npt.NDArray] | None

find_side_sets_spherical()

def find_side_sets_spherical(
    mesh: UnstructuredMesh,
    tolerance: float = 1e-08,
    is_chunk: bool,
    is_vertical: bool,
) -> None: ...

Find spherical side sets.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • tolerance float — Distance tolerance.
  • is_chunk bool — Is a chunk, not a full sphere.
  • is_vertical bool — Is a vertically oriented chunk.
Returns None

find_surface()

def find_surface(
    mesh: UnstructuredMesh, side_set_name: str = "surface"
) -> None: ...

Mark all surface faces as a side set.

Parameters
  • mesh UnstructuredMesh — The mesh to use.
  • side_set_name str — Name to give to the found surface.
Returns None

get_side_set()

def get_side_set(
    mesh: UnstructuredMesh, name: str, allow_empty: bool = False
) -> set[tuple[int, int]]: ...

Get one side set as a set.

Useful for logical operations on side sets.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • name str — Name of the side set.
  • allow_empty bool — Return an empty set if the side set is not present.
Returns set[tuple[int, int]]

get_side_set_facet_indexer()

def get_side_set_facet_indexer(
    mesh: UnstructuredMesh, name: str
) -> npt.NDArray[np.int64]: ...

Get the facet indexer for a side set.

This is an array of shape (n_elem_on_side_set, n_dof_per_facet) which gives the facet id for each element in the side set. This is useful for indexing into element nodal fields to get parameter values along a side set. For instance, given a side set “r1” and an element nodal field “VP”, you can get the VP values along the side set as follows:

elements, _ = mesh.side_sets["r1"]
indexer = get_side_set_facet_indexer(mesh, "r1")
vp_on_side_set_elms = mesh.element_nodal_fields["VP"][elements]
vp_on_side_set = np.take_along_axis( vp_on_side_set_elms, indexer, axis=1)
Parameters
  • mesh UnstructuredMesh — The mesh.
  • name str — The name of the side set.
Returns npt.NDArray[np.int64] — An array of shape (n_elem_on_side_set, n_dof_per_facet) which gives the facet id for each element in the side set.

get_side_set_facet_nodes()

def get_side_set_facet_nodes(
    mesh: UnstructuredMesh, name: str
) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.int64]]: ...

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.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • name str — The name of the side set.
Returns tuple[npt.NDArray[np.float64], npt.NDArray[np.int64]] — A tuple of two values: 1st value: The tensorized nodes along the side set, with the shape (n_elem_on_side_set, n_points_per_facet, n_dim). 2st value: The global element nodes indices corresponding to the returned tensorized points.

get_side_set_nodes()

def get_side_set_nodes(mesh: UnstructuredMesh, name: str) -> npt.NDArray: ...

Return side set node ids as an array.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • name str — Name of the side set.
Returns npt.NDArray

side_sets_for_element_ids()

def side_sets_for_element_ids(
    mesh: UnstructuredMesh, ids: npt.NDArray
) -> set[str]: ...

Determine the side sets associated with a set of element IDs.

Identifies which side sets in the mesh contain nodes that are part of the specified element IDs.

Parameters
  • mesh UnstructuredMesh — The mesh.
  • ids npt.NDArray — An array of element IDs for which to find the associated side sets.
Returns set[str] — set[str]: A set of side set names that are associated with the given element IDs.