Hi, the numberings of any mesh entities and DOFS in general do not coincide. You get indices of DOFs of function from function space using its dofmap. Below is an example of how to obtain index of DOF on a facet. As you can see, you visit each DOF on a shared facet twice. A faster way is shown in the part of code that computes u, but it does not use FacetFunction.
from dolfin import *
from math import hypot
mesh = UnitSquareMesh(2, 2)
V = FunctionSpace(mesh, "CR", 1)
dofmap = V.dofmap()
#------------------------------------------------
facet_f = FacetFunctionDouble(mesh, 0)
for facet in facets(mesh):
facet_f[facet] = facet.midpoint().norm()
v = Function(V)
v_v = v.vector()
for cell in cells(mesh):
dofs = dofmap.cell_dofs(cell.index())
#dofs_x = dofmap.tabulate_coordinates(cell)
for i, facet in enumerate(facets(cell)):
v_v[dofs[i]] = facet_f[facet]
#------------------------------------------------
N = V.dim()
dof_x = dofmap.tabulate_all_coordinates(mesh)
dof_x.resize(N, 2)
u = Function(V)
u_v = u.vector()
for i in range(N):
u_v[i] = hypot(dof_x[i, 0], dof_x[i, 1])
plot(u, interactive=True)
plot(v, interactive=True)