MMS: 2D Steady-State Heat Conduction
Concept: decide the answer first
Overview
I want to verify my own heat-conduction solver, but there are no analytical solutions for complex shapes and boundary conditions. What can I do?
Make up the answer yourself — that's the method of manufactured solutions (MMS). Choose a smooth function such as T = cos(πx/3)·sin(πy) as 'the answer'. Substituting it into the conduction equation gives the source q and boundary conditions needed to produce it. Feed those to the solver, and compare the computed temperature with the chosen answer. If the error falls at the theoretical rate as the grid is refined, the code is correctly implemented.
Equation and manufactured solution
Unit square with conductivity $k = 1$. At $x = 0$, $y = 0$ and $y = 1$ the manufactured values are imposed as temperatures; at $x = 1$ the heat flux derived from the manufactured solution (a Neumann condition) is imposed. $a$ changes the solution's shape.
Order of convergence
$e_h$ is the error at grid spacing $h$. The five-point central-difference scheme is second-order, so $p$ should approach 2. Mistakes in boundary conditions or source implementation make $p$ fall below the theoretical value.
Two ways to write the boundary condition
The left form uses a ghost node outside the boundary (second order); the right uses a one-sided difference (first order). The right form is planted as a 'bug' to see whether MMS finds it.
Building the problem from the answer
The manufactured-solution idea circulated among numerical analysts from the 1980s, but Roache and colleagues systematised it as a code-verification method, spreading it through a 1998 book and early-2000s papers. Its breakthrough was removing the barrier 'no analytical solution, so no verification' by working backwards. Many commercial and research codes now publish MMS verification results, and ASME V&V 10 and 20 treat it as a central code-verification method.
Worked examples
Example 1: convergence of the correct implementation
| Divisions | Max error (a = 2) | Order | Max error (a = 3) | Order |
|---|---|---|---|---|
| 8 | 5.93×10⁻³ | — | 8.27×10⁻³ | — |
| 16 | 1.49×10⁻³ | 1.99 | 2.07×10⁻³ | 2.00 |
| 32 | 3.74×10⁻⁴ | 2.00 | 5.16×10⁻⁴ | 2.00 |
| 64 | 9.34×10⁻⁵ | 2.00 | 1.29×10⁻⁴ | 2.00 |
With either manufactured solution, error drops to a quarter with each halving — the theoretical second-order convergence.
Example 2: a boundary-condition bug
| Divisions | a = 2 (zero boundary curvature) | Order | a = 3 (non-zero boundary curvature) | Order |
|---|---|---|---|---|
| 8 | 5.97×10⁻³ | — | 5.77×10⁻³ | — |
| 16 | 1.50×10⁻³ | 2.00 | 4.13×10⁻³ | 0.48 |
| 32 | 3.74×10⁻⁴ | 2.00 | 2.39×10⁻³ | 0.79 |
| 64 | 9.35×10⁻⁵ | 2.00 | 1.28×10⁻³ | 0.90 |
With a = 2 it looks second-order even though there's a bug!
That's the MMS trap. The one-sided difference error is proportional to the second derivative (curvature) of temperature at the boundary. cos(πx/2) has exactly zero curvature at x = 1, so the bug's error vanishes and hides. With a = 3 curvature remains at the boundary, the order goes 0.48 → 0.79 → 0.90 toward 1, and the first-order bug is plain. Choose manufactured solutions so every term is non-zero and nothing takes special values at boundaries — the standard practice is somewhat 'irregular' functions mixing trigonometric, exponential and polynomial parts.
How to run MMS
Procedure
- Choose a smooth manufactured solution for which no term (diffusion, advection, nonlinear terms, boundary derivatives) vanishes.
- Derive sources and boundary conditions with symbolic software to avoid hand errors.
- Solve on three or four grid levels and compute errors and orders.
- Check the order approaches the theoretical value; if not, isolate terms and boundary conditions one at a time.
“Small error, wrong order”
An MMS run showed error below 0.1% and was declared a pass — yet the order later turned out to be 1. Error magnitude can be driven down arbitrarily by refinement, so it isn't proof of correctness; a first-order bug still shrinks with refinement, just more slowly than theory. Real problems often can't afford such fine grids, and then the bug affects results. What MMS must look at is not the size of the error but how it decreases with refinement — the order.
Common mistakes
Mistakes and fixes
| Mistake | Effect | Fix |
|---|---|---|
| Overly simple manufactured solution | Bugs hide | Exercise every term |
| Judging by error size | Low-order bugs missed | Judge by order |
| Deriving sources by hand | Derivation errors mistaken for bugs | Use symbolic derivation |
| Orders from coarse grids only | Not in the asymptotic range | Use 3–4 levels to see the trend |
| Not verifying boundary conditions | Boundary bugs remain | Test each boundary type |
I'd like to know more about MMS and convergence orders.
The overall idea is in MMS overview, order assessment in convergence-rate assessment, deriving sources in MMS source terms, code verification as a whole in code verification, and numerical-error estimation for real problems in Roache's GCI. Try order calculations with the Richardson extrapolation tool and 2D conduction with the 2D heat conduction tool.