# [Gmsh] surface mesh coarsening

Hans Dierckx h.dierckx at kuleuven.be
Mon Apr 13 21:50:45 CEST 2020

```Dear all,

With the help of Christophe Geuzaine and the gmsh FAQ, I was able to create a tetrahedral mesh from a mask file (3D boolean matrix with 0=outside, 1=inside) by combining matlab and gmesh.
For future reference, I summarize my workflow. Perhaps it can be useful to others. Most likely, it can be further optimized.

Best regards,
Hans

Step-by-step guide to convert a mask in matlab to a tetrahedral mesh in matlab, using gmesh:

1) Create a surface mesh in matlab and save it as a stl file
--
[f,v] = isosurface(mask, 0.2);
stlwrite2('heart_sm2.stl', f,v);
--
stlwrite2 can be found on matlab central.

Smoothing and putting a lower threshold helps to avoid some mesh errors in highly curved regions later on.

2)  Remesh the surface mesh using gmsh:
(After support from gmsh developer Christophe Geuzaine, thank you!)

On the command line / in terminal do:

\$ gmsh heart_sm2.stl -reparam 180
This means reparameterising the mesh, dividing it in regions when the angle between adjacent faces is smaller/larger than 180 degrees(?). This seems to be mostly useful for cubes etc. since the faces are then stored separately.
It makes filename.msh.
If you want to see it, open the GUI and in the top bar: file  > open > ... select this .msh file

Then in command window:
\$ gmsh heart_sm2.msh -clcurv 2 -2 -o heart_sm2_2.msh

This remeshes the surface according to curvature (-clcurv). The higher the number that follows, the more elements are created. I put it as low as possible without getting errors. (-clcurv 1 did not work).

-2 argument means meshing in 2D, so it creates edges and faces. We cannot do a 3D mesh here, another step is needed.

-o heart_sm2_2.msh : output, otherwise the previous msh file is overwritten.

3) Make gmsh recognize the interior region as the part to be meshed with tetrahedra
(see gmsh FAQs)

open the lastly created heart_sm2_2.msh in the GUI and do file > export as .stl file.

then, create a gmsh script to add the volume. E.g. make a file "heart_sm2_2.geo" containing:

Merge "heart_sm2_2.stl";
Surface Loop(1) = {1};
Volume(1) = {1};

Then open this script in gmesh GUI: file > open > heart_sm2.2.geo.

Now gmsh recognizes that there is an interior.

4) Create and export the tetrahedral mesh

In the GUI, with the geo-file opened (and the 2D mesh visible): in the left navigation bar, click Modules > Mesh > 3D and the 3D mesh generation starts.
Thereafter you may want to click 'optimize 3D' just beneath.

Finally, in order to work with it in matlab: file > export > as matlab file (or use extension .m), e.g. heart_sm2_2.m

In matlab, run the file as a script

heart_sm2_2;

which creates a structure called 'msh' listing the vertices, edges, faces and tetrahedra.

From: Hans Dierckx <h.dierckx at kuleuven.be>
Date: Wednesday, 18 March 2020 at 08:56
To: "gmsh at onelab.info" <gmsh at onelab.info>
Subject: surface mesh coarsening

Dear all,

Can someone explain me how to use gmesh to coarsen a closed surface mesh? I attach a simple geometry as test data.
I tried in vain in the GUI to put ‘options > mesh > element size’ to a value bigger than one.
The data I want to apply it to is a heart geometry which has originally 10^6 vertices and 5 10^5 faces, which should be reduced to approx. 500 faces.

Thank you very much for your assistance.

Hans Dierckx
Leuven University

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://onelab.info/pipermail/gmsh/attachments/20200413/9e8178e0/attachment.html>
```