Setting Dirichlet boundary condition/constraint on 3D edges

I have experimented with setting constant Dirichlet constraints on 3D edges, but run into the error:

 *** Warning: Found no facets matching domain for boundary condition.

and

*** Error:   Unable to create Dirichlet boundary condition.
*** Reason:  User MeshFunction is not a facet MeshFunction (dimension is wrong).

It seems to me that maybe this isn’t currently supported, or maybe I have gotten the syntax wrong. Can someone clarify if this should work?

My simple test script is below:

from fenics import *
from dolfin import *

mesh = BoxMesh(Point(0,0,0), Point(1,1,1), 10,10,10)

E = FiniteElement("P", mesh.ufl_cell(), 3)
V = FunctionSpace(mesh, E)
u = Function(V)
v = TestFunction(V)

def boundary(x, on_boundary):
    return on_boundary
bc = DirichletBC(V, Constant(0), boundary)

edge_function = MeshFunction("size_t", mesh, mesh.topology().dim()-2, 0)
class Edge(SubDomain):
    def inside(self, x, on_boundary):
        return near(x[0], 0) and near(x[1], 0) and on_boundary
Edge().mark(edge_function,1)
bc_edge = DirichletBC(V, Constant(1), Edge())

a = dot(grad(u), grad(v))*dx
f = Constant(1.0)*v*dx
solve(a - f == 0, u, [bc, bc_edge])

The only location this is true is at (x, y) = (0, 0). I assume you intended to write:

        return (near(x[0], 0) or near(x[1], 0)) and on_boundary

Thank you, that was an embarrassing miss.

In the end I was trying to use edge markers from a file, which seems to load fine, but marker type of BC application does not seem to be supported for edges:

bc_edge = DirichletBC(V, Constant(1), edge_function, 1) 

Where I’m getting (while for face BCs this works fine):

*** Error: Unable to create Dirichlet boundary condition.
*** Reason: User MeshFunction is not a facet MeshFunction (dimension is wrong).
*** Where: This error was encountered inside DirichletBC.cpp.

This is because applying BCs to mesh entities of topology dimension d - 2 is not mathematically consistent with the original boundary value problem.

However, you can commit this variational crime in DOLFIN by applying DirichletBCs to DoFs by geometric search, e.g.

DirichletBC(V, Constant(1.0), "near(x[0], 0.0)", "geometric")