Boundary condition based on mesh index

Hello,

I have a problem picking the correct indices on a mesh.

I’m using an external tool for picking a face on a mesh with corresponding indices and then I import that list of indices to Fenics, hoping to use the list for applying boundary condition on those points.

As I’ve understood Fenics forces UFC-ordering of the mesh and I suspect that has something to do with it. I’ve looked in to the dofmapping, but I seem to not understand it fully.

This is my code for picking the bound indices and below you can see a picture of the result.

def _DirichletBC_On_Vertices(mesh, V, condition):
    bc = []

    for vertex in vertices(mesh):
        if vertex.global_index() in bound_idxs:
            point = vertex.point().array()

            bc.append(
                DirichletBC(
                    V,
                    condition,
                    "near(x[0],"
                    + str(vertex.point().x())
                    + ") && near(x[1],"
                    + str(vertex.point().y())
                    + ") && near(x[2],"
                    + str(vertex.point().z())
                    + ")",
                    method="pointwise",
                )
            )

    return bc

In the external tool I’ve placed a boundary in the middle of each flat surface of the bolt, but the results seem almost random. Any thoughts?