Hello. I am trying to make a function that takes a known solution and returns its Laplacian. The sig expression is there to make my 1D solution match the 3D one which is spherically symmetric. for a specified coordinate system. When I run the code I get the correct solution (Laplacian=6) but with large oscillations at the boundaries (see figure). I have also confirmed this is also a problem when using a 2D mesh also.
Am I using the a wrong approach to calculating the Laplacian? I know I could use something like ‘project(div(grad(f)))’ but that would only work in Cartesian coordinates, where as using the integration by parts allows me to works with different sig.
FEinCS version - 2019.1.0 (installed with conda-forge).
Thanks in advance.
import dolfin as d
mesh = d.UnitIntervalMesh(1000)
sig = d.Expression("pow(x[0], 2)", degree=0) # in spherica coordinates.
V = d.FunctionSpace(mesh, 'CG', 1)
v = d.TestFunction(V)
u = d.TrialFunction(V)
f = d.interpolate(d.Expression("pow(x[0], 2)", degree=1), V)
solver = d.KrylovSolver(method="richardson", preconditioner="icc")
n = d.FacetNormal(mesh)
ds = d.Measure('ds', domain=mesh)
A = d.assemble(u*v*sig*d.dx)
G = d.assemble(d.dot(d.grad(f), n)*v*sig*ds
- d.dot(d.grad(f), d.grad(v*sig))*d.dx)
laplacian = d.Function(V)
solver.solve(A, laplacian.vector(), G)
d.plot(laplacian)