carbonfly.fv_writer module
Writers and patchers for OpenFOAM system/fvSchemes and system/fvSolution.
This module helps manage finite-volume (FV) configuration files by: - Selecting and copying built-in fvSchemes / fvSolution templates into an
OpenFOAM case (<case>/system/).
Optionally patching solver settings in fvSolution, currently focused on the PIMPLE { … } block (e.g., pRefPoint and residualControl).
The functions are intended for programmatic case generation workflows, where users may start from carbonfly templates and then apply small, targeted edits without maintaining full custom dictionaries.
- carbonfly.fv_writer.copy_fv_templates_to_case(case_root: Path, *, fvSchemes_src: Path, fvSolution_src: Path, overwrite: bool = True) dict[str, Path][source]
Copy fvSchemes and fvSolution templates into case_root/system/.
- Parameters:
case_root (Path) – Case root directory.
fvSchemes_src (Path) – Source file for fvSchemes.
fvSolution_src (Path) – Source file for fvSolution.
overwrite (bool) – If False, keep existing destination files.
- Returns:
Paths of copied files: {“fvSchemes”: …, “fvSolution”: …}.
- Return type:
dict[str, Path]
- Raises:
FileNotFoundError – If any template source file does not exist.
- carbonfly.fv_writer.get_template_path(kind: Literal['fvSchemes', 'fvSolution'], mode: str | None) Path[source]
Return the absolute path to a built-in fv template file.
- Parameters:
kind (Literal["fvSchemes","fvSolution"]) – Template filename.
mode (str | None) – Mode selector (e.g., “transient”, “steady”, …).
- Returns:
Absolute template path under templates/<mode>/<kind>.
- Return type:
Path
- carbonfly.fv_writer.patch_fvSolution_pimple(fvsolution_path: Path, pRefPoint: Tuple[float, float, float] | None, residual_value: float | None) Path[source]
Patch PIMPLE{} entries in an fvSolution file.
- Modifies (if present) within the PIMPLE { … } block:
pRefPoint (if pRefPoint is provided)
residualControl { … } (if residual_value is provided)
- Parameters:
fvsolution_path (Path) – Path to an fvSolution file to patch in-place.
pRefPoint (tuple[float, float, float] | None) – Target pRefPoint (x, y, z).
residual_value (float | None) – Target residualControl value.
- Returns:
The same fvsolution_path (patched in-place).
- Return type:
Path