# I use DMplex for reading GMSH meshes, how to save in Freefem format?

**URL:** <https://community.freefem.org/t/i-use-dmplex-for-reading-gmsh-meshes-how-to-save-in-freefem-format/1861>\
**Category:** General Discussion\
**Created:** [June 30, 2022, 4:32pm UTC](https://community.freefem.org/t/i-use-dmplex-for-reading-gmsh-meshes-how-to-save-in-freefem-format/1861 "2022-06-30T16:32:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![felric](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@felric](https://community.freefem.org/u/felric)\
**Post date:** [June 30, 2022, 4:32pm UTC](https://community.freefem.org/t/i-use-dmplex-for-reading-gmsh-meshes-how-to-save-in-freefem-format/1861/1 "2022-06-30T16:32:05Z")

</div>

Dear sir,

I need to import a GMSH mesh comprising some physical volumes/surfaces.  
Following your suggestion, I tried to use DMplex instead of standard freefem mesh loader, as often suggested by you.  
Now, after some effort I was able to generate a mesh (version 4.1) and apparently no errors reading it with DMplex. However, I am unable to save the mesh in Freefem format: if I add the line:

savemesh(Th,“meshSrc.mesh”);

then segmentation fault appears.

Please notice that since PETSc seems to require MPI, and since I am working on Windows, I used:  
“mpiexec.exe -np 2 FreeFem+±mpi.exe meshtest5.edp”

Thanks very much in advance  
Riccardo

[meshtest5.edp](https://community.freefem.org/uploads/short-url/baSJVDvSXmQhMT4QdEi0seQsVWW.edp) (668 Bytes)  
[tritrasd.zip](https://community.freefem.org/uploads/short-url/6PWJ60IUHSRrhL91Bcgr95H3mIP.zip) (215.7 KB)

---

<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:** [June 30, 2022, 8:28pm UTC](https://community.freefem.org/t/i-use-dmplex-for-reading-gmsh-meshes-how-to-save-in-freefem-format/1861/2 "2022-06-30T20:28:21Z")

</div>

Hi,

I tested you code and I get no segmentation fault. I am using FreeFem v4.11. If you are using an older FreeFem version, I suggest you consider upgrading it. Otherwise, I have no idea what might causes the segmentation fault.

---

<div class="post-metadata">

**Author:** ![felric](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@felric](https://community.freefem.org/u/felric)\
**Post date:** [June 30, 2022, 10:55pm UTC](https://community.freefem.org/t/i-use-dmplex-for-reading-gmsh-meshes-how-to-save-in-freefem-format/1861/3 "2022-06-30T22:55:50Z")

</div>

Thanks for your prompt reply!  
Yes, I am using version 4.11 that I downloaded few days ago.  
More precisely, I downloaded the PETSc version, already in binary format, for Windows.  
I tried with:

> mpiexec.exe -np 2 FreeFem+±mpi.exe meshtest5.edp  
> FreeFem+±mpi.exe meshtest5.edp

from both PowerShell and Command Prompt. Same answer:

> Number of triangle(s) = 14169  
> Mesh area = 60978.2  
> Border length = 12548.4  
> [0]PETSC ERROR: ------------------------------------------------------------------------  
> [0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range […]

BUT I ALSO DISCOVERED THAT I HAVE THE SAME PROBLEM ON ANY 3D MESH.  
HERE A VERY SIMPLE EXAMPLE:

This FAILS with seg fault, creating a file “meshCubeDiff.mesh” with size equal to zero:

> load “PETSc” // PETSc plugin  
> macro dimension()3// EOM // 2D or 3D  
> include “macro\_ddm.idp” // additional DDM functions  
> int[int] LL = [1,2, 1,2, 1,1];  
> mesh3 Tht = cube(10,10,10, [x, y, z], label = LL); // global mesh  
> savemesh(Tht,“meshCubeDiff.mesh”);

However THIS WORKS LIKE A CHARM (PERFECTLY), creating two mesh files:

> load “PETSc” // PETSc plugin  
> macro dimension()2// EOM // 2D or 3D  
> include “macro\_ddm.idp” // additional DDM functions  
> mesh Th2D = square(50, 10, [5 \* x, y]);  
> savemesh(Th2D,“meshSquareDiff.mesh”);

THE ONLY DIFFERENCE I SEE IS THAT THE FIRST IS A 3D MESH WHILE THE SECOND IS A 2D MESH.  
[Square.edp](https://community.freefem.org/uploads/short-url/zJLyOgaaj5sRn2YgRofG1lNYMYj.edp) (313 Bytes)  
[Cube.edp](https://community.freefem.org/uploads/short-url/1HsKWxU5ccWeuO8i5HaXgj4blgc.edp) (364 Bytes)

These are very simple examples.  
Do you see the same results?  
Thanks again  
Best regards  
Riccardo

---

<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:** [July 1, 2022, 6:16am UTC](https://community.freefem.org/t/i-use-dmplex-for-reading-gmsh-meshes-how-to-save-in-freefem-format/1861/4 "2022-07-01T06:16:08Z")

</div>

This is a Windows-specific issue, I believe. Do you have access to another machine?

---

<div class="post-metadata">

**Author:** ![felric](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@felric](https://community.freefem.org/u/felric)\
**Post date:** [July 1, 2022, 5:28pm UTC](https://community.freefem.org/t/i-use-dmplex-for-reading-gmsh-meshes-how-to-save-in-freefem-format/1861/5 "2022-07-01T17:28:35Z")

</div>

Dear sir,  
I tried to reinstall freefem++ (“ **FreeFem+±4.11-win64-petsctest.exe** ”) but no change.

I have Ubuntu on a **Windows Subsystem for Linux** (WSL 2.0). I tried to build it. Everythings was fine, until it failed to set an environment variable because it pointed to the Windows system (I guess, because it is a subsystem).  
Finally the “make check” failed.

---

<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:** [July 1, 2022, 5:45pm UTC](https://community.freefem.org/t/i-use-dmplex-for-reading-gmsh-meshes-how-to-save-in-freefem-format/1861/6 "2022-07-01T17:45:55Z")

</div>

If you try on a non-Windows machine, you’ll see it works. I don’t know why it’s failing there, I don’t have a fix available, sorry.
