Fine-tuning a large language model for automating computational fluid dynamics simulations

Zhen Dong, Zhen Lu, Yang Yue

TL;DR

This paper introduces a novel approach to automate complex Computational Fluid Dynamics (CFD) simulations using a fine-tuned Large Language Model (LLM). By training a specialized LLM on a custom dataset of natural language descriptions and corresponding CFD configurations, the system can translate user requests into executable simulation setups, significantly reducing the need for expert knowledge and manual effort.

What Problem Does This Paper Address?

Computational Fluid Dynamics (CFD) is a powerful tool for simulating fluid behavior across various scientific and engineering disciplines. However, setting up and running CFD simulations is notoriously complex, requiring deep expertise in numerical methods, software like OpenFOAM, and domain-specific knowledge. This steep learning curve limits broader access to CFD for researchers and engineers. While general-purpose LLMs have shown promise in scientific computing, they often struggle with the precise physical understanding and intricate syntax required for reliable CFD automation, leading to incorrect configurations or physically inconsistent results. This paper aims to bridge this gap by developing a domain-specific LLM capable of accurately automating CFD workflows.

Methods

The core of this work is a domain-specific fine-tuning approach. Instead of relying solely on retrieval-augmented generation (RAG), which accesses external knowledge, the authors embed CFD expertise directly into the LLM's parameters. They fine-tune the Qwen2.5-7B-Instruct model using Low-Rank Adaptation (LoRA), a parameter-efficient fine-tuning technique that significantly reduces computational burden while maintaining performance.

This fine-tuned LLM acts as the central reasoning engine within a multi-agent system. This system comprises four specialized agents:

  • Pre-checker: Validates user inputs and extracts information from mesh files.
  • LLM Generator: The fine-tuned LLM, which generates the complete OpenFOAM configuration using chain-of-thought (CoT) reasoning.
  • Runner: Executes the generated CFD simulations.
  • Corrector: Analyzes simulation errors and iteratively refines the configurations.

This orchestrated workflow ensures OpenFOAM syntax compliance and numerical stability, automating the entire process from natural language description to simulation results.

Datasets

The authors introduce a new dataset called NL2FOAM. This dataset comprises 28,716 pairs of natural language descriptions and corresponding executable OpenFOAM configurations. It was constructed by starting with 16 curated OpenFOAM tutorials, augmenting them to create over 100,000 variations, and then filtering out cases with errors, divergence, or excessive runtime. Crucially, the dataset includes chain-of-thought (CoT) annotations to capture expert reasoning during configuration generation.

The evaluation benchmark consists of 21 diverse incompressible flow cases, spanning laminar and turbulent regimes with a wide range of Reynolds numbers (Re from 40 to 5 × 10⁸). This benchmark is designed to assess generalization capabilities by including cases beyond standard OpenFOAM tutorials and using multiple solvers for certain geometries.

Key Insights and Ideas

  • Domain-specific fine-tuning is crucial for complex engineering tasks: Simply using general-purpose LLMs, even with RAG, is insufficient for reliable CFD automation due to the need for deep physical understanding and precise syntax. Embedding this knowledge directly into the model through fine-tuning yields superior results.
  • Chain-of-Thought (CoT) reasoning significantly boosts performance: The ablation study clearly shows that including CoT annotations in the training data leads to substantial improvements in accuracy and first-attempt success rates, highlighting the importance of explicit reasoning steps for complex problem-solving.
  • A multi-agent system is essential for robust automation: The combination of specialized agents (pre-checker, generator, runner, corrector) creates a resilient workflow that can handle errors and iteratively refine solutions, mimicking a human expert's debugging process.
  • Parameter-efficient fine-tuning (LoRA) makes LLM adaptation practical: LoRA allows for effective domain-specific adaptation without the prohibitive computational cost of full fine-tuning, making such specialized models more accessible.

Key Results

The fine-tuned LLM achieved state-of-the-art performance on the benchmark:

  • 88.7% accuracy
  • 82.6% pass@1 (first-attempt success rate)

This significantly outperformed larger general-purpose models like Qwen2.5-72B-Instruct (31.4% accuracy, 47.1% pass@1), DeepSeek-R1 (41.7% accuracy, 22.4% pass@1), and Llama3.3-70B-Instruct (4.7% accuracy, 0.5% pass@1).

The system also demonstrated high efficiency:

  • Required only 2.6 correction iterations on average, compared to 7.2 for the runner-up.
  • Achieved a token usage of 1.8k tokens/case, leading to a low cost of 0.020 USD per solution.

Limitations and Future Work

The authors acknowledge that the current dataset and framework are limited to incompressible flow cases. More complex phenomena like multiphase, compressible, or reacting flows, which involve additional configuration files and solver settings, are not yet supported.

Future work will focus on:

  • Expanding the NL2FOAM dataset to include more complex transport phenomena.
  • Assessing computational efficiency and accuracy for industrial-level problems.
  • Exploring fine-tuning larger base models to enhance robustness and handle a wider variety of cases.

Summary updated

Abstract

• We fine-tuned a domain-specific LLM, empowering a multi-agent system to automate CFD simulation from natural language input. • We developed NL2FOAM, a dataset containing 28716 cases designed for automated OpenFOAM simulation driven by natural language. • The system achieves an 82.6% first-attempt success rate on the benchmark with an average accuracy of 88.7%, demonstrating superior generalization and robustness. 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 28,716 natural language-to-OpenFOAM configuration pairs with chain-of-thought (CoT) annotations enables direct translation from natural language descriptions to executable CFD setups. A multi-agent system 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 such as 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 .
BibTeX
@inproceedings{dong2025fine,
  author = {Zhen Dong and Zhen Lu and Yang Yue},
  title = {{Fine-tuning a large language model for automating computational fluid dynamics simulations}},
  booktitle = {Theoretical},
  year = {2025},
  doi = {10.1016/j.taml.2025.100594},
}
Figure