Hi, I need get the norm and seminorm H^2 of an analytic function to estimate of convergence error. I am be thankful if anyone can help me.
Given a function f that is in H^2, you can use the assemble
function to directly integrate the (semi)norm definition, e.g.,
from dolfin import *
N = 10
mesh = UnitSquareMesh(N,N)
x = SpatialCoordinate(mesh)
f = x[0]*x[1]
ggf = grad(grad(f))
H2_seminorm_of_f = sqrt(assemble(inner(ggf,ggf)*dx))
print(H2_seminorm_of_f)
Notes:
- It’s worth pointing out that functions in standard finite element spaces are not in H^2, because they have discontinuous first derivatives. Thus, the H^2 norm of, say, the error between a finite element solution and a smooth exact solution is not a well-defined quantity. (The code above would still run and give you a number if
f
were replaced with such an error, but it would be the sum of H^2 norms squared on element interiors, not the ill-defined H^2 norm of a function not in H^2.) - Although, anecdotally, I’ve never run into this problem in practice, the approach of directly integrating formulas for error norms can potentially be susceptible to floating-point precision issues, which is why the
errornorm
function exists. (It uses a more robust procedure, involving interpolating functions into higher-order finite element spaces.)
1 Like
Ok, that is correct, but, what happen if f=(x[0]*x[1], x[1]*x[1]-x[0]), that is, f is a vector field?
The code of @kamensky works just as well with a vector field:
from dolfin import *
N = 10
mesh = UnitSquareMesh(N,N)
x = SpatialCoordinate(mesh)
f=as_vector([x[0]*x[1], x[1]*x[1]-x[0]])
ggf = grad(grad(f))
H2_seminorm_of_f = sqrt(assemble(inner(ggf,ggf)*dx))
print(H2_seminorm_of_f)
Thanks, Now is working!!