Non-matching UFL cell and mesh cell shapes from XDMFFile mesh

Hi everyone,
I am quite new to FeniCSx, I have dolfinx 0.7.2 installed.

I am sharing a code below, which is creating a 1D mesh, exporting it as an XDMF file, and importing it back to build a FunctionSpace.

By running this code, I get the following error: ValueError: Non-matching UFL cell and mesh cell shapes.

Any ideas of what is causing this? Thank you in advance.

# FeniCSx
from basix.ufl import element, mixed_element
from dolfinx import mesh, fem 
from dolfinx.fem import Function, FunctionSpace
from dolfinx import io
from mpi4py import MPI


nel = 30                                         # number of elements per domain
msh = mesh.create_interval(comm=MPI.COMM_WORLD, nx=3*nel, points=(0, 3))


with io.XDMFFile(msh.comm, "./samples/mymesh.xdmf", "w") as xdmf:
    xdmf.write_mesh(msh)

with io.XDMFFile(MPI.COMM_WORLD, "./samples/mymesh.xdmf", "r") as xdmf:
    msh2 = xdmf.read_mesh()

finite_element = element("P", msh2.basix_cell(), 1)
V = FunctionSpace(msh2, finite_element)

I can’t pinpoint what the issue is, but I can tell you that your code runs correctly with 0.8.0. Simplest course of action would be to upgrade your dolfinx installation.

There was an issue with how basix compares elements in 0.7.x. There was some discussions regarding this in the #development channel on Slack with @Massimiliano_Leoni and @mscroggs. I think we concluded that it was the unset Lagrange variant (in C++) that caused an issue. I would advice you to upgrade to 0.8.x as Francesco points out, there shouldn’t be an issue there.