AI for CFD Setup and Debugging: Making Tribal Knowledge Permanent

6 minute read

Published:

It’s been forever since I posted anything, and I had promised myself this would be my year for it. What happened was: work piled up, life happened, and I got completely absorbed in learning how AI could actually solve real problems we encounter in CFD. This blog post is about that last part and my experience so far with AI workflows.

Every value I've ever held is being questioned and I'm loving it

The CFD Setup Problem

Anyone who has set up an OpenFOAM case knows the pain. Unfortunately, you’re not just picking a solver and hitting run. You’re setting up dozens of dictionaries scattered across 0/, constant/, and system/. Patches need to match between boundary files and field files. Schemes have to align with your solver. Time steps depend on the mesh, the velocity, and the Courant number. Change one thing and you might silently break something three layers away.

Then there’s the versioning headache. Code written for OpenFOAM.org doesn’t necessarily work for ESI. A keyword that runs fine in one version is a fatal error in another. CFD-online or other resources gets you halfway there, but halfway in CFD often means a segfault at a random timestep that you spend days figuring out why.

Debugging is worse. When a run crashes, the cause and symptom are miles apart. That segfault at meshToMesh::update() might not have anything to do with mesh motion: it could be patch ordering in a file you haven’t looked at in weeks (which is the example I will share, wink wink). You get a 15,000-line log, a 38 MB core file, cutplane plots, checkMesh output, and the dictionaries. All of it’s raw. None of it points you at the problem.

Where AI Gets It Right

An AI can read thousands of lines without fatigue. It correlates facts across a dozen different files. It recalls every obscure bug report and forum thread from your version. And it writes throwaway scripts faster than you can open an editor.

An AI can take a crash with a cryptic stack trace and ask the right questions. What was the Courant number doing? Do the mesh instances look identical? How do the residuals look? Is the motion solver configuration valid? It can rank these by how easy they are to test and suggest which one to check first.

The key insight: AI is strong at breadth, weak at exactness. It can juggle many files and many hypotheses. However, tt cannot reliably count lines, parse version-specific syntax, or extract precise numbers from a log. So don’t ask it to.

The Fix: Code Reads, AI Thinks

The approach that works is quite simple: Write code to do the parsing, the counting, and the extraction. Let it build a digest: the Courant maxima, the solver residuals over many iterations reduced to a few lines, the boundary file diffs, the checkMesh results. Then hand the digest to the AI.

This solves three problems at once. First, the AI gets the facts it needs without hallucinating. Second, the digest is small and cheap so you’re not reprocessing the same 1 MB log every conversation turn. Third, every statement the AI makes can point back to a source: a file, a line number, a specific result. You can verify it yourself.

The pattern has three layers:

Layer 1: Automated Parsing (Scripts) Write scripts that extract, calculate, and verify facts from your logs and files. Parse the entire output, expand includes, run mesh checks, compare configurations. These scripts run once and produce exact, reproducible results. No guessing, no approximations.

Layer 2: Verification and Constraints (Rules) Build deterministic checks that validate the AI’s output. If it makes a recommendation, have a rule that checks whether that recommendation is consistent with what your scripts found. Set boundaries: read-only access, all claims must cite their source, human approval for any actual changes. This keeps the AI grounded in evidence.

Layer 3: Structured Handoff (Harness) Package the evidence from your scripts into a focused context window. Frame the problem clearly. Give the AI the digest, not the raw data. Ask a specific question. Then verify its answer against the sources you’ve already extracted. This creates a closed loop—every AI output can be traced back to a fact you verified yourself.

How This Pattern Works: A Generic Example

Here’s how the layers work together on any simulation debugging problem:

Start with the raw output: You have a crash with an unclear error message. The log is thousands of lines. You have multiple configuration files. The cause and symptom are far apart.

Run your scripts: Extract the numeric facts. Courant numbers over time. Residual trends. Solver output for each iteration. File comparisons (config, mesh, boundary definitions). Let the scripts build a small, structured summary, maybe 50 lines instead of 15,000.

Ask the AI with constraints: Hand the summary to the AI and ask it to form hypotheses. Tell it what you’ve already ruled out. Tell it what the scripts found. Ask it to rank the most likely causes by how easy they are to test, and how likely they are to match the evidence.

Check every answer: Before you run a fix or change a setting, trace the AI’s claim back to the script output. Does it cite a real number? A specific file? Can you verify it yourself? If not, ask for the source.

Turn the fix into a check: Once you’ve solved it, write a script that detects this condition. Next time someone or you hit a similar issue, the detector flags it automatically. No AI needed. That’s how tribal knowledge becomes permanent infrastructure.

Closing

Once a bug is solved and turned into a check, the next person doesn’t need an AI. The detector catches it, and the team should know the fix.

This is how tribal knowledge, the stuff that lives in someone’s head or in forum threads scattered across the internet can become permanent infrastructure.

The pattern isn’t about building perfect AI, so it thinks better than the human engineer. It’s about building the scaffolding that keeps AI honest, grounded, and useful. Scripts that extract truth. Rules that enforce boundaries. A structured handoff that lets you verify everything the AI claims.

Leave a Comment