foamToPython is a Python package for reading and writing OpenFOAM field/list
data and running POD-related workflows. The main package lives in
src/foamToPython/, with POD helpers in src/PODopenFOAM/.
Prioritize correctness for OpenFOAM file formats, NumPy array behavior, and backward-compatible public APIs.
- Use
uvfor dependency and virtual environment management. - Do not create separate
venvor conda environments for this workspace. - Prefer
uv run <command>when running Python tools. - Python support starts at 3.8, so avoid syntax or typing features that require newer versions unless the project metadata is updated intentionally.
Common commands:
uv pip install -e .[dev]
uv run pytest
uv run pytest tests/test_of_field.pyOptional example dependencies:
uv pip install -e .[examples]src/foamToPython/readOFField.py: OpenFOAM field reading API.src/foamToPython/readOFList.py: OpenFOAM list/listList parsing API.src/foamToPython/_field_parser.py: Shared parsing helpers.src/foamToPython/_field_writer.py: Field writing helpers.src/foamToPython/_mp_utils.py: Multiprocessing utilities.src/PODopenFOAM/: POD analysis helpers.tests/: Pytest suite.examples/: Example and validation scripts.
- Keep changes focused and small; avoid unrelated refactors.
- Preserve existing public names and call patterns unless the user explicitly asks for an API change.
- Prefer simple, explicit parsing and writing logic over clever abstractions; OpenFOAM syntax edge cases should remain easy to reason about.
- Maintain NumPy array shape and dtype behavior carefully, especially for scalar versus vector fields and serial versus parallel cases.
- Use ASCII for new text unless an existing file already uses non-ASCII content.
- Add comments only when they clarify non-obvious OpenFOAM format handling or performance-sensitive logic.
- Run
uv run pytestafter code changes when feasible. - For targeted changes, run the nearest focused test first, then the full suite if the change is not trivial.
- The cavity validation example may require OpenFOAM and
foamlib; do not assume those are installed or sourced in every environment. - If a test cannot run because an external OpenFOAM dependency is unavailable, report that clearly and include the command attempted.
- Keep runtime dependencies minimal. The core package currently depends on
numpy. - Add new runtime dependencies only when they are clearly justified.
- Put test-only or example-only dependencies in the appropriate optional
dependency group in
pyproject.toml.
- Check
git status --shortbefore editing. - Do not revert or overwrite user changes unless explicitly asked.
- Do not commit, amend, merge, or push unless the user asks.
- Do not remove generated or data files unless the user asks or the task clearly requires it and the action is safe.
- Update
README.mdwhen behavior, user-facing APIs, installation, or example commands change. - Keep examples runnable and aligned with the current API.