OpenFOAM Case Generator (Brief)

This project is a RAG + LLM pipeline to generate and debug OpenFOAM cases from a text prompt.

---
Place the tutorial files of your OpenFOAM version at ./files/tutorials
---
QUICK SETUP (Recommended)

A startup script is provided for automatic environment setup and initialization.

Run:

chmod +x startup.sh
./startup.sh

This automatically handles:

- Python environment setup
- Dependency installation
- Ollama setup guidance
- Virtual environment creation
- Setup instructions generation

After setup, initialize and run the full workflow using:

chmod +x allrun
./allrun

The allrun script:

- Checks existing databases
- Avoids unnecessary database regeneration
- Generates missing retrieval databases
- Runs case generation
- Optionally starts the automated debugging loop

---

MANUAL SETUP (Fallback)

If the automated scripts fail or require manual debugging, run the setup pipeline manually in the following order:

python Tut_Creation.py
python build_structure_db.py
python VectorDB.py

This creates:

- Flattened tutorial data
- StructureDB.json
- VectorDB/

---

INPUT

Write your prompt in:

input/prompt

(Optional) Place your mesh in:

input/polyMesh/

If present:
→ the mesh will be reused directly.

If absent:
→ the system attempts fallback generation (less reliable).

---

USAGE

1. Generate OpenFOAM Case

python scripts/run_case.py

This creates the Case/ directory containing generated OpenFOAM files.

---

2. Run Automated Debugging Pipeline

python scripts/run_error_loop.py

This workflow:

- Runs the OpenFOAM solver
- Detects execution errors
- Identifies problematic files
- Regenerates incorrect configurations iteratively

---

MODEL

Default model:

gpt-oss:120b-cloud

Can be changed in:

LLM/llm_manager.py

Requires Ollama setup and login.

---

IMPORTANT NOTES

- Vector database generation may take significant time depending on hardware.
- The generated outputs are intended as strong initialization templates and may still require minor manual correction before production-level simulation execution.
- The system performs best when a valid mesh is provided through input/polyMesh/.
