Computing Library › Verification Validation
Verification Validation

The Method of Manufactured Solutions

Choose an exact solution first, substitute it into the equations to derive a source term, then check that the code recovers the solution you picked.

The Trick

Most useful partial differential equations have no closed-form solutions, which seems to block exact verification. The method of manufactured solutions (MMS) inverts the problem. Instead of solving the equation to find a solution, you choose a smooth analytic function, insert it into the governing operator, and analytically compute whatever source term makes that function an exact solution. Add that source to the code and the chosen function becomes ground truth.

A Worked Sketch

Kronos motion — materials first

Suppose the code solves the steady heat equation, a temperature Laplacian equals a source. Pick a manufactured field such as a product of sines. Apply the Laplacian by hand (or with a symbolic tool) to get the required source. Feed the code that source and the same boundary values the chosen field implies. The exact error at every grid point is then known: it is the code output minus the chosen field.

python
import sympy as sp
x, y = sp.symbols('x y')
T = sp.sin(sp.pi*x)*sp.sin(sp.pi*y)   # chosen exact solution
source = -(sp.diff(T,x,2) + sp.diff(T,y,2))  # required source term
print(sp.simplify(source))            # feed this into the solver

Why It Is Powerful

Cautions

Choose solutions that are smooth and non-trivial. A field that is linear or constant will silently skip terms and hide bugs; a good manufactured solution has non-zero derivatives of every order the scheme touches, and does not accidentally satisfy the homogeneous equation. The boundary conditions must be applied consistently with the chosen field. MMS verifies the discretization and its implementation; it says nothing about whether the equation matches physics.

MMS is the workhorse of code verification precisely because it converts an intractable check into an arithmetic one.