Gmsh import error/ Keyword "tetra"

hello all,

I have created a 3D mesh with gmsh.
Now when I want to convert it from .msh to .xdmf I get the following error:

Traceback (most recent call last):
File “/home/noya/hallo.py”, line 5, in
tet_data = msh.cell_data_dict[“gmsh:physical”][“tetra”]
KeyError: ‘tetra’

from fenics import*
import meshio

msh = meshio.read("torus.msh")
tet_data = msh.cell_data_dict["gmsh:physical"]["tetra"]
tri_data = msh.cell_data_dict["gmsh:physical"]["triangle"]

How can I fix it? What do I wrong?

Best regards,
Noya

Start by printing: msh.cell_data_dict, then you can see what contents you have in it. As long as you haven’t provided us with how you generated the mesh, there isn’t much we can do to help you.

Okay, thank you.

the output from print(msh.cell_data_dict) is

{‘gmsh:physical’: {‘triangle6’: array([4, 4, 4, …, 3, 3, 3]), ‘tetra10’: array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1])}, ‘gmsh:geometrical’: {‘triangle6’: array([1, 1, 1, …, 8, 8, 8]), ‘tetra10’: array([2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3])}}

I cannot input the msh file cause it has to much characters
I have done the following :
Bildschirmfoto von 2021-08-19 21-59-45
Bildschirmfoto von 2021-08-19 21-59-48
and created it before with Mesh 3; in the geo file

I have now replaced each tetra with tetra10 and each triangle with triangle6. now the previous error is gone, but I get the error

Traceback (most recent call last):
File “/home/noya/hallo.py”, line 30, in
mshfile.read(mesh)
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at


*** fenics-support@googlegroups.com


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to recognise cell type.
*** Reason: Unknown value “tetrahedron_10”.
*** Where: This error was encountered inside XDMFFile.cpp.
*** Process: 0


*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: unknown
*** -----------------------

mesh = Mesh()
with XDMFFile("mesht.xdmf") as mshfile:
    mshfile.read(mesh)

Are there to much elements?

best regards, noya

Dolfin does not support second order geometries from GMSH, you need to use dolfinx as menitioned here: Cell type is tetra10
and here: Import second order mesh to FEnics using mesh.io - #2 by dokken

Note that you do not need a second order mesh to use higher order function spaces.

Thank you.
But why have I second order elements? I set in the .geo-file Mesh.ElementOrder = 1 . I’m a little bit confused.

Edit: Got it. Thank you. You should also save the mesh again and not only the geo-file. :woman_facepalming: