polyfoammesh.core.openfoam_runner
OpenFOAM subprocess runner with retry, error classification, and quality reporting.
- This module provides:
MeshWorker: interruptible subprocess runner for cartesianMesh via WSL2
RetryRunner: orchestrates cartesianMesh with up to 3 automatic retries
CheckMeshWorker / PolyDualWorker: quality-check and conversion workers
QualityFixWorker: auto-fix loop (mesh -> checkMesh -> fix -> re-mesh)
analyze_error / parse_checkmesh_output: error and quality parsers
Module Attributes
|
Upper bound of the size-scaled no-output budget (large jobs). |
|
Estimated-cell bounds over which the budget ramps from base to the max. |
|
set alongside POLYFOAMMESH_GMSH_ROBUST on a signature-triggered retry only (the venturi MeshAdapt runaway class), enabling the 2D optimizer inside robust mode. |
|
the worker sets this on its last-ditch attempt so the wrapper runs the explicit-size path with sizes derived to match the adaptive request's cell target (adaptive sizing OFF). |
Functions
|
Classify cartesianMesh errors using cfMesh-specific patterns. |
|
Number of prism-shaped cells in |
|
Run surfaceFeatureEdges to produce an .fms file from the surface STL. |
|
Parse checkMesh stdout into a structured report. |
|
Decide which boundary patches the poly BL step may touch. |
|
Geometric wall fallback for raw GMSH cases (every patch type 'patch', |
|
Wall-like patches of a polyMesh |
|
True only when the polyMesh already carries a REAL boundary layer. |
|
Detect a doomed maxCellSize/geometry combination before running cfMesh. |
Classes
|
Runs checkMesh via WSL2 in a QThread and returns a quality report. |
|
Runs decomposePar -force in a background QThread to decompose an existing mesh into processorN/ directories for parallel SOLVING. |
|
Runs TetPolyDualConverter (tet -> polyhedral by barycentric dual) in a background QThread. |
|
|
|
|
|
Export mesh to a format in a background thread. |
|
Stateful, content-aware runaway detector for the GMSH volume stream. |
|
Runs GMSH surface STL generation + sizing in a subprocess. |
|
Runs GMSH volume mesh generation in a subprocess. |
|
Structured output from checkMesh. |
|
Runs cartesianMesh via WSL2 in a background QThread. |
|
Runs ParallelMeshEngine.run() (synchronous, MPI-based) in a background QThread so it doesn't freeze the GUI's own event loop. |
|
Runs polyDualMesh via WSL2 in a background QThread. |
|
A problem detectable before launching cfMesh. |
|
Runs meshing + checkMesh + auto-fix loop with max 3 iterations. |
|
Orchestrates cartesianMesh with up to 3 automatic retries on known errors. |
|
Runs the solution-adaptive refinement loop in a background QThread. |
|
Runs watertight check + optional pymeshfix repair in a subprocess. |
|
Runs OFConfig.validate() (blocking wsl.exe call) in a background QThread. |
- class polyfoammesh.core.openfoam_runner.ErrorType(value)[source]
Bases:
Enum- NONE = 'none'
- NON_WATERTIGHT = 'non_watertight'
- SURFACE_READ = 'surface_read'
- PATCH_NOT_FOUND = 'patch_not_found'
- FOAM_FATAL = 'foam_fatal'
- CRASH = 'crash'
- NON_MAPPABLE = 'non_mappable'
- BOUNDARY_NOT_FOUND = 'boundary_not_found'
- BL_FAILURE = 'boundary_layer_failure'
- class polyfoammesh.core.openfoam_runner.ErrorInfo(error_type=ErrorType.NONE, message='', suggestion='', detail='')[source]
Bases:
object
- polyfoammesh.core.openfoam_runner.analyze_error(full_output)[source]
Classify cartesianMesh errors using cfMesh-specific patterns.
- class polyfoammesh.core.openfoam_runner.MeshWorker(case_dir, of_config, parent=None)[source]
Bases:
QObjectRuns cartesianMesh via WSL2 in a background QThread.
Reads stdout from a dedicated reader thread (NOT select.select(), which on Windows only works on sockets, never on pipes) so that interruption requests are still honoured while the subprocess is silent for a long time.
Contract: run() ALWAYS emits finished exactly once, on every path including unexpected errors. Callers block on that signal, so a missing emit is not a lost error message — it is a permanent hang.
- log_line
- finished
- cell_count_found
- progress_update
- eta_update
- MAX_RUNTIME_SECONDS = 14400
- staticMetaObject = PySide6.QtCore.QMetaObject("MeshWorker" inherits "QObject": Methods: #4 type=Signal, signature=log_line(QString), parameters=QString #5 type=Signal, signature=finished(int,QString), parameters=int, QString #6 type=Signal, signature=cell_count_found(int), parameters=int #7 type=Signal, signature=progress_update(int), parameters=int #8 type=Signal, signature=eta_update(QString), parameters=QString #9 type=Slot, signature=run() )
- class polyfoammesh.core.openfoam_runner.RetryRunner(of_config, parent=None)[source]
Bases:
QObjectOrchestrates cartesianMesh with up to 3 automatic retries on known errors.
- V1.1 additions:
F2: cell_count_relay for real cell count.
F6: automatic fallback without boundary layers if BL causes failure.
F7: exit-code 15 treated as non-fatal for unconnected regions.
- Parameters:
of_config (OFConfig)
- MAX_RETRIES = 3
- cell_count_found
- log_emitted
- cell_count_relay
- progress_update
- eta_update
- run(case_dir, on_log=None, on_finished=None, fix_action=None, bl_params=None, max_cell=0.05, min_cell=0.01, patch_cell_size=None, patch_names=None)[source]
- Parameters:
- staticMetaObject = PySide6.QtCore.QMetaObject("RetryRunner" inherits "QObject": Methods: #4 type=Signal, signature=cell_count_found(int), parameters=int #5 type=Signal, signature=log_emitted(QString), parameters=QString #6 type=Signal, signature=cell_count_relay(int), parameters=int #7 type=Signal, signature=progress_update(int), parameters=int #8 type=Signal, signature=eta_update(QString), parameters=QString #9 type=Slot, signature=_on_attempt_finished(int,QString), parameters=int, QString )
- class polyfoammesh.core.openfoam_runner.MeshQualityReport(cells=0, faces=0, points=0, max_non_ortho=0.0, avg_non_ortho=0.0, max_skewness=0.0, avg_skewness=0.0, max_aspect_ratio=0.0, neg_cells=0, min_volume=0.0, has_fatal=False, raw_output='')[source]
Bases:
objectStructured output from checkMesh.
- Parameters:
- polyfoammesh.core.openfoam_runner.parse_checkmesh_output(text)[source]
Parse checkMesh stdout into a structured report.
- Return type:
- Parameters:
text (str)
- class polyfoammesh.core.openfoam_runner.CheckMeshWorker(case_dir, of_config, parent=None, pipeline_staged=False)[source]
Bases:
QObjectRuns checkMesh via WSL2 in a QThread and returns a quality report.
- log_line
- finished
- failed
- cancel()[source]
Kill the live subprocess (wsl.exe), if any is running right now. See GmshSurfaceWorker.cancel for why this exists — same gap here even though _on_cancel_meshing’s _kill_wsl_processes() gives this one partial coverage already, killing wsl.exe directly by PID is faster and doesn’t depend on process-name matching.
- staticMetaObject = PySide6.QtCore.QMetaObject("CheckMeshWorker" inherits "QObject": Methods: #4 type=Signal, signature=log_line(QString), parameters=QString #5 type=Signal, signature=finished(PyObject), parameters=PyObject #6 type=Signal, signature=failed(QString), parameters=QString #7 type=Slot, signature=cancel() #8 type=Slot, signature=run() )
- class polyfoammesh.core.openfoam_runner.PolyDualWorker(case_dir, of_config, feature_angle=90, parent=None)[source]
Bases:
QObjectRuns polyDualMesh via WSL2 in a background QThread.
polyDualMesh converts the hexahedral mesh from cartesianMesh into an arbitrary polyhedral mesh (reduces cell count while preserving surface quality). It writes output to the same case directory.
- log_line
- finished
- failed
- staticMetaObject = PySide6.QtCore.QMetaObject("PolyDualWorker" inherits "QObject": Methods: #4 type=Signal, signature=log_line(QString), parameters=QString #5 type=Signal, signature=finished(PyObject), parameters=PyObject #6 type=Signal, signature=failed(QString), parameters=QString #7 type=Slot, signature=run() )
- class polyfoammesh.core.openfoam_runner.QualityFixWorker(of_config, parent=None)[source]
Bases:
QObjectRuns meshing + checkMesh + auto-fix loop with max 3 iterations.
Uses RetryRunner internally for the meshing step, then runs checkMesh. If quality checks fail, applies meshDict fixes and re-runs.
- Parameters:
of_config (OFConfig)
- MAX_FIX_ATTEMPTS = 3
- log_line
- finished
- failed
- staticMetaObject = PySide6.QtCore.QMetaObject("QualityFixWorker" inherits "QObject": Methods: #4 type=Signal, signature=log_line(QString), parameters=QString #5 type=Signal, signature=finished(int), parameters=int #6 type=Signal, signature=failed(QString), parameters=QString #7 type=Slot, signature=run() )
- class polyfoammesh.core.openfoam_runner.ParallelMeshWorker(case_dir, of_config, max_cell, min_cell, n_cores, patch_names=None, method='scotch', parent=None, bl_params=None)[source]
Bases:
QObjectRuns ParallelMeshEngine.run() (synchronous, MPI-based) in a background QThread so it doesn’t freeze the GUI’s own event loop.
Supports cancellation via cancel(): sets an event that the engine’s polling subprocess runner checks every 0.5s and kills the MPI ranks.
- Parameters:
- log_line
- finished
- failed
- cancelled
- cancel()[source]
Request cancellation of the running parallel meshing. Safe to call from any thread; triggers a process-tree kill inside WSL2 on the next 0.5s poll cycle.
- Return type:
- staticMetaObject = PySide6.QtCore.QMetaObject("ParallelMeshWorker" inherits "QObject": Methods: #4 type=Signal, signature=log_line(QString), parameters=QString #5 type=Signal, signature=finished(PyObject), parameters=PyObject #6 type=Signal, signature=failed(QString), parameters=QString #7 type=Signal, signature=cancelled() #8 type=Slot, signature=run() )
- class polyfoammesh.core.openfoam_runner.DecomposeParWorker(case_dir, of_config, n_cores, method='scotch', parent=None)[source]
Bases:
QObjectRuns decomposePar -force in a background QThread to decompose an existing mesh into processorN/ directories for parallel SOLVING.
- log_line
- finished
- failed
- staticMetaObject = PySide6.QtCore.QMetaObject("DecomposeParWorker" inherits "QObject": Methods: #4 type=Signal, signature=log_line(QString), parameters=QString #5 type=Signal, signature=finished(PyObject), parameters=PyObject #6 type=Signal, signature=failed(QString), parameters=QString #7 type=Slot, signature=run() )
- class polyfoammesh.core.openfoam_runner.WslCheckWorker(of_config, parent=None)[source]
Bases:
QObjectRuns OFConfig.validate() (blocking wsl.exe call) in a background QThread. WSL2 auto-shuts-down its VM after inactivity, so this can take well over a minute on a cold boot — running it on the GUI thread freezes the whole window with no feedback, indistinguishable from a crash.
- Parameters:
of_config (OFConfig)
- finished
- staticMetaObject = PySide6.QtCore.QMetaObject("WslCheckWorker" inherits "QObject": Methods: #4 type=Signal, signature=finished(bool), parameters=bool #5 type=Slot, signature=run() )
- polyfoammesh.core.openfoam_runner.generate_fms(case_dir, angle=60.0, timeout=60)[source]
Run surfaceFeatureEdges to produce an .fms file from the surface STL.
Wraps the WSL2 call to
surfaceFeatureEdges -angle <angle>, run from within the case directory so that output paths are relative and OpenFOAM can find its config files.The FMS file is written to
constant/triSurface/surface.fms.- Parameters:
- Return type:
- Returns:
Path to the generated
.fmsfile, orNoneon failure.
- polyfoammesh.core.openfoam_runner.poly_wall_patch_names(case_dir)[source]
Wall-like patches of a polyMesh
boundaryfile — the default target set for the poly BL step (FASE 1): a patch qualifies if its boundary type iswall(set by the BC editor /set_wall_patch_types) or its name explicitly says wall (*wall*). GMSHsurface_Npatches and role-named patches (inlet/outlet/opening) do NOT qualify — a raw GMSH case returns an empty list and the worker falls back to the geometric inference (poly_geo_wall_patch_names), so the default BL never touches inlet/outlet even without explicit wall naming.
- polyfoammesh.core.openfoam_runner.poly_geo_wall_patch_names(case_dir)[source]
Geometric wall fallback for raw GMSH cases (every patch type ‘patch’,
surface_Nnames): infer inlet/outlet from the geometry (case_setup.infer_patch_roles) and treat every other patch as a wall — so the default BL never touches inlet/outlet even when no patch is explicitly named/typed wall. Returns [] when the roles cannot be inferred (e.g. a fully closed domain) — the caller then falls back to ALL with a warning.
- polyfoammesh.core.openfoam_runner.poly_bl_patch_selection(case_dir, apply_to_all_override=False)[source]
Decide which boundary patches the poly BL step may touch.
Returns
(patch_names, apply_to_all, notes):patch_names is None-> skip the BL entirely (nothing safe to extrude from). The caller must report this rather than extruding.
Three tiers, cheapest and most authoritative first:
An explicit user override means “all patches” and is honoured literally — that is the user’s call to make.
Boundary type / name, then the geometric inference (
poly_wall_patch_names/poly_geo_wall_patch_names).When both fail (every patch unnamed GMSH
surface_Nand no inlet/outlet could be placed — closed domains, external aero, multi-inlet manifolds), exclude only what is positively known to be a non-wall and extrude from the rest. If that leaves nothing, skip.
Tier 3 is the one that used to be “apply to ALL”. It fired on exactly the geometries where the least is known, and it put prism stacks in the inlets and outlets: checkMesh accepts that, so the failure only surfaces when the solver diverges. A mesh without layers is a recoverable warning; a mesh with layers in the inlet is a wrong answer.