Code Verification

Category: V&V – ASME Standards | Revised 2026-10-01
CAE visualization for code verification theory - technical simulation diagram
Code Verification

Theory: showing correctness in numbers

Overview

🙋

I've been asked to demonstrate the quality of an in-house analysis program. Isn't it enough that examples give plausible results?

🎓

It isn't. Small errors shift results only slightly, so they're almost never visible. Code verification checks, on problems with known answers, that error shrinks to round-off level or falls at the theoretical order under refinement. For finite elements, the basic check is the patch test: can the elements reproduce a solution they should represent, even when distorted? The key is that pass/fail comes out clearly in numbers.

Test problems

$$ \nabla^2 u = 0,\qquad u_{patch} = 1 + 2x + 3y,\qquad u_{order} = e^{x}\sin y $$

Both are exact solutions of Laplace's equation. The linear field is represented exactly by linear triangles, suiting the patch test; the exponential–sine product serves the order test.

Element stiffness and error measures

$$ K^e = \frac{1}{4A^e}\,B^{T}B,\qquad \|e\|_\infty = \max_i |u_i - u(\mathbf x_i)|,\qquad p = \frac{\ln(e_{2h}/e_h)}{\ln 2} $$

$A^e$ is triangle area and $B$ the shape-function gradient matrix. Look at maximum nodal error and the order $p$ when spacing is halved.

Coffee Break Trivia

The birth of the patch test

The patch test was devised in the mid-1960s by Irons and colleagues while developing plate-bending elements. Some elements ran fine yet didn't approach the correct answer under refinement. Irons proposed applying a simple state the elements should represent (such as uniform strain) to a small 'patch' of elements and judging correctness by whether it was reproduced exactly. Strang and others later clarified its mathematical meaning, and it remains the first test for new elements and in-house programs.

Worked example: a small finite element program

Example 1: patch test

A unit square meshed 6×6 with linear triangles had interior nodes shifted by up to 30% of spacing. Imposing 1 + 2x + 3y on the boundary and solving gave a maximum nodal error of 1.8×10⁻¹⁵ — round-off level — evidence of correct implementation.

Example 2: order test and catching a bug

With the exponential–sine solution under refinement, the correct implementation was compared with one planted with an error halving the area of elements in x > 0.5:

DivisionsCorrect errorOrderFaulty errorOrder
45.8×10⁻⁴—8.8×10⁻²—
81.6×10⁻⁴1.861.0×10⁻¹−0.21
164.1×10⁻⁵1.981.0×10⁻¹0.01
321.0×10⁻⁵2.009.9×10⁻²0.02
🙋

The faulty implementation's error doesn't shrink at all with refinement.

🎓

Right. Halving the area doubles stiffness in those elements — a shift in the equations themselves that refinement can't cure, hence order 0. The same error also sent patch-test error up to 0.23. Conversely, passing the patch and order tests lets you say in numbers that at least this kind of error is absent. The key is automating these tests and running them on every change — passing once doesn't prevent later edits from breaking things.

Code verification workflow

  1. Confirm element basics with patch tests (uniform strain, linear temperature, etc.).
  2. On problems with exact solutions, check the theoretical order appears under refinement.
  3. Check equations or terms without exact solutions using manufactured solutions.
  4. Prepare tests for each boundary-condition type, element type and nonlinear setting.
  5. Automate tests, run them on every change and record results.
Coffee Break Trivia

“New version shifted results 0.3%”

A new version of an in-house structural program, run on the same model, gave stresses differing by just 0.3%. It was nearly dismissed as within tolerance, but one automated patch test failed. Investigation found that element integration, rewritten for speed, swapped weights only on distorted elements. 0.3% may look small, but an error that fails the patch test won't vanish with refinement. A test with a numerical pass/fail caught it before release.

Common mistakes

Mistakes and fixes

MistakeEffectFix
Judging by plausible resultsSmall errors missedNumerical pass/fail
Testing only regular meshesDistorted-element bugs remainDistorted patches
Single-grid comparisonOrder drop missedRefine and compute order
Not testing boundary conditionsBoundary implementation errorsTest each type
One-off testingLater changes break thingsAutomate and run every time
🙋

I'd like to learn related topics.

Related Simulators

Experience the theory firsthand with the interactive simulator for this field

All Simulators

Related fields

Structural AnalysisFluid AnalysisThermal Analysis
Rate this article
Thank you for your feedback!
Helpful
More details
Report error
Helpful
0
More details
0
Report error
0