# Trunc boolean function to keep elements

**URL:** https://community.freefem.org/t/trunc-boolean-function-to-keep-elements/1896
**Category:** General Discussion
**Created:** [July 15, 2022, 12:50pm UTC](https://community.freefem.org/t/trunc-boolean-function-to-keep-elements/1896 "2022-07-15T12:50:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![miguelpicos](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@miguelpicos](https://community.freefem.org/u/miguelpicos)
#### Post date: [July 15, 2022, 12:50pm UTC](https://community.freefem.org/t/trunc-boolean-function-to-keep-elements/1896/1 "2022-07-15T12:50:16Z")

</div>

Hello,

When you use the trunc function to keep elements from a mesh using a boolean function, you keep a element of the mesh if, at all vertices, the function is true. I need to do the oposite. I need to keep a element on the mesh if, at one of the vertex, the function is true, even if it is false on the other vertices. Is there a way to do this? I also tried to use labels to each element region label but I don´t know a way to change the region label of a single element at a time, using something like:

```auto
Th[i].region=1;

```

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: [July 17, 2022, 10:36am UTC](https://community.freefem.org/t/trunc-boolean-function-to-keep-elements/1896/2 "2022-07-17T10:36:39Z")

</div>

You can try

```auto
Th=trunc(Thg,région==1);

```

---

<div class="post-metadata">

### Author: ![miguelpicos](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@miguelpicos](https://community.freefem.org/u/miguelpicos)
#### Post date: [July 17, 2022, 12:23pm UTC](https://community.freefem.org/t/trunc-boolean-function-to-keep-elements/1896/3 "2022-07-17T12:23:24Z")

</div>

That is what I’m trying to do but i don’t know a way to change region labels of the elements of the mesh. Is there some function to change them directly (one element at a time) or by using a global change of the labels? All i found on the documentation is a way to change the already existings label to a different label but I could not find a way to split different element with the same label into having 2 different labels.

---

<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: [July 17, 2022, 1:11pm UTC](https://community.freefem.org/t/trunc-boolean-function-to-keep-elements/1896/4 "2022-07-17T13:11:13Z")

</div>

The simple way is introduction a P1 finite element function ok

ok = 1 if vertex ok  
ok =1 if vertex is not ok.

```auto
mesh Th1=trunc(Th,ok>0); // remove all triangle if the 3 vertices are not ok
mesh Th1=trunc(Th,ok>0.9999); // remove all triangle if one of 3 vertex are not ok. 

```

---

<div class="post-metadata">

### Author: ![miguelpicos](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@miguelpicos](https://community.freefem.org/u/miguelpicos)
#### Post date: [July 19, 2022, 6:53am UTC](https://community.freefem.org/t/trunc-boolean-function-to-keep-elements/1896/5 "2022-07-19T06:53:55Z")

</div>

Thank you, that works (I think that you wanted to use ok = 0 if vertex is not ok).

By your answer, I understand there is no way to change the label of the elements or that that is hard to do.
