# Get labels of boundary nodes for P2 elements

**URL:** https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471
**Category:** General Discussion
**Created:** [June 15, 2020, 11:04am UTC](https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471 "2020-06-15T11:04:58Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)
#### Post date: [June 15, 2020, 11:04am UTC](https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471/1 "2020-06-15T11:04:58Z")

</div>

Hi everyone!

I use FreeFem++ to get the matrices of a given problem and then solve the system in Matlab for some reason. I build the matrices with P2 elements. However I need to export the label (for boundary elements) of each node of the fespace P2. So far I succeeded to have the region(s) of each nodes, but still have issues to get the label of “boundary nodes”.  
Does someone know how to do it?

Thank you for your help!  
Julien

---

<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 15, 2020, 3:18pm UTC](https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471/2 "2020-06-15T15:18:27Z")

</div>

Nodes don’t have a region, they have a label. Triangles/tetrahedra have region. Your question doesn’t make much sense, sorry.

---

<div class="post-metadata">

### Author: ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)
#### Post date: [June 15, 2020, 4:36pm UTC](https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471/3 "2020-06-15T16:36:17Z")

</div>

Thank you for your answer. I agree that It wasn’t clear.

Given a boundary label, (label = 1 for instance). Is it possible to export the nodes whose label=1 when dealing with P2 elements. By exporting the node I mean to export the number of the node nb\_node such that x[][nb\_node] should be its x coordinate.

Best regards.  
Julien

---

<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 15, 2020, 4:48pm UTC](https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471/4 "2020-06-15T16:48:43Z")

</div>

So, what doesn’t work if you write this down in FreeFEM? It seems like you know what you want to do.

---

<div class="post-metadata">

### Author: ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)
#### Post date: [June 15, 2020, 5:26pm UTC](https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471/5 "2020-06-15T17:26:06Z")

</div>

Actually I don’t know how to get “nb\_node” for a given label. What I would expect is to make loop over the elements as followed :

for(int i=0 ; i\<Th.nt ; i++){  
for(int j=0 ; j\<Th.ndofK ; j++){  
lab = Vh(i,j).label; //equivalent to Th[i][j].label  
}  
}

Obviously it doesn’t work since Vh(i,j) is an integer…

Is there a trick to export the label of a node with P2 ?

---

<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 15, 2020, 5:28pm UTC](https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471/6 "2020-06-15T17:28:53Z")

</div>

```auto
mesh Th = square(10, 10);
fespace Vh(Th, P2);
Vh u = label;

```

?

> export the label of a node with P2

Again, you are asking questions that don’t make sense 😕

---

<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 16, 2020, 10:11am UTC](https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471/7 "2020-06-16T10:11:59Z")

</div>

This is a little bit more complexe because a node could be on more the 1 boundary (corner ponts  
for examples).

```
mesh Th=square (10,10);
fespace Vh(Th,P2);

Vh l2 = label;
plot(l2, wait=1);

// it is correct expect on corner ..

// border l;
for(int l=1; l<=4; ++l)
{
varf vb1(u,v)= on(l,u=1);
Vh l1;
l1[] = vb1(0,Vh,tgv=1);// 1 on l border ..
plot(l1,wait=1,cmm=" border l="+l);
}
```

---

<div class="post-metadata">

### Author: ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)
#### Post date: [June 16, 2020, 11:28am UTC](https://community.freefem.org/t/get-labels-of-boundary-nodes-for-p2-elements/471/8 "2020-06-16T11:28:03Z")

</div>

Thank you for this help, it is exactly what I was searching for ! Good to see how flexible is FreeFem++ !
