Table of Contents
Fetching ...

Fine-tuning a Large Language Model for Automating Computational Fluid Dynamics Simulations

Zhehao Dong, Zhen Lu, Yue Yang

TL;DR

This work tackles the barrier to CFD adoption by domain-specifically adapting a compact LLM to automate OpenFOAM setup from natural language. By fine-tuning Qwen2.5-7B-Instruct with LoRA on NL2FOAM, and deploying a four-agent workflow, the approach translates problem descriptions into executable CFD configurations with high reliability. On a 21-case incompressible-flow benchmark, it achieves 88.7% accuracy and 82.6% pass@1 while requiring fewer correction iterations than larger general-purpose models, illustrating the value of domain-specific adaptation for engineering automation. The results suggest a practical path toward democratizing CFD tooling, while pointing to extensions toward more complex flow regimes and larger-scale models in future work.

Abstract

Configuring computational fluid dynamics (CFD) simulations typically demands extensive domain expertise, limiting broader access. Although large language models (LLMs) have advanced scientific computing, their use in automating CFD workflows is underdeveloped. We introduce a novel approach centered on domain-specific LLM adaptation. By fine-tuning Qwen2.5-7B-Instruct on NL2FOAM, our custom dataset of 28716 natural language-to-OpenFOAM configuration pairs with chain-of-thought (CoT) annotations, we enable direct translation from natural language descriptions to executable CFD setups. A multi-agent framework orchestrates the process, autonomously verifying inputs, generating configurations, running simulations, and correcting errors. Evaluation on a benchmark of 21 diverse flow cases demonstrates state-of-the-art performance, achieving 88.7% solution accuracy and 82.6% first-attempt success rate. This significantly outperforms larger general-purpose models like Qwen2.5-72B-Instruct, DeepSeek-R1, and Llama3.3-70B-Instruct, while also requiring fewer correction iterations and maintaining high computational efficiency. The results highlight the critical role of domain-specific adaptation in deploying LLM assistants for complex engineering workflows. Our code and fine-tuned model have been deposited at https://github.com/YYgroup/AutoCFD.

Fine-tuning a Large Language Model for Automating Computational Fluid Dynamics Simulations

TL;DR

This work tackles the barrier to CFD adoption by domain-specifically adapting a compact LLM to automate OpenFOAM setup from natural language. By fine-tuning Qwen2.5-7B-Instruct with LoRA on NL2FOAM, and deploying a four-agent workflow, the approach translates problem descriptions into executable CFD configurations with high reliability. On a 21-case incompressible-flow benchmark, it achieves 88.7% accuracy and 82.6% pass@1 while requiring fewer correction iterations than larger general-purpose models, illustrating the value of domain-specific adaptation for engineering automation. The results suggest a practical path toward democratizing CFD tooling, while pointing to extensions toward more complex flow regimes and larger-scale models in future work.

Abstract

Configuring computational fluid dynamics (CFD) simulations typically demands extensive domain expertise, limiting broader access. Although large language models (LLMs) have advanced scientific computing, their use in automating CFD workflows is underdeveloped. We introduce a novel approach centered on domain-specific LLM adaptation. By fine-tuning Qwen2.5-7B-Instruct on NL2FOAM, our custom dataset of 28716 natural language-to-OpenFOAM configuration pairs with chain-of-thought (CoT) annotations, we enable direct translation from natural language descriptions to executable CFD setups. A multi-agent framework orchestrates the process, autonomously verifying inputs, generating configurations, running simulations, and correcting errors. Evaluation on a benchmark of 21 diverse flow cases demonstrates state-of-the-art performance, achieving 88.7% solution accuracy and 82.6% first-attempt success rate. This significantly outperforms larger general-purpose models like Qwen2.5-72B-Instruct, DeepSeek-R1, and Llama3.3-70B-Instruct, while also requiring fewer correction iterations and maintaining high computational efficiency. The results highlight the critical role of domain-specific adaptation in deploying LLM assistants for complex engineering workflows. Our code and fine-tuned model have been deposited at https://github.com/YYgroup/AutoCFD.

Paper Structure

This paper contains 11 sections, 7 figures, 2 tables.

Figures (7)

  • Figure 1: The multi-agent system for automated CFD simulation, centered on a fine-tuned LLM. The workflow progresses from user input through a pre-checker, LLM-based generation of input files, simulation execution by the runner, and an iterative error correction loop involving the corrector, ultimately producing simulation results.
  • Figure 1: Evolution of the performance pass@1 across epochs on our benchmark. The model reached a peak pass@1 of 82.6% at epoch two.
  • Figure 2: NL2FOAM construction pipeline. From 16 curated OpenFOAM cases, automated tools modify input files (controlDict, fvScheme, and fvSolution) to create 100k variations, while an LLM enhances linguistic diversity through description rephrasing. Simulation testing eliminates cases with errors, solution divergence, or excessive runtime, followed by CoT reasoning to structure solutions.
  • Figure 3: Structure of an example case within the NL2FOAM dataset used for fine-tuning. The input consists of a natural language description (Question), mesh file references, and input templates. The output (Response) includes CoT reasoning steps followed by the generated OpenFOAM files and execution script.
  • Figure 4: Simulation results from benchmark cases generated using our automation workflow based on the fine-tuned LLM: (a) vorticity magnitude $\vert\bm{\omega}\vert$ for cylinder wake ($Re = 200$), (b) velocity component $u$ for jet flow ($Re = 3.3 \times 10^5$), (c) velocity component $v$ for square bend ($Re = 2 \times 10^4$), (d) velocity magnitude $U$ for cylinder wake ($Re = 1 \times 10^5$), (e) voricity magnitude $\vert\bm{\omega}\vert$ for square column wake in a channel ($Re = 5 \times 10^5$), and (f) pressure field $p$ for forward-facing step ($Re = 50$).
  • ...and 2 more figures