It should be noted that dolfin as yet has no support for non-conforming meshes and hanging nodes. You refine cells of a mesh. You can provide a CellFunction
which marks which cells should be refined. Consider the following to refine the cells adjacent to the exterior boundary:
from dolfin import *
mesh = UnitSquareMesh(1, 1)
for j in range(4):
mesh.init(1, 2) # Initialise facet to cell connectivity
markers = CellFunction('bool', mesh, False)
for c in cells(mesh):
for f in facets(c):
if f.exterior():
markers[c] = True
break
mesh = refine(mesh, markers)
plot(mesh)
interactive()