polyfoammesh.core.validation

Functions

mesh_remeshable(case_dir)

Whether an existing mesh may be replaced by a fresh cfMesh cartesianMesh.

sanitise_filename(name)

Remove characters unsafe for Windows/NTFS filenames.

sanitise_patch_name(name)

Remove characters that OpenFOAM forbids in patch names.

validate_bl_params(n_layers, ...[, wall_patches])

Validate boundary-layer parameters.

validate_case_dir(case_dir)

Validate that a case directory is usable for OpenFOAM.

validate_cell_size(max_cell, min_cell[, ...])

Validate global cell size pair.

validate_detail_level(detail)

Validate detail-level string.

validate_geometry_path(path)

Validate that a geometry file path is usable.

validate_settings(key, value)

Validate a single QSettings key/value pair.

Classes

ValidationResult([valid, message, warnings])

class polyfoammesh.core.validation.ValidationResult(valid=True, message='', warnings=<factory>)[source]

Bases: object

Parameters:
valid: bool = True
message: str = ''
warnings: list[str]
polyfoammesh.core.validation.validate_cell_size(max_cell, min_cell, bbox_dim=None)[source]

Validate global cell size pair.

Parameters:
  • max_cell (float) – global maximum cell size (m).

  • min_cell (float) – global minimum cell size (m).

  • bbox_dim (float | None) – bounding-box max dimension (m). When provided, extra sanity checks against the domain size are performed.

Return type:

ValidationResult

Returns:

ValidationResult — valid is False when values are out of range or inconsistent.

polyfoammesh.core.validation.validate_bl_params(n_layers, thickness_ratio, expansion_ratio, wall_patches=None)[source]

Validate boundary-layer parameters.

Parameters:
  • n_layers (int) – Number of prism layers (1–10).

  • thickness_ratio (float) – Ratio of first-layer thickness to local cell size (typical 0.001–0.1).

  • expansion_ratio (float) – Ratio between successive layer thicknesses (typical 1.1–1.5).

  • wall_patches (Optional[Sequence[str]]) – List of patch names to apply BL to.

Return type:

ValidationResult

polyfoammesh.core.validation.validate_detail_level(detail)[source]

Validate detail-level string.

Return type:

ValidationResult

Parameters:

detail (str)

polyfoammesh.core.validation.validate_geometry_path(path)[source]

Validate that a geometry file path is usable.

Checks: - File exists - Extension is supported (.step/.stp/.stl) - File size is within limits - Path contains no characters that break WSL/bash

Return type:

ValidationResult

Parameters:

path (str | Path)

polyfoammesh.core.validation.validate_case_dir(case_dir)[source]

Validate that a case directory is usable for OpenFOAM.

Checks: - No spaces in path - Path exists (or parent exists and can be created) - No characters that would break WSL/bash

Return type:

ValidationResult

Parameters:

case_dir (str | Path)

polyfoammesh.core.validation.validate_settings(key, value)[source]

Validate a single QSettings key/value pair.

Use before writing to QSettings to catch data corruption early.

Return type:

ValidationResult

Parameters:
polyfoammesh.core.validation.sanitise_patch_name(name)[source]

Remove characters that OpenFOAM forbids in patch names.

Return type:

str

Parameters:

name (str)

polyfoammesh.core.validation.sanitise_filename(name)[source]

Remove characters unsafe for Windows/NTFS filenames.

Return type:

str

Parameters:

name (str)

polyfoammesh.core.validation.mesh_remeshable(case_dir)[source]

Whether an existing mesh may be replaced by a fresh cfMesh cartesianMesh.

quality_engine.auto_fix / optimizer.MeshOptimizer re-run cartesianMesh on whatever mesh already exists in the case — if that mesh came from the GMSH tet / tet→poly pipeline, re-meshing would SILENTLY replace the user’s chosen mesh with an unrelated cfMesh hex at different dimensions. That silent-swap class of bug is forbidden (docs §5/§6): this guard refuses when the case carries a non-cfMesh signal.

Return type:

tuple[bool, str]

Parameters:

case_dir (str | Path)

Signals (all offline, no WSL needed):
  • constant/polyMesh_tet_backup exists → the tet→poly pipeline built this case (both the GUI barycentric-dual path and poly_aggregator back the tet mesh up there before converting).

  • the existing mesh is a pure tetrahedral mesh (every cell has exactly 4 faces) → direct GMSH tet output.

Returns (True, reason) when re-meshing is safe, (False, reason) when it would silently destroy a non-cfMesh mesh.