Dear all,

I'm trying to use adaptive algorithm in Firedrake. Because it's essential in my thesis. I have problem with marking cell and locally refining step.  The following is my test code for one iteration:

      REFINE_RATIO = 0.50  # Refine 50 % of the cells in each iteration
      mesh = UnitSquareMesh(4, 4)
     BDM = FunctionSpace(mesh, "BDM", 1)
     DG = FunctionSpace(mesh, "DG", 0)
     W = BDM * DG
     sigma, u = TrialFunctions(W)
     tau, v = TestFunctions(W)
     x, y = SpatialCoordinate(mesh)
     f = Function(DG).interpolate(
         10*exp(-(pow(x - 0.5, 2) + pow(y - 0.5, 2)) / 0.02))
     a = (dot(sigma, tau) + div(tau)*u + div(sigma)*v)*dx
     L = - f*v*dx
     bc0 = DirichletBC(W.sub(0), as_vector([0.0, -sin(5*x)]), 1)
     bc1 = DirichletBC(W.sub(0), as_vector([0.0, sin(5*y)]), 2)
     w = Function(W)
     solve(a == L, w, bcs=[bc0, bc1])
     sigma, u = w.split()
     expr = (div(sigma)+f)*(div(sigma)+f)
     P0 = FunctionSpace(mesh, "DG", 0)
     Re = project(expr, P0)
     coeffs = Re.dat.data
     ss = sorted(coeffs, reverse=True)[int(len(coeffs)*REFINE_RATIO)]
     #-------------------------The followin are marking and refining  which work in Dolfin  ---------------------------
     cell_markers = MeshFunction("bool", mesh, mesh.topology().dim())
     for c in cells(mesh):
         cell_markers[c] = coeffs[c.index()] > ss
     mesh = refine(mesh, cell_markers)
 

1) How can I use the loop over the cells in Firedrake? ( for c in ?)
2) Is there a way to refine some marked cell in Firedrake?

Your answer will be greatly appreciated.

All the best,
Amireh