Partition Model

Overview

The PartitionModel handles mesh partitioning and rebalancing across MPI processes. This is important for parallel simulations where the mesh must be evenly distributed to ensure good load balancing. After operations such as adaptive refinement, rebalancing can redistribute the mesh to prevent performance degradation. Note that this is only supported for non-conformal meshes.

This model also registers a partition index as a coefficient function to visualize which cells belong to which MPI rank.

Functions

class PartitionModel

The PartitionModel provides mesh partitioning and rebalancing capabilities in the simulation.

rebalance()

Rebalances the mesh across MPI ranks to improve load distribution.

Typically called after significant mesh changes (e.g., refinement). Redistributes elements to balance the number of cells per rank, improving solver performance.

Note that this operation is only effective for non-conformal meshes.

Returns: None

Coefficient Functions

The following field is registered by the PartitionModel for visualization or analysis:

List of functions

Name

Example

Description

Partition Index [-] (Scalar Field)

Partition Index

The Partition Index provides the MPI rank each cell belongs to. It is useful for debugging load balancing and visualizing mesh distribution across processors.

Example

The following example loads a mesh and performs a repartitioning using the PartitionModel.

import mufem

sim = mufem.Simulation.New("My Parallel Case", f"data/geometry.mesh", print_only_warnings=True)

partition_model = mufem.PartitionModel()

sim.get_model_manager().add_model(partition_model)

# Rebalance the mesh after refinement or load (requires non-conformal mesh)
# partition_model.rebalance()

# Export the partition index field for visualization
field_exporter = sim.get_field_exporter()
field_exporter.add_field_output("Partition Index")
field_exporter.save()