Saving mixed vector element as xdmf | FEniCSx 0.7.2

Hello everyone,

I recently upgraded from FEniCSx version 0.6.0 to 0.7.2. Now I get an error message when saving the results from a mixed functionspace as an xdmf file.

The mixed functionspace consists of vector elements and finite elements. I do not get an error message if I save only the scalar field, but the vector field. In paraview, the scalar field also looks as expected. I have tested the elements from the ufl, as well as from the basix library and both lead to this error.

Here is my code:

from dolfinx.mesh import create_unit_square
from dolfinx.fem import (Function, FunctionSpace)
from dolfinx.io import XDMFFile
from basix.ufl import (element, mixed_element)
from mpi4py import MPI

mesh = create_unit_square(MPI.COMM_WORLD, 50, 50)

u_el = element("Lagrange", mesh.basix_cell(), 1, shape=(mesh.topology.dim, )) #Vector element
p_el = element("Lagrange", mesh.basix_cell(), 1) #Finite element
V_up = FunctionSpace(mesh, mixed_element([u_el, p_el]))

U = Function(V_up)
with U.vector.localForm() as bc_local:
    bc_local.set(0.0)
u_parav, p_parav = U.split()

with XDMFFile(MPI.COMM_WORLD,  "Results.xdmf", "w") as xdmf:
    xdmf.write_mesh(mesh)
    xdmf.write_function(u_parav, 0) #Results in error
    xdmf.write_function(p_parav, 0) #Works
    xdmf.close()

I get the following error message:

python3: /src/dolfinx/cpp/dolfinx/io/xdmf_function.cpp:140: void dolfinx::io::xdmf_function::add_function(MPI_Comm, const dolfinx::fem::Function<T, U>&, double, pugi::xml_node&, hid_t) [with T = double; U = double; MPI_Comm = int; hid_t = long int]: Assertion `dofs.size() == dofs_x.size()' failed.

Loguru caught a signal: SIGABRT
Stack trace:
27      0x56105bdf0ba5 _start + 37
26      0x7ff3e7516e40 __libc_start_main + 128
25      0x7ff3e7516d90 /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7ff3e7516d90]
24      0x56105bdf0cad Py_BytesMain + 45
23      0x56105be1a41e Py_RunMain + 702
22      0x56105be27653 _PyRun_AnyFileObject + 67
21      0x56105be27a08 _PyRun_SimpleFileObject + 424
20      0x56105be28525 python3(+0x264525) [0x56105be28525]
19      0x56105be220bb python3(+0x25e0bb) [0x56105be220bb]
18      0x56105be287d8 python3(+0x2647d8) [0x56105be287d8]
17      0x56105bdfdcf6 PyEval_EvalCode + 134
16      0x56105bdfde56 python3(+0x239e56) [0x56105bdfde56]
15      0x56105bd0cf52 _PyEval_EvalFrameDefault + 2050
14      0x56105bd2470c _PyFunction_Vectorcall + 124
13      0x56105bd128a2 _PyEval_EvalFrameDefault + 24914
12      0x56105bd327bb python3(+0x16e7bb) [0x56105bd327bb]
11      0x56105bd1a5eb _PyObject_MakeTpCall + 603
10      0x56105bd23e0e python3(+0x15fe0e) [0x56105bd23e0e]
9       0x7ff3db990ae8 /usr/local/dolfinx-real/lib/python3.10/dist-packages/dolfinx/cpp.cpython-310-x86_64-linux-gnu.so(+0xb2ae8) [0x7ff3db990ae8]
8       0x7ff3dbad355f /usr/local/dolfinx-real/lib/python3.10/dist-packages/dolfinx/cpp.cpython-310-x86_64-linux-gnu.so(+0x1f555f) [0x7ff3dbad355f]
7       0x7ff3db7e8c43 void dolfinx::io::XDMFFile::write_function<double, double>(dolfinx::fem::Function<double, double> const&, double, std::string) + 995
6       0x7ff3db800b66 void dolfinx::io::xdmf_function::add_function<double, double>(int, dolfinx::fem::Function<double, double> const&, double, pugi::xml_node&, long) + 8038
5       0x7ff3e7526e96 /lib/x86_64-linux-gnu/libc.so.6(+0x39e96) [0x7ff3e7526e96]
4       0x7ff3e751571b /lib/x86_64-linux-gnu/libc.so.6(+0x2871b) [0x7ff3e751571b]
3       0x7ff3e75157f3 abort + 211
2       0x7ff3e752f476 raise + 22
1       0x7ff3e75839fc pthread_kill + 300
0       0x7ff3e752f520 /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7ff3e752f520]
2023-12-11 14:40:57.026 (   0.090s) [main            ]                       :0     FATL| Signal: SIGABRT
Aborted

FEniCSx: 0.7.2 (installed via docker-container)
Ubuntu: 22.04

Thank you in advance!

With kind regards
Dejan

1 Like

I am also having a similar problem!

Many thanks,
Katie

I can’t reproduce that error with the debian or ubunta (PPA) packages.

$ python3 test.py 
$ ls -l 
total 260
-rw-r--r-- 1 root root 252408 Dec 11 19:23 Results.h5
-rw-r--r-- 1 root root   1504 Dec 11 19:23 Results.xdmf
-rw-r--r-- 1 root root    775 Dec 11 19:23 test.py

Looks like the binaries for the docker context need rebuilding.

What docker image are you using?

The image that I used is dolfinx/dolfinx:stable.

After running the container for the first time, I also executed the following commands:

export HDF5_MPI=β€œON”
export CC=mpicc
export HDF5_DIR=β€œ/usr/lib/x86_64-linux-gnu/hdf5/mpich/”
pip3 install --no-cache-dir --no-binary=h5py h5py meshio
pip3 install lxml
pip3 install tqdm
pip3 install pygmsh
pip3 install matplotlib
pip3 install pyvista
pip3 install pyvistaqt
pip3 install PyQt5
pip3 install ipygany

I just tested and the additional commands I mentioned have no influence on the error. So the error occurs even if the container is not changed.