Skip to content

PartitionerRegistry

PartitionerRegistry

Registry and manager for Femora mesh partitioners.

This registry maintains a collection of partitioner algorithms (both built-in and optional dependency-based, like METIS) that map a PyVista UnstructuredGrid's mesh cells to integer partition IDs in [0, num_partitions - 1].

Attributes:

Name Type Description
_partitioners Dict[str, _RegisteredPartitioner]

Internal registry map storing registered partitioner functions and their availability checks.

Example
import pyvista as pv
from femora.components.partitioner.partitioner import PartitionerRegistry

# Construct a simple VTK grid and partition its cells
grid = pv.UnstructuredGrid(...)
labels = PartitionerRegistry.partition(
    grid,
    num_partitions=4,
    partitioner="hilbert",
)

Methods:

register staticmethod

register(name: str, func: Callable[..., ndarray], *, is_available: Optional[Callable[[], bool]] = None) -> None

Register a custom partitioner algorithm in Femora.

Parameters:

Name Type Description Default
name str

Unique string identifier for the partitioner (case-insensitive).

required
func Callable[..., ndarray]

A callable of type PartitionerFunc mapping a PyVista UnstructuredGrid and partition count to a 1D NumPy array of cell partition IDs.

required
is_available Optional[Callable[[], bool]]

Optional callback returning True if the partitioner's system dependencies are met. Defaults to None (always available).

None

Raises:

Type Description
ValueError

If name is empty or whitespace-only.

get_available_types staticmethod

get_available_types(*, include_unavailable: bool = False) -> List[str]

Get the names of all registered partitioner algorithms.

Parameters:

Name Type Description Default
include_unavailable bool

If True, returns all registered algorithms even if their external library dependencies (like pymetis) are missing. Defaults to False.

False

Returns:

Type Description
List[str]

List[str]: A sorted list of registered partitioner name keys.

validate staticmethod

validate(name: str) -> None

Validate if a partitioner name is registered and available.

Parameters:

Name Type Description Default
name str

The case-insensitive name of the partitioner to validate.

required

Raises:

Type Description
ValueError

If the partitioner name is not registered.

ImportError

If the partitioner requires missing external dependencies.

partition staticmethod

partition(mesh: UnstructuredGrid, num_partitions: int, *, partitioner: str = 'kd-tree', **kwargs: Any) -> np.ndarray

Partition a mesh's cells into a specified number of balanced domains.

Parameters:

Name Type Description Default
mesh UnstructuredGrid

The PyVista UnstructuredGrid representing the global assembled mesh.

required
num_partitions int

Target number of partitions/cores (must be >= 1).

required
partitioner str

Registered case-insensitive name of the partitioning algorithm to use. Defaults to "kd-tree".

'kd-tree'
**kwargs Any

Extra parameters passed to the underlying partitioner function.

{}

Returns:

Type Description
ndarray

np.ndarray: A 1D integer NumPy array of shape (mesh.n_cells,) mapping each cell index to a partition ID in [0, num_partitions - 1].

Raises:

Type Description
ValueError

If num_partitions is less than 1.

PartitionerError

If the partitioning function fails, returns an incorrect array shape, or produces out-of-bound partition IDs.