polyfoammesh.config
Functions
|
Extract |
Classes
|
- polyfoammesh.config.extract_poly_mesh_archive(case_dir)[source]
Extract
constant/polyMesh.tar.gz→constant/polyMesh(Windows side).The tmpfs bash scripts (
build_parallel_commandand friends) now copy the mesh back as a single compressed archive (tar -czf) instead ofcp -rof thousands of small files over the slow 9P/mnt/cbridge. This helper is where that archive is unpacked, replacing the old direct read ofconstant/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).
- 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:
- set_openmp_threads(n)[source]
Override the OpenMP thread count used in commands. Pass None to restore auto-detection via OpenMPAccel.
- 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 "...".
- 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/cbridge (~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 viaconfig.extract_poly_mesh_archive().- Parameters:
- Return type:
- Returns:
The
wsl.execommand 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.
- 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.
- 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
-constantflag 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:
- Return type:
- 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).
- 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.
- 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).