MMS: 2D Elasticity
Theory: fix the answer first, then test the code
Overview
How can I check my own finite element code? Few problems have exact solutions.
That's what the method of manufactured solutions (MMS) is for. Pick any displacement field as the answer and back-calculate the body force that makes it satisfy the equations — now you have an exactly solvable problem of any shape. Then check that error falls at the theoretical rate as the mesh is refined. If even the rate (convergence order) matches, nearly everything in the code — assembly, integration, boundary conditions — is right. Let's try it on our own code and plant bugs to see how they show up.
Manufactured solution and body force
Unit square, plane stress, Young's modulus 1, Poisson's ratio 0.3. The body force $\mathbf{b}$ was derived symbolically (sympy); all boundaries prescribe the manufactured displacement.
Theoretical orders
$p$ is the element order (1 for Q4, 2 for Q8). $p_{obs}$ is the observed order from the error ratio when divisions double.
The reversal: manufacture the answer
The manufactured-solution idea was in use from the 1980s, but it was popularised as a code-verification method by Roache and by Salari and Knupp at Sandia National Laboratories. Around 2000 their reports and papers organised the procedure of checking convergence order with manufactured solutions, arguing that matching the order rules out every error that affects it. Manufacturing exact solutions rather than searching for them made the method usable for any equation and code.
Worked example: convergence of our code
Correct code
| Element, divisions | Displacement error L2 | Order | Gradient error H1 | Order |
|---|---|---|---|---|
| Q4, 8 | 2.25e-3 | 2.04 | 7.74e-2 | 0.99 |
| Q4, 16 | 5.58e-4 | 2.01 | 3.88e-2 | 1.00 |
| Q4, 32 | 1.39e-4 | 2.00 | 1.94e-2 | 1.00 |
| Q4, 64 | 3.48e-5 | 2.00 | 9.70e-3 | 1.00 |
| Q8, 8 | 1.41e-4 | 2.93 | 7.37e-3 | 2.00 |
| Q8, 16 | 1.78e-5 | 2.99 | 1.85e-3 | 2.00 |
| Q8, 32 | 2.23e-6 | 3.00 | 4.62e-4 | 2.00 |
Code with planted bugs
| Element, divisions | Displacement error L2 | Order |
|---|---|---|
| Q4, wrong ν, 8 | 2.55e-3 | 1.88 |
| Q4, wrong ν, 16 | 1.22e-3 | 1.06 |
| Q4, wrong ν, 32 | 1.07e-3 | 0.19 |
| Q4, wrong ν, 64 | 1.06e-3 | 0.02 |
| Q8, mid-side error, 8 | 4.42e-4 | 2.23 |
| Q8, mid-side error, 16 | 1.05e-4 | 2.08 |
| Q8, mid-side error, 32 | 2.56e-5 | 2.03 |
The Poisson's-ratio bug shows order 1.9 up to 8 divisions — it looks normal.
On coarse meshes discretisation error dominates, hiding the small shift from the bug. As refinement shrinks discretisation error, the bug's 1.1×10⁻³ offset remains and the order drops to zero. So check that the order settles at the theoretical value over at least four mesh levels. The Q8 mid-side bug is subtler: error stays small, but the order falls from 3 to 2 because linear boundary values waste the quadratic elements' capability at the boundary. It's a bug found precisely because MMS looks at order, not error size.
How to apply MMS
- Choose a smooth, non-trivial manufactured solution that exercises every term (all strain components, boundaries).
- Derive the body force symbolically to avoid hand errors.
- Refine by factors of two over four or more levels and tabulate observed orders.
- Check orders for both displacement (L2) and gradient (H1).
- Integrate error with enough Gauss points so quadrature error doesn't contaminate results.
“It passed the benchmarks”
A research group's code matched several benchmarks within 1% and was assumed correct. MMS showed the stress error's order was about 0.5 below theory. The cause was too few integration points for loads on curved boundaries. Comparing with benchmark references only says whether error is below some level, while the MMS order sensitively reveals that something is wrong somewhere.
Common mistakes
Mistakes and fixes
| Mistake | Effect | Fix |
|---|---|---|
| Only two or three meshes | Bugs hidden | Four or more levels |
| Looking only at error size | Order drop missed | Compute observed order |
| Too simple a solution | Some terms untested | Exercise all components |
| Hand-derived body force | Derivation errors | Use symbolic tools |
| Too few error-integration points | Wrong orders | Higher-order quadrature |
I'd like to learn related topics.
Related pages include MMS overview, MMS: 2D heat conduction, MMS convergence rate, code verification and NAFEMS LE1.
Related Topics
Experience the theory firsthand with the interactive simulator for this field
All Simulators