What are default boundary conditions?

I have noticed that KrylovSolver is able to solve Poisson equation with no boundary condition given explicitly. What are the default boundary conditions?

My MWE:

from fenics import *

# Create mesh and define function space
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'P', 1)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression('(x[0] - 0.5) + (x[1] - 0.5)', degree=1)
a = dot(grad(u), grad(v))*dx
L = f*v*dx

# Compute solution
u = Function(V)
solver = KrylovSolver("cg", "ilu")
solver.parameters["maximum_iterations"] = 20000
solver.parameters["absolute_tolerance"] = 1E-8
solver.parameters["monitor_convergence"] = True
solver.solve(assemble(a), u.vector(), assemble(L))

The “default” boundary condition is implied by your variational form; to obtain it from the strong problem via integration-by-parts, you must assume that \nabla u\cdot\mathbf{n} = 0 to get rid of the boundary term. Note, however, that this problem is ill-posed, in the sense that, given any solution u, u + C will also be a solution for some constant C\in\mathbb{R} (since neither the differential operator nor the boundary condition will notice C). Sometimes you can get lucky in problems like this with infinitely-many solutions, and iterative solvers will converge, essentially choosing the arbitrary C for you. Also note that your f also happens to satisfy a compatibility condition with the boundary condition \nabla u\cdot\mathbf{n} = 0; by plugging in the test function v=1, you can verify that one must have \int_\Omega f = 0. If you, say, add 1 to f, the solver will not converge.

For an example of a more robust treatment of the Poisson problem with Neumann BCs using FEniCS, see this demo:

https://fenicsproject.org/docs/dolfin/2018.1.0/python/demos/neumann-poisson/demo_neumann-poisson.py.html

1 Like