Mayank Deshpande / All posts

PDEpilot: Natural Language to Verified Solver Code

By Mayank Deshpande ·

PDEpilot hero artwork — computational fluid dynamics visualisation

What if you could describe a physical problem in plain English and have an AI system automatically write, configure, and verify production-grade solver code for it? That is the premise behind PDEpilot -- a fully autonomous multi-agent application I built that transforms natural language PDE descriptions into verified classical solver code.

Built on Google ADK (Agent Development Kit) and powered by Gemini 2.5 Pro, PDEpilot routes problems to the optimal computational backend -- OpenFOAM, FEniCSx, or SciPy -- configures numerical solvers with intelligent preconditioning, generates complete executable code, and iteratively refines until quality thresholds are met. Zero manual coding required.

CFD mesh visualization showing structured grid around a cylinder
CFD mesh visualization showing structured grid around a cylinder
Computational mesh for flow around a cylinder -- the kind of problem PDEpilot solves autonomously.

From PINNs to Classical Solvers

In previous articles, I explored Physics-Informed Neural Networks and the Lang-PINN framework -- systems that use neural networks to approximate PDE solutions. PINNs are powerful for certain problems, but classical numerical methods (Finite Volume, Finite Element, Finite Difference) remain the gold standard for production CFD and structural analysis.

The bottleneck is not the math. It is the engineering: choosing the right solver, configuring mesh resolution, selecting preconditioners, writing syntactically correct case files, and debugging convergence failures. A single OpenFOAM case requires coordinating 9+ configuration files. A FEniCSx simulation needs careful PETSc solver/preconditioner pairing.

The Solver Gap

Different PDE families need different backends. Navier-Stokes demands OpenFOAM's pressure-velocity coupling; elliptic PDEs suit FEniCSx's finite elements. Manually choosing is error-prone.

The Configuration Gap

Each backend has its own configuration language. OpenFOAM uses dictionary files; FEniCSx uses PETSc options; SciPy uses sparse matrix APIs. Getting any of them wrong means silent divergence.

The Debugging Gap

When a solver diverges, interpreting residual logs, continuity errors, or CFL violations requires deep domain expertise. Most users give up before finding the fix.

The Five-Agent Pipeline

PDEpilot is a SequentialAgent orchestrating five stages. Each agent reads from a shared state, processes its task with specialized tools, and writes structured output (Pydantic schemas) for the next agent.

pde_roadmap_orchestrator (SequentialAgent)
├── [1] pde_parser_agent        → NL → canonical PDE (multi-CoT + consensus)
├── [2] solver_strategy_agent   → PDE → backend + solver method
├── [3] preconditioner_agent    → solver → optimal preconditioner config
├── [4] code_generator_agent    → all → executable solver code
└── [5] feedback_loop (LoopAgent)
    ├── execution_agent         → runs code in isolated sandbox
    └── evaluator_agent         → quality scoring + accept/refine
1. PDE Parser Agent: The Translator

The first agent converts a natural language problem description into a canonical mathematical form. It uses Multi-CoT Sampling -- generating three independent Chain-of-Thought reasoning paths, each producing a candidate PDE.

  • Symbolic Equivalence: Uses SymPy AST comparison to check if candidates are mathematically identical.
  • Semantic Similarity: Bag-of-words cosine similarity against the original description.
  • Consensus Voting: Weighted combination (60% symbolic, 40% semantic) selects the best candidate.
S(Ei, Ej) = α · sym(Ei, Ej) + (1 - α) · sem(Ei, Ej)

Output: a PDEDefinition containing the SymPy expression, domain, boundary conditions, initial conditions, and PDE family classification.

2. Solver Strategy Agent: The Router

This agent analyzes the parsed PDE's properties -- linearity, dimensionality, convection dominance, stiffness -- and routes it to the optimal backend.

  • Navier-Stokes, turbulence, multiphase → OpenFOAM (simpleFoam, pisoFoam, pimpleFoam)
  • Poisson, heat, wave, elasticity → FEniCSx (CG/DG FEM + PETSc KSP)
  • Simple 1D/2D, educational → SciPy/NumPy (FDM, Crank-Nicolson, upwind)

It also selects mesh resolution, time-stepping scheme, element type, and turbulence model -- all encoded into a SolverStrategy schema.

3. Preconditioner Agent: The Optimizer

Preconditioner selection can make or break solver convergence. This agent estimates the degrees of freedom (DOF) and selects optimal solver/preconditioner pairs from a curated database.

Why does this matter? A wrong preconditioner can turn a 30-second solve into a divergent mess. For example, using CG on an indefinite Helmholtz system will fail -- you need FGMRES with ILU. PDEpilot encodes these rules automatically.

For OpenFOAM, it generates a complete fvSolution dictionary. For FEniCSx, it produces PETSc KSP/PC options. For SciPy, it decides between direct (spsolve) and iterative (CG/GMRES + ILU).

4. Code Generator Agent: The Engineer

Synthesizes complete, backend-specific executable code using modular generation. Each backend gets a different set of outputs:

  • OpenFOAM: 9 files -- blockMeshDict, controlDict, fvSchemes, fvSolution, boundary files (0/p, 0/U), transport properties, turbulence properties, and an Allrun script.
  • FEniCSx: 4 Python modules -- problem.py (mesh/FEM), solver.py (KSP solve), postprocess.py (visualization), run.py.
  • SciPy: 4 Python modules -- discretize.py (grid/matrix), solve.py (sparse solve), plot.py, run.py.

Each module is validated independently -- OpenFOAM dictionary syntax, Python import availability, stability conditions -- before assembly.

5. Feedback Loop: The QA Inspector

A LoopAgent containing two sub-agents that run iteratively until quality is satisfied (up to 5 iterations):

  • Execution Agent: Runs the generated code in an isolated sandbox with timeout. For OpenFOAM: creates a case directory, runs blockMesh, then the solver. For FEniCSx/SciPy: writes and executes Python scripts.
  • Evaluator Agent: Computes a backend-specific composite quality score (0--1) and decides accept or refine.

If the score falls below 0.7, the evaluator writes targeted feedback (e.g., "High residuals on field p. Switch to GAMG with GaussSeidel.") and the Code Generator refines only the failing module.

Three Solver Backends, One Pipeline

PDEpilot does not force every problem through the same solver. It matches the PDE to the backend that handles it best.

OpenFOAM

Finite Volume Method

  • Navier-Stokes (incompressible & compressible)
  • SIMPLE / PISO / PIMPLE algorithms
  • RANS / LES turbulence models
  • Multiphase flows
simpleFoam, pisoFoam, pimpleFoam

FEniCSx

Finite Element Method

  • Poisson, Heat, Wave, Helmholtz
  • Linear elasticity
  • CG/DG elements with PETSc KSP
  • Complex geometries, high-order
AMG, GMRES, FieldSplit (Schur)

SciPy / NumPy

Finite Difference Method

  • 1D/2D educational problems
  • Prototyping and visualization
  • Crank-Nicolson, upwind schemes
  • Minimal dependencies
spsolve, CG + ILU(0)

The Toy Backend, Running in Your Browser

The SciPy card above says "1D/2D educational problems" — so here is one. This is the heat equation solved with exactly the kind of explicit finite-difference scheme the FDM backend generates, running live. Draw some heat, pick a "prompt", and watch it diffuse.

Live demo · The toy FDM backend96×160 grid · explicit FTCS

Backend-Specific Quality Scoring

Each backend has a different definition of "good enough." The evaluator agent computes a composite score tailored to each:

OpenFOAM
Residual convergence0.35
Continuity error0.25
Stability (CFL)0.20
Physical plausibility0.20
FEniCSx
Accuracy (L2 error)0.45
Solver performance0.30
Solution health0.25
SciPy
Accuracy (rel. error)0.50
Convergence0.25
Solution health0.25

Example: Lid-Driven Cavity

Here is how PDEpilot handles a classic CFD benchmark from a single sentence:

"Solve the 2D lid-driven cavity problem for incompressible flow at Reynolds number 100. Domain is a 1x1 square. Top wall moves at u=1 m/s, other walls are no-slip."
1

PDE Parser

Recognizes incompressible Navier-Stokes. Extracts continuity + momentum equations, domain [0,1]x[0,1], boundary conditions. Classifies as navier_stokes.

2

Solver Strategy

Routes to OpenFOAM with simpleFoam (steady SIMPLE algorithm). Sets mesh to 32x32, turbulence model to laminar (Re=100).

3

Preconditioner

DOF ~ 1024 (small mesh). Selects pressure: PCG + DIC, velocity: PBiCGStab + DILU. Generates complete fvSolution.

4

Code Generator

Produces 9 OpenFOAM case files: blockMeshDict, controlDict, fvSchemes, fvSolution, 0/p, 0/U, transport properties, turbulence properties, Allrun.

5

Feedback Loop

Runs blockMesh → simpleFoam. Parses log: final residuals p=1e-6, Ux=1e-7, Uy=1e-7. Continuity error=1e-9. Quality score = 0.92. Accepted on first iteration.

Key Advantages

5
Specialized Agents

Parse, Route, Precondition, Generate, Verify

3
Solver Backends

OpenFOAM, FEniCSx, SciPy

100%
Self-Correcting

Autonomous feedback loops with targeted refinement

0
Manual Coding

From natural language to verified solver output

Technology Stack

Orchestration & Models
  • Google ADK: SequentialAgent, LoopAgent, LlmAgent, FunctionTool
  • Gemini 2.5 Pro: LLM backbone for all agent reasoning
  • Pydantic: Type-safe state schemas for deterministic inter-agent handoffs
Specialized Tools
  • SymPy: PDE parsing, symbolic equivalence checking, AST validation
  • OpenFOAM tools: Case creation, dictionary validation, log parsing, case execution
  • PETSc options: KSP/PC configuration generation for FEniCSx
  • Sandbox executor: Isolated subprocess execution with timeout for all backends
  • Debug tools: Import checking, PyPI search, URL content fetching

Why This Matters

PDEpilot represents a step toward making production-grade numerical simulation accessible to anyone who can describe a physical problem in words. By combining multi-agent orchestration, intelligent backend routing, and self-correcting feedback loops, it removes the engineering barrier between a scientist's intuition and a working simulation.

This is not a replacement for domain expertise -- it is a force multiplier. The preconditioner databases, solver rankings, and quality heuristics encode decades of computational physics knowledge into a system that can be iterated on, extended, and improved. The goal is not to eliminate the expert, but to let the expert skip the boilerplate and focus on the physics.

References & Links

Project Repository

View PDEpilot on GitHub

Foundational Paper

Lang-PINN on arXiv
Related Reading
  • Maziar Raissi et al. Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations. Journal of Computational Physics, 2019.
  • George Em Karniadakis et al. Physics-informed machine learning. Nature Reviews Physics, 2021.
  • Zhongkai Hao et al. PINNacle: A comprehensive benchmark of physics-informed neural networks for solving PDEs. arXiv:2306.08827, 2023.
  • OpenFOAM Foundation. OpenFOAM: The Open Source CFD Toolbox. User Guide, 2024.
  • FEniCS Project. The FEniCSx computing platform for solving partial differential equations. Documentation, 2024.
  • Satish Balay et al. PETSc: Portable, Extensible Toolkit for Scientific Computation. Argonne National Laboratory, 2024.
  • Google ADK. Agent Development Kit: Build, deploy, and orchestrate AI agents. Documentation, 2025.
Thank You!