# To replace Gmsh

**URL:** <https://community.freefem.org/t/to-replace-gmsh/3716>\
**Category:** General Discussion\
**Created:** [January 30, 2025, 4:10pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716 "2025-01-30T16:10:52Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [January 30, 2025, 4:10pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/1 "2025-01-30T16:10:52Z")

</div>

Hi all,

In FreeFEM I have problems reading meshes generated by Gmsh as soon as there are labelled surfaces (e.g. Physical Surface(“inlet”, 26) = {7};). Reading the posts in this forum, I have the feeling that no solution has been yet identified (?).  
Am I right concerning the problem with labelled surfaces in Gmsh (my version is v4.11.1) ?  
Is there another open source candidate to replace Gmsh ?

Thanks  
Dominique

---

<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:** [January 30, 2025, 5:19pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/2 "2025-01-30T17:19:28Z")

</div>

Could you please share a small mesh example reproducing the behavior?

---

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [January 31, 2025, 7:06am UTC](https://community.freefem.org/t/to-replace-gmsh/3716/3 "2025-01-31T07:06:03Z")

</div>

Below the gmsh geo file:

SetFactory(“OpenCASCADE”);

// Parameters  
r\_cylinder = 0.2; // Radius of the main cylinder  
h\_cylinder = 1.0; // Height of the main cylinder  
r\_inlet = 0.05; // Radius of the inlet pipe  
h\_inlet = 0.3; // Length of the inlet pipe  
r\_outlet\_gas = 0.04; // Radius of the gas outlet pipe  
h\_outlet\_gas = 0.4; // Length of the gas outlet pipe  
r\_outlet\_liquid = 0.04; // Radius of the liquid outlet pipe  
h\_outlet\_liquid = 0.3; // Length of the liquid outlet pipe

// Main cylinder  
Cylinder(1) = {0, 0, 0, 0, 0, h\_cylinder, r\_cylinder, 2\*Pi};

// Tangential inlet pipe  
inlet\_offset = r\_cylinder - r\_inlet; // Offset to ensure tangential alignment  
Cylinder(2) = {0, inlet\_offset, 2 \* h\_cylinder / 3, h\_inlet, 0, 0, r\_inlet, 2\*Pi};

// Gas outlet pipe  
//Cylinder(3) = {0, 0, h\_cylinder + h\_outlet\_gas, 0, 0, -h\_outlet\_gas, r\_outlet\_gas, 2_Pi};  
Cylinder(3) = {0, 0, h\_cylinder, 0, 0, h\_outlet\_gas, r\_outlet\_gas, 2_Pi};

// Liquid outlet pipe  
Cylinder(4) = {0, 0, -h\_outlet\_liquid, 0, 0, h\_outlet\_liquid, r\_outlet\_liquid, 2\*Pi};

BooleanUnion(20) = { Volume{1}; Delete; }{ Volume{2}; Delete; };  
BooleanUnion(21) = { Volume{20}; Delete; }{ Volume{3}; Delete; };  
BooleanUnion(22) = { Volume{21}; Delete; }{ Volume{4}; Delete; };

## Physical Surface(“inlet”, 26) = {7}; Physical Surface(“liqoutlet”, 28) = {8}; Physical Surface(“gasoutlet”, 23) = {9};

In freefem, I tried to read directly the msh file:

mesh3 Th = gmshload3(“glcc.msh”);

or to generate it:

lockOrientation = false;  
system(“gmsh -format msh22 -3 -o glcc.msh glcc.geo”);  
mesh3 Th = gmshload3(“glcc.msh”);  
lockOrientation = true;

Thanks

---

<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:** [January 31, 2025, 7:06am UTC](https://community.freefem.org/t/to-replace-gmsh/3716/4 "2025-01-31T07:06:25Z")

</div>

Can’t copy/paste your code =\> can’t help. Put everything in between code blocks.

---

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [January 31, 2025, 7:08am UTC](https://community.freefem.org/t/to-replace-gmsh/3716/5 "2025-01-31T07:08:15Z")

</div>

hoping it’s getting better

```auto
SetFactory("OpenCASCADE");

// Parameters
r_cylinder = 0.2; // Radius of the main cylinder
h_cylinder = 1.0; // Height of the main cylinder
r_inlet = 0.05; // Radius of the inlet pipe
h_inlet = 0.3; // Length of the inlet pipe
r_outlet_gas = 0.04; // Radius of the gas outlet pipe
h_outlet_gas = 0.4; // Length of the gas outlet pipe
r_outlet_liquid = 0.04; // Radius of the liquid outlet pipe
h_outlet_liquid = 0.3; // Length of the liquid outlet pipe

// Main cylinder
Cylinder(1) = {0, 0, 0, 0, 0, h_cylinder, r_cylinder, 2*Pi};

// Tangential inlet pipe
inlet_x_offset = r_cylinder - r_inlet; // Offset to ensure tangential alignment
Cylinder(2) = {0, inlet_x_offset, 2 * h_cylinder / 3, h_inlet, 0, 0, r_inlet, 2*Pi};

// Gas outlet pipe
//Cylinder(3) = {0, 0, h_cylinder + h_outlet_gas, 0, 0, -h_outlet_gas, r_outlet_gas, 2*Pi};
Cylinder(3) = {0, 0, h_cylinder, 0, 0, h_outlet_gas, r_outlet_gas, 2*Pi};

// Liquid outlet pipe
Cylinder(4) = {0, 0, -h_outlet_liquid, 0, 0, h_outlet_liquid, r_outlet_liquid, 2*Pi};

BooleanUnion(20) = { Volume{1}; Delete; }{ Volume{2}; Delete; };
BooleanUnion(21) = { Volume{20}; Delete; }{ Volume{3}; Delete; };
BooleanUnion(22) = { Volume{21}; Delete; }{ Volume{4}; Delete; };

Physical Surface("inlet", 26) = {7};
Physical Surface("liqoutlet", 28) = {8};
Physical Surface("gasoutlet", 23) = {9};

```

---

<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:** [January 31, 2025, 7:33am UTC](https://community.freefem.org/t/to-replace-gmsh/3716/6 "2025-01-31T07:33:01Z")

</div>

You have not defined the volume to mesh, so Gmsh is not producing a 3D mesh.

---

<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:** [January 31, 2025, 7:34am UTC](https://community.freefem.org/t/to-replace-gmsh/3716/7 "2025-01-31T07:34:57Z")

</div>

The surface is also not well-defined:

```auto
Info : - Creating surface mesh
Info : Found two duplicated facets.
Info : 1st: [62, 137, 142] #5
Info : 2nd: [62, 137, 142] #5
Error : Invalid boundary mesh (overlapping facets) on surface 5 surface 5
Error : No elements in volume 22 
Info : Done meshing 3D (Wall 0.00305525s, CPU 0.00282s)
Info : 183 nodes 436 elements
Error : ------------------------------
Error : Mesh generation error summary
Error : 0 warnings
Error : 2 errors
Error : Check the full log for details
Error : ------------------------------

```

---

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [January 31, 2025, 7:58am UTC](https://community.freefem.org/t/to-replace-gmsh/3716/8 "2025-01-31T07:58:16Z")

</div>

Thank prj, I’m going to investigate

---

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [January 31, 2025, 11:23am UTC](https://community.freefem.org/t/to-replace-gmsh/3716/9 "2025-01-31T11:23:06Z")

</div>

the code below does not provide errors. FreeFem is able to load, but it detects only one label instead of three:

```auto
SetFactory("OpenCASCADE");

DefineConstant[
    N = {10, Name "input/1N"},
    Li = {0.2, Name "input/2length inlet "},
    ri = {0.05, Name "input/3radius inlet "},   
    hi = {1.0, Name "input/4height inlet "},
    Lg = {0.2, Name "input/5length gas out "},
    rg = {0.05, Name "input/6radius gas out "},
    Ll = {0.2, Name "input/7length liquid out "},
    rl = {0.05, Name "input/8radius liquid out "},
    Lc = {1, Name "input/9length cylinder "},
    rc = {0.2, Name "input/10radius cylinder "}
];

Cylinder(1) = {0, 0, 0, 0, 0, Ll, rl, 2*Pi};
Cylinder(2) = {0, 0, Ll, 0, 0, Lc, rc, 2*Pi};
Cylinder(3) = {0, 0, Ll+Lc, 0, 0, Lg, rg, 2*Pi};
Cylinder(4) = {-Li, rc-ri, hi, Li, 0, 0, ri, 2*Pi};

//+
BooleanUnion(5) = { Volume{2}; Delete; }{ Volume{4}; Delete; };
BooleanUnion(6) = { Volume{5}; Delete; }{ Volume{1}; Delete; };
BooleanUnion(7) = { Volume{6}; Delete; }{ Volume{3}; Delete; };

//+
Physical Surface("inlet", 14) = {7};
Physical Surface("liquid", 15) = {8};
Physical Surface("gas", 16) = {9};

```

---

<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:** [January 31, 2025, 1:53pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/10 "2025-01-31T13:53:40Z")

</div>

You still have no physical volume, so this can’t be used for a `mesh3`.

---

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [January 31, 2025, 2:12pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/11 "2025-01-31T14:12:38Z")

</div>

same behavior when adding the following line :

```auto
Physical Volume("glcc", 17) = {7};

```

To check whether the labels are considered, I have written the following in the edp file:

```auto
int[int] labs = labels(Th);
cout << "List of labelled surfaces:" << endl;
for (int i = 0; i < labs.n; i++) {
    cout << "Label: " << labs[i] << endl;
}

```

---

<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:** [January 31, 2025, 2:42pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/12 "2025-01-31T14:42:13Z")

</div>

We are starting to get somewhere. Your mesh is not a closed surface, you are missing surface elements everywhere outside of your current three labels.

---

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [February 4, 2025, 8:27am UTC](https://community.freefem.org/t/to-replace-gmsh/3716/13 "2025-02-04T08:27:03Z")

</div>

prj, thanks for your feedback. Below a version where a volume is defined, including all the elements (I think so), but still only one label detected with freefem++.

```auto
SetFactory("OpenCASCADE");

DefineConstant[
    N = {10, Name "input/1N"},
    Li = {0.2, Name "input/2length inlet "},
    ri = {0.05, Name "input/3radius inlet "},   
    hi = {1.0, Name "input/4height inlet "},
    Lg = {0.2, Name "input/5length gas out "},
    rg = {0.05, Name "input/6radius gas out "},
    Ll = {0.2, Name "input/7length liquid out "},
    rl = {0.05, Name "input/8radius liquid out "},
    Lc = {1, Name "input/9length cylinder "},
    rc = {0.2, Name "input/10radius cylinder "}
];

Cylinder(1) = {0, 0, 0, 0, 0, Ll, rl, 2*Pi};
Cylinder(2) = {0, 0, Ll, 0, 0, Lc, rc, 2*Pi};
Cylinder(3) = {0, 0, Ll+Lc, 0, 0, Lg, rg, 2*Pi};
Cylinder(4) = {-Li, rc-ri, hi, Li, 0, 0, ri, 2*Pi};

//+
BooleanUnion(5) = { Volume{2}; Delete; }{ Volume{4}; Delete; };
Coherence;

Physical Volume("glcc", 17) = {3, 5, 1};
Physical Surface("liquid", 18) = {3};
Physical Surface("gas", 19) = {8};
Physical Surface("inlet", 20) = {14};

```

---

<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:** [February 4, 2025, 12:03pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/14 "2025-02-04T12:03:32Z")

</div>

This is still not a closed surface.

 ![Screenshot 2025-02-04 at 1.03.01 PM](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/e/e40216ec3f09e13feb8dc75003cc8de45fc856cd.jpeg)

---

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [February 4, 2025, 1:14pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/15 "2025-02-04T13:14:51Z")

</div>

Sorry to bother again. I guess that I have now closed surface (?), but still problem of label with freefem++.

```auto
SetFactory("OpenCASCADE");

DefineConstant[
    N = {10, Name "input/1N"},
    Li = {0.2, Name "input/2length inlet "},
    ri = {0.05, Name "input/3radius inlet "},   
    hi = {1.0, Name "input/4height inlet "},
    Lg = {0.2, Name "input/5length gas out "},
    rg = {0.05, Name "input/6radius gas out "},
    Ll = {0.2, Name "input/7length liquid out "},
    rl = {0.05, Name "input/8radius liquid out "},
    Lc = {1, Name "input/9length cylinder "},
    rc = {0.2, Name "input/10radius cylinder "}
];

Cylinder(1) = {0, 0, 0, 0, 0, Ll, rl, 2*Pi};
Cylinder(2) = {0, 0, Ll, 0, 0, Lc, rc, 2*Pi};
Cylinder(3) = {0, 0, Ll+Lc, 0, 0, Lg, rg, 2*Pi};
Cylinder(4) = {-Li, rc-ri, hi, Li, 0, 0, ri, 2*Pi};

//+
BooleanUnion(5) = { Volume{2}; Delete; }{ Volume{4}; Delete; };
Coherence;

Physical Volume("glcc", 22) = {3, 5, 1};
Physical Surface("liquid", 18) = {3};
Physical Surface("gas", 19) = {8};
Physical Surface("inlet", 20) = {14};
Physical Surface("wall", 21) = {12, 7, 10, 13, 11, 1};

```

 ![closedsurface](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/0/0f9115fd48c7124454538651674a57c501ba8864.png)

---

<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:** [February 4, 2025, 2:09pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/16 "2025-02-04T14:09:16Z")

</div>

And what is the problem precisely?  
Here is what I get as list of labels with your mesh.

```auto
4	
	 18 19 20 21

```

This is OK, isn’t it?

---

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [February 4, 2025, 2:25pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/17 "2025-02-04T14:25:43Z")

</div>

You got those labels using freefem++ ? Below is how I check the labels using freefem++, it might be an error

```auto
load "msh3"
load "gmsh"
load "medit"

mesh3 Th = gmshload3("glcc.msh"); 

plot(Th,wait=1);

int[int] labs = labels(Th);

cout << "List of labelled surfaces:" << endl;

for (int i = 0; i < labs.n; i++) {
    cout << "Label: " << labs[i] << endl;
}

medit("glcc",Th,wait=1);

```

---

<div class="post-metadata">

**Author:** ![dominiquebodin](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@dominiquebodin](https://community.freefem.org/u/dominiquebodin)\
**Post date:** [February 4, 2025, 2:39pm UTC](https://community.freefem.org/t/to-replace-gmsh/3716/18 "2025-02-04T14:39:55Z")

</div>

I’ve been able to retrieve the labels using the lines:

```auto
lockOrientation = false;
system("gmsh -format msh22 -3 -o glcc.msh glcc.geo");
mesh3 Th = gmshload3("glcc.msh"); 
lockOrientation = true;

```

prj, many thanks for your patience, you helped a lot
