carbonfly.snappy_writer module

Writers for OpenFOAM snappyHexMesh configuration files.

This module provides helper functions to generate OpenFOAM dictionaries required for surface-based mesh refinement using snappyHexMesh, including:

  • system/surfaceFeaturesDict for extracting feature edges from STL geometry,

  • system/snappyHexMeshDict for castellated meshing, snapping, and layer addition,

with support for multi-region STL files.

carbonfly.snappy_writer.write_snappy_geometry(case_root: Path, stl_file_name: str, regions: List[str], region_levels: Dict[str, Tuple[int, int]], *, castellated_mesh: bool = True, snap: bool = False, add_layers: bool = False, feature_level: int = 3, resolve_feature_angle_deg: float = 30.0, n_cells_between_levels: int = 3, max_local_cells: int = 1000000, max_global_cells: int = 20000000, min_refinement_cells: int = 2, snap_n_smooth_patch: int = 5, snap_tolerance: float = 1.0, snap_n_solve_iter: int = 200, snap_n_relax_iter: int = 10, mesh_quality_block: str | None = None, extra_blocks: List[str] | None = None, merge_tolerance: float = 1e-06, allow_free_standing_zone_faces: bool = True, inside_point: Tuple[float, float, float] = (0.5, 0.5, 0.5)) Path[source]

Write system/snappyHexMeshDict for a multi-region STL.

Notes

The feature edges file <stl stem>.eMesh is expected to be generated by the OpenFOAM surfaceFeatures utility using system/surfaceFeaturesDict.

Parameters:
  • case_root (Path) – OpenFOAM case root directory.

  • stl_file_name (str) – STL filename under constant/triSurface/.

  • regions (List[str]) – Region names inside the STL (triSurfaceMesh regions).

  • region_levels (Dict[str, Tuple[int, int]]) – Per-region refinement levels as (min, max).

  • inside_point (Tuple[float, float, float]) – locationInMesh point for castellatedMeshControls.

  • mesh_quality_block (str | None) – Optional full meshQualityControls { … } block override.

  • extra_blocks (List[str] | None) – Optional additional raw blocks appended to the dict.

  • meaning. (Other parameters map directly to snappyHexMeshDict entries with the same)

Returns:

Path to the written system/snappyHexMeshDict.

Return type:

Path

carbonfly.snappy_writer.write_surface_features_dict(case_root: Path, stl_file_name: str, *, included_angle_deg: float = 150.0) Path[source]

Write system/surfaceFeaturesDict for OpenFOAM surfaceFeatures.

Parameters:
  • case_root (Path) – OpenFOAM case root directory.

  • stl_file_name (str) – STL filename under constant/triSurface/.

  • included_angle_deg (float) – Feature angle threshold in degrees.

Returns:

Path to the written system/surfaceFeaturesDict.

Return type:

Path