FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
776 stars 181 forks source link

[BUG]: Multiple calls of write_function produce redundant data #3026

Closed ordinary-slim closed 7 months ago

ordinary-slim commented 9 months ago

Summarize the issue

Beyond the first call of write_function, postfiles have repeated data.

How to reproduce the bug

Writing two scalar functions u1 and u2 using VTKFile.write_function will result in the following pvtu in serial:

<?xml version="1.0"?>
<VTKFile type="PUnstructuredGrid" version="1.0">
  <PUnstructuredGrid GhostLevel="1">
    <PPointData>
      <PDataArray type="Int64" Name="vtkOriginalPointIds" IdType="1" />
      <PDataArray type="UInt8" Name="vtkGhostType" />
      <PDataArray type="Float64" Name="u1" NumberOfComponents="0" />
      <PDataArray type="Float64" Name="u2" NumberOfComponents="0" />
    </PPointData>
    <PCellData>
      <PDataArray type="UInt8" Name="vtkGhostType" />
      <PDataArray type="Int64" Name="vtkOriginalCellIds" IdType="1" />
    </PCellData>
    <PPoints>
      <PDataArray type="Float64" NumberOfComponents="3" />
    </PPoints>
    <Piece Source="dolfinx_out_p0_000000.vtu" />
    <Piece Source="dolfinx_out_p0_000000.vtu" />
  </PUnstructuredGrid>
</VTKFile>

where the line <Piece Source="dolfinx_out_p0_000000.vtu" /> should only have appeared once. When read from Paraview, this results in double the elements in the Information window. The issue also happens with XDMFFile.write_function, with one block of data hiding the other one. I use Paraview 5.11.

Minimal Example (Python)

from dolfinx import mesh, io, fem
from mpi4py import MPI

nels_per_side = 2
mesh  = mesh.create_unit_square(MPI.COMM_WORLD, nels_per_side, nels_per_side, mesh.CellType.quadrilateral)

V = fem.functionspace(mesh, ("Lagrange", 1))

u1, u2 = fem.Function(V, name="u1"), fem.Function(V, name="u2")
u1.interpolate( lambda x : x[0]**2 )
u2.interpolate( lambda x : x[1]**2 )

# VTK out
with io.VTKFile(mesh.comm, "out/dolfinx_out.pvd", "w") as iofile:
    iofile.write_function([u1, u2])
# XDMF out
with io.XDMFFile(mesh.comm, "out/dolfinx_out.xdmf", "w") as iofile:
    iofile.write_mesh(mesh)
    iofile.write_function(u1)
    iofile.write_function(u2)

Output (Python)

No response

Version

main branch

DOLFINx git commit

920e91f2a253e43c2e5bcb229a4f9a3274504c70 (25 of January)

Installation

Development docker image

Additional information

No response

jorgensd commented 7 months ago

As mentioned in: https://fenicsproject.discourse.group/t/how-to-write-binary-data-with-vtk-xdmffile/14095/6?u=dokken There are multi-block data sets that are pointing to the same h5 file. I.e. the storage is minimized. How Paraview chooses to display multi-block data is not an issue of DOLFINx.

You need to use the Extract Block filter in Paraview when working with multiblock datasets.

For the VTKFile issues, see: https://github.com/FEniCS/dolfinx/pull/3120