Method of Manufactured Solutions (MMS) — Overview and Procedure
Theory: choose the solution first
Overview
I want to verify my own thermal code, but there's no exact solution for conductivity that varies with temperature. What can I do?
Use the Method of Manufactured Solutions. Flip the approach: decide the solution you want first. Substituting it into the equation leaves a mismatch between the two sides; add that as a source term, and your chosen solution becomes exactly the solution of the modified equation. Then solve with that source in your code and check, as the grid is refined, whether error falls at the scheme's theoretical rate. The key is judging by how error decreases, not by whether the solution looks right.
The example equation
A nonlinear diffusion equation whose conductivity depends on the solution. The manufactured solution is smooth and equals 0 and 1 at the ends.
Source term and convergence order
Derive the source symbolically (e.g. with sympy) to avoid hand-algebra slips. The observed order follows from the error ratio when spacing is halved.
The reversal: manufacture the solution
Problems with analytical solutions are few and rarely cover the nonlinear, multidimensional, complex-boundary equations real software handles. In the 1980s Steinberg and Roache showed how to choose the solution first and fit the equation with a source term, and in the 2000s Roache, Salari, Knupp and others set it out as a standard procedure for code verification. It is now widely used to verify fluid codes including turbulence models, as well as solid, thermal and electromagnetic software, and ASME verification standards treat it as a central code-verification method.
Worked example: catching a small bug
With finite differences, a correct implementation evaluating face conductivity at the average of neighbouring values was compared with a faulty one using only the left value (a one-character difference). Solved by Picard iteration; maximum nodal error:
| Cells | Correct error | Order | Faulty error | Order |
|---|---|---|---|---|
| 10 | 1.13×10⁻² | — | 4.62×10⁻² | — |
| 20 | 2.85×10⁻³ | 1.98 | 2.13×10⁻² | 1.11 |
| 40 | 7.10×10⁻⁴ | 2.00 | 1.04×10⁻² | 1.03 |
| 80 | 1.78×10⁻⁴ | 2.00 | 5.15×10⁻³ | 1.02 |
| 160 | 4.44×10⁻⁵ | 2.00 | 2.56×10⁻³ | 1.01 |
Even the faulty version has only about 1% error and it shrinks with refinement. I'd never notice.
That's MMS's strength. Judged by error size alone, the faulty version seems roughly right and improving with refinement — on a plot it would almost overlap the manufactured solution. But the rate differs clearly: second order for the correct version, first for the faulty one. Evaluating the face coefficient one-sidedly injected first-order error into a nominally second-order scheme. In real problems that difference persists as a few percent of error even on fine grids. MMS brings invisible errors to the surface as a number: the order.
Procedure and tips
- Choose a manufactured solution that exercises every term (convection, diffusion, source, nonlinear coefficients); overly simple solutions hide errors.
- Derive source and boundary conditions symbolically and export them to code automatically.
- Solve on four or more grids and compute error norms and orders.
- Vary boundary conditions, grid types and nonlinear-iteration settings, checking each.
- Turn results into automated tests that check the order on every code change.
“First order only at the boundary”
Verifying a fluid code with MMS, interior error fell at second order, yet the overall maximum error fell only at first. The error map showed large error only at points next to walls — the boundary condition was implemented to first order, approximating the wall gradient with a one-sided difference. Switching to a second-order one-sided difference made the whole solution second order. Looking at the error distribution, not just its size, pinpoints where errors live.
Common mistakes
Mistakes and fixes
| Mistake | Effect | Fix |
|---|---|---|
| Judging by error size alone | Order drop missed | Always compute order |
| Overly simple solution | Terms inactive, errors hidden | Exercise all terms |
| Hand-derived source | Errors in the source itself | Automate symbolically |
| Insufficient iteration convergence | Erratic order | Tight tolerance |
| Judging from two grids | Asymptotic range unknown | Four or more levels |
I'd like to learn related topics.
Try convergence order with the Richardson extrapolation tool. Related pages include MMS convergence rates, MMS source terms, 2D heat conduction MMS, Navier–Stokes MMS and code verification.
Related Topics
Experience the theory firsthand with the interactive simulator for this field
All Simulators