# How to define boundary when mesh is imported from gmsh?

**URL:** <https://community.freefem.org/t/how-to-define-boundary-when-mesh-is-imported-from-gmsh/1054>\
**Category:** General Discussion\
**Created:** [June 23, 2021, 9:00am UTC](https://community.freefem.org/t/how-to-define-boundary-when-mesh-is-imported-from-gmsh/1054 "2021-06-23T09:00:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![distractor](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@distractor](https://community.freefem.org/u/distractor)\
**Post date:** [June 23, 2021, 9:00am UTC](https://community.freefem.org/t/how-to-define-boundary-when-mesh-is-imported-from-gmsh/1054/1 "2021-06-23T09:00:10Z")

</div>

Hi,

I have been struggling with this question for quite a while now and it seems I am no closer to solving it than I was 14 days ago.

So the issue is, I want to import the \*.msh file available [HERE](https://drive.google.com/file/d/1hxeKcDGZihd9R0gDtqWRcZo6-9S9ZqAv/view?usp=sharing) using the

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

// Load mesh.
mesh3 Th = gmshload3("../processed_data/EPC.msh");

```

and this works just fine however the following two lines

```auto
cout << "Volume = " << Th.measure << ", border area = " << Th.bordermeasure << endl;
cout << "Number of vertices = " << Th.nv << endl;

```

print out that the border area is zero. Of course it is zero, I have not defined it and that is the issue. I do not know how to define/label the borders.

So my question:

- How do I define/label borders when the mesh is imported from gmsh?
- Should I modify the gmsh file? In that case, do you have an idea how?

Thank you.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [June 23, 2021, 11:42am UTC](https://community.freefem.org/t/how-to-define-boundary-when-mesh-is-imported-from-gmsh/1054/2 "2021-06-23T11:42:55Z")

</div>

can I see the gmsh data file to create EPC.msh file, to see where is the mistake

---

<div class="post-metadata">

**Author:** ![distractor](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@distractor](https://community.freefem.org/u/distractor)\
**Post date:** [June 23, 2021, 12:12pm UTC](https://community.freefem.org/t/how-to-define-boundary-when-mesh-is-imported-from-gmsh/1054/3 "2021-06-23T12:12:30Z")

</div>

The file is generated by some python script. The workflow is as follows:  
The original data is written in Abaqus ODB file. From that data, geometry somehow needs to be extracted and the only way I found reasonable to do that was by writing a python script that reads the ODB and saves relevant geometry data to MSH.

So I guess:

- Either there is something missing in the MSH or
- I am missing to see a way to assign label to specific nodes within the FreeFem++

Because all I actually need is to just assign some label at the bottom nodes, so I can fix their displacement to 0.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [June 23, 2021, 12:42pm UTC](https://community.freefem.org/t/how-to-define-boundary-when-mesh-is-imported-from-gmsh/1054/4 "2021-06-23T12:42:55Z")

</div>

I am not complet sure, theoretically the boudary is reconstructed by freefem.

to be sure try put verbosity = 5; before loadgmsh3

or your freefem version is to old …

after that what is the label boundary numbering ???

you can use change function to change the label number with :

```
 real[int] bb[6];
 boundingbox(Th,bb);
 real zmin = bb[4]; 
 real eps = (bb[5]-bb[4])*0.0001; 
 Th = change(Th,flabel = z <= zmin+eps ? 1: 0);  

```

now you can take your B.C of label 1 …

---

<div class="post-metadata">

**Author:** ![distractor](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@distractor](https://community.freefem.org/u/distractor)\
**Post date:** [June 23, 2021, 1:41pm UTC](https://community.freefem.org/t/how-to-define-boundary-when-mesh-is-imported-from-gmsh/1054/5 "2021-06-23T13:41:09Z")

</div>

Hi,

Sorry but I am getting compile error at line 11 (the `real[int] bb[6]`).

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

// Load mesh.
verbosity = 5;
mesh3 Th = gmshload3("../processed_data/EPC.msh");
cout << "Volume = " << Th.measure << ", border area = " << Th.bordermeasure << endl;
cout << "Number of vertices = " << Th.nv << endl;

real[int] bb[6];
boundingbox(Th,bb);
real zmin = bb[4]; 
real eps = (bb[5]-bb[4])*0.0001; 
Th = change(Th,flabel = z <= zmin+eps ? 1: 0);  

```

Also the `verbosity = 5;` did not change anything. I am using the latest version, that is version 4.6 on Windows.

---

<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:** [June 23, 2021, 1:53pm UTC](https://community.freefem.org/t/how-to-define-boundary-when-mesh-is-imported-from-gmsh/1054/6 "2021-06-23T13:53:39Z")

</div>

Try `bb(6)` instead of `bb[6]`, and 4.6 is not the latest version, 4.9 is, see [Releases · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/releases).

---

<div class="post-metadata">

**Author:** ![distractor](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@distractor](https://community.freefem.org/u/distractor)\
**Post date:** [June 23, 2021, 2:24pm UTC](https://community.freefem.org/t/how-to-define-boundary-when-mesh-is-imported-from-gmsh/1054/7 "2021-06-23T14:24:13Z")

</div>

Thank you both for helping, but I tried to print the labels and somehow I am not convinced this works. Btw I also upgraded to version 4.9.

So my code is as suggested:

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

// Load mesh.
verbosity = 5;
mesh3 Th = gmshload3("../processed_data/EPC.msh");

real[int] bb(6);
boundingbox(Th,bb);
real zmin = bb[4]; 
real eps = (bb[5]-bb[4])*0.0001; 
cout << zmin+eps << endl;
Th = change(Th,flabel = z <= zmin + eps ? 5: 1);  

```

However, when I wanted to print out the vertices with label 5:

```auto
int NbVertices = Th.nv;
cout << "Number of verticesssssss = " << NbVertices << endl;

for (int i = 0; i < NbVertices; i++){
    if (Th(i).label != 1){
        cout << "hello" << endl;
        cout << "Th(" << i << ") : " << Th(i).x << " " << Th(i).y << " " << Th(i).z << " " << Th(i).label << endl;
    }
}

```

There is no output, nothing is printed. Which makes me seriously doubt if the labels were actually changed. Am I getting this wrong or better said, how can I be sure the labels were actually modified?
