# Need help converting GMSH to FEniCS

**URL:** <https://fenicsproject.discourse.group/t/need-help-converting-gmsh-to-fenics/5192>\
**Category:** installation\
**Created:** [March 1, 2021, 4:07pm UTC](https://fenicsproject.discourse.group/t/need-help-converting-gmsh-to-fenics/5192 "2021-03-01T16:07:28Z")\
**Posts on this page:** 1\
**Showing post:** 54

<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:** [November 19, 2021, 11:06am UTC](https://fenicsproject.discourse.group/t/need-help-converting-gmsh-to-fenics/5192/54 "2021-11-19T11:06:54Z")

</div>

Please note that you have some errors in your `geo`-file, i.e.

> [@Ben\_Bird](#):
>
> Line(10) = {7, 7};  
> Line(10) = {7, 10};

Correcting these, and adding

```python
Physical Surface("surf", 1) = {2};

```

at the end, the following file (`mesh.geo`)

```auto
// Gmsh project created on Thu Nov 18 16:23:27 2021
SetFactory("OpenCASCADE");
Rectangle(1) = {0, 0, 0, 18, 6, 0};
Point(5) = {3, 2.8, 0, 0.05};
Point(6) = {3, 3.2, 0, 0.05};
Point(7) = {3.3464, 3.4, 0, 0.05};
Point(8) = {3.3464, 2.6, 0, 0.05};
Point(9) = {3.6928, 2.8, 0, 0.05};
Point(10) = {3.6928, 3.2, 0, 0.05};
Point(11) = {3.6928, 3.2, 0, 0.05};
Line(5) = {6, 7};
Line(6) = {10, 9};
Line(7) = {9, 8};
Line(8) = {8, 5};
Line(9) = {5, 6};
Line(10) = {7, 10};
Curve Loop(2) = {4, 1, 2, 3};
Curve Loop(3) = {5, 10, 6, 7, 8, 9};
Plane Surface(2) = {2, 3};
Physical Curve("inlet", 11) = {4};
Physical Curve("outlet", 12) = {2};
Physical Curve("top", 13) = {3};
Physical Curve("bottom", 14) = {1};
Physical Curve("hex", 15) = {5, 6, 7, 8, 9, 10};
Physical Point("points", 16) = {4, 1, 3, 2, 5, 6, 7, 10, 9, 8};
Physical Curve("curves", 17) = {4, 3, 1, 2, 9, 5, 8, 10, 6, 7};
Physical Surface("surf", 1) = {2};

```

can be read and converted with:

```auto
import meshio
import numpy
def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    out_mesh = meshio.Mesh(points=mesh.points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
    if prune_z:
        out_mesh.prune_z_0()
    return out_mesh

mesh = meshio.read("mesh.msh")

mesh_out = create_mesh(mesh, "triangle", prune_z=True)
meshio.write("mesh.xdmf", mesh_out)

```

---

_[View the full topic](https://fenicsproject.discourse.group/t/need-help-converting-gmsh-to-fenics/5192)._
