Abstract
Significant advances have been achieved in leveraging foundation models, such as large language models (LLMs), to accelerate complex scientific workflows. In this work we introduce FoamPilot, a proof-of-concept LLM agent designed to enhance the usability of FireFOAM, a specialized solver for fire dynamics and fire suppression simulations built using OpenFOAM, a popular open-source toolbox for computational fluid dynamics (CFD). FoamPilot provides three core functionalities: code insight, case configuration and simulation evaluation. Code insight is an alternative to traditional keyword searching leveraging retrieval-augmented generation (RAG) and aims to enable efficient navigation and summarization of the FireFOAM source code for developers and experienced users. For case configuration, the agent interprets user requests in natural language and aims to modify existing simulation setups accordingly to support intermediate users. FoamPilot's job execution functionality seeks to manage the submission and execution of simulations in high-performance computing (HPC) environments and provide preliminary analysis of simulation results to support less experienced users. Promising results were achieved for each functionality, particularly for simple tasks, and opportunities were identified for significant further improvement for more complex tasks. The integration of these functionalities into a single LLM agent is a step aimed at accelerating the simulation workflow for engineers and scientists employing FireFOAM for complex simulations critical for improving fire safety.
Introduction
Computational Fluid Dynamics (CFD) is essential for fire safety engineering, but tools like FireFOAM have a notoriously steep learning curve. Users must typically be experts in three distinct areas: fire science, the underlying C++ codebase, and the intricacies of Linux-based high-performance computing (HPC) environments. Even for experienced researchers, setting up a simulation involves navigating a maze of keywords and configuration files. FoamPilot aims to bridge this "usability gap" by creating an AI assistant that handles the technical "plumbing" of the simulation workflow, allowing researchers to focus on the science rather than the syntax.
System Design and Methodology
FoamPilot was developed using the LangChain/LangGraph framework, utilizing GPT-4o as its primary reasoning engine. The agent operates through a graph-based structure that connects user queries to specific tools and LLM reasoning steps.
Key technical innovations include:
- Custom RAG for C++: To assist in code navigation, the system uses a preprocessing pipeline that combines C++ header (.H) and implementation (.C) files into single documents before embedding. This provides the LLM with full context for functions and classes.
- Context Compression: To manage the 128k token context window efficiently, the agent strips boilerplate headers and license information from configuration files, compressing entire simulation directories into a single string for "whole-case" prompting.
- Integrated Toolset: The agent utilizes a Shell Command Tool for Linux operations, a Python Interpreter for data analysis, and a RAG Tool for semantic code lookups.
Core Capabilities
FoamPilot is designed to handle the multi-layered complexity of FireFOAM cases, which involve intricate directory structures and physics parameters.
- Code Insight: The RAG system translates natural language queries (e.g., "find the energy equation for the solid phase") into specific LaTeX equations derived from the source code, outperforming traditional keyword searches.
- Case Configuration: The agent interprets natural language requests to modify existing simulation setups, such as changing burner sizes or material properties, by directly editing the underlying configuration files.
- Job Execution: The agent manages the submission of simulations to HPC environments, including the generation of SLURM scripts and preliminary analysis of results.
Performance Evaluation
The agent was tested across several categories with five repeats each to account for LLM variability. While simple tasks showed high success rates, complex multi-step tasks revealed a "complexity wall."
| Functionality | Task | Success Rate |
|---|---|---|
| Code Insight | Explaining energy/drag equations | 100% |
| Case Config | Modifying burner size/material thickness | 100% |
| Job Execution | Running a serial job locally | 80% |
| Job Execution | Submitting a complex HPC/SLURM job | 20% |
| Multi-Function | Modify model based on RAG insight | 40% |
Conclusion and Future Work
FoamPilot demonstrates the potential for LLM agents to lower the barrier to entry for complex CFD tools. However, significant challenges remain in managing asynchronous operations (waiting for long-running simulations) and handling the high sensitivity of HPC scheduler syntax. Future work will focus on domain-specific pre-training on the FireFOAM codebase, implementing human-in-the-loop verification for shell commands, and incorporating multimodal capabilities to allow the agent to visually inspect mesh geometries and simulation renders.
Summary updated