# 2d integral over one triangle element

**URL:** <https://community.freefem.org/t/2d-integral-over-one-triangle-element/963>\
**Category:** General Discussion\
**Created:** [May 5, 2021, 6:29pm UTC](https://community.freefem.org/t/2d-integral-over-one-triangle-element/963 "2021-05-05T18:29:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharon](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@Sharon](https://community.freefem.org/u/Sharon)\
**Post date:** [May 5, 2021, 6:29pm UTC](https://community.freefem.org/t/2d-integral-over-one-triangle-element/963/1 "2021-05-05T18:29:38Z")

</div>

Hi, I am a question about using int2d to calculate integral over one element(triangle). I have a mesh Th, how could I find integral only over Th[0]( the first triangle element) ?  
Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![fivanci](https://avatars.discourse-cdn.com/v4/letter/f/e95f7d/32.png) [@fivanci](https://community.freefem.org/u/fivanci)\
**Post date:** [May 6, 2021, 7:54am UTC](https://community.freefem.org/t/2d-integral-over-one-triangle-element/963/2 "2021-05-06T07:54:10Z")

</div>

Hi !

In lack of the better idea, you can always use the trick with P0 finite elements ([Finite element](https://doc.freefem.org/documentation/finite-element.html#p0-element)) - dofs of P0 elements are the numbering of mesh elements (triangle in 2d and tetrahedra in 3d). Hence, you can multiply whatever you have under the integral with characteristic function of certain element. E.g.

```
   mesh Th=square(5,6);

   fespace Vh(Th,P0);
   Vh th;

   th[][15]=1; // th is zero everywhere except on triangle number 15
   cout << int2d(Th)(th*x) << " " << int2d(Th)(x) << endl;

```

There is also mentioning of characteristic function in this section in documentation: [Finite element](https://doc.freefem.org/documentation/finite-element.html#variational-form-sparse-matrix-pde-data-vector)

if

---

<div class="post-metadata">

**Author:** ![Sharon](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@Sharon](https://community.freefem.org/u/Sharon)\
**Post date:** [May 6, 2021, 3:44pm UTC](https://community.freefem.org/t/2d-integral-over-one-triangle-element/963/3 "2021-05-06T15:44:04Z")

</div>

It works. Thanks very much ! @fivanci
