Muscat.MeshContainers.PartitionedMesh module

Storage and reconstruction utilities for partitioned meshes.

Each local Mesh stored by PartitionedMesh must define integral, non-negative global IDs in its nodeFields["GlobalIDs"] and elemFields["GlobalIDs"] fields. Equal node IDs identify duplicate interface nodes. Element IDs identify global elements and are normally unique.

A PartitionedMesh may store several local partitions on a rank. Setting isDistributed to True makes collective operations use the active MPI communicator supplied by Muscat.Helpers.MPIInterface.MPIInterface.

CheckIntegrity(GUI: bool = False) → str[source]

Check partitioned-mesh validation, numbering, and reconstruction.

The GUI argument is retained for the project-wide integrity-test API and is intentionally unused.

class PartitionedMesh[source]

Bases: object

Store mesh partitions sharing a global node and element numbering.

The meshes passed to AddMesh() are retained by reference. Their global-ID fields are consequently part of this object’s public invariant: they must remain aligned with the mesh nodes and elements while the mesh is stored here. Direct insertion into storage bypasses validation; callers using that setup path are responsible for coherent fields.

Notes

GetNumberOfNodes counts local nodes, including duplicated interface nodes. ComputeNumberOfGlobalNodes() counts unique values in the nodal global-ID field.

AddMesh(mesh: Mesh, nodesGlobalIDs: np.ndarray | None = None, elementsGlobalIDs: np.ndarray | None = None) → None[source]

Add a mesh partition.

Parameters:
  • mesh (Mesh) – Local partition to retain by reference.

  • nodesGlobalIDs (np.ndarray, optional) – One non-negative integral global ID per node. When omitted, the IDs must already be present in mesh.nodeFields["GlobalIDs"].

  • elementsGlobalIDs (np.ndarray, optional) – One non-negative integral global ID per element. When omitted, the IDs must already be present in mesh.elemFields["GlobalIDs"].

Raises:
  • TypeError – If the mesh or the ID dtype is invalid.

  • ValueError – If an ID field is not one-dimensional, has the wrong size, or contains negative values.

  • RuntimeError – If a required global-ID field is absent.

ComputeNumberOfGlobalElements() → int64[source]

Return the number of distinct global element IDs, or zero if empty.

ComputeNumberOfGlobalNodes() → int64[source]

Return the number of distinct global node IDs, or zero if empty.

GenerateGlobalIdsBasedOnNodePositions() → None[source]

Assign global IDs from node coordinates and local element ordering.

Candidate nodes are taken from a "SurfaceIds" tag when available, otherwise from the computed partition skin; orphan nodes are included as candidates. A scipy.spatial.KDTree finds nearby candidate coordinate pairs, which are then grouped transitively. The coordinate tolerance is max(domain_diameter * 1e-12, machine_epsilon). Consequently, geometrically distinct nodes closer than that tolerance are merged.

In distributed mode this is a collective operation. Rank zero gathers all node coordinates, assigns IDs, then scatters one ID array to each rank. It is intended for setup and is not memory scalable to very large globally distributed meshes.

GetMonolithicMesh(onRank: int | None = None, removeInterfaceNodes: bool = True) → Mesh | None[source]

Merge all partitions into one mesh.

Parameters:
  • onRank (int, optional) – In distributed mode, rank that receives the merged mesh. If omitted, every rank receives it. Non-target ranks return None.

  • removeInterfaceNodes (bool, optional) – If True, merge nodes with equal global IDs and remap nodal fields, tags, and connectivity. The default is True.

Returns:

The merged mesh, or None on a non-target distributed rank.

Return type:

Mesh or None

GetNumberOfElements() → int64[source]

Return the total element count across local partitions and MPI ranks.

GetNumberOfNodes() → int64[source]

Return the total local-node count, including interface duplicates.

PrepareForOutput(verifyIntegrity: bool = True) → None[source]

Prepare each local partition for output.

This does not merge partitions or remove duplicated interface nodes.

static RemoveInterfaceNodes(mesh: Mesh) → Mesh[source]

Return mesh with nodes sharing a global ID merged.

The node with the first local occurrence of each global ID supplies the output coordinates, original ID, and nodal-field values. Nodal tags are remapped and deduplicated; connectivity is updated for every element. The input mesh is not modified.

property isDistributed: bool

Whether collective operations use the active MPI communicator.