carbonfly.case module
High-level OpenFOAM case builder.
This module orchestrates the full case generation workflow by combining geometry processing (Rhino Breps -> meshes -> STL export) with OpenFOAM dictionary and field writers.
It is intended as a convenience layer for Grasshopper components where a single function call generates a runnable OpenFOAM case folder.
- carbonfly.case.build_case(case_root: Path, cfgeos: Iterable[CFGeo], stl_file_name: str = 'model.stl', unit: str = 'mm', internal_U=None, internal_T=None, internal_CO2=None, internal_P=None, internal_P_rgh=None, internal_alphat=None, internal_epsilon=None, internal_k=None, internal_nut=None, internal_G=None, internal_Ydefault=None, write_blockmesh: bool = True, padding_m: float = 1.0, cell_size_m: float = 0.25, write_snappy: bool = True, snap: bool = False, inside_point: Tuple[float, float, float] = (0.5, 0.5, 0.5), write_constant: bool = True, write_fv: bool = True, fvSchemes_path: Path | None = None, fvSolution_path: Path | None = None, write_residuals: bool = True)[source]
Build an OpenFOAM case folder structure and write key dictionaries/fields.
- Steps:
Mesh each CFGeo.brep and export a multi-solid ASCII STL.
Optionally write system/blockMeshDict.
Optionally write system/surfaceFeaturesDict and system/snappyHexMeshDict.
Optionally write constant/ dictionaries and FV templates.
Aggregate patch boundary specs and write 0/ fields as needed.
Create a <caseName>.foam marker file for ParaView.
- Parameters:
case_root (Path) – Case root directory (e.g. /path/to/case_dir/case_name).
cfgeos (Iterable[CFGeo]) – CFGeo objects (expects attributes: name, brep, boundary, refine).
stl_file_name (str) – Output STL file name under constant/triSurface/.
unit (str) – Input geometry unit (e.g., “mm”, “cm”, “m”). Export is scaled to meters.
internal_U – Optional internalField for U (tuple).
internal_T – Optional internalField for T (K).
internal_CO2 – Optional internalField for CO2 (volume fraction).
internal_P – Optional internalField for p (Pa).
internal_P_rgh – Optional internalField for p_rgh.
internal_alphat – Optional internalField for alphat.
internal_epsilon – Optional internalField for epsilon.
internal_k – Optional internalField for k.
internal_nut – Optional internalField for nut.
internal_G – Optional internalField for G.
internal_Ydefault – Optional internalField for Ydefault.
write_blockmesh (bool) – If True, write system/blockMeshDict.
padding_m (float) – Extra margin (in meters) added around the union of all CFGeo bounding boxes when computing the blockMesh domain extents.
cell_size_m (float) – Target cell size (m) used to derive blockMesh cell counts.
write_snappy (bool) – If True, write snappyHexMesh-related dictionaries.
snap (bool) – snap switch in snappyHexMeshDict.
inside_point (Tuple[float, float, float]) – Reference point inside model.
write_constant (bool) – If True, write constant/ dictionaries.
write_fv (bool) – If True, write/copy fvSolution & fvSchemes.
fvSchemes_path (Path, optional) – Optional fvSchemes template path.
fvSolution_path (Path, optional) – Optional fvSolution template path.
write_residuals (bool) – If True, write system/residuals.
- Returns:
logs: List of messages describing written outputs / warnings. paths: Dict of written/expected paths (e.g., “stl”, “snappy”, “blockMesh”, “U”, …).
- Return type:
Tuple[List[str], Dict[str, Optional[Path]]]