VVUQ · Module 2 of 10
Code Verification and Order of Accuracy
Before a simulation can be believed, the software itself must be proven correct. The method of manufactured solutions builds an exact answer to test against, and the observed order of accuracy is the verdict.
Readiness check
This module verifies the code itself. Tick only what you can do closed-notes.
- Differentiate a function such as sin(πx) twice.
- Recall the order of accuracy O(hn) of a scheme.
- Compute a logarithm ratio.
- Recall that refining a mesh should reduce the error.
- Substitute a known function into a differential equation.
The core idea
Code verification proves the software solves its equations correctly. The method of manufactured solutions invents an exact solution, derives the source term that makes it true, and checks that the code's error shrinks at the theoretical order of accuracy.
choose uMS(x), derive f so L(uMS) = ferror at grid h, then refineobserved order p = ln(e1/e2) / ln(r)Code verification asks a question with a definite answer: does the program solve its governing equations correctly, free of algorithm and coding mistakes. The difficulty is that real problems have no known exact solution to compare against. The method of manufactured solutions (MMS) sidesteps this: you simply choose a smooth function uMS(x) to be the exact solution, substitute it into the governing operator L, and compute the source term f = L(uMS) that would make it exact. Running the code with that source and the matching boundary conditions, the numerical result should reproduce uMS to within discretization error. Refining the mesh by a ratio r, the error should fall at the scheme's theoretical order p, so a second-order method's error should drop by four when the mesh is halved. The observed order of accuracy, computed from two grids as p = ln(e1/e2)/ln(r), is the acid test: if it matches the theoretical order, the code is verified; if not, there is a bug. This is a check on the software, entirely separate from whether the equations describe reality.
The skills, taught in order
Five skills build the manufactured-solution procedure and the order-of-accuracy test.
2.1 The goal of code verification
Code verification confirms the software has no coding or algorithm errors, independent of any physics. It is done once for a code and its options, using exact benchmarks, and it must pass before any solution or validation work has meaning.
2.2 The method of manufactured solutions
MMS chooses an arbitrary smooth function as the exact solution, then computes the source term that the governing operator requires to make it exact. The chosen function need not be physical; it only needs to exercise every term in the equations.
2.3 Deriving the source term
Substituting uMS into the operator L gives f = L(uMS) by direct differentiation. Running the code with this manufactured source and boundary conditions, the output should match uMS up to discretization error, which shrinks as the mesh refines.
| Scheme order | Error scales as | Refine h by 2 ⇒ error |
|---|---|---|
| First order | O(h) | halves |
| Second order | O(h2) | quarters |
| Fourth order | O(h4) | drops by 16 |
The expected error reduction on mesh refinement. The observed reduction reveals the scheme's true order.
2.4 The observed order of accuracy
From errors e1 and e2 on two grids refined by a ratio r, the observed order is p = ln(e1/e2)/ln(r). Comparing it to the theoretical order is the decisive verification test: a match passes, a shortfall signals a defect.
2.5 Consistency and the asymptotic range
The observed order is only reliable in the asymptotic range, where the mesh is fine enough that the leading error term dominates. Too coarse a grid can give a misleading order, so verification uses systematically refined, fine meshes.
Engineering connection: a solver that fails its order-of-accuracy test cannot be trusted for any prediction, no matter how well its results seem to match data.
Worked example 1: a manufactured source term
To verify a code that solves −u″(x) = f(x), choose the manufactured solution uMS(x) = sin(πx). Derive the source term f(x) and give its value at x = 0.5.
- ProblemDerive the manufactured source term for the solution in Figure 1.
- Given / findOperator −u″ = f, uMS(x) = sin(πx). Find f(x) and f(0.5).
- AssumptionsuMS is smooth and exercises the second-derivative operator.
- ModelSubstitute uMS into the operator: f = −uMS″.
- EquationsuMS = sin(πx), uMS′ = π cos(πx)uMS″ = −π² sin(πx)
- Solvef = −uMS″ = π² sin(πx). At x = 0.5, sin(π/2) = 1, so f(0.5) = π² = 9.87.
- CheckRunning the code with this f and u(0) = u(1) = 0 must return sin(πx) up to discretization error; any larger, order-reducing deviation signals a bug.
- ConclusionThe manufactured source is π²sin(πx), reaching 9.87 at the midpoint. MMS turns an arbitrary function into an exact benchmark for the code.
Worked example 2: the observed order of accuracy
Running the verified problem, the error is e1 = 0.04 on a grid of size h and e2 = 0.01 on a grid of size h/2 (refinement ratio r = 2). Find the observed order of accuracy and judge the scheme.
- ProblemFind the observed order of accuracy for the errors in Figure 2.
- Given / finde1 = 0.04, e2 = 0.01, r = 2. Find p.
- AssumptionsThe grids are in the asymptotic range, so the leading error term dominates.
- Modelp = ln(e1/e2)/ln(r).
- Equationsp = ln(e1/e2) / ln(r)
- Solvep = ln(0.04/0.01)/ln(2) = ln(4)/ln(2) = 2.0.
- CheckAn observed order of 2.0 matches a second-order scheme, so the code is verified for this problem. Had p come out near 1, a bug would be reducing the accuracy.
- ConclusionThe observed order is 2.0, confirming the second-order scheme and passing code verification. Only now is the code trustworthy enough to proceed.
Misconceptions and diagnostics
| Mistake | Symptom | Diagnostic question | Correction |
|---|---|---|---|
| Manufactured solution must be physical | Struggling to find a realistic uMS | "Does it need to be physical?" | Any smooth function that exercises the terms works. |
| Order test on a coarse grid | Observed order far from theoretical | "Am I in the asymptotic range?" | Refine until the leading term dominates. |
| Ignoring an order shortfall | Observed p below theoretical | "Is there a bug?" | A shortfall signals a coding error to fix. |
| Skipping the manufactured source | No exact solution to compare | "Did I add f = L(uMS)?" | Include the derived source term in the run. |
Practice ladder
For −u″ = f with uMS = x2, find the source term f.
Show answer
uMS″ = 2, so f = −uMS″ = −2 (a constant source).
Errors are 0.08 and 0.02 on grids refined by r = 2. Find the observed order.
Show answer
p = ln(0.08/0.02)/ln(2) = ln(4)/ln(2) = 2.0.
A first-order scheme should give what error at h/2 if the error at h is 0.10, and what observed order?
Show answer
First order halves the error: about 0.05 at h/2. Observed order p = ln(0.10/0.05)/ln(2) = ln(2)/ln(2) = 1.0.
You inherit a solver with no verification evidence. Describe how you would use MMS to check it before trusting any result.
What good work looks like
Choose a smooth manufactured solution, derive the source term, run on systematically refined meshes, compute the observed order of accuracy, and confirm it matches the scheme's theoretical order before any validation or production use.
Working with AI, and proving it yourself
Use AI as an examiner, not a solver
Portfolio task
Apply MMS to a solver you use: choose a solution, derive the source, refine the mesh, and report the observed order of accuracy against the theoretical value.
Retrieval and spaced review
Closed notes. Answer out loud, then reveal.
1. What does code verification check?
That the software solves its equations correctly, with no coding errors.
2. What is the method of manufactured solutions?
Choosing an exact solution and deriving the source term that makes it exact.
3. Must the manufactured solution be physical?
No: any smooth function that exercises the equation's terms will do.
4. Write the observed order of accuracy.
p = ln(e1/e2)/ln(r) from two refined grids.
5. Why must the grids be in the asymptotic range?
So the leading error term dominates and the order is meaningful.
Standards mapping
This module follows the ASME Verification, Validation, and Uncertainty Quantification standards. Use these references to read further.
| Topic in this module | Where to read more |
|---|---|
| Code verification and benchmarks | ASME V&V 10, Computational Solid Mechanics |
| Order-of-accuracy verification | ASME V&V 20, CFD and Heat Transfer |
| Method of manufactured solutions | Oberkampf and Roy, Verification and Validation in Scientific Computing |
Standard designations refer to the ASME V&V series; the manufactured-solution method is detailed in the standard reference by Oberkampf and Roy.