Paraview crash when exporting XDMF or VTX files

, ,

Dear FEniCS community,

I’m facing a Paraview crash when exporting files from the latest stable release of Dolfinx. Even the most simple example is failing. For instance, the Poisson_demo taken from Dolfinx repo:

from petsc4py.PETSc import ScalarType  # type: ignore

# +
import numpy as np

import ufl
from dolfinx import fem, io, mesh, plot
from dolfinx.fem.petsc import LinearProblem
from ufl import ds, dx, grad, inner

# +
msh = mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, 0.0), (2.0, 1.0)), n=(32, 16),
                            cell_type=mesh.CellType.triangle)
V = fem.functionspace(msh, ("Lagrange", 1))


facets = mesh.locate_entities_boundary(msh, dim=(msh.topology.dim - 1),
                                       marker=lambda x: np.logical_or(np.isclose(x[0], 0.0),
                                                                      np.isclose(x[0], 2.0)))


dofs = fem.locate_dofs_topological(V=V, entity_dim=1, entities=facets)


bc = fem.dirichletbc(value=ScalarType(0), dofs=dofs, V=V)

# +
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
x = ufl.SpatialCoordinate(msh)
f = 10 * ufl.exp(-((x[0] - 0.5) ** 2 + (x[1] - 0.5) ** 2) / 0.02)
g = ufl.sin(5 * x[0])
a = inner(grad(u), grad(v)) * dx
L = inner(f, v) * dx + inner(g, v) * ds
# -

# +
problem = LinearProblem(a, L, bcs=[bc], petsc_options={
                        "ksp_type": "preonly", "pc_type": "lu"})
uh = problem.solve()
# -


# +
with io.XDMFFile(msh.comm, "out_poisson/poisson.xdmf", "w") as file:
    file.write_mesh(msh)
    file.write_function(uh)

make Paraview crash. If I only do file.write_mesh(msh), then it works. Something fails on my side when using file.write_function(uh).

I have tested the following dolfinx builds:

Docker image dolfinx/dolfinx:v0.7.3
Dolfinx intalled on docker image ubuntu:jammy using PPA
Anaconda env fenics-dolfinx

Paraview versions tested are 5.11.0, 5.11.1, 5.11.2 and 5.12.0RC on Linux, Windows and MACOS with X86 and ARM systems.

I could upload the crash report from Paraview but I don’t know how. I put a link to share:

crash report

I appreciate any help.

What XDMF reader are you using in paraview to open the files?
I cannot reproduce the issue with the docker image you refer to on ubuntu 22.04 with Paraview 5.11.0

Could you please check if you can open:


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

# +
msh = mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, 0.0), (2.0, 1.0)), n=(2, 2),
                            cell_type=mesh.CellType.triangle)
V = fem.functionspace(msh, ("Lagrange", 1))
uh = fem.Function(V)
uh.interpolate(lambda x: x[0])


with io.XDMFFile(msh.comm, "out_poisson/poisson.xdmf", "w", encoding=io.XDMFFile.Encoding.ASCII) as file:
    file.write_mesh(msh)
    file.write_function(uh)

and add data in out_poisson/poisson.xdmf to your reply:

<?xml version="1.0"?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf Version="3.0" xmlns:xi="https://www.w3.org/2001/XInclude">
  <Domain>
    <Grid Name="mesh" GridType="Uniform">
      <Topology TopologyType="Triangle" NumberOfElements="8" NodesPerElement="3">
        <DataItem Dimensions="8 3" NumberType="Int" Format="XML">0 1 2
0 3 2
4 0 3
3 2 5
4 6 3
3 7 5
6 3 7
6 8 7
</DataItem>
      </Topology>
      <Geometry GeometryType="XY">
        <DataItem Dimensions="9 2" Format="XML">1 0
2 0
2 0.5
1 0.5
0 0
2 1
0 0.5
1 1
0 1
</DataItem>
      </Geometry>
    </Grid>
    <Grid Name="f" GridType="Collection" CollectionType="Temporal">
      <Grid Name="f" GridType="Uniform">
        <xi:include xpointer="xpointer(/Xdmf/Domain/Grid[@GridType='Uniform'][1]/*[self::Topology or self::Geometry])" />
        <Time Value="0" />
        <Attribute Name="f" AttributeType="Scalar" Center="Node">
          <DataItem Dimensions="9 1" Format="XML">1
2
2
1
2.154228071576087e-17
2
2.154228071576087e-17
1
-2.154228071576087e-17
</DataItem>
        </Attribute>
      </Grid>
    </Grid>
  </Domain>
</Xdmf>

in my case

Dear dokken, thanks for your reply.

I have tried to use XDMF3 READER, XDMF3 READER S and XDMF3 READER T. All of them crash. The same happen when I export to VTX and use ADIOS reader.

The data in out_poisson/poisson.xdmf is the following:

<?xml version="1.0"?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf Version="3.0" xmlns:xi="https://www.w3.org/2001/XInclude">
  <Domain>
    <Grid Name="mesh" GridType="Uniform">
      <Topology TopologyType="Triangle" NumberOfElements="8" NodesPerElement="3">
        <DataItem Dimensions="8 3" NumberType="Int" Format="XML">0 1 2
0 3 2
4 0 3
3 2 5
4 6 3
3 7 5
6 3 7
6 8 7
</DataItem>
      </Topology>
      <Geometry GeometryType="XY">
        <DataItem Dimensions="9 2" Format="XML">1 0
2 0
2 0.5
1 0.5
0 0
2 1
0 0.5
1 1
0 1
</DataItem>
      </Geometry>
    </Grid>
    <Grid Name="f" GridType="Collection" CollectionType="Temporal">
      <Grid Name="f" GridType="Uniform">
        <xi:include xpointer="xpointer(/Xdmf/Domain/Grid[@GridType='Uniform'][1]/*[self::Topology or self::Geometry])" />
        <Time Value="0" />
        <Attribute Name="f" AttributeType="Scalar" Center="Node">
          <DataItem Dimensions="9 1" Format="XML">1
2
2
1
2.154228071576087e-17
2
2.154228071576087e-17
1
-2.154228071576087e-17
</DataItem>
        </Attribute>
      </Grid>
    </Grid>
  </Domain>
</Xdmf>

EDIT: I was able to open the file when using XDMF3 READER S.

As this file is exactly the same as mine (and runs on my system), there must be an issue with how you install Paraview.

I’m still facing an error when exporting using VTK. The MWE is as follows.

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

# +
msh = mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, 0.0), (2.0, 1.0)), n=(2, 2),
                            cell_type=mesh.CellType.triangle)
V = fem.functionspace(msh, ("DG", 1))
uh = fem.Function(V)
uh.interpolate(lambda x: x[0])


with io.VTKFile(msh.comm, "out_poisson/poisson.vtk", "w") as file:
    file.write_mesh(msh)
    file.write_function(uh)

EDIT: change from VTX to VTK.

Thanks @dokken , I was able to fix the XMDF output.

You say VTX, but send code for VTK:

Anyhow, the VTKFile extensions is .pvd, not .vtk.

Post edited. Using .pvd as the extension fix the problem. Thank you very much.