polyfoammesh.core.case_setup

Functions

infer_patch_roles(case_dir, patches[, ...])

Assign inlet/outlet/wall roles from mesh geometry when patch names carry none (GMSH physical surfaces are surface_0 … surface_N).

mesh_bounds(case_dir)

(xmin, xmax, ymin, ymax, zmin, zmax) of the polyMesh points (metres).

set_wall_patch_types(case_dir, wall_names[, ...])

Rewrite constant/polyMesh/boundary so the named patches get type wall instead of the generic patch type gmshToFoam writes.

setup_case(case_dir, patches[, application, ...])

Write a runnable OpenFOAM case into case_dir.

suggest_flow_direction(case_dir)

Unit vector along the dominant (largest-extent) mesh axis — the obvious default flow direction for an internal-flow passage.

write_control_dict(case_dir)

Write the minimal controlDict cartesianMesh needs to run.

polyfoammesh.core.case_setup.infer_patch_roles(case_dir, patches, flow_direction=(1.0, 0.0, 0.0))[source]

Assign inlet/outlet/wall roles from mesh geometry when patch names carry none (GMSH physical surfaces are surface_0 … surface_N).

The inlet and outlet are the patches sitting at the two extremes of the dominant flow axis whose outward normals are most aligned with that axis; the one whose normal opposes flow_direction is the inlet (flow enters where the wall normal points back at the oncoming stream). Everything else is a wall. Patches whose name already encodes a role are respected.

Returns a {patch_name: role} map covering every boundary patch.

Return type:

dict[str, str]

Parameters:
polyfoammesh.core.case_setup.mesh_bounds(case_dir)[source]

(xmin, xmax, ymin, ymax, zmin, zmax) of the polyMesh points (metres).

Return type:

tuple[float, float, float, float, float, float]

Parameters:

case_dir (Path | str)

polyfoammesh.core.case_setup.suggest_flow_direction(case_dir)[source]

Unit vector along the dominant (largest-extent) mesh axis — the obvious default flow direction for an internal-flow passage.

Return type:

tuple[float, float, float]

Parameters:

case_dir (Path | str)

polyfoammesh.core.case_setup.write_control_dict(case_dir)[source]

Write the minimal controlDict cartesianMesh needs to run.

Single implementation used by every meshing path (mesh_engine, snappy_hex_mesh, main_window) — formerly duplicated verbatim in mesh_engine.py and snappy_hex_mesh.py with subtle field drift.

Return type:

None

Parameters:

case_dir (Path)

polyfoammesh.core.case_setup.set_wall_patch_types(case_dir, wall_names, boundary_type='wall')[source]

Rewrite constant/polyMesh/boundary so the named patches get type wall instead of the generic patch type gmshToFoam writes.

Wall-function boundary conditions (nutkWallFunction, kqRWallFunction, omegaWallFunction) abort at construction time from simpleFoam startup if their patch is typed patch — the wall-function code requires the mesh boundary to say wall. Seen live on the venturi first run: exit 134 in nutkWallFunctionFvPatchScalarField’s constructor.

Return type:

None

Parameters:
polyfoammesh.core.case_setup.setup_case(case_dir, patches, application='simpleFoam', turbulence_model='kOmegaSST', inlet_velocity=None, end_time=None, residual_control=None, write_interval=None, patch_roles=None)[source]

Write a runnable OpenFOAM case into case_dir.

Parameters:
  • inlet_velocity (tuple[float, float, float] | None) – velocity vector imposed on every patch whose name contains “inlet”. Leave as None for the historical placeholder (zero velocity — a case that is set up but not meant to be run).

  • end_time (int | None) – SIMPLE iteration ceiling (controlDict endTime).

  • residual_control (float | None) – if given, adds a SIMPLE residualControl block so the run stops on convergence rather than always running to end_time.

  • write_interval (int | None) – how often to write a time directory. Solution-adaptive refinement only ever reads the last one, so it passes a large value to avoid writing gigabytes of intermediate fields on a big mesh.

  • patch_roles (dict[str, str] | None) – per-patch role overrides (see _boundary_block). When meshing with GMSH the patches are named surface_N and the name-based roles are useless — pass infer_patch_roles() output.

  • case_dir (Path | str)

  • patches (list[PatchInfo])

  • application (str)

  • turbulence_model (str)