# Number of vertices on a boundary

**URL:** <https://community.freefem.org/t/number-of-vertices-on-a-boundary/1415>\
**Category:** General Discussion\
**Created:** [January 6, 2022, 2:11pm UTC](https://community.freefem.org/t/number-of-vertices-on-a-boundary/1415 "2022-01-06T14:11:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [January 6, 2022, 2:11pm UTC](https://community.freefem.org/t/number-of-vertices-on-a-boundary/1415/1 "2022-01-06T14:11:39Z")

</div>

Is there a direct way to calculate the number of boundary vertices? I know that for instance Th.nv gives the total number of vertices in the domain so I was wondering if there is a similar way to do it on boundary faces, if not how can I approach this problem?

---

<div class="post-metadata">

**Author:** ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)\
**Post date:** [January 6, 2022, 2:36pm UTC](https://community.freefem.org/t/number-of-vertices-on-a-boundary/1415/2 "2022-01-06T14:36:21Z")

</div>

the command `Th.nbe` should give you the number of edges I think. See the documentation [here](https://doc.freefem.org/documentation/mesh-generation.html#mesh-connectivity-and-data)

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [January 6, 2022, 2:51pm UTC](https://community.freefem.org/t/number-of-vertices-on-a-boundary/1415/3 "2022-01-06T14:51:58Z")

</div>

Th.nbe gives you the total number of boundary elements from which you can get the vertex ID for each element. I need the total number of vertices which is basically the number of unique IDs.

---

<div class="post-metadata">

**Author:** ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)\
**Post date:** [January 12, 2022, 1:07am UTC](https://community.freefem.org/t/number-of-vertices-on-a-boundary/1415/4 "2022-01-12T01:07:49Z")

</div>

For a simple closed curve boundary, you just call `Th.nbe` as Julien suggested. And for those more complex cases, you can also use the following FreeFEM code and it’s fast

```auto
fespace Bh(Th, P1);
varf vGamma(u, v) = on(labels(Th), u=1);
real[int] gamma = vGamma(0, Bh, tgv=-1);
int nbv = gamma.sum;
```
