Can LLMs Write a CFD Solver? A Real Case and Its Capability Limits

    This article examines a recent case in which a large language model wrote a computational fluid dynamics (CFD) solver during a task, refined its solution plan, and generated visualization animations. It breaks down what a CFD solver requires, explains why some developers build custom solvers instead of using mature ones, and assesses what this kind of demonstration does and does not show about LLM capabilities. It also covers where LLMs fit in professional engineering toolchains and how to verify their output.

    1. Case Breakdown: What Makes a CFD Solver Hard?

    A CFD solver is not just code that looks like scientific computing. It depends on a tightly linked chain of decisions:

    1. Physical model selection: Which governing equations apply: the Navier-Stokes equations, the Euler equations, or simplified potential flow equations? Is a turbulence model required?
    2. Geometry and mesh handling: How is the computational domain described, and how is the mesh generated? Structured meshes, unstructured meshes, and adaptive refinement each affect the computational cost.
    3. Numerical scheme design: Is spatial discretization based on finite difference, finite volume, or finite element methods? Is time integration explicit or implicit? These choices directly determine stability and accuracy.
    4. Boundary condition handling: Inlets, outlets, walls, symmetry planes, and far-field pressure boundaries each have different mathematical formulations. A single incorrect boundary setting can cause the whole flow field to diverge.
    5. Solving the equation system: How do you solve the large, sparse linear systems produced by discretization efficiently? Which preconditioner should you use? How do you speed up nonlinear iterations?
    6. Convergence criteria and error control: What residual level counts as converged? Has mesh independence been demonstrated? Do the results have physical meaning?
    7. Post-processing and visualization: How do you extract flow field data, draw streamlines, and generate animations?

    A failure at any one of these steps can leave results that look like a fluid flow but have no physical meaning. An LLM can quickly write code that contains mesh loops, finite difference formulas, iterative updates, and output routines. Code that runs and results that are correct are two very different things.

    The significance of this case is that the model compresses knowledge from several disciplines into a working workflow. Whether the solver actually handles numerical stability, physical consistency, and mesh sensitivity requires careful verification.

    2. Why Would Anyone Bypass Mature Solvers?

    Mature CFD solvers have been developed over several decades. They come with extensive validation cases, efficient parallel computing, comprehensive boundary condition libraries, and well-established post-processing tools. For production projects, a mature solver is usually the most efficient and reliable choice.

    So why ask a model to write a solver from scratch? There are several possible motivations:

    • Teaching and understanding: Some settings require understanding an algorithm from the ground up instead of relying on a black box.
    • Heavy toolchains: Installing, configuring, and licensing mature solvers, or formatting their input files, can be complicated. For a very narrow problem, a lightweight implementation can be faster.
    • Customization: Some nonstandard equations or special boundary conditions may not be supported by mature tools, so custom code is needed.
    • Showcasing coding ability: For example, a demonstration can test whether a model can write core algorithms in an unfamiliar domain. Such demonstrations work more like technical showcases than production solutions.

    If the goal is to solve a problem, calling a mature solver is the rational choice. If the goal is to demonstrate capability, building a solver on the spot can serve as a capability test. Treating the second as the first, however, easily overestimates AI’s engineering ability.

    3. Can LLMs Write CFD Solvers? Where Are the Real Limits?

    LLMs can write code, and they can produce the skeleton of a solver. Whether the result is correct and usable is a separate question.

    3.1 From the code generation perspective

    LLMs are good at pattern matching, syntax organization, and interface assembly. Given a clear requirement, a model can generate complete classes, functions, and loops. The hardest part of scientific computing code, however, is checking constraints. Is the CFL condition satisfied? Is the scheme conservative? Are boundaries reflecting incorrectly? Is numerical diffusion too large? Code syntax alone cannot answer these questions.

    A model may produce code that looks reasonable. For example, it might use central differencing for convective terms and cause numerical oscillations, or set a time step too large for a transient problem so the results diverge. Developers without a CFD background will have difficulty spotting these errors.

    3.2 From the complete system perspective

    A valuable CFD solver must be validated against many benchmark cases. For instance, you might first compute laminar flow between parallel plates, then flow over a backward-facing step, then flow around a circular cylinder, and compare each result with experimental data or classic analytical solutions. This validation loop requires repeated modification, debugging, and rerunning, and it sometimes requires human judgment.

    A single generation pass rarely completes this loop. The model works more like an extremely fast but inexperienced code assistant. It can produce a first draft, but it cannot guarantee that the draft is trustworthy.

    3.3 What one evaluation suggests

    Some researchers have run similar tests. They asked LLMs to implement a CFD solver from scratch under defined conditions. Even when the task was narrowed to a single scenario and a single function, the pass rate was not high. This does not mean the models cannot write code. Scientific computing sets a high bar for correctness. Compiling is only the starting point, and numerical convergence, mesh independence, and physical plausibility each act as a separate test.

    4. Where LLMs Can Really Help

    Rather than expecting LLMs to replace mature solvers, it is more practical to place them in a supporting role within the toolchain. They are well suited to the following tasks:

    • Generating pre-processing scripts: Batch-generating geometry parameters, mesh configuration files, and boundary condition templates.
    • Wrapping solver workflows: Turning the steps for calling a mature solver into automated scripts to avoid repetitive manual work.
    • Post-processing automation: Reading data from result files, plotting curves and contour maps, creating animations, and generating brief reports.
    • Parameter sweeps and optimization: Writing loop scripts that adjust design variables, run calculations, and summarize results automatically.
    • Code translation and interface adaptation: Migrating algorithms from legacy code into new projects and completing interface documentation.
    • Explanation and teaching: Explaining numerical schemes, deriving discretized equations, and describing the physical meaning of boundary conditions.

    These tasks share common traits: clear goals, well-defined boundaries, and relatively easy verification. LLMs can significantly shorten the time from idea to prototype, but they cannot replace the final judgment of domain experts.

    The following is an illustrative AI-assisted development direction:

    1. # Illustrative pseudocode: solving a 1D steady-state heat conduction problem
    2. function solve_steady_heat_1d(...)
    3. # Initialize the mesh and temperature field
    4. # Assemble the coefficient matrix of the discretized equations
    5. # Solve the linear system
    6. # Compute the residual and check for convergence
    7. # Output the temperature distribution

    In this scenario, the model can generate the code, but decisions such as grid spacing, how to write the boundary conditions, and the convergence threshold still need to be made by a person.

    5. How to Evaluate LLMs in Professional Toolchains

    Checking whether the code can be written is not enough. More useful criteria include:

    Dimension Key Question
    Correctness Has it been validated against benchmark cases, and do the results match known solutions?
    Stability Do the results still converge after mesh refinement or time step changes?
    Maintainability Is the generated code clear, well commented, and easy to read?
    Performance Are computation time and memory usage acceptable compared with mature solutions?
    Reusability Does it run only one case, or can it extend to similar scenarios?
    Security Do inputs and outputs follow specifications, and are there hidden logic errors?

    Put simply, an LLM can help you build a car, but whether the car is fit for the road requires someone to test drive it, inspect it, and review its crash tests. In scientific computing, that inspector must be a developer who understands both the physics and the numerical methods.

    6. Practical Advice: Use AI as a Copilot

    If you plan to bring LLMs into CFD or similar professional toolchains, a layered strategy works best:

    1. Split the requirements: Do not ask the model to “write a CFD solver.” Instead, ask it to “write an explicit time-stepping code for the one-dimensional diffusion equation and output the maximum error at each step.”
    2. Develop at the component level: Have the model handle one module at a time, such as mesh generation, format definitions, or post-processing scripts.
    3. Compare with mature solutions: Have the model write wrapper scripts that call a mature solver instead of reinventing the solver itself. This uses AI while preserving reliability.
    4. Build an automated verification pipeline: After each code generation, verify the output immediately with simple test cases. If the results disagree, send the feedback to the model for revision. This creates a generate, verify, and feedback loop.
    5. Keep human review: Numerical code must be reviewed by an experienced engineer before it enters production.

    When deploying in the cloud, you can run the task scripts generated by the model on a container platform, store intermediate results in object storage, chain computation steps with a message queue, and record run status with a log service. This makes the pipeline more stable and easier to trace when problems occur.

    7. Conclusion: Stay Calm Beyond the Impressive Demo

    Writing a CFD solver on the spot does show that LLM capabilities now extend beyond business code. Models can grasp domain concepts and ass