# Meshio does not read Gmsh physical groups

**URL:** <https://fenicsproject.discourse.group/t/meshio-does-not-read-gmsh-physical-groups/5561>\
**Category:** mesh\
**Created:** [April 11, 2021, 4:03am UTC](https://fenicsproject.discourse.group/t/meshio-does-not-read-gmsh-physical-groups/5561 "2021-04-11T04:03:24Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![fen](https://avatars.discourse-cdn.com/v4/letter/f/b487fb/32.png) [@fen](https://fenicsproject.discourse.group/u/fen)\
**Post date:** [April 11, 2021, 2:10pm UTC](https://fenicsproject.discourse.group/t/meshio-does-not-read-gmsh-physical-groups/5561/5 "2021-04-11T14:10:17Z")

</div>

Thank you @bhaveshshrimali for your detailed response. My ultimate goal is to use gmsh API/pygmsh to generate the mesh, and solve in FEniCS. Since I have little to no knowledge of any of them, I had to divide them and learn step by step.

As to your suggestions

1. I tried the geo file. Your geo file opens OK in my Gmsh GUI 4.8.0. However I meshed the model, and exported to .msh. The same problems remain when I ran my python code: Meshio.read() can read ver2 msh file, but does not recognize physical groups; ver4 msh file cannot be properly read by Meshio.

2. I also tried to run your python/pygmsh code. I had to install pygmsh and gmsh to the FEniCS container following this thread ([Problem with installation of latest gmsh 4.6.0 via pip - #3 by Nexius](https://fenicsproject.discourse.group/t/problem-with-installation-of-latest-gmsh-4-6-0-via-pip/4078/3)). I could import meshio and pygmsh in container’s bash, but not directly in jupyter notebook (Jupyter did not find module of pygmsh). I did the following in Jupyter to be able to import gmsh and pygmsh. However there are errors about opencascade, see below.

```python
import sys
sys.path.append('/usr/local/gmsh-4.6.0-Linux64-sdk/lib') # have to add path manually to import gmsh
sys.path.append('/usr/local/gmsh-4.6.0-Linux64-sdk/bin')
import meshio
import gmsh
import pygmsh, os
import numpy as np

#geom = pygmsh.opencascade.Geometry() # pygmsh has no opencascade attribute
geom = pygmsh.geo.Geometry() # pygmsh.geo.Geometry() works
b1 = geom.add_box([0.0, 0.0, 0.0], [1.0, 1.0, 1.0]) # error: add_box() missing 4 required positional arguments: 'y0', 'y1', 'z0', and 'z1'

```

It seems pygmsh (v7.1.8) has no .opencascade, but .geo attribute. ‘add\_box’ needs 4 arguments. I have not yet started studying pygmsh/gmsh API but your code provides me a good point to start with.

At this point I will try to stick to 1), i.e. generate a mesh from Gmsh GUI with physical groups, and then use my python code to read (via meshio) and export to separate xdmf files. Any insights?

---

_[View the full topic](https://fenicsproject.discourse.group/t/meshio-does-not-read-gmsh-physical-groups/5561)._
