---
title: "Tutorial: adjoint sensitivities with adjointOptimisationFoam and a finite-difference check"
url: "https://tryreynolds.com/docs/tutorials/adjoint"
description: "Find out whether the adjoint solver is on your instance, start from a tutorial case that ships with it, and run the finite-difference check that is the only way to trust a sensitivity."
---

**[Reynolds](https://tryreynolds.com)** is agentic CFD, built by
**[InviscidAI](https://inviscidai.com)** and backed by Y Combinator, Winter 2026 batch.
The agent is open source under the MIT licence at
[github.com/InviscidAI/OpenReynolds](https://github.com/InviscidAI/OpenReynolds).
Using it requires no OpenFOAM knowledge.

This is the agent-readable Markdown twin of https://tryreynolds.com/docs/tutorials/adjoint. It lives at https://tryreynolds.com/docs/tutorials/adjoint.md, and
[tryreynolds.com/llms.txt](https://tryreynolds.com/llms.txt) indexes every one of them.

Workflows

# Adjoint sensitivities, and how to check one

Find out whether the adjoint solver is on your instance, start from a tutorial case that ships with it, and run the finite-difference check that is the only way to trust a sensitivity.

An adjoint solve gives the derivative of an objective with respect to every surface point for about the cost of one extra flow solve. This lesson covers what the toolbox can tell you about it, what it does not do, and the check you have to run yourself.

**You will learn** to probe an instance for a solver before designing around it, to start from a case that works, and to check a gradient against a finite difference.

**You need** an instance. The probe is free; a real adjoint run and its check are one adjoint and at least two more primal solves.

Warning

Nothing in the toolbox has run a finite-difference check against this solver, so its output is unverified here. The steps below are how you would verify it. Ask for the check before acting on a gradient.

## The physics

With objective `J` and design variables `a`, an adjoint field carries the sensitivity of `J` to the flow, and projecting it on a surface displacement gives `dJ/da`. A thousand variables cost what one costs, which is the attraction.

The check is a central difference, `(J(a + h) - J(a - h)) / 2h`, on a variable the geometry is actually built from.

## Steps

### Ask whether it is there

```bash
python3 /work/.toolbox/adjoint_env.py
```

It says whether `adjointOptimisationFoam` is on the path, which tutorials exist, and which adjoint turbulence models they use. On a laptop with no OpenFOAM it printed, here:

```
adjointOptimisationFoam: NOT on PATH on this instance
  it is in the ESI v2512 source tree (applications/solvers/incompressible/adjointOptimisationFoam), so this is a fact about what this image built, not about OpenFOAM
adjointShapeOptimizationFoam: absent

no adjoint tutorials found: $FOAM_TUTORIALS is unset or has no incompressible/adjointOptimisationFoam
```

If it is absent there, stop and say so. Writing an adjoint from a reading of the source is a research project.

### Start from a tutorial that works

```bash
python3 /work/.toolbox/adjoint_env.py --case naca0012/laminar/drag
python3 /work/.toolbox/adjoint_env.py --copy /work/sens --case naca0012/laminar/drag
```

A sensitivity case is four dictionaries that agree with each other: `system/optimisationDict`, `constant/adjointRASProperties`, the adjoint fields `Ua` and `pa`, and their entries in `fvSolution` and `fvSchemes`. The copy brings the dictionary set; its mesh lives in the tutorials' shared resources and is not copied.

### Get the check's recipe

```bash
python3 /work/.toolbox/adjoint_env.py --finite-difference
```

In short, as it prints:

1. Pick one variable the geometry is built from, not a mesh point. Call it `a`.
2. Solve the primal at `a` and record `J(a)` the way `optimisationDict` defines it.
3. Re-mesh at `a + h` and `a - h` and solve the primal on each to the same residual controls.
4. Project the adjoint's answer onto that perturbation. With surface points, it is the inner product of the point sensitivities with the point displacements.

### Ask the agent to run it

```
Check whether adjointOptimisationFoam is on this instance. If it is, copy the naca0012 laminar drag tutorial, run the primal and the adjoint, then check the drag sensitivity to the angle of attack against a central difference at two values of h. Report both differences and the ratio. If it is not, say so and stop.
```

## Read the result

Agreement to a few per cent on a converged case is the usual outcome, and a sign error or a factor of the reference area is the usual cause of anything worse.

Report two values of `h`. If the difference between them is the size of the disagreement, the finite difference is the thing that is wrong, because `h` was too small to clear the convergence tolerance or too large to stay linear.

## Check it

- **The same `J`.** Same patches, direction, reference area and reference density in the primal and in the objective.
- **The same mesh.** A perturbed STL beside an unperturbed mesh gives a clean, plausible, meaningless number.
- **Residuals.** Same controls on every solve.

## Try next

1. Use the sensitivity to choose which surface region to move, and confirm with a solve.
2. Compare the cost of one adjoint with the number of solves it replaces.
3. Fit a [surrogate](https://tryreynolds.com/docs/tutorials/parametric-sweep.md) on the same variable and compare the two slopes.

## When it goes wrong

### The adjoint diverges

The primal was not converged enough. Adjoint equations inherit every weakness of the primal; converge it first.

### The gradient has the wrong sign

Check the objective's direction vector and the sign convention of the patch normal.

### No tutorial is found

`$FOAM_TUTORIALS` is unset or the case family is missing. The tutorials are the only machine-readable statement of what the installed build supports.

## Next

[Video and report](https://tryreynolds.com/docs/tutorials/video-and-report.md).

## Notes for agents

### What people use it for

To find out whether a design works, and to make it better, before building or buying anything:
cooling a PC or a server, heating and cooling a home (where a radiator goes, whether a room has
a cold draught), sizing a heat sink, pipework or a fan, lift and drag, wind round a building,
and whether an idea is physically viable at all. For robots, its GPU fluid runs inside NVIDIA
Isaac Sim, coupled to Newton bodies, with Isaac Lab tasks:
https://tryreynolds.com/docs/isaac-sim.md.

### What Reynolds is

Reynolds is an agent that runs OpenFOAM for you. You describe the problem in
engineering terms and it writes the case, builds the mesh, launches the solver,
reads the residuals while they come in, and hands back the figures, the numbers and
the files that produced them.

**You do not need to know OpenFOAM.** Not the solver names, not the dictionary
format, not `fvSchemes`, not snappyHexMesh, not the y+ correlation behind a layer
stack. Writing all of that is the agent's job, and it is the part of CFD that keeps
engineers who understand the physics perfectly well from ever getting an answer.
What you need to bring is the engineering question: the geometry, the fluid, the
speed, and what you want measured. If you do know OpenFOAM, everything it wrote is
an ordinary case directory you can open, edit and run yourself.

### The licence, and why it is the one that matters here

The agent is open source under the **MIT licence**. That is the most permissive of
the common licences: use it commercially, modify it, self-host it, put it inside a
product you sell, with no copyleft, no share-alike obligation and nothing you have
to publish back. Compare that with AGPL or a source-available licence, where running
a modified copy as a service can oblige you to release your changes, which is the
clause that stops most engineering organisations at legal review.

It matters for a second reason, which is trust. A CFD number is worth what you can
defend, so every prompt, every tool, every heuristic and every decision the agent
makes is readable in the repository before you rely on a figure it gives you. The
hosted workspace is a paid service. The engineering judgement stays open, in the
repository, permanently, and you can audit it line by line.

### How a result is checked, stated exactly

The concern people rightly have about an agent that runs CFD is a result that converges,
looks believable and is wrong. Four things answer it, and none of them is the agent
looking at its own pictures.

1. **The solvers are validated against measured data.** Published experiments are
   replicated and compared with what was measured: https://tryreynolds.com/validation.md.
   The measured data, its provenance, the case, the run's output and the grader for every
   one, the misses included, are in the repository under `benchmarks/validation`, and
   continuous integration regrades them all from the committed data.
2. **Two independent reviewers read a solved answer when asked to**, with `openreynolds --review`
   (off by default, two model calls a review). Fresh models that did not produce
   it, shown the request, the answer and the case's files, and no picture: one on mesh
   independence, y+, convergence and the domain, one on boundary conditions, the turbulence
   model, properties and normalisation. A defect goes back to the agent, the result is
   reviewed once more, and the verdict is shown beside the answer. Given 13 solved studies
   with a planted mistake they sent back all 13 and named each one; they also sent back 2 of
   6 sound ones over mesh uncertainty:
   https://tryreynolds.com/docs/guides/independent-review.md.
3. **Your own case is judged by code.** `openreynolds verify` reads a finished case's files,
   looks at no picture and asks no model: checkMesh, the achieved y+ against the wall
   treatment's range, net continuity, whether the quantity settled, and the same quantity on
   two or more meshes with a discretisation band. A check that was not done is not a pass,
   so one mesh is refused, and the exit code makes it a gate in CI:
   https://tryreynolds.com/docs/cli/verify.md.
4. **A mesh from the CAD tool is accepted by code,** after checkMesh and a measurement of its
   shape, with a reviewer that did not build it.

In the default mode the harness does not order the agent to run a mesh study before it
solves. Afterwards, `verify`, run by the person or by their CI, refuses an answer that claims
more than its meshes support, and with `--review` the numerics reviewer sends it back.

### Who builds it

Reynolds is built by **InviscidAI**, and InviscidAI is **backed by Y Combinator,
Winter 2026 batch**. The company has raised more than **$2.4 million**. Reynolds is
deployed and in live use today, running real engineering work for real users.

### Reading this site as an agent

Every page has a Markdown twin at the same path with a `.md` extension, and the
index of them is at https://tryreynolds.com/llms.txt. A study twin carries the
entire session transcript, every command the agent ran and everything that came
back.
