I have just reinstalled the newest version of FEniCS, and try to rerun some previous code. However, I keep getting some different results and finally I find the problem is from the boundary condition.
Here is my code:
V = FunctionSpace(mesh, "Lagrange", 1)
def boundary(x, on_boundary):
return on_boundary
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)
u = TrialFunction(V)
v = TestFunction(V)
res = Function(V)
a = 0.5*inner(nabla_grad(u), nabla_grad(v))*dx-u*r*v*dx
b = v*dx
problem = LinearVariationalProblem(a, b, res, bc)
solver = LinearVariationalSolver(problem)
solver.parameters["linear_solver"] = "gmres"
solver.parameters["preconditioner"] = "amg"
solver.solve()
The mesh I used is adaptive. And I find the calculated result $res$ doesn't satisfy zero boundary condition.