# 2D Gmsh mesh saved/recognized as 3D mesh

**URL:** <https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357>\
**Category:** General Discussion\
**Created:** [March 27, 2023, 9:41am UTC](https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357 "2023-03-27T09:41:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![etj](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@etj](https://community.freefem.org/u/etj)\
**Post date:** [March 27, 2023, 9:41am UTC](https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357/1 "2023-03-27T09:41:17Z")

</div>

Hello,

I am trying to build a simple 2D mesh with Gmsh and use it in FreeFem.

I save the mesh with File → Export → Mesh - INRIA Medit (\*.mesh), with “Physical entities” and “Save all elements” checked. I obtain a mesh file that start like this:

> MeshVersionFormatted 2  
> Dimension  
> 3  
> Vertices  
> 18144  
> -9 1.5 0 1  
> -9 1 0 2  
> 0 1 0 3  
> 0 0 0 4  
> …

If I try to import it in FreeFem v.3.38 with `mesh Th = readmesh("xxx.mesh");` I get his error message:

> ReadMesh: Dimension \<\> 2  
> In file …/data/gamma0.666667\_ER3//msh\_n128//mesh\_Li9\_Lo90\_n4\_128\_ER3.mesh, Erreur Lecture 0, good=0, bad=0, fail=0, eof=0 Line 19835  
> the next character :  
> 34603  
> 8250 11606 15509 0  
> current line = 31  
> Exec error : Mesh IO Error  
> – number :1  
> Exec error : Mesh IO Error  
> – number :1  
> err code 7 , mpirank 0

So it seems that there is a problem of dimensions (2D vs 3D). What should I modify to get it working? Thank you in advance.

---

<div class="post-metadata">

**Author:** ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)\
**Post date:** [March 27, 2023, 1:37pm UTC](https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357/2 "2023-03-27T13:37:03Z")

</div>

Without either the FreeFem or the GMSH files it is hard to help.  
However, using a newer FreeFem version might solves the problem.

---

<div class="post-metadata">

**Author:** ![etj](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@etj](https://community.freefem.org/u/etj)\
**Post date:** [March 27, 2023, 2:08pm UTC](https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357/3 "2023-03-27T14:08:46Z")

</div>

Hi, thanks for your reply. I have the same error with FreeFem v4.11.

Here are the .geo and .mesh files: [gmsh\_mesh.zip](https://community.freefem.org/uploads/short-url/gvGdoekxurpHvhKcRzb3ZOH5vd2.zip) (14.8 KB)

---

<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 27, 2023, 2:29pm UTC](https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357/4 "2023-03-27T14:29:41Z")

</div>

I believe FreeFEM `readmesh` automatically assumes .mesh extensions are 3D. Try saving this with a .msh extension.

---

<div class="post-metadata">

**Author:** ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)\
**Post date:** [March 27, 2023, 2:49pm UTC](https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357/5 "2023-03-27T14:49:35Z")

</div>

@cmd is right. Save in .msh format, using the version 2 ASCII option.

---

<div class="post-metadata">

**Author:** ![etj](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@etj](https://community.freefem.org/u/etj)\
**Post date:** [March 27, 2023, 3:38pm UTC](https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357/6 "2023-03-27T15:38:01Z")

</div>

I see. So now I am saving with File → Export → Guess from extension → test.msh → Version 2 ASCII. I leave both “Save all elements” and “Save parametric coordinates” unchecked.

Reading the mesh with `Th = gmshload(meshdir+"/test.msh");` seems to work. Also, the output of `cout << labels(Th) << endl;` is:

> 6  
> 2 3 4 11 12 13

which seems to agree with the labels (2, 3, 4, 11, 12, 13) I assigned to the boundaries in Gmesh (with e.g. `Physical Line(11) = {2};`).

Thank you both.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [March 27, 2023, 3:48pm UTC](https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357/7 "2023-03-27T15:48:04Z")

</div>

You can save to version 4 binary and use `DM dm("your_mesh.mesh"); mesh converted = DM;` as well, if you are using `load "PETSc"`.

---

<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 30, 2023, 12:51pm UTC](https://community.freefem.org/t/2d-gmsh-mesh-saved-recognized-as-3d-mesh/2357/8 "2023-03-30T12:51:13Z")

</div>

The initial problem is simple, gmsh build only 3d mesh of type “mesh”

see lines in file,

Dimension  
3

so the simple way is to read in  
meshS ThS=readmeshS( " …");  
mesh Th2 = movemesh(Thf,transfo=[x,y]); // flatten the mesh,
