# Error converting mesh from GMSH to DOLFINx

**URL:** <https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554>\
**Category:** mesh\
**Created:** [June 20, 2023, 8:55am UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554 "2023-06-20T08:55:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giulio\_Pelenghi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/giulio_pelenghi/32/5239_2.png) [@Giulio\_Pelenghi](https://fenicsproject.discourse.group/u/Giulio_Pelenghi)\
**Post date:** [June 20, 2023, 8:55am UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/1 "2023-06-20T08:55:54Z")

</div>

I’m running one of the base tutorials by @dokken (deflection of a membrane). I’m using WSL (Ubuntu 22.04.2 LTS distro) with minconda and vscode as interface, here are the versions of the relevant packages:

```auto
fenics-basix 0.6.0 py310hdf3cbec_0 conda-forge
fenics-dolfinx 0.6.0 py310h25dff07_104 conda-forge
fenics-ffcx 0.6.0 pyh56297ac_0 conda-forge
fenics-libbasix 0.6.0 h1284905_0 conda-forge
fenics-libdolfinx 0.6.0 h67f7cd0_104 conda-forge
fenics-ufcx 0.6.0 h56297ac_0 conda-forge
fenics-ufl 2023.1.1 pyhd8ed1ab_1 conda-forge
gmsh 4.11.1 h28bb747_2 conda-forge
mpi 1.0 openmpi conda-forge
mpi4py 3.1.4 py310h6075a6b_0 conda-forge
python 3.10.11 he550d4f_0_cpython conda-forge
python-gmsh 4.11.1 h57928b3_2 conda-forge

```

The minimal working example is:

```python
import gmsh
from dolfinx.io import gmshio
from mpi4py import MPI

# meshing example taken from https://jsdokken.com/dolfinx-tutorial/chapter1/membrane_code.html
gmsh.initialize()
membrane = gmsh.model.occ.addDisk(0, 0, 0, 1, 1)
gmsh.model.occ.synchronize()
gdim = 2
gmsh.model.addPhysicalGroup(gdim, [membrane], 1)
gmsh.model.mesh.generate(gdim)

gmsh_model_rank = 0
mesh_comm = MPI.COMM_WORLD
domain, cell_markers, facet_markers = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank, gdim=2)
gmsh.finalize()

```

I get the following error:

```auto
Traceback (most recent call last):
  File "/home/giulio/paraffinator/meshingTest.py", line 15, in <module>
    domain, cell_markers, facet_markers = gmshio.model_to_mesh(model=gmsh.model, comm=mesh_comm, rank=gmsh_model_rank, gdim=2)
  File "/home/giulio/miniconda3/envs/new-env/lib/python3.10/site-packages/dolfinx/io/gmshio.py", line 250, in model_to_mesh
    mesh = create_mesh(comm, cells, x[:, :gdim], ufl_domain, partitioner)
  File "/home/giulio/miniconda3/envs/new-env/lib/python3.10/site-packages/dolfinx/mesh.py", line 177, in create_mesh
    cmap = _cpp.fem.CoordinateElement(_uflcell_to_dolfinxcell[cell_shape], cell_degree, variant)
TypeError: __init__ (): incompatible constructor arguments. The following argument types are supported:
    1. dolfinx.cpp.fem.CoordinateElement(celltype: dolfinx.cpp.mesh.CellType, degree: int)
    2. dolfinx.cpp.fem.CoordinateElement(celltype: dolfinx.cpp.mesh.CellType, degree: int, variant: basix::element::lagrange_variant)

Invoked with: <CellType.triangle: 3>, 1, <LagrangeVariant.equispaced: 0>

```

Pylance also displays the error on gmsh.model:

```auto
Argument of type "Type[model]" cannot be assigned to parameter "model" of type "model" in function "model_to_mesh"
  "Type[type]" is incompatible with "Type[model]"

```

I’m new to python and dolfinx, so I apologize in advance if it’s a really stupid mistake

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 20, 2023, 9:25am UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/2 "2023-06-20T09:25:28Z")

</div>

Could you add the exact `conda` commands you used to install the library, as I cannot reproduce this with the 0.6.0 release through docker.

---

<div class="post-metadata">

**Author:** ![Giulio\_Pelenghi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/giulio_pelenghi/32/5239_2.png) [@Giulio\_Pelenghi](https://fenicsproject.discourse.group/u/Giulio_Pelenghi)\
**Post date:** [June 20, 2023, 9:39am UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/3 "2023-06-20T09:39:46Z")

</div>

I’ve installed everything again in a new environment, and the error is still the same. Here are the commands I used:

```auto
conda install -c conda-forge fenics-dolfinx
conda install -c conda-forge gmsh python-gmsh

```

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 20, 2023, 10:25am UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/4 "2023-06-20T10:25:58Z")

</div>

Could you try installing Gmsh prior to installing dolfinx?

---

<div class="post-metadata">

**Author:** ![Giulio\_Pelenghi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/giulio_pelenghi/32/5239_2.png) [@Giulio\_Pelenghi](https://fenicsproject.discourse.group/u/Giulio_Pelenghi)\
**Post date:** [June 20, 2023, 12:27pm UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/5 "2023-06-20T12:27:26Z")

</div>

The gmsh install went fine, but when it came to DOLFINx compatibility problems came up:

```auto
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - fenics-dolfinx -> python[version='2.7.*|3.5.*|3.6.*|3.6.12|3.6.12|3.7.10|3.7.10|3.7.12|3.8.12|3.8.16|3.9.16|>=3.11,<3.12.0a0|3.9.10|>=3.6,<3.7.0a0|3.7.9|3.6.9|3.6.9|3.6.9|>=2.7,<2.8.0a0|3.6.9|>=3.5,<3.6.0a0|3.4.*|>=3.7|3.9.*|3.10.*|3.8.*|3.7.*',build='0_73_pypy|1_73_pypy|2_73_pypy|3_73_pypy|4_73_pypy|5_73_pypy|5_73_pypy|0_73_pypy|0_73_pypy|1_73_pypy']
  - fenics-dolfinx -> python[version='>=3.10,<3.11.0a0|>=3.9,<3.10.0a0|>=3.8,<3.9.0a0|>=3.7,<3.8.0a0']

Your python: python=3.11

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with your system:

  - feature:/linux-64::__glibc==2.35=0
  - feature:|@/linux-64::__glibc==2.35=0

Your installed version is: 2.35

```

I guess I’ll use docker containers to avoid this or other compatibilty issues, unless there’s another simpler solution.  
Thank you in any case!

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [June 20, 2023, 12:52pm UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/6 "2023-06-20T12:52:04Z")

</div>

> [@Giulio\_Pelenghi](#):
>
> unless there’s another simpler solution

If you’re running it on an ubuntu system then why not use the ubuntu packages?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 20, 2023, 2:01pm UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/7 "2023-06-20T14:01:32Z")

</div>

I can reproduce the issue with conda.  
I’m not sure what happens there, seems like DOLFINx is not recognizing the Basix data-type

---

<div class="post-metadata">

**Author:** ![Giulio\_Pelenghi](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/giulio_pelenghi/32/5239_2.png) [@Giulio\_Pelenghi](https://fenicsproject.discourse.group/u/Giulio_Pelenghi)\
**Post date:** [June 21, 2023, 9:47am UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/8 "2023-06-21T09:47:50Z")

</div>

This solves the problem indeed. Thank you all!  
It’s not as optimal as keeping environments but it’s enough for my use case.

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/minrk/32/3866_2.png) [@minrk](https://fenicsproject.discourse.group/u/minrk)\
**Post date:** [June 21, 2023, 11:38am UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/9 "2023-06-21T11:38:43Z")

</div>

I tracked it down to the pybind11 ABI changing when the compiler version changes, so dolfinx must be compiled with the same compiler version as basix, and dolfinx build 102 upgraded to gcc 12, while basix has not yet been rebuilt with gcc 12. I’m still not really sure why no tests had failed, but gmsh in particular is not exercised in the dolfinx package.

So for now you can select `fenics-dolfinx=0.6.0=*_101` to choose the build that works.

I’ll upload fixed builds of basix and dolfinx to conda-forge soon.

---

<div class="post-metadata">

**Author:** ![Rui\_Fang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rui_fang/32/5226_2.png) [@Rui\_Fang](https://fenicsproject.discourse.group/u/Rui_Fang)\
**Post date:** [June 22, 2023, 3:06am UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/10 "2023-06-22T03:06:55Z")

</div>

I am using linux and I install dolfinx use conda but it also give the same issue. I did the following:  
./mamba install -n fenicsx-env -c conda-forge fenics-dolfinx mpich pyvista gmsh python-gmsh

How to make sure they are compatible? Thank you

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 23, 2023, 5:08am UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/11 "2023-06-23T05:08:34Z")

</div>

As stated by Min above, you should call  
`mamba install -n fenicsx-env -c conda-forge fenics-dolfinx=0.6.0=*_101`  
(With your additional dependencies after this).

---

<div class="post-metadata">

**Author:** ![Rui\_Fang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rui_fang/32/5226_2.png) [@Rui\_Fang](https://fenicsproject.discourse.group/u/Rui_Fang)\
**Post date:** [July 13, 2023, 5:08pm UTC](https://fenicsproject.discourse.group/t/error-converting-mesh-from-gmsh-to-dolfinx/11554/12 "2023-07-13T17:08:44Z")

</div>

> [@dokken](#):
>
> enicsx-env -c conda-forge fenics-dolfinx=0.6.0=\*\_101

I tried the thing you recommended, still not working.

Here is what I did:  
./mamba install -n fenicsx-env -c conda-forge fenics-dolfinx=0.6.0=\*\_101 mpich pyvista gmsh python-gmsh pip adios2 numba  
then I go to the virtual environment I created then the bin:  
./pip install git+https://github.com/jorgensd/adios4dolfinx@v0.1.0

The error is:  
Traceback (most recent call last):  
File “write\_checking.py”, line 16, in   
adx.write\_mesh(domain, mesh\_checkpoint\_file, engine=“BP4”)  
File “miniconda3/envs/fenicsx-env-new/lib/python3.10/site-packages/adios4dolfinx/checkpointing.py”, line 53, in write\_mesh  
io.DefineAttribute(“LagrangeVariant”, np.array([mesh.geometry.cmap.variant], dtype=np.int32))  
TypeError: Unable to convert function return value to a Python type! The signature was  
(arg0: dolfinx.cpp.fem.CoordinateElement) → basix::element::lagrange\_variant

My old dolfinx 0.6 installed on my laptop works well for the mesh and adios, I believe there is some change of newer dolfinx 0.6. I couldn’t run my code on my laptop because I am running a three D test, need more power, so I have to make sure everything is working on my virtual environment. Could you please help em with that?  
Thank you so much!
