Stability vs. Creativity in AI Coding Agents for CFD Problems

    This article examines how AI coding agents perform on computational fluid dynamics (CFD) tasks, which combine high knowledge density with strict engineering constraints. It contrasts two capability profiles—stable convergence and divergent exploration—and analyzes a common failure mode caused by inconsistent array indexing bases between Fortran and C++. The article also proposes a four-dimension evaluation framework, a reliable human-AI collaboration workflow, and practical engineering recommendations for making model selection measurable and reproducible.

    1. Background: Why Asking AI to Write CFD Code Is Hard

    Computational fluid dynamics (CFD) code is a typical “high knowledge density + high engineering constraint” task. It requires the model to understand discretization schemes, boundary conditions, time advancement, and convergence criteria, while also generating code that is completely correct at low-level details such as array layout, index bases, and memory access order.

    Recent hands-on observations show that mainstream AI coding tools are now usable for this task, but their capability profiles differ markedly. One type exhibits very high stability and instruction compliance, typically converging to a correct version within two or three rounds of interaction. The other is more divergent, often requiring seven or eight rounds to fix errors, yet producing surprisingly good results in creative tasks such as visualization.

    It is worth emphasizing that this difference is not simply a matter of “better or worse,” but a difference in applicability boundaries driven by different capability orientations. Understanding the causes is more valuable than remembering the outcome of any single comparison.

    2. Capability Profiles: Stable Convergence vs. Divergent Exploration

    2.1 Characteristics of the Stable Convergence Type

    The core strength of this profile is state consistency. The model follows system prompts and user constraints closely and rarely “drifts off course” midway, so once an error surfaces it can be quickly located and corrected. In CFD scenarios, this means the structure of modules such as mesh generation, flux computation, and pressure correction is not arbitrarily restructured, and the scope of changes during iteration remains controllable.

    The trade-off is limited flexibility. When a task calls for proactive optimization—such as choosing a more visually appealing color scheme, adding extra diagnostic curves, or adjusting the layout—the output tends to be conventional and lacks “spark.” Strictly speaking, this is a design orientation rather than a defect.

    2.2 Characteristics of the Divergent Exploration Type

    The strength of this profile lies in association and creativity. In plotting and result presentation, it can proactively offer better-looking solutions, reducing the cost of manual rework. It also has a natural tendency to “try several possibilities,” making it more likely to step outside established paths in format selection and algorithm substitution.

    The risk is weaker stability. In long-chain tasks, once an intermediate version introduces a hidden error, the model may repeatedly patch the same point over multiple rounds, and convergence efficiency drops noticeably. For engineering delivery, this volatility directly amplifies review and regression testing costs.

    3. Common Defect Analysis: Inconsistent Index Bases Across Languages

    The most typical failure mode in practice is the index-base difference between legacy Fortran implementations and C++ implementations. Fortran arrays default to starting at 1, while C/C++ starts at 0. This seemingly basic difference causes systematic offsets in loop bounds, stencil templates, and boundary-layer handling, leading to results that “run but are wrong.”

    Illustrative code:

    1. // Wrong: directly reusing 1-based loop bounds
    2. for (int i = 1; i <= nx; ++i)
    3. for (int j = 1; j <= ny; ++j)
    4. u[idx(i, j)] = ...; // out of bounds or globally offset
    5. // Correct: explicitly declare the base and manage it centrally
    6. constexpr int kBase = 0;
    7. for (int i = kBase; i < kBase + nx; ++i)
    8. for (int j = kBase; j < kBase + ny; ++j)
    9. u[idx(i, j)] = ...;

    The engineering recommendation is to consolidate the index base, dimension order, and flattening scheme into a single configuration source and declare it explicitly in the prompt, rather than relying on the model to infer it:

    1. Constraints:
    2. 1. Arrays are 0-based, flattened in row-major order, index = i*ny + j;
    3. 2. Do not modify the confirmed boundary condition function signatures;
    4. 3. Submit only one change at a time and explain the expected physical quantity affected.

    4. Evaluation Framework: How to Quantify “Usability”

    It is advisable to build a reproducible evaluation table from four dimensions rather than relying on subjective impressions:

    • Convergence rounds: the number of interaction rounds needed to meet the correctness criterion, reflecting the first-pass rate;
    • Correctness criterion: whether the L2/L∞ error against an analytical solution or an existing reference solution falls within tolerance;
    • Constraint compliance: whether interfaces, dependencies, or output formats are changed without authorization;
    • Creative gain: whether visualization and diagnostic information reduce manual effort.

    In engineering practice on platforms such as Baidu AI Cloud, these metrics can be connected to logging services and monitoring alerts, turning each session’s rounds, error types, and repair time into observable data, with versioned artifacts stored in object storage. This moves model selection from “feeling” to “measurement.”

    5. A Reliable Human-AI Collaboration Workflow

    1. Fix the contract first: define inputs and outputs, mesh scale, formats, and convergence tolerances before letting the model start;
    2. Submit in small steps: change only one thing per round to lower the cost of locating errors;
    3. Automated verification: use unit tests and conservation checks as objective gates; if physics is not conserved, the result fails;
    4. Divide the work: assign core solver logic to the stable convergence type and visualization and report presentation to the divergent type;
    5. Keep version traces: use container platforms and message queues to build a rollback-capable pipeline, avoiding “getting worse while fixing.”

    6. Conclusion

    The two capability orientations are not substitutes for each other. High stability is suited to carrying correctness-sensitive core numerical logic, while high divergence is suited to creative and presentation tasks. Real engineering gains come from making index bases, boundary conditions, and acceptance tolerances explicit, and from using automated verification to turn subjective experience into objective metrics, ultimately forming a stable, measurable, and reproducible closed loop for human-AI collaborative development.