The Method of Manufactured Solutions
Source: PHY653B Ch. 1
Intuition
Verification needs an exact solution to measure error against — but most interesting equations have none. The method of manufactured solutions (MMS) escapes this by choosing the answer first and then working out what equation it solves.
The trick
You want to verify a solver for \(\mathcal{L}[u] = 0\).
- Invent a solution \(u_M(x,t)\). It does not need to be physical. It needs to be smooth, non-trivial, and to exercise every term — something like \(u_M = \sin(2\pi x)\cos(3\pi t) + \tfrac12 x^2\).
- Substitute it into the operator. It will not satisfy the equation; call the residual \(S = \mathcal{L}[u_M]\). Compute \(S\) symbolically (SymPy, once).
- Solve the modified problem \(\mathcal{L}[u] = S\) with your code, using \(u_M\) for initial and boundary conditions.
- Compare the computed \(u\) against \(u_M\), which is now an exact solution by construction. Refine and extract the observed order of accuracy.
The physics is irrelevant. That is the feature: MMS tests the implementation, cleanly separated from any question about whether the model is right.
Why it catches what nothing else does
Ordinary benchmarks are usually simple — a steady state, a symmetric configuration, a single wave. Bugs hide in the terms those cases do not activate: a cross-derivative that vanishes in 1-D, a boundary stencil that is only wrong at a corner, a source term dropped when the solution is time-independent. A manufactured solution deliberately makes every term non-zero, so every term gets checked.
What a 2% bug looks like
This is the part worth remembering. Suppose a coefficient is wrong by 2% somewhere. Run the code and the answer looks... fine. Plots are smooth, conservation is clean, and it agrees with your intuition to the precision your intuition has. You would ship it.
Now run MMS. The error stops converging at the design rate: instead of \(p_{\rm obs} = 2\) you get \(p_{\rm obs} \to 0\) at fine resolution, because the error tends to a constant floor set by the bug rather than to zero. A convergence study turns a 2% error from invisible into unmissable, because it changes the shape of the error curve, not just its size.
Practical rules for manufacturing
- Make it smooth. Non-smooth solutions destroy the formal order and you learn nothing.
- Avoid accidental symmetry. A solution even in \(x\) will not test odd-order terms. Use incommensurate frequencies and add a term without symmetry.
- Keep it in a sane range. If \(u_M\) is \(10^{-9}\) the test measures round-off.
- Exercise the boundaries. Choose \(u_M\) that is non-trivial at the boundary; boundary conditions are where most order reductions live.
- Watch for a source that dominates. If \(S\) is far larger than the physical terms, you are verifying your source-evaluation routine and little else.
Common mistakes
- Choosing a manufactured solution that satisfies the original equation. Then \(S = 0\) and you have merely re-run an ordinary benchmark.
- Computing \(S\) by finite differences. It must be exact (symbolic), or its discretisation error contaminates the very thing you are measuring.
- Applying MMS and reporting only the final error. The deliverable is the rate.
Related concepts
Knowledge graph position
Prerequisites: verification and validation, Taylor-series error analysis. Leads to: defensible numerical results; standard practice in every serious CFD/MHD code.
Quiz
Q1 (conceptual). Why must the manufactured solution not satisfy the original equation?
Answer
If it did, the source \(S\) would vanish and the test would reduce to an ordinary exact-solution benchmark — exercising only the terms that particular solution activates. The whole point is a non-zero \(S\) that forces every term in the operator to be evaluated and checked.
Q2 (conceptual). How does a convergence study expose a 2% coefficient error that eyeballing the output cannot?
Answer
The bug contributes a resolution-independent error. As \(h\to0\) the discretisation error falls as \(h^p\) while the bug's contribution stays fixed, so the total error plateaus and \(p_{\rm obs}\) collapses toward zero. The signature is a change in the shape of the error curve — obvious on a log–log plot, invisible in a single run.
Q3 (MCQ). The source term \(S\) in MMS should be computed:
- (a) by finite differences on a fine grid
- (b) symbolically and exactly
- (c) by running the code once
- (d) by fitting to data
Answer
(b). Any discretisation error in \(S\) pollutes the measured convergence rate, defeating the purpose. Symbolic differentiation once, hard-coded thereafter.