# Error reading gmsh file

**URL:** <https://community.freefem.org/t/error-reading-gmsh-file/3035>\
**Category:** General Discussion\
**Created:** [March 13, 2024, 11:47am UTC](https://community.freefem.org/t/error-reading-gmsh-file/3035 "2024-03-13T11:47:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [March 13, 2024, 11:47am UTC](https://community.freefem.org/t/error-reading-gmsh-file/3035/1 "2024-03-13T11:47:24Z")

</div>

Hello,

I’m trying to read a msh file and I’m getting the following error

```auto
 SetOfEdges4::add
overflow de la pile 24 24
 Fatal error in the mesh generator 888
  current line = 34
Meshing error: Bamg
 number : 888, 
Meshing error: Bamg
 number : 888, 
 err code 5 , mpirank 0

```

This is the file octogon\_Lshaped1.msh:

```auto
35 8 42
0.0000000000000000 0.0000000000000000 1
0.1666666666666667 0.0000000000000000 2
0.3333333333333333 0.0000000000000000 3
0.5000000000000000 0.0000000000000000 4
0.6666666666666666 0.0000000000000000 5
0.8333333333333333 0.0000000000000000 6
1.0000000000000000 0.0000000000000000 7
0.0000000000000000 0.2500000000000000 8
0.1666666666666667 0.2500000000000000 9
0.3333333333333333 0.2500000000000000 10
0.5000000000000000 0.2500000000000000 11
0.6666666666666666 0.2500000000000000 12
0.8333333333333333 0.2500000000000000 13
1.0000000000000000 0.2500000000000000 14
0.0000000000000000 0.5000000000000000 15
0.1666666666666667 0.5000000000000000 16
0.3333333333333333 0.5000000000000000 17
0.5000000000000000 0.5000000000000000 18
0.6666666666666666 0.5000000000000000 19
0.8333333333333333 0.5000000000000000 20
1.0000000000000000 0.5000000000000000 21
0.0000000000000000 0.7500000000000000 22
0.1666666666666667 0.7500000000000000 23
0.3333333333333333 0.7500000000000000 24
0.5000000000000000 0.7500000000000000 25
0.6666666666666666 0.7500000000000000 26
0.8333333333333333 0.7500000000000000 27
1.0000000000000000 0.7500000000000000 28
0.0000000000000000 1.0000000000000000 29
0.1666666666666667 1.0000000000000000 30
0.3333333333333333 1.0000000000000000 31
0.5000000000000000 1.0000000000000000 32
0.6666666666666666 1.0000000000000000 33
0.8333333333333333 1.0000000000000000 34
1.0000000000000000 1.0000000000000000 35
1 2 3 10 9 16 15 1
3 4 5 12 11 18 17 2
5 6 7 14 21 20 13 3
9 10 17 18 25 24 23 4
11 12 13 20 27 26 19 5
15 16 23 24 31 30 29 6
18 19 26 33 32 31 24 7
20 21 28 35 34 33 26 8
1 2 1 1
2 3 1 2
3 4 1 3
4 5 1 4
5 6 1 5
6 7 1 6
9 10 0 7
11 12 0 8
12 13 0 9
15 16 0 10
17 18 0 11
18 19 0 12
20 21 0 13
23 24 0 14
24 25 0 15
26 27 0 16
29 30 3 17
30 31 3 18
31 32 3 19
32 33 3 20
33 34 3 21
34 35 3 22
1 8 4 23
3 10 0 24
5 12 0 25
7 14 2 26
8 15 4 27
9 16 0 28
10 17 0 29
11 18 0 30
13 20 0 31
14 21 2 32
15 22 4 33
16 23 0 34
18 25 0 35
19 26 0 36
20 27 0 37
21 28 2 38
22 29 4 39
24 31 0 40
26 33 0 41
28 35 2 42

```

what I’m doing in the code:

```auto
mesh calP = readmesh("octogon_Lshaped1.msh");

```

anyone might know what I did wrong?

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [March 13, 2024, 11:50am UTC](https://community.freefem.org/t/error-reading-gmsh-file/3035/2 "2024-03-13T11:50:03Z")

</div>

The same with this file:

```auto
4 1 4
0.0000000000000000 0.0000000000000000 1
1.0000000000000000 0.0000000000000000 2
0.0000000000000000 1.0000000000000000 3
1.0000000000000000 1.0000000000000000 4
1 2 4 3 1
1 2 1 1
3 4 3 2
1 3 4 3
2 4 2 4

```

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [March 13, 2024, 11:57am UTC](https://community.freefem.org/t/error-reading-gmsh-file/3035/3 "2024-03-13T11:57:36Z")

</div>

Are you using the gmshload function?  
[https://doc.freefem.org/references/external-libraries.html#gmsh](https://doc.freefem.org/references/external-libraries.html#gmsh)

Make sure you’re saving your gmsh msh file with the old version 2.2.

Note: There are better approaches for compatibility with gmsh using DMPlex if you’re using PETSc.

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [March 13, 2024, 12:01pm UTC](https://community.freefem.org/t/error-reading-gmsh-file/3035/4 "2024-03-13T12:01:37Z")

</div>

No, I’m using readmesh

I did a shell script to transform a mesh generate by triangle to a msh file as show in here [Mesh Generation](https://doc.freefem.org/documentation/mesh-generation.html#d-case)

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [March 13, 2024, 12:02pm UTC](https://community.freefem.org/t/error-reading-gmsh-file/3035/5 "2024-03-13T12:02:56Z")

</div>

when I try I get the following:

```auto
 The points 3 and 4 are to close 
 The points 4 and 5 are to close 
 The points 5 and 6 are to close 
 The points 6 and 7 are to close 
 The points 7 and 8 are to close 
 The points 8 and 9 are to close 
 The points 9 and 10 are to close 
 The points 10 and 11 are to close 
 The points 11 and 12 are to close 
 The points 12 and 13 are to close 
mshptg bug 2 
 Sorry Error build delaunay triangle error = 2
  current line = 35
Exec error : Error mshptg8_
   -- number :1
Exec error : Error mshptg8_
   -- number :1
 err code 8 , mpirank 0

```

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [March 13, 2024, 1:09pm UTC](https://community.freefem.org/t/error-reading-gmsh-file/3035/6 "2024-03-13T13:09:32Z")

</div>

How did you produce your .msh file?  
At least, the short file of your second post is not respecting the format needed for readmesh, which is described in the freefem doc.  
A correct file corresponding to the unit square with two triangles is for example

```auto
4 2 4
0.0000000000000000 0.0000000000000000 1
1.0000000000000000 0.0000000000000000 2
0.0000000000000000 1.0000000000000000 3
1.0000000000000000 1.0000000000000000 4
1 2 4 0
1 4 3 0
1 2 1
2 4 2
4 3 3
3 1 4

```

---

<div class="post-metadata">

**Author:** ![larismartins](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/larismartins/32/2712_2.png) [@larismartins](https://community.freefem.org/u/larismartins)\
**Post date:** [March 13, 2024, 2:29pm UTC](https://community.freefem.org/t/error-reading-gmsh-file/3035/7 "2024-03-13T14:29:25Z")

</div>

Its from a unit\_quad file from triangle, the elemets as suposed to be squares  
The first file, the elements are L-shaped

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [March 14, 2024, 12:48pm UTC](https://community.freefem.org/t/error-reading-gmsh-file/3035/8 "2024-03-14T12:48:46Z")

</div>

Sorry but this file is not a FreeFem++ mesh file

the element must be triangle so with 4 value ( vertex number, and region number)  
not

1 2 3 10 9 16 15 1  
3 4 5 12 11 18 17 2  
5 6 7 14 21 20 13 3  
9 10 17 18 25 24 23 4  
11 12 13 20 27 26 19 5  
15 16 23 24 31 30 29 6  
18 19 26 33 32 31 24 7  
20 21 28 35 34 33 26 8

I think you make a missed a gmsh file
