I’m using a simple 1D mesh which I refine in a specific zone using the recommended marking and refine method:
size = 4e-3
nb_cells_init = 4000
mesh = IntervalMesh(nb_cells_init,0, size)
Adding at least 100 cells in the first 50e-8m:
nb_cells = 100
distance = 50e-8
while count < nb_cells and nb_cells > 0:
count = 0
cell_markers = MeshFunction("bool", mesh, mesh.topology().dim())
cell_markers.set_all(False)
for cell in cells(mesh):
if cell.midpoint().x() < distance:
count = count+1
cell_markers_left[cell] = True
if count == 0:
for cell in cells(mesh):
if cell.midpoint().x() < size/nb_cells_init:
cell_markers[cell]=True
mesh = refine(mesh, cell_markers)
print("Nb of cells in the mesh:" + str(len(mesh.cells())))
The print allows me to check that the mesh has more cells than initially.
In postprocessing, I use a XDMF/h5 file to save my solution. This file is initialized with
xdmf_sol = XDMFFFile(mesh.mpi_comm(), "solution.xdmf")
and updated at each timestep:
xdmf_sol.write(solution, t)
However when I check the output file with Paraview, the solution is only plotted over the points of the unrefined mesh.
I printed mesh.coordinates() in order to check that there are some added points and noticed that they are put at the end of the array:
[[0.00000000e+00]
[1.00000000e-06]
[2.00000000e-06]
…
[3.37890625e-07]
[3.30078125e-07]
[3.33984375e-07]]
Using mesh.order() does not change this.
In the h5 file, the mesh is refined and the solution matches the refined mesh.
What am I missing here? Is it just a Paraview issue ?