This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to compute the difference to an analytical solution

0 votes

I want to compare my computed solution uh from the FEM space V to the analytical solution u taking the $L^2$ norm of the difference.

What options do I have?

I can project/interpolate u to a V function pu and use

dolfin.norm(uh - u_prj) 

but this is not optimal because it includes a projection/interpolation error...

asked Sep 8, 2014 by Jan FEniCS User (8,290 points)

1 Answer

+2 votes
 
Best answer

Comparing the solution in the solution space is only good for knowing how far your solution is from the interpolation of the exact solution but this entirely ignores the approximation part of the error, i.e., you won't capture the errors which are simply not seen in V.

The better solution would be to project the exact solution to a higher degree polynomial space and/or finer mesh and evaluate the error there. This also introduces a (higher order) error and which one is better (h- vs. p-refinement) is a matter of the regularity of your solution. Adaptive integration should also work well, but as far as I know there is no such thing yet in FEniCS. It should be possible to implement this with a couple of lines in C++ and interface it in Python though.

answered Sep 8, 2014 by Christian Waluga FEniCS Expert (12,310 points)
selected Sep 8, 2014 by Jan

Thanks for the answer. I already thought I need to interpolate/project (not sure about that by now) to a 'finer' space and then use dolfin.errornorm. The best thing would be to have the difference in the quadrature points. But this, probably, involves much more programming.

Actually errornorm already 'raises' the order of the discrete solution (by a specified degree) and interpolates both the exact and approximate solution with this order before computing the L2 norm of the error. When you have non-smooth exact solutions I know of no better solution than interpolating to finer meshes first (although refining just in terms of adding more quadrature points in the right places would be a much better approach).

...