*** Unable to find cells of supported type. when converting from Gmsh format (.msh, .gmsh) to DOLFIN XML format

Hi, I am trying to convert the following msh file to DOLFIN XML:

$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
6
2 6 "contorno"
3 1 "medula"
3 2 "hueso"
3 3 "musculo"
3 4 "grasa"
3 5 "piel"
$EndPhysicalNames
$Nodes
45422
1 47 0 0
2 45 0 0
3 42 0 0
4 34 14 0
5 -6 6 0
6 -14 6 0
7 26 14 0
8 -14 6 175
9 26 14 175
10 34 14 175
11 -6 6 175
12 42 0 175 and so on

and I get the following error from the command dolfin-convert my_mesh.msh my_mesh.xml:

Converting from Gmsh format (.msh, .gmsh) to DOLFIN XML format
*** Unable to find cells of supported type.

Hi,
Dolfin-convert is no longer maintained. I suggest you use meshio to convert your mesh:

Hi,
I get the same error as @siriusf when converting my gmsh mesh to xml files.
I used the code you sent using meshio, but I get the following error for the part msh.cells[“tetra”]:


TypeError Traceback (most recent call last)
Cell In[97], line 6
1 import meshio
3 msh = meshio.read(“beam.msh”)
----> 6 meshio.write(“mesh.xdmf”, meshio.Mesh(points=msh.points, cells={“tetra”: msh.cells[“tetra”]}))
7 meshio.write(“mf.xdmf”, meshio.Mesh(points=msh.points, cells={“triangle”: msh.cells[“triangle”]},
8 cell_data={“triangle”: {“name_to_read”: msh.cell_data[“triangle”][“gmsh:physical”]}}))
9 meshio.write(“cf.xdmf”, meshio.Mesh(
10 points=msh.points, cells={“tetra”: msh.cells[“tetra”]},
11 cell_data={“tetra”: {“name_to_read”:
12 msh.cell_data[“tetra”][“gmsh:physical”]}}))

TypeError: list indices must be integers or slices, not str

Can you help me with this?

That post is 4 years old, and has many updated posts for newer versions below in the same thread. You could also follow: Mesh generation and conversion with GMSH and PYGMSH | Jørgen S. Dokken
which has the latest syntax.

Thank you for your reply. I used the one you sent as well but I get the error:

ValueError Traceback (most recent call last)
Cell In[111], line 1
----> 1 line_mesh = create_mesh(mesh_from_file, “line”, prune_z=True)
2 meshio.write(“new_facet_mesh.xdmf”, line_mesh)
4 triangle_mesh = create_mesh(mesh_from_file, “triangle”, prune_z=True)

Cell In[110], line 4, in create_mesh(mesh, cell_type, prune_z)
2 def create_mesh(mesh, cell_type, prune_z=False):
3 cells = mesh.get_cells_type(cell_type)
----> 4 cell_data = mesh.get_cell_data(“gmsh:physical”, cell_type)
5 points = mesh.points[:,:2] if prune_z else mesh.points
6 out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={“name_to_read”:[cell_data]})

File /opt/anaconda3/envs/fenicss/lib/python3.11/site-packages/meshio/_mesh.py:249, in Mesh.get_cell_data(self, name, cell_type)
248 def get_cell_data(self, name: str, cell_type: str):
→ 249 return np.concatenate(
250 [d for c, d in zip(self.cells, self.cell_data[name]) if c.type == cell_type]
251 )

File <array_function internals>:200, in concatenate(*args, **kwargs)

ValueError: need at least one array to concatenate


my gmsh mesh file is looks correct which is:

$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
3
2 5 “Fixed”
2 6 “Force”
3 7 “beam”
$EndPhysicalNames
$Nodes
4410
1 0 0 5
2 1.000000003627494e-15 1 5
3 4.163336342344337e-16 0.75 5
4 2.775557561562891e-16 0.5 5
5 1.387778780781446e-16 0.25 5
6 1 0 5
7 0.25 0 5
8 0.5 0 5
9 0.75 0 5
10 1 1 5
11 1 0.25 5
12 1 0.5 5
13 1 0.75 5
14 0.75 1 5
15 0.5 1 5
16 0.25 1 5
17 0.6339163780212402 0.4695656597614288 5
18 0.3135612607002258 0.4157798588275909 5
19 0.437676876783371 0.6760674715042114 5
20 0.5522602200508118 0.2255466431379318 5
.
.
.

Please read the post with some care. Each of the create_mesh statements takes in a cell_type.
In your case, as it seems like your mesh is 3D (ie tetrahedral cells and triangular facets), you should use the cell_type: triangle and tetra instead of line and triangle.

Thank you dear @dokken . I could create the xdmf files for the fenics.
Can you help me with implementing the BCs? I read different things here but I got confused.
In my .msh file I have these physical regions:
2 4010 “RV”
2 4011 “LV”
2 4012 “Fix”
3 4013 “Vol”
I need to add pressure to the first two surfaces and make the third one fixed.
Thank you so much for your help.

Without having the xdmf file, and the script you are trying to use, i cannot really help you any further.

Hi, dokken,

Thank you for your pygmsh_tutorial. I have a small problem, when I run this tutorial, there is an error: AttributeError: module ‘pygmsh’ has no attribute ‘geo’. Could you help me fix it?

What version of pygmsh are you using?

I use the osx-64 v6.1.1 installed by anacodna.

Update your version of pygmsh, as that release is ~3.5 years old.