How to Refine IntervalMesh properly?

Hi,
I am trying to refine a 1d interval mesh near the boundary.
for example:
The original mesh
mesh= IntervalMesh(10,0,1)

and I want it to be refined until 0.5 distance for which I use:

cell_markers = MeshFunction("bool", mesh, mesh.topology().dim())
cell_markers.set_all(False)
for cell in cells(mesh):
if cell.midpoint().x() < .5:
cell_markers[cell] = True
mesh = refine(mesh, cell_markers)

and I save the the mesh in xml format
mesh_file=File("mesh_refined.xml")
mesh_file<<mesh

To me this should have added 5 more vertices between 0 to 0.5 distance along the mesh but when I open the xml file, I see that these new vertices appear after the original 11 vertices. imgae for reference, the xml file:

It would be great if someone can help me figure where I am mistaking and how to have these new refined vertices on correct order (between my specified distance of 0.5). Thanks!

If you have a look at the rest of your xml file, you will observe that you have a dataset called cells, with 15 entries:

    <cells size="15">
      <interval index="0" v0="0" v1="11" />
      <interval index="1" v0="1" v1="11" />
      <interval index="2" v0="1" v1="12" />
      <interval index="3" v0="2" v1="12" />
      <interval index="4" v0="2" v1="13" />
      <interval index="5" v0="3" v1="13" />
      <interval index="6" v0="3" v1="14" />
      <interval index="7" v0="4" v1="14" />
      <interval index="8" v0="4" v1="15" />
      <interval index="9" v0="5" v1="15" />
      <interval index="10" v0="5" v1="6" />
      <interval index="11" v0="6" v1="7" />
      <interval index="12" v0="7" v1="8" />
      <interval index="13" v0="8" v1="9" />
      <interval index="14" v0="9" v1="10" />
    </cells>

These indicate which vertices each cell is made up of. as you can observe with the first cell, it is made up of the 0th and 11th vertex, i.e.
x=0.0 and x=0.05, creating the cell you wanted. Similarly, you can go through all the other coordinates, and observe that the connectivity is correct.

1 Like

Thanks dokken, Yes I noticed that, and I assume that it does not matter if in the cells dataset, v0 and v1 are interchanged as long as both of them are correct vertices?.

Correct, it does not matter

1 Like