In the following code, I define two Dirichlet bc on a unit square domain, one on the left boundary ("x[0]<=DOLFIN_EPS") and one on the "top and bottom" (defined by "on_boundary and x[0]>=DOLFIN_EPS and x[0]<=1-DOLFIN_EPS"). It seems to me that FEniCS doesn't interpret the top-bottom boundary condition correctly. If A=(0,0) is the point in the lower left corner and B=(0.1, 0) is its closest point on the "bottom boundary", then A is contained in the "left" and B in the "top-bottom" region. However, using a quadratic function space, FEniCS doesn't apply the bc to the midpoint of the AB facet -- which is used in the computation -- although this point is contained in the "top-bottom" region. It can be vizualized by projecting the solution to a finer mesh where the (A+B)/2 point is visible and the solution is nonzero there. In this case, it really doesn't matter but I encountered this in a problem where it changed the solution completely..
from dolfin import *
mesh=UnitSquareMesh(10,10)
mesh_ref=refine(mesh)
V = FunctionSpace(mesh, "CG", 2)
V_ref = FunctionSpace(mesh_ref, "CG", 1)
def left(x, on_boundary):
return on_boundary and x[0]<=DOLFIN_EPS
def bt(x, on_boundary):
return on_boundary and x[0]>=DOLFIN_EPS and x[0]<=1.0-DOLFIN_EPS
left_bc = DirichletBC(V, Expression('x[1]*(1.0-x[1])') , left)
bt_bc = DirichletBC(V, Constant(0.0), bt)
bcs = [left_bc, bt_bc]
u,v=TrialFunction(V), TestFunction(V)
F = inner(grad(u), grad(v))*dx
a,L=system(F)
sol=Function(V)
solve(a == L, sol, bcs)
plot(sol, title="solution")
# interpolate to finer mesh:
plot(interpolate(sol, V_ref), title="interpolation on refined mesh", interactive=True)