# How to apply the GMSH boundary label in FreeFEM

**URL:** <https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167>\
**Category:** General Discussion\
**Created:** [November 5, 2019, 5:31am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167 "2019-11-05T05:31:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dylan](https://community.freefem.org/u/Dylan)\
**Post date:** [November 5, 2019, 5:31am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/1 "2019-11-05T05:31:15Z")

</div>

Dear developers,

How to apply the boundary labels from an external mesh generator such as GMSH?  
The boundary patches are identified in the Gmsh step using its Physical Surface command.  
I import the gmsh to freefem++, but it can’t catch the labels I had identified.

Thanks a lot!

---

<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:** [November 5, 2019, 7:12am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/2 "2019-11-05T07:12:28Z")

</div>

What mesh format are you using? In Gmsh, if you export using INRIA Medit (.mesh) format, you should automatically get the correct labels (as set in Gmsh). See [this](https://community.freefem.org/t/how-to-identify-the-boundary-label-for-an-import-mesh/161/3) post to verify the labels of your imported mesh.

---

<div class="post-metadata">

**Author:** ![Dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dylan](https://community.freefem.org/u/Dylan)\
**Post date:** [November 5, 2019, 7:37am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/3 "2019-11-05T07:37:57Z")

</div>

What mesh format are you using?

I use gmsh .msh.

---

<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:** [November 5, 2019, 7:48am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/4 "2019-11-05T07:48:57Z")

</div>

OK, does my suggestion (switching to .mesh) fix your issue?

---

<div class="post-metadata">

**Author:** ![Dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dylan](https://community.freefem.org/u/Dylan)\
**Post date:** [November 6, 2019, 6:57am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/5 "2019-11-06T06:57:01Z")

</div>

I am a beginner of freefem. I can’t import the .mesh.  
I use the GMSH to draw the mesh, and export the file using INRIA Medit(.mesh).  
How to import the file(.mesh) to the freefem, and use the labels that I have identified?

Thank you for help!

---

<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:** [November 6, 2019, 7:25am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/6 "2019-11-06T07:25:59Z")

</div>

In my previous [solution](https://community.freefem.org/t/how-to-identify-the-boundary-label-for-an-import-mesh/161/2), replace

```auto
mesh Th = square(10, 10);

```

by

```auto
mesh Th("my2DMesh.mesh");

```

or

```auto
mesh3 Th("my3DMesh.mesh");

```

---

<div class="post-metadata">

**Author:** ![Dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dylan](https://community.freefem.org/u/Dylan)\
**Post date:** [November 6, 2019, 8:01am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/7 "2019-11-06T08:01:52Z")

</div>

int[int] lab = labels(Th);  
varf onG(u, v) = on(lab, u = label);

I don’t understand this part. what is the difference between lab and label?  
If my file(.mesh) is a square. The left side is 1, top is 2, right is 3, bottom is 4.  
The left side don’t move(u=0).  
How to enter the code for this problem?

Thank you for help!

---

<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:** [November 6, 2019, 8:15am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/8 "2019-11-06T08:15:30Z")

</div>

Please read the [documentation](https://doc.freefem.org/documentation/mesh-generation.html). `lab` is an array of integers corresponding to labels on which you want to impose boundary conditions. `label` is a reserved keyword in the FreeFEM grammar that returns the label of the current boundary element.

---

<div class="post-metadata">

**Author:** ![Dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dylan](https://community.freefem.org/u/Dylan)\
**Post date:** [November 7, 2019, 10:24am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/9 "2019-11-07T10:24:44Z")

</div>

I use the code to test my problem,

1 mesh Th(“test.mesh”);  
2 plot(Th);

It’s error.

– Mesh::read On file “test.mesh”  
current line = 1  
Assertion fail : (f.good() && nt && nv)  
line :668, in file …/femlib/fem.cpp  
Assertion fail : (f.good() && nt && nv)  
line :668, in file …/femlib/fem.cpp  
err code 6 , mpirank 0

How can I to solve the problem?

Thank you for help!

---

<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:** [November 7, 2019, 1:26pm UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/10 "2019-11-07T13:26:31Z")

</div>

Is `test.mesh` in the same folder as your script? Could you send your mesh file?

---

<div class="post-metadata">

**Author:** ![Dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dylan](https://community.freefem.org/u/Dylan)\
**Post date:** [November 11, 2019, 6:43am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/12 "2019-11-11T06:43:14Z")

</div>

[https://drive.google.com/open?id=1pfFOF79VirmdyynFWTO8xSHcYgn22vWg](https://drive.google.com/open?id=1pfFOF79VirmdyynFWTO8xSHcYgn22vWg)

The test.mesh is in the same folder.

---

<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:** [November 11, 2019, 7:48am UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/13 "2019-11-11T07:48:48Z")

</div>

Could you try to mesh your .geo with the following command, please?

```auto
gmsh -2 -format msh2 -string 'Mesh.SaveElementTagType=2;' input.geo

```

If it doesn’t work, put your .geo in the Google Drive as well, please.

---

<div class="post-metadata">

**Author:** ![Dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@Dylan](https://community.freefem.org/u/Dylan)\
**Post date:** [November 11, 2019, 12:04pm UTC](https://community.freefem.org/t/how-to-apply-the-gmsh-boundary-label-in-freefem/167/15 "2019-11-11T12:04:41Z")

</div>

When I enter the command "gmsh -2 -format msh2 -string ‘Mesh.SaveElementTagType=2;’ input.geo ", it generated the .msh file not .mesh.  
I use the command " gmshload test.msh ", it is successful.  
But the numbers of mesh is a bit less.(picture in the Google Drive)  
How to generate more numbers of mesh?

Thank you for help!
