polyfoammesh.commercial.parallel_mesh

Parallel meshing engine using MPI + cartesianMesh’s own -parallel mode.

Runs cartesianMesh across N MPI ranks and reconstructs the result — real wall-clock speedup on multi-core machines.

This is NOT decomposePar-based domain decomposition: decomposePar splits an EXISTING mesh/fields for parallel SOLVING, and requires a mesh to already exist — at this point in the pipeline there is no mesh yet, since generating one is the whole point. cartesianMesh’s own -parallel flag does the geometry-based decomposition internally; it only needs each processorN/ directory to exist with its own copy of the case’s system/ and constant/ input files (confirmed live: without them, cartesianMesh -parallel fails with “cannot open case directory processorN”).

Pipeline:
  1. Write meshDict (cell sizes, BL, patch names) to the Windows case dir

  2. Clean residual /tmp/cfmesh_parallel_* from previous killed runs

  3. Clean residual processorN/ dirs from previous runs

  4. build_parallel_command() copies system/+constant/ into a native WSL tmpfs (/tmp/cfmesh_parallel_XXXXX) and runs mpirun there — this avoids SIGSEGV from mmap on /mnt/c (Windows filesystem).

  5. reconstructParMesh inside tmpfs, then copies back constant/polyMesh and per_rank_cells.txt

  6. Collect per-rank cell counts from per_rank_cells.txt

Classes

DecomposeParams([method, n_cores, ...])

Parameters for domain decomposition.

ParallelMeshEngine([of_config])

Parallel meshing engine using MPI + cartesianMesh's own -parallel mode.

ParallelMeshResult([success, case_dir, ...])

Exceptions

CancelledError

Raised inside ParallelMeshEngine when cancel() is called mid-run.

exception polyfoammesh.commercial.parallel_mesh.CancelledError[source]

Bases: RuntimeError

Raised inside ParallelMeshEngine when cancel() is called mid-run.

class polyfoammesh.commercial.parallel_mesh.DecomposeParams(method='scotch', n_cores=4, preserve_patches=<factory>, overlap=0)[source]

Bases: object

Parameters for domain decomposition.

Parameters:
method: str = 'scotch'
n_cores: int = 4
preserve_patches: list[str]
overlap: int = 0
class polyfoammesh.commercial.parallel_mesh.ParallelMeshResult(success=False, case_dir='', n_cores=0, cell_count=0, cell_count_per_rank=<factory>, warnings=<factory>, errors=<factory>, wall_time_seconds=0.0)[source]

Bases: object

Parameters:
success: bool = False
case_dir: str = ''
n_cores: int = 0
cell_count: int = 0
cell_count_per_rank: list[int]
warnings: list[str]
errors: list[str]
wall_time_seconds: float = 0.0
class polyfoammesh.commercial.parallel_mesh.ParallelMeshEngine(of_config=None)[source]

Bases: object

Parallel meshing engine using MPI + cartesianMesh’s own -parallel mode.

Usage:

pe = ParallelMeshEngine(of_config)
pe.setup_case(case_dir, n_cores=8)
result = pe.run()
Parameters:

of_config (OFConfig | None)

MAX_CORES = 128
MIN_CORES = 2
cancel()[source]

Request cancellation of a running meshing operation. Sets an internal event that is polled between steps and during the blocking subprocess call (via Popen + polling loop). Also cleans up stray WSL processes and orphaned tmp dirs.

Return type:

None

setup_case(case_dir, n_cores=4, method='scotch')[source]
Return type:

None

Parameters:
set_cell_sizes(max_cell, min_cell)[source]
Return type:

None

Parameters:
set_patch_names(patch_names)[source]
Return type:

None

Parameters:

patch_names (list[str] | None)

set_bl_params(bl_params)[source]
Return type:

None

Parameters:

bl_params (dict | None)

run()[source]

Execute the parallel meshing workflow.

Return type:

ParallelMeshResult

Steps:
  1. Kill stray MPI processes from previous runs

  2. Clamp core count to available WSL2 memory

  3. Clean orphaned /tmp/cfmesh_parallel_* from killed runs

  4. Clean residual processorN/ dirs from previous runs

  5. Write meshDict (cell sizes, BL, patch names)

  6. Run cartesianMesh -parallel via tmpfs bash script

  7. Collect per-rank cell counts from per_rank_cells.txt

  8. Standalone reconstruct fallback (if bundled one didn’t run)

static estimate_speedup(n_cores, efficiency=0.85)[source]
Return type:

dict[str, float]

Parameters: