Skip to content

salvus.mesh.data_structures.distributed_mesh.distributed_mesh

salvus.mesh.data_structures.distributed_mesh.distributed_mesh salvus mesh data_structures distributed_mesh distributed_mesh

The distributed mesh data structure.

Classes

DistributedMesh

class DistributedMesh(builtins.object):
    def __init__(
        self,
        comm: int,
        embedding: Mesh,
        mesh: Mesh,
        global_element_map: list[npt.NDArray],
        dmplex: bindings.DMPlex | None,
    ) -> None: ...

A mesh distribtuted across multiple MPI ranks.

Parameters
  • comm int — The MPI communicator.
  • embedding Mesh — The embedding mesh.
  • mesh Mesh — The local mesh on this rank.
  • global_element_map list[npt.NDArray] — A list mapping from rank to the global element IDs owned by that rank.
  • dmplex bindings.DMPlex | None — The distributed DMPlex object.
Attributes
all_nodal_fields set[str]

All nodal fields across all blocks.

global_element_ids_rank npt.NDArray

The global element ids of the elements on this rank.

global_variables dict[str, allowed_global_types]

The global variables.

model_order int

Alias of shape_order.

nodal_fields_per_block dict[int, set[str]]

The nodal fields per block.

number_of_dimensions int

The number of spatial dimensions.

number_of_elements int

The total number of elements.

shape_order int

This mesh’s own geometric/shape order.

Same quantity as Mesh.model_order, NOT the simulation’s solution order. The name to use for consistency across mesh formats.

side_sets tuple[SideSet, ...]

The side sets.

Methods
from_h5()
def from_h5(path: str | pathlib.Path, comm: int) -> DistributedMesh: ...

Read a distributed mesh from a directory.

This is a collective operation that must be called on all ranks of the reading communicator. Reading is only supported when the reading communicator has the same size as the communicator the mesh was written with.

Parameters
  • path str | pathlib.Path — The directory containing the distributed mesh.
  • comm int — The MPI communicator to read into.
Returns DistributedMesh — The distributed mesh.
reduce_from_mesh()
def reduce_from_mesh(
    self,
    element_selection_function: collections.abc.Callable,
    mesh: Mesh | None,
    reduction_operations_per_field: dict[str, str],
    timer: Timer | None = None,
    log_to_logger: bool = False,
    reentrant_timer: bool = False,
    artifacts: ArtifactsFromToMesh | None = None,
) -> None: ...

Reduce a mesh into the distributed mesh.

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
  • element_selection_function collections.abc.Callable — Function that takes the global element indices returns the indices to keep.
  • mesh Mesh | None — The mesh to reduce from. Can be None on ranks that have no elements selected by the element selection function.
  • reduction_operations_per_field dict[str, str] — Dictionary mapping field names to reduction operations. Reduction operations can be “sum”, “min”, “max”, or “replace”.
  • timer Timer | None = None — Execution timer.
  • log_to_logger bool = False — Whether to log timing to the logger.
  • reentrant_timer bool = False — Whether the timer is reentrant.
  • artifacts ArtifactsFromToMesh | None = None — Optional cached intermediates from a prior to_mesh_with_artifacts() call on the same distributed mesh and selection. When given, the element selection call, discretize_blocks, and get_aperture_sfs are skipped.
Returns None
to_mesh()
def to_mesh(
    self,
    element_selection_function: collections.abc.Callable,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    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
  • element_selection_function collections.abc.Callable — Function that takes the global element indices returns the indices to keep.
  • timer Timer | None = None — Execution timer.
  • log_to_logger bool = False — Whether to log timing to the logger.
  • reentrant_timer bool = False — Whether the timer is reentrant.
Returns Mesh | None — The assembled Mesh.
to_mesh_with_artifacts()
def to_mesh_with_artifacts(
    self,
    element_selection_function: collections.abc.Callable,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    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 cacheable intermediates.

The returned ArtifactsFromToMesh can be passed back to reduce_from_mesh() (via its artifacts argument) on the same distributed mesh and selection to skip redundant work.

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
  • element_selection_function collections.abc.Callable — Function that takes the global element indices and returns the indices to keep.
  • timer Timer | None = None — Execution timer.
  • log_to_logger bool = False — Whether to log timing to the logger.
  • reentrant_timer bool = False — Whether the timer is reentrant.
  • cached_block_dms list[tuple[bindings.DMPlex, bindings.DMPlex]] | None = None — Optional pre-computed per-block DMPlex objects from a previous call. 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.
write_h5()
def write_h5(self, path: str | pathlib.Path) -> None: ...

Write the distributed mesh to a directory.

This is a collective operation that must be called on all ranks of the distributed mesh’s communicator. The target directory must not yet exist and is created by rank 0. Each rank writes its local mesh, while rank 0 additionally writes the embedding, the global element map, and a small metadata file. The dmplex attribute is not written but reconstructed when reading.

Parameters
  • path str | pathlib.Path — The target directory. Must not already exist.
Returns None