i'm new to fenics so started with the programs provided by FEniCS tutorial (dn1_p2d.py) as in link
https://fenicsproject.org/pub/book/chapters/01/stationary/poisson/dn1_p2D.py
I tried to get the L2 norm of the same but its order of convergence is very low. It should be two. and it shows that error is increasing with decrease in element size. I used element no 2,4,8,16,32 etc.
Thanks in advance.
program is as below-
{}
from dolfin import *
import numpy
Create mesh and define function space
mesh = UnitSquareMesh(2, 2)
V = FunctionSpace(mesh, 'Lagrange', 1)
Define Dirichlet boundary conditions
u0 = Expression('1 + x[0]x[0] + 2x[1]*x[1]')
class DirichletBoundary(SubDomain):
def inside(self, x, on_boundary):
tol = 1E-14 # tolerance for coordinate comparisons
return on_boundary and \
(abs(x[0]) < tol or abs(x[0] - 1) < tol)
u0_boundary = DirichletBoundary()
bc = DirichletBC(V, u0, u0_boundary)
Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
g = Expression('-4x[1]')
a = inner(grad(u), grad(v))dx
L = fvdx - gvds
Compute solution
u = Function(V)
solve(a == L, u, bc)
Dump solution to the screen
u_nodal_values = u.vector()
u_array = u_nodal_values.array()
coor = mesh.coordinates()
for i in range(len(u_array)):
print 'u(%8g,%8g) = %g' % (coor[i][0], coor[i][1], u_array[i])
Verification for the L2 norm
u_e = interpolate(u0, V)
error = (u-u_e)**2*dx
L2_err= sqrt(abs(assemble(error)))
print L2_err