This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to keep grids ordered during refinement?

+1 vote

I'm trying to use IntervalMeshes for time discretizations to be able to use the refinement methods and to iterate my grids with:

for cell in cells(mesh):
    ...

The problem I ran into is that the cells may not be well ordered after several steps of refinement, meaning the cell-wise iteration will be wrong.
Example:

mesh = IntervalMesh(10,0,1)
for i in range(2):
    markers = CellFunction('bool', mesh)
    # refine last 2 cells
    markers[-1], markers[-2] = True, True
    mesh = refine(mesh, markers)
    # checks if cells are well ordered
    left, right, right_old  = 0,0,0
    for cell in cells(mesh):
       left, right = min(cell.get_vertex_coordinates()), max(cell.get_vertex_coordinates())
       if left < right_old:
           print('Cells not well ordered', cell.get_vertex_coordinates(), right_old)
           break
   right_old = right

This will return "'Cells not well ordered', array([0.95, 0.975]), 1.0".

Is there a way to keep the ordering throughout refinement?

asked Feb 6, 2017 by Peter Meisrimel FEniCS Novice (250 points)
edited Feb 7, 2017 by Peter Meisrimel
...