Compute and return the error \(e = u - u_h\) in the given norm.
In simple cases, one may just define
e = u - uh
and evalute for example the square of the error in the \(L^2\) -norm by
assemble(e**2*dx(mesh))
However, this is not stable w.r.t. round-off errors considering that the form compiler may expand(#) the expression above to:
e**2*dx = u**2*dx - 2*u*uh*dx + uh**2*dx
and this might get further expanded into thousands of terms for higher order elements. Thus, the error will be evaluated by adding a large number of terms which should sum up to something close to zero (if the error is small).
This module computes the error by first interpolating both \(u\) and \(u_h\) to a common space (of high accuracy), then subtracting the two fields (which is easy since they are expressed in the same basis) and then evaluating the integral.
(#) If using the tensor representation optimizations. The quadrature represenation does not suffer from this problem.