Why does the `'Mesh' object layout differ from` `mesh.create_unit_square`?

Hello,

I am trying to follow the tutorial of
DOLFINx
, but when I
got to

A [0,1]\times[0,1] mesh distributed among processes

from mpi4py import MPI
from dolfinx import mesh

domain = mesh.create_unit_square(
    MPI.COMM_WORLD, 8, 8, mesh.CellType.quadrilateral)

, it showed the message

Traceback (most recent call last):
  File "<string>", line 17, in __PYTHON_EL_eval
  File "<string>", line 12, in <module>
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.11/site-packages/dolfinx/mesh.py", line 417, in create_unit_square
    return create_rectangle(comm, [np.array([0.0, 0.0]),
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dolfinx/mesh.py", line 392, in create_rectangle
    return Mesh.from_cpp(mesh, domain)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dolfinx/mesh.py", line 58, in from_cpp
    obj.__class__ = Mesh
    ^^^^^^^^^^^^^
TypeError: __class__ assignment: 'Mesh' object layout differs from 'dolfinx.cpp.mesh.Mesh'

How do I solve it? Thanks.

These may be related

https://github.com/FEniCS/dolfinx/issues/2423
https://github.com/FEniCS/dolfinx/pull/2500
https://github.com/FEniCS/dolfinx/issues/2519

Software

* FEniCSx software
dolfinx 0.6.0_r27402.24f86a9.log
basix 0.6.0_r922.36fb8a4
ufl 2023.1.1.post0_r3524.512ee20
ffcx 0.6.0_r7049.7fdc60f

* Dependencies
python 3.11.5
numpy 1.26.0
petsc 3.19.5.1171.g37df9106526-1
hdf5-openmpi 1.14.2-1
boost 1.83.0-2
adios2 2.8.3-5
scotch 7.0.4-1
pybind11 2.11.1-1
python-build 1.0.1-1
python-cffi 1.15.1-4
python-cppimport 22.08.02.r6.g0849d17-1
python-installer 0.7.0-3
python-pytest 7.4.2-1
python-scikit-build 0.17.6-1
python-setuptools 1:68.0.0-1
python-wheel 0.40.0-3
xtensor 0.24.0-2
xtensor-blas 0.20.0-1

* Operating system
Arch Linux 6.5.4-arch2-1

Hi, I could run your code in dolfinx, although I am not sure how to fix the problem :slight_smile:

1 Like

Python 3.11 support was added after the 0.6.0 release. To use dolfinx with Python 3.11 you need to work on the main branch.

1 Like

I appreciate the effort (see the solution below)