MMS Convergence Rate Calculation
Theory: reading order from error ratios
Overview
After computing MMS errors, how is the order calculated? Is it just a division?
The formula is simple, but there are traps: mixing up the grid ratio, refining into the round-off floor, computing in single precision, non-smooth solutions, and lower-order formulas at boundaries — all push the order away from theory. To tell them apart from real bugs, know how each one looks. Let's check them one by one with second-order central differences for 1D Poisson.
Observed order
$e_1, e_2$ are coarse- and fine-grid errors and $r$ the spacing ratio; only for $r = 2$ can it be written $\log_2(e_1/e_2)$.
The round-off floor
Second-derivative differences divide by $h^2$, so round-off grows as $h$ shrinks. Beyond the grid where discretisation and round-off errors sum to a minimum, error rises again.
Round-off and grid fineness
That shrinking the step in numerical differentiation eventually loses accuracy to round-off has been known since the earliest computers. Floating-point representation was standardised as IEEE 754 in 1985, giving about 16 significant digits in double and 7 in single precision. With GPUs, single and half precision are back in use, and the problem of refinement no longer improving accuracy is once again a practical concern.
Worked example: 1D Poisson
−u″ = f with manufactured u = sin(πx) + x³, second-order central differences, Dirichlet at both ends; max-norm error.
Double and single precision
| Cells | Double-precision error | Order | Cells | Single-precision error | Order |
|---|---|---|---|---|---|
| 100 | 8.23e-5 | 2.00 | 30 | 9.14e-4 | 2.00 |
| 1,000 | 8.22e-7 | 2.00 | 100 | 8.27e-5 | 2.00 |
| 10,000 | 8.24e-9 | 2.00 | 300 | 3.03e-5 | 0.91 |
| 100,000 | 3.26e-10 | 1.40 | 1,000 | 4.01e-4 | −2.15 |
| 1,000,000 | 6.85e-7 | −3.32 | 3,000 | 2.90e-3 | −1.80 |
Other pitfalls
| Situation | Observed order | Expected |
|---|---|---|
| Solution x^1.5 (max norm, 512 cells) | 1.44 | 2 (for smooth solutions) |
| Solution x^1.5 (L2 norm, 512 cells) | 1.47 | 2 |
| Ratio 1.5 computed with log₂ | 1.17 | 2.00 |
| Neumann end, one-sided (1st order) | 0.99 | 2 |
| Neumann end, ghost node (2nd order) | 2.00 | 2 |
Even in double precision, error grows at a million cells. So finer isn't always better.
Second-derivative differences divide tiny differences of neighbouring values by h². As h shrinks, those differences approach round-off size and the division magnifies them. Double precision hits the floor around 100,000 cells; single precision breaks at just 300. When checking order with MMS, use only the range where orders line up at the theoretical value and discard points on the floor. Equally important is diagnosing a drop: a non-smooth solution settles at an in-between value like 1.44, a first-order boundary formula drops the order cleanly to 1, and round-off makes it collapse abruptly and go negative. These signatures help tell bugs from everything else.
Procedure for computing order
- Build four or more grids at a constant ratio and record r.
- Compute order for each adjacent pair with p = ln(e₁/e₂)/ln r and tabulate.
- Use the range where orders line up at theory as the asymptotic range.
- If error rises on fine grids, suspect the round-off floor and confirm with higher precision.
- Use smooth manufactured solutions and check boundary-condition order too.
“Moving to GPU broke the order”
A team switched a heat-conduction code to single precision to speed it up on GPU, and MMS verification showed negative orders on fine grids. They spent days hunting a porting bug, but the cause was single-precision round-off; in double precision orders lined up at 2.00. Keeping the main computation in single precision but doing residuals and some summations in double kept the speed and delivered the needed accuracy.
Common mistakes
Mistakes and fixes
| Mistake | Effect | Fix |
|---|---|---|
| log₂ with ratio ≠ 2 | Wrong order | Divide by ln r |
| Over-refining | Round-off floor | Use asymptotic range only |
| Verifying in single precision | Early breakdown | Confirm in double |
| Non-smooth manufactured solution | In-between orders | Smooth functions |
| Ignoring boundary-formula order | Overall first order | Match boundary order |
I'd like to learn related topics.
Related pages include MMS overview, MMS: 2D elasticity, MMS: 2D heat conduction, code verification and Richardson extrapolation.