# yygroup/autocfd architecture

> Architecture diagram of the GitHub repository yygroup/autocfd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yygroup/autocfd
- Repository: https://github.com/yygroup/autocfd

## Overview

This repository automates CFD simulations from a configured natural-language request: a multi-agent workflow checks the request and mesh, generates OpenFOAM inputs, runs the case, and iteratively corrects failures. The `butterfly` package supplies OpenFOAM case, mesh, dictionary, and parsing abstractions; statistics track execution outcomes. The README documents the workflow and correction loop. Some implementation details, especially post-processing and unsampled agent actions, are not shown, so their relationships are omitted rather than inferred.

Main entry points: [`src/main.py`](https://github.com/yygroup/autocfd/blob/main/src/main.py) (Workflow entry), [`src/actions/RunnerAction.py`](https://github.com/yygroup/autocfd/blob/main/src/actions/RunnerAction.py) (Simulation runner), [`src/qa_module.py`](https://github.com/yygroup/autocfd/blob/main/src/qa_module.py) (Async LLM clients), [`src/actions/PrecheckerAction.py`](https://github.com/yygroup/autocfd/blob/main/src/actions/PrecheckerAction.py) (Input precheck)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Agent workflow"]
  node_main["Workflow entry<br/>[main.py]"]
  node_precheck["Input precheck"]
  node_writer["Input generation"]
  node_runner["Simulation runner<br/>[RunnerAction.py]"]
  node_corrector["Error correction<br/>[CorrectorAction.py]"]
  node_precheck_role["Prechecker agent<br/>[Prechecker.py]"]
  node_writer_role["Writer agent<br/>[InputWriter.py]"]
  node_runner_role["Runner agent<br/>[Runner.py]"]
  node_corrector_role["Corrector agent<br/>[Corrector.py]"]
  node_config["Run configuration<br/>[config_path.py]"]
end

subgraph group_llm["LLM services"]
  node_llm_service["Async LLM clients<br/>[qa_module.py]"]
end

subgraph group_foam["OpenFOAM tooling"]
  node_foam_case["Case assembly<br/>[case.py]"]
  node_foam_geometry["Geometry and mesh<br/>[geometry.py]"]
  node_foam_dicts["Foam dictionaries<br/>[foamfile.py]"]
  node_foam_parser["Dictionary parser<br/>[parser.py]"]
  node_foam_meshdict["Mesh dictionaries<br/>[blockMeshDict.py]"]
end

subgraph group_results["Results and metrics"]
  node_postprocess["Post-processing"]
  node_statistics["Run statistics<br/>[Statistics.py]"]
end

node_user(("User request"))
node_openfoam["OpenFOAM runtime"]

node_user -->|"starts run"| node_main
node_main -->|"publishes request"| node_precheck_role
node_main -->|"registers agent"| node_writer_role
node_main -->|"registers agent"| node_runner_role
node_main -->|"registers agent"| node_corrector_role
node_precheck_role -->|"runs action"| node_precheck
node_writer_role -->|"runs action"| node_writer
node_runner_role -->|"runs action"| node_runner
node_corrector_role -->|"runs action"| node_corrector
node_precheck -->|"asks model"| node_llm_service
node_writer -->|"generates inputs"| node_llm_service
node_corrector -->|"requests fixes"| node_llm_service
node_precheck -->|"parses dictionaries"| node_foam_parser
node_writer -->|"parses response"| node_foam_parser
node_runner -->|"executes case"| node_openfoam
node_corrector_role -->|"reruns case"| node_runner
node_foam_case -->|"uses dictionaries"| node_foam_dicts
node_foam_case -->|"uses geometry"| node_foam_geometry
node_foam_geometry -->|"uses mesh definitions"| node_foam_meshdict
node_foam_dicts -->|"parses files"| node_foam_parser
node_main -->|"reads settings"| node_config
node_main -->|"records runs"| node_statistics
node_runner -->|"updates outcome"| node_statistics
node_llm_service -->|"counts tokens"| node_statistics

click node_main "https://github.com/yygroup/autocfd/blob/main/src/main.py"
click node_precheck "https://github.com/yygroup/autocfd/blob/main/src/actions/PrecheckerAction.py"
click node_writer "https://github.com/yygroup/autocfd/blob/main/src/actions/InputWriterAction.py"
click node_runner "https://github.com/yygroup/autocfd/blob/main/src/actions/RunnerAction.py"
click node_corrector "https://github.com/yygroup/autocfd/blob/main/src/actions/CorrectorAction.py"
click node_precheck_role "https://github.com/yygroup/autocfd/blob/main/src/roles/Prechecker.py"
click node_writer_role "https://github.com/yygroup/autocfd/blob/main/src/roles/InputWriter.py"
click node_runner_role "https://github.com/yygroup/autocfd/blob/main/src/roles/Runner.py"
click node_corrector_role "https://github.com/yygroup/autocfd/blob/main/src/roles/Corrector.py"
click node_llm_service "https://github.com/yygroup/autocfd/blob/main/src/qa_module.py"
click node_foam_case "https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/case.py"
click node_foam_geometry "https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/geometry.py"
click node_foam_dicts "https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/foamfile.py"
click node_foam_parser "https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/parser.py"
click node_foam_meshdict "https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/blockMeshDict.py"
click node_postprocess "https://github.com/yygroup/autocfd/blob/main/src/openfoam_postprocess.py"
click node_statistics "https://github.com/yygroup/autocfd/blob/main/src/Statistics.py"
click node_config "https://github.com/yygroup/autocfd/blob/main/src/config_path.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_precheck,node_writer,node_runner,node_corrector,node_precheck_role,node_writer_role,node_runner_role,node_corrector_role,node_config,node_user toneBlue
class node_llm_service toneAmber
class node_foam_case,node_foam_geometry,node_foam_dicts,node_foam_parser,node_foam_meshdict toneMint
class node_postprocess,node_statistics toneRose
class node_openfoam toneIndigo
```

## Components

### Agent workflow

- [Workflow entry](https://github.com/yygroup/autocfd/blob/main/src/main.py): `src/main.py`
- [Input precheck](https://github.com/yygroup/autocfd/blob/main/src/actions/PrecheckerAction.py): `src/actions/PrecheckerAction.py`
- [Input generation](https://github.com/yygroup/autocfd/blob/main/src/actions/InputWriterAction.py): `src/actions/InputWriterAction.py`
- [Simulation runner](https://github.com/yygroup/autocfd/blob/main/src/actions/RunnerAction.py): `src/actions/RunnerAction.py`
- [Error correction](https://github.com/yygroup/autocfd/blob/main/src/actions/CorrectorAction.py): `src/actions/CorrectorAction.py`
- [Prechecker agent](https://github.com/yygroup/autocfd/blob/main/src/roles/Prechecker.py): `src/roles/Prechecker.py`
- [Writer agent](https://github.com/yygroup/autocfd/blob/main/src/roles/InputWriter.py): `src/roles/InputWriter.py`
- [Runner agent](https://github.com/yygroup/autocfd/blob/main/src/roles/Runner.py): `src/roles/Runner.py`
- [Corrector agent](https://github.com/yygroup/autocfd/blob/main/src/roles/Corrector.py): `src/roles/Corrector.py`
- [Run configuration](https://github.com/yygroup/autocfd/blob/main/src/config_path.py): `src/config_path.py`

### LLM services

- [Async LLM clients](https://github.com/yygroup/autocfd/blob/main/src/qa_module.py): `src/qa_module.py`

### OpenFOAM tooling

- [Case assembly](https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/case.py): `src/utils/butterfly/case.py`
- [Geometry and mesh](https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/geometry.py): `src/utils/butterfly/geometry.py`
- [Foam dictionaries](https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/foamfile.py): `src/utils/butterfly/foamfile.py`
- [Dictionary parser](https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/parser.py): `src/utils/butterfly/parser.py`
- [Mesh dictionaries](https://github.com/yygroup/autocfd/blob/main/src/utils/butterfly/blockMeshDict.py): `src/utils/butterfly/blockMeshDict.py`

### Results and metrics

- [Post-processing](https://github.com/yygroup/autocfd/blob/main/src/openfoam_postprocess.py): `src/openfoam_postprocess.py`
- [Run statistics](https://github.com/yygroup/autocfd/blob/main/src/Statistics.py): `src/Statistics.py`

### Other components

- **User request**
- **OpenFOAM runtime**

## Connections

- User request → Workflow entry: starts run (evidence: `README.md`)
- Workflow entry → Prechecker agent: publishes request (evidence: `src/main.py`)
- Workflow entry → Writer agent: registers agent (evidence: `src/main.py`)
- Workflow entry → Runner agent: registers agent (evidence: `src/main.py`)
- Workflow entry → Corrector agent: registers agent (evidence: `src/main.py`)
- Prechecker agent → Input precheck: runs action (evidence: `src/roles/Prechecker.py`)
- Writer agent → Input generation: runs action (evidence: `src/roles/InputWriter.py`)
- Runner agent → Simulation runner: runs action (evidence: `src/roles/Runner.py`)
- Corrector agent → Error correction: runs action (evidence: `src/roles/Corrector.py`)
- Input precheck → Async LLM clients: asks model (evidence: `src/actions/PrecheckerAction.py`)
- Input generation → Async LLM clients: generates inputs (evidence: `src/actions/InputWriterAction.py`)
- Error correction → Async LLM clients: requests fixes (evidence: `src/actions/CorrectorAction.py`)
- Input precheck → Dictionary parser: parses dictionaries (evidence: `src/actions/PrecheckerAction.py`)
- Input generation → Dictionary parser: parses response (evidence: `src/actions/InputWriterAction.py`)
- Simulation runner → OpenFOAM runtime: executes case (evidence: `src/actions/RunnerAction.py`)
- Corrector agent → Simulation runner: reruns case (evidence: `src/roles/Corrector.py`)
- Case assembly → Foam dictionaries: uses dictionaries (evidence: `src/utils/butterfly/case.py`)
- Case assembly → Geometry and mesh: uses geometry (evidence: `src/utils/butterfly/case.py`)
- Geometry and mesh → Mesh dictionaries: uses mesh definitions (evidence: `src/utils/butterfly/geometry.py`)
- Foam dictionaries → Dictionary parser: parses files (evidence: `src/utils/butterfly/foamfile.py`)
- Workflow entry → Run configuration: reads settings (evidence: `src/main.py`)
- Workflow entry → Run statistics: records runs (evidence: `src/main.py`)
- Simulation runner → Run statistics: updates outcome (evidence: `src/actions/RunnerAction.py`)
- Async LLM clients → Run statistics: counts tokens (evidence: `src/qa_module.py`)
