# Using levelset to integrate a fespace variable in a subregion of the mesh

**URL:** https://community.freefem.org/t/using-levelset-to-integrate-a-fespace-variable-in-a-subregion-of-the-mesh/3561
**Category:** General Discussion
**Created:** [October 23, 2024, 1:35pm UTC](https://community.freefem.org/t/using-levelset-to-integrate-a-fespace-variable-in-a-subregion-of-the-mesh/3561 "2024-10-23T13:35:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Christian](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@Christian](https://community.freefem.org/u/Christian)
#### Post date: [October 23, 2024, 1:35pm UTC](https://community.freefem.org/t/using-levelset-to-integrate-a-fespace-variable-in-a-subregion-of-the-mesh/3561/1 "2024-10-23T13:35:12Z")

</div>

Hi there!  
I was wondering if it is possible to integrate a FESpace variable over a subregion of the original mesh.  
Let’s suppose `Th3D` in my example is a cylinder with a height of 0.0 to 100 cm. I want to integrate the `Pow` FESpace variable over just the axial region where z≥10.0z \geq 10.0z≥10.0 and z≤20.0z \leq 20.0z≤20.0. I tried the following approach, but it only generates a vector composed entirely of zeros.

Thank you in advance!

Christian

```auto
ofstream fffout("power_density_results/PowerDensity_levelset_testing.txt");
real[int] PowerDensityRegionsLevelsetTest(64);

// Defintion of the function that has to be used in levelset
func flevelset = (z>= 10.0 && z<=20.0);
//

for (int i=0; i<64; i++)
{
  real xc =vecCenters(i,0);
  real yc =vecCenters(i,1);
  int thisregion = Th3D(xc,yc,10.0).region;
  PowerDensityRegionsLevelsetTest[i] = int3d(Th3D,levelset=flevelset)(PowerDensityFespaceVariable)/int3d(Th3D,levelset=flevelset)(1.0);
  fffout.scientific<<PowerDensityRegionsLevelsetTest[i]<<endl;

}

```

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [October 24, 2024, 9:31am UTC](https://community.freefem.org/t/using-levelset-to-integrate-a-fespace-variable-in-a-subregion-of-the-mesh/3561/2 "2024-10-24T09:31:29Z")

</div>

Hello,  
according to the FreeFem documentation, when you write  
`int3d(Th3D,levelset=phi)` the integral is performed where phi\<0.  
Thus you must change your definition of `flevelset`  
Otherwise you can do also as in [Vectorial PDE, conditions, stiffness matrix - #4 by fb77](https://community.freefem.org/t/vectorial-pde-conditions-stiffness-matrix/3543/4)
