2D Gmsh mesh saved/recognized as 3D mesh

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.

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

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

Here are the .geo and .mesh files: gmsh_mesh.zip (14.8 KB)

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

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

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.

2 Likes

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".

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,

1 Like