Hi all,
I thought this should be a simple problem, but I am having some trouble so hoping someone can help. I have a parabolic function defined on a unit square (like a fully-developed steady 2D fluid flow). I want to calculate the second derivative of this function. Since ${\rm vel} = 4y - 4y^2$, I know the answer should be -8 everywhere. My code is given below. What I get is +8 everywhere, except at the (top/bottom) boundaries where vel is zero, where I get large noise-like results. The thickness of the noisy "boundary layer" is wider for a lower mesh density and gets worse if I increase the element order. I tried including the boundary term which arises after integration by parts, but this introduces error at the left/right boundaries. If I make vel a function of FS rather than VFS, then the ()*ds term does help, but I don't understand why.
Any help would be greatly appreciated.
mesh = UnitSquareMesh(100, 100)
VFS = VectorFunctionSpace(mesh, "CG", 1)
FS = FunctionSpace(mesh, "CG", 1)
velexp = Expression(('4.0*x[1]*(1 - x[1])', '0'), element=VFS.ufl_element())
vel = Function(VFS)
vel.interpolate(velexp)
du2 = Function(VFS)
u = TestFunction(VFS)
v = TrialFunction(VFS)
a0 = assemble(inner(v, u)*dx)
L0 = assemble(inner(grad(v), grad(vel))*dx )
# L0 = assemble(inner(grad(v), -grad(vel))*dx ) # Adding negative sign does nothing
# n = FacetNormal(mesh)
# L0 = assemble(inner(grad(v), grad(vel))*dx - inner(v, grad(vel).T*n)*ds )
solve(a0, du2.vector(), L0, 'gmres', 'ilu')
File("du2.pvd") << du2