Mondaic

salvus.mesh.algorithms.distributed_mesh.convert

salvus.mesh.algorithms.distributed_mesh.convert salvus mesh algorithms distributed_mesh convert

Convert an MPI distributed mesh to a regular Mesh on a single rank.

Functions

to_mesh()

def to_mesh(
    distributed_mesh: DistributedMesh,
    element_selection_function: collections.abc.Callable,
    timer: Timer | None = None,
    log_to_logger: bool = True,
    reentrant_timer: bool = False,
) -> Mesh | None: ...

Convert to a regular Mesh by selecting elements.

It will gather the selected elements from all ranks.

This function needs to be called on all ranks of a distributed mesh’s communicator. Each rank usually will define its own element selection function.

Parameters
  • distributed_mesh DistributedMesh — The distributed mesh to convert.
  • element_selection_function collections.abc.Callable — Function that takes the global element indices returns the indices to keep.
  • timer Timer | None — Execution timer.
  • log_to_logger bool — Whether to log timing to the logger.
  • reentrant_timer bool — Whether the timer is reentrant.
Returns Mesh | None — The assembled Mesh, or None if no elements were selected on this rank. Note: Even if this rank selects no elements, it still participates in collective MPI operations.

to_mesh_with_artifacts()

def to_mesh_with_artifacts(
    distributed_mesh: DistributedMesh,
    element_selection_function: collections.abc.Callable,
    timer: Timer | None = None,
    log_to_logger: bool = True,
    reentrant_timer: bool = False,
    cached_block_dms: (
        list[tuple[bindings.DMPlex, bindings.DMPlex]] | None
    ) = None,
) -> tuple[Mesh | None, ArtifactsFromToMesh]: ...

Like to_mesh but also returns the cacheable intermediate values.

Always uses the DMPlex-based code path. The returned ArtifactsFromToMesh can be passed to from_mesh() (via its artifacts argument) to skip the corresponding work on a subsequent reduction call for the same distributed mesh and selection.

This function needs to be called on all ranks of a distributed mesh’s communicator. Each rank usually will define its own element selection function.

Parameters
  • distributed_mesh DistributedMesh — The distributed mesh to convert.
  • element_selection_function collections.abc.Callable — Function that takes the global element indices and returns the indices to keep.
  • timer Timer | None — Execution timer.
  • log_to_logger bool — Whether to log timing to the logger.
  • reentrant_timer bool — Whether the timer is reentrant.
  • cached_block_dms list[tuple[bindings.DMPlex, bindings.DMPlex]] | None — Optional pre-computed per-block DMPlex objects. If given, the Discretize blocks step is skipped.
Returns tuple[Mesh | None, ArtifactsFromToMesh] — A tuple (mesh, artifacts). mesh is None if no elements were selected on this rank.

Classes

ArtifactsFromToMesh

class ArtifactsFromToMesh(builtins.object):
    def __init__(
        self,
        selected_element_ids: npt.NDArray,
        block_dms: list[tuple[bindings.DMPlex, bindings.DMPlex]],
        sf_sec: list[bindings.PetscStarForest],
        sf_ap: list[bindings.PetscStarForest],
    ) -> None: ...

Cacheable intermediate values produced by to_mesh_with_artifacts.

These can be reused by a subsequent from_mesh() call (via its artifacts argument) on the same distributed mesh and element selection to skip recomputing the element selection, the per-block DMPlex objects, and the nodal aperture star forests.

Parameters
  • selected_element_ids npt.NDArray — The pre-filtered Salvus global element IDs for the local rank (the result of the element selection function intersected with the IDs known to this rank).
  • block_dms list[tuple[bindings.DMPlex, bindings.DMPlex]] — The per-block DMPlex objects produced by dmplex.discretize_blocks. Selection-independent and may be reused across calls with different element selections.
  • sf_sec list[bindings.PetscStarForest] — Per-block nodal section star forests for this selection.
  • sf_ap list[bindings.PetscStarForest] — Per-block nodal aperture star forests for this selection.