Hi all,
I would like to solve the poisson equation in cylindrical coordinates.
\frac{1}{r} \frac{d}{dr}(r \frac{du}{dr}) + f = 0
I found this old post giving the variational formulation.
However, when running a MMS case on this, the computed solution doesn’t equal the expected solution.
Say my exact solution is u_D = 1 + r^2, the source term should be f=-4.
from fenics import *
mesh = IntervalMesh(100, 1, 2)
V = FunctionSpace(mesh, "P", 1)
u = Function(V)
v = TestFunction(V)
uD = interpolate(Expression("1 + x[0]*x[0]", degree=3), V)
bcs = [
DirichletBC(V, uD, "on_boundary")
]
x = SpatialCoordinate(mesh)
r = x[0]
# cylindrical diffusive term
F = r*dot(grad(u), grad(v))*dx
# source term
f = Constant(-4)
F += -f*v*dx
solve(F==0, u, bcs)
XDMFFile("computed_solution.xdmf").write(u)
XDMFFile("real_solution.xdmf").write(uD)
error_L2 = errornorm(uD, u, 'L2')
print(error_L2)
Maybe there’s something wrong in my variational formulation.
Any idea?
Thanks all!