Computing Library › Numerical Methods
Numerical Methods

Verification and Order of Convergence

Confirming that a code solves its equations correctly by measuring how fast the error shrinks under mesh refinement.

Verification versus validation

Two distinct questions face any simulation. Verification asks whether the code correctly solves the equations it claims to solve, a mathematical question about the implementation. Validation asks whether those equations describe reality, a physical question answered against experiment. This page concerns verification: catching bugs and confirming that the discretization behaves as the theory predicts before trusting any result.

Observed order of convergence

Kronos motion — fast proton

Every discretization has a theoretical order: the error should decrease as a known power of the mesh spacing or time step. To verify, one runs the code on a sequence of progressively finer meshes and measures how fast the error actually falls. Fitting the error against the spacing gives the observed order of convergence, which should match the theoretical order. A mismatch signals a bug, an inconsistent boundary treatment, or a loss of smoothness.

python
import numpy as np

def observed_order(errors, h):
    # errors and h are arrays for successively refined runs
    p = np.log(np.array(errors[:-1]) / np.array(errors[1:]))
    p /= np.log(np.array(h[:-1]) / np.array(h[1:]))
    return p  # should approach the theoretical order

The method of manufactured solutions

Real problems rarely have exact solutions to compare against. The method of manufactured solutions solves this: choose an arbitrary smooth function, substitute it into the governing equation to compute the source term it would require, then run the code with that source and boundary data. The known function is now the exact solution, so the error is exactly measurable and the observed order can be checked rigorously anywhere in the code.

Why it matters

Order verification is the most powerful routine test in scientific computing: a code that converges at the wrong rate has a defect, however plausible its output looks. It complements the ideas of error estimation and Richardson extrapolation, which use the same convergence structure to estimate error at runtime. For fusion simulations underpinning design decisions, documented verification is the foundation of credibility, ensuring the numerics are sound before physical conclusions are drawn.