I tried the same but for maxwell. I could not do it with the tools directly given by fenics. You will have to iterate through all the cells and evaluate some error-function that you defined.
cell_markers = CellFunction("bool", mesh)
cell_markers.set_all(False)
for cell in cells(mesh):
if error_function==True:
cell_markers[cell] = True
mesh = refine(mesh, cell_markers)
I know that this is not really an answer, but i hope it helps for you. The error function depends to much on your exact application to give an answer.