Mesh unrefinement/coarsening

Hi all,
I am looking for mesh unrefinement/coarsening in fenics which is substitute to this:

mesh = refine(mesh)

Also in mesh = refine(mesh) what is the refinement rate and how can I change it.

I think that there is no function that coarsens your mesh. I solved this problem by starting with a very coarse mesh and then refining it in areas where refinement is needed. Your refinement criterion is highly specific to your problem. In my case, I needed refinement where a function c has a value within a certain range:

cell_markers = MeshFunction("bool", mesh_initial, mesh_initial.topology().dim())
            cell_markers.set_all(False)
            for cell in cells(mesh_initial):
                if c (cell.midpoint()) > 0.01 and c (cell.midpoint()) < 0.99:
                    cell_markers[cell] = True
            mesh = refine(mesh_initial, cell_markers)

As you can see, you can pass a MeshFunction as an argument to the refine() function.
For a 2D mesh, the marked cells are refined by splitting them once (I think). You can repeat this process to further refine the mesh. Mesh coarsening can be achieved by interpolating the solution from the refined mesh onto the initial coarse mesh and then refining it again (if needed). There might be other more efficient methods but this one worked for me.

Cells are in general split by looking at the edges of the cell, and finding the midpoint of those.
Thus in 1D a cell is split into 2, in 2D a cell can be split into more than 2 subdomains, if all edges are refined (and depending on the cell type, triangle or quadrilateral).
The mesh refinement then has some additional rules to avoid squashed cells in the case of partial refinement of a cell (a single edge is refined, but not the remaining edges).
See some of the last slides in: https://fenicsproject.org/pub/workshops/fenics13/slides/Richardson.pdf
for examples.

Mesh coarsening is quite hard in general (Chris Richardson has been working on this).