Error exporting field to XDMF in DolfinX v0.9.0.post1

The following program solves the Maxwell’s equations and stores fields to XDMF file. Paraview crashes when trying to open the result. Is it a bug, or did I do something wrong?

This MWE is similar to Error exporting field to XDMF, updated to the newer DolfinX version.

from dolfinx import (io, fem, mesh, cpp)
import ufl
from basix.ufl import element, mixed_element
import numpy as np
from mpi4py import MPI
from slepc4py import SLEPc
from dolfinx.fem.petsc import assemble_matrix as petsc_assemble_matrix
from petsc4py.PETSc import ScalarType


def interpolate(V, f):
    u, v = ufl.TrialFunction(V), ufl.TestFunction(V)
    a_p = ufl.inner(u, v) * ufl.dx
    L_p = ufl.inner(f, v) * ufl.dx
    return fem.petsc.LinearProblem(a_p, L_p).solve()


msh = mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0, 0), (1, 1)),
                            n=(40, 40),
                            cell_type=mesh.CellType.triangle)

msh.topology.create_connectivity(msh.topology.dim-1, msh.topology.dim)

N1curl = element("Nedelec 1st kind H(curl)", msh.basix_cell(), 1)
V = fem.functionspace(msh, N1curl)
Vproj = fem.functionspace(msh, ("Lagrange", 1, (msh.topology.dim,)))

u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)

a = ufl.inner(ufl.curl(u), ufl.curl(v)) * ufl.dx
b = ufl.inner(u, v) * ufl.dx

bc_facets = mesh.exterior_facet_indices(msh.topology)
bc_dofs = fem.locate_dofs_topological(V, msh.topology.dim-1, bc_facets)

u_bc = fem.Function(V)
u_bc.x.array[:] = 0
bc = fem.dirichletbc(u_bc, bc_dofs)

A = fem.petsc.create_matrix(fem.form(a))
petsc_assemble_matrix(A, fem.form(a), bcs=[bc])
A.assemble()
B = fem.petsc.create_matrix(fem.form(b))
petsc_assemble_matrix(B, fem.form(b), bcs=[bc])
B.assemble()

eps = SLEPc.EPS().create(MPI.COMM_WORLD)
eps.setOperators(A, B)
eps.setType(SLEPc.EPS.Type.KRYLOVSCHUR)
st = eps.getST()
st.setType(SLEPc.ST.Type.SINVERT)
eps.setWhichEigenpairs(SLEPc.EPS.Which.TARGET_MAGNITUDE)
eps.setTarget(5.5)
eps.setDimensions(20)
eps.solve()

vals = [(i, eps.getEigenvalue(i)) for i in range(eps.getConverged())]

E = fem.Function(V)
with io.XDMFFile(MPI.COMM_WORLD, "out.xdmf", "w") as xdmf:
    xdmf.write_mesh(msh)
    for i, _ in vals:
        print(f"eigenvalue: {eps.getEigenpair(i, E.x.petsc_vec).real:.12f}")
        Eproj = interpolate(Vproj, E)
        Eproj.name = f"E-{i+1:03d}-{eps.getEigenpair(i, E.x.petsc_vec).real:.4f}"
        xdmf.write_function(Eproj)

Paraview error:

Loguru caught a signal: SIGSEGV
Stack trace:
76      0x555c20586de1 paraview(+0x8de1) [0x555c20586de1]
75      0x7f49f0e20305 __libc_start_main + 133
74      0x7f49f0e2024a /usr/bin/../lib/x86_64-linux-gnu/libc.so.6(+0x2724a) [0x7f49f0e2024a]
73      0x555c2058e01d paraview(+0x1001d) [0x555c2058e01d]
72      0x7f49eeab8316 QCoreApplication::exec() + 150
71      0x7f49eeab01bb QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 299
70      0x7f49eeb09876 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 102
69      0x7f49e531cacc g_main_context_iteration + 44
68      0x7f49e531ca38 /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x54a38) [0x7f49e531ca38]
67      0x7f49e531c7a9 g_main_context_dispatch + 665
66      0x7f49a9efbeca /lib/x86_64-linux-gnu/libQt5XcbQpa.so.5(+0x6deca) [0x7f49a9efbeca]
65      0x7f49eef11cec QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 172
64      0x7f49eef3d42d QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*) + 2061
63      0x7f49eeab1738 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 280
62      0x7f49f0162fae QApplicationPrivate::notify_helper(QObject*, QEvent*) + 126
61      0x7f49f01c0f60 /usr/bin/../lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x1c0f60) [0x7f49f01c0f60]
60      0x7f49f01bdbd8 /usr/bin/../lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x1bdbd8) [0x7f49f01bdbd8]
59      0x7f49f016965e QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool, bool) + 446
58      0x7f49eeab1738 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 280
57      0x7f49f016b552 QApplication::notify(QObject*, QEvent*) + 5058
56      0x7f49f0162fae QApplicationPrivate::notify_helper(QObject*, QEvent*) + 126
55      0x7f49f01a4db8 QWidget::event(QEvent*) + 424
54      0x7f49f0256fd7 QAbstractButton::mouseReleaseEvent(QMouseEvent*) + 247
53      0x7f49f0256db8 /usr/bin/../lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x256db8) [0x7f49f0256db8]
52      0x7f49f025522a /usr/bin/../lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x25522a) [0x7f49f025522a]
51      0x7f49f0254fc2 QAbstractButton::clicked(bool) + 66
50      0x7f49eeae8fbc /usr/bin/../lib/x86_64-linux-gnu/libQt5Core.so.5(+0x2e8fbc) [0x7f49eeae8fbc]
49      0x7f49efaf45d2 /usr/bin/../lib/x86_64-linux-gnu/libpqComponents-pv5.11.so.1(+0xf45d2) [0x7f49efaf45d2]
48      0x7f49efc9fe1a pqPropertiesPanel::apply() + 556
47      0x7f49efaf4df4 pqPropertiesPanel::applied(pqProxy*) + 94
46      0x7f49eeae8f8f /usr/bin/../lib/x86_64-linux-gnu/libQt5Core.so.5(+0x2e8f8f) [0x7f49eeae8f8f]
45      0x7f49f08f314c /usr/bin/../lib/x86_64-linux-gnu/libpqApplicationComponents-pv5.11.so.1(+0xf314c) [0x7f49f08f314c]
44      0x7f49f08f401d /usr/bin/../lib/x86_64-linux-gnu/libpqApplicationComponents-pv5.11.so.1(+0xf401d) [0x7f49f08f401d]
43      0x7f49f08f46ad /usr/bin/../lib/x86_64-linux-gnu/libpqApplicationComponents-pv5.11.so.1(+0xf46ad) [0x7f49f08f46ad]
42      0x7f49f08eecd6 pqApplyBehavior::onApplied(pqProxy*) + 82
41      0x7f49f08eee5f pqApplyBehavior::applied(pqPropertiesPanel*, pqProxy*) + 187
40      0x7f49f08efbe1 pqApplyBehavior::showData(pqPipelineSource*, pqView*) + 355
39      0x7f49e4fa2dfc vtkSMParaViewPipelineControllerWithRendering::ShowInPreferredView(vtkSMSourceProxy*, int, vtkSMViewProxy*) + 794
38      0x7f49e4fa3cdc vtkSMParaViewPipelineControllerWithRendering::UpdatePipelineBeforeDisplay(vtkSMSourceProxy*, int, vtkSMViewProxy*) + 666
37      0x7f49ee4eb275 vtkSMSourceProxy::UpdatePipeline(double) + 129
36      0x7f49ee42616e vtkSMOutputPort::UpdatePipeline(double) + 56
35      0x7f49ee4262b0 vtkSMOutputPort::UpdatePipelineInternal(double, bool) + 318
34      0x7f49ee46c5a0 vtkSMProxy::ExecuteStream(vtkClientServerStream const&, bool, unsigned int) + 170
33      0x7f49ee2f2546 vtkPVSessionBase::ExecuteStream(unsigned int, vtkClientServerStream const&, bool) + 96
32      0x7f49ee2f6834 vtkPVSessionCore::ExecuteStream(unsigned int, vtkClientServerStream const&, bool) + 516
31      0x7f49ee2f6a84 vtkPVSessionCore::ExecuteStreamInternal(vtkClientServerStream const&, bool) + 250
30      0x7f49ef533955 vtkClientServerInterpreter::ProcessStream(vtkClientServerStream const&) + 47
29      0x7f49ef533af2 vtkClientServerInterpreter::ProcessOneMessage(vtkClientServerStream const&, int) + 364
28      0x7f49ef53460f vtkClientServerInterpreter::ProcessCommandInvoke(vtkClientServerStream const&, int) + 513
27      0x7f49ef536270 vtkClientServerInterpreter::CallCommandFunction(char const*, vtkObjectBase*, char const*, vtkClientServerStream const&, vtkClientServerStream&) + 878
26      0x7f49e58ab24a vtkSIMetaReaderProxyCommand(vtkClientServerInterpreter*, vtkObjectBase*, char const*, vtkClientServerStream const&, vtkClientServerStream&, void*) + 1789
25      0x7f49ef536270 vtkClientServerInterpreter::CallCommandFunction(char const*, vtkObjectBase*, char const*, vtkClientServerStream const&, vtkClientServerStream&) + 878
24      0x7f49e58b2445 vtkSISourceProxyCommand(vtkClientServerInterpreter*, vtkObjectBase*, char const*, vtkClientServerStream const&, vtkClientServerStream&, void*) + 2301
23      0x7f49ee34ad40 vtkSISourceProxy::UpdatePipeline(int, double, bool) + 600
22      0x7f49e9f43209 vtkStreamingDemandDrivenPipeline::Update(int) + 51
21      0x7f49e9f43380 vtkStreamingDemandDrivenPipeline::Update(int, vtkInformationVector*) + 372
20      0x7f49e9e7761f vtkDemandDrivenPipeline::UpdateData(int) + 913
19      0x7f49e9f42ff0 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 3238
18      0x7f49e9e76cdd vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1259
17      0x7f49e9e6dd05 vtkCompositeDataPipeline::ForwardUpstream(vtkInformation*) + 963
16      0x7f49e9f42ff0 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 3238
15      0x7f49e9e76de7 vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1525
14      0x7f49e9e6aa39 vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1663
13      0x7f49e9e7783a vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 112
12      0x7f49e9e814ad vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 199
11      0x7f49e2a4e4b4 vtkFileSeriesReader::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 604
10      0x7f49e2a4f392 vtkFileSeriesReader::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 252
9       0x7f49e24226a2 vtkXdmfReader::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 112
8       0x7f49e9e74c52 vtkDataObjectAlgorithm::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 92
7       0x7f49e242428f vtkXdmfReader::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1499
6       0x7f49e244214b vtkXdmfHeavyData::ReadData() + 409
5       0x7f49e2442253 vtkXdmfHeavyData::ReadData(xdmf2::XdmfGrid*, int) + 155
4       0x7f49e244276b vtkXdmfHeavyData::ReadTemporalCollection(xdmf2::XdmfGrid*, int) + 729
3       0x7f49e2442292 vtkXdmfHeavyData::ReadData(xdmf2::XdmfGrid*, int) + 218
2       0x7f49e2442ae5 vtkXdmfHeavyData::ReadUniformData(xdmf2::XdmfGrid*, int) + 357
1       0x7f49dae5c9d6 xdmf2::XdmfDOM::FindElement(char const*, int, _xmlNode*, int) + 50
0       0x7f49f0e35050 /usr/bin/../lib/x86_64-linux-gnu/libc.so.6(+0x3c050) [0x7f49f0e35050]
(   7.629s) [paraview        ]                       :0     FATL| Signal: SIGSEGV

Build script is attached to the message Error reading gmsh mesh - #4 by MatsievskiySV
Build component git tags:

  • Basix: v0.9.0
  • UFL: 2024.2.0
  • FFCX: v0.9.0
  • Dolfinx: v0.9.0.post1

What version of Paraview are you using?

I get the same error in paraview v5.11.0 from debian repo and v5.13.1 from paraview’s site.

Update: Just noticed that the first line of code got lost during copy-pasting. Updated the code to fix this issue.