polyfoammesh.config

Functions

extract_poly_mesh_archive(case_dir)

Extract constant/polyMesh.tar.gz → constant/polyMesh (Windows side).

Classes

OFConfig([wsl_distro, env_script, ...])

polyfoammesh.config.extract_poly_mesh_archive(case_dir)[source]

Extract constant/polyMesh.tar.gz → constant/polyMesh (Windows side).

The tmpfs bash scripts (build_parallel_command and friends) now copy the mesh back as a single compressed archive (tar -czf) instead of cp -r of thousands of small files over the slow 9P /mnt/c bridge. This helper is where that archive is unpacked, replacing the old direct read of constant/polyMesh.

Returns True if an archive was found and extracted; False when there was nothing to do (no archive present — e.g. a non-tmpfs path).

Return type:

bool

Parameters:

case_dir (Path | str)

class polyfoammesh.config.OFConfig(wsl_distro='Ubuntu', env_script='/usr/lib/openfoam/openfoam2512/etc/bashrc', cartesian_mesh_bin='cartesianMesh', check_mesh_bin='checkMesh', _validated=False, _n_physical=None, _openmp_threads=None)[source]

Bases: object

Parameters:
  • wsl_distro (str)

  • env_script (str)

  • cartesian_mesh_bin (str)

  • check_mesh_bin (str)

  • _validated (bool)

  • _n_physical (int | None)

  • _openmp_threads (int | None)

wsl_distro: str = 'Ubuntu'
env_script: str = '/usr/lib/openfoam/openfoam2512/etc/bashrc'
cartesian_mesh_bin: str = 'cartesianMesh'
check_mesh_bin: str = 'checkMesh'
set_openmp_threads(n)[source]

Override the OpenMP thread count used in commands. Pass None to restore auto-detection via OpenMPAccel.

Return type:

None

Parameters:

n (int | None)

validate()[source]
Return type:

bool

static validate_case_path(case_dir)[source]
Return type:

tuple[bool, str]

Parameters:

case_dir (Path | str)

wsl_linux_case_path(case_dir)[source]
Return type:

str

Parameters:

case_dir (Path | str)

build_command(case_dir, extra_args=None, cell_estimate=0)[source]
Return type:

list[str]

Parameters:
build_parallel_command(case_dir, n_cores, method='scotch')[source]

Build WSL command for MPI-parallel cartesianMesh.

Writes a shell script to the case dir and executes it. The script runs cartesianMesh -parallel inside WSL2’s native Linux tmpfs (/tmp/) to avoid the Windows filesystem (/mnt/c/) which does not support shared memory, file locking, and mmap that OpenMPI needs — these cause SIGSEGV (exit 139) on WSL2.

Using a shell script avoids quoting/glob issues with inline bash commands passed via wsl.exe bash -lc "...".

Return type:

list[str]

Parameters:
build_staged_pipeline_command(case_dir, steps, stage_root='~/cfmesh_cases')[source]

Run a sequence of OpenFOAM/cfMesh steps inside WSL native storage.

Today only cartesianMesh runs on tmpfs; STL export, gmshToFoam, polyDual and checkMesh still hammer the slow 9P /mnt/c bridge (~3-5x slower than native Linux storage). This stages the case under ~/cfmesh_cases/<ts>/, runs the requested steps sequentially THERE, then copies back ONLY the final artifacts as one compressed archive (tar -czf), unpacked on the Windows side via config.extract_poly_mesh_archive().

Parameters:
  • case_dir (Path | str) – Windows case directory (source of inputs / target of outputs).

  • steps (list[str]) – shell commands to run sequentially in the staged case (e.g. ["cartesianMesh", "polyDualMesh 90 -overwrite"]).

  • stage_root (str) – WSL directory under which timestamped cases are made.

Return type:

list[str]

Returns:

The wsl.exe command list (run via subprocess).

build_serial_tmpfs_command(case_dir, extra_args=None, cell_estimate=0)[source]

Build WSL command for serial cartesianMesh on native tmpfs.

Like build_parallel_command but for serial runs: copies the case to /tmp/ (native Linux tmpfs) to avoid the ~3-5× I/O penalty of /mnt/c/ (Windows filesystem), runs cartesianMesh there, then copies the polyMesh result back.

Return type:

list[str]

Parameters:
build_check_mesh_cmd(case_dir)[source]
Return type:

list[str]

Parameters:

case_dir (Path | str)

build_decompose_par_cmd(case_dir, n_cores, method='scotch')[source]

Build WSL command to decompose an existing mesh for parallel solving. Writes a temporary decomposeParDict, runs decomposePar -force, and cleans up — leaving the original mesh intact plus processorN/ dirs.

Return type:

list[str]

Parameters:
build_poly_dual_cmd(case_dir, feature_angle=90, split_all_faces=False)[source]

Build WSL command to run polyDualMesh.

polyDualMesh REQUIRES a featureAngle (positional arg, 0-180). The old -constant flag does NOT exist — it was silently ignored (exit 0, but did nothing), so every poly conversion before this fix was a no-op.

polyDualMesh creates the DUAL of the existing hex mesh — this INCREASES cell count (each hex vertex becomes a poly cell centre). This is NOT the same as STAR-CCM+ direct polyhedral generation.

For STAR-CCM+ style quality, the key is: - Higher featureAngle (90°) produces smoother polyhedral cells

with lower skewness (1.29 vs 1.44 at 45°)

  • Better meshDict settings (boundaryCellSize, maxNumIterations)

  • Proper boundary layer preservation (already handled by -overwrite)

Parameters:
  • case_dir (Path | str) – Case directory

  • feature_angle (float) – Feature angle in degrees [0-180]. Higher = smoother cells, better orthogonality. 90 recommended for best polyhedral quality.

  • split_all_faces (bool) – Have multiple faces between cells (increases cell count, use only for specific needs).

Return type:

list[str]

build_gmsh_to_foam_cmd(case_dir, msh_filename)[source]

Build WSL command to convert a GMSH .msh file to OpenFOAM polyMesh via OpenFOAM’s own gmshToFoam utility.

Replaces the app’s custom Python meshio-based converter (mesh_converter.msh_to_of_polymesh), which turned out to have several correctness bugs once real tetrahedra started flowing through it (owner/neighbour indexing offset by the surface-element count, boundary patches tagged from the wrong entity, and — never fully resolved — face-winding/orientation errors producing negative-volume cells). gmshToFoam is OpenFOAM’s own mature, already-shipped converter and produces a clean mesh from the same .msh file (verified: 8665/8665 real tetrahedra, only a 0.5% residual quality warning, vs. ~40% negative-volume cells from the custom converter on the same input).

Return type:

list[str]

Parameters:
build_surface_orient_cmd(case_dir, stl_filename)[source]

Build WSL command to run surfaceOrient on a triSurface STL, making its normals consistently point outward from a point known to be inside the volume — foamyHexMesh requires this (“space to be meshed always on the inside of all surfaces”); GMSH’s own STL export doesn’t guarantee it. Point (0,0,0) is a placeholder — the real inside point is substituted by the caller.

Return type:

list[str]

Parameters:
build_foamy_hex_mesh_cmd(case_dir)[source]

Build WSL command to run foamyHexMesh — OpenFOAM’s native conformal-Voronoi mesher. Generates genuine polyhedra directly from the surface geometry with no tet-mesh + dual-conversion step at all, sidestepping polyDualMesh’s face-orientation defect entirely (confirmed on a real complex part: persists across every tet-generation strategy tried — curvature, feature-size, gap-aware, budget-driven sizing, both HXT and classic Delaunay — so it’s a limitation of polyDualMesh itself, not of the input tet mesh’s quality).

Return type:

list[str]

Parameters:

case_dir (Path | str)