# Partial Boundary Integration

**URL:** <https://community.freefem.org/t/partial-boundary-integration/3711>\
**Category:** General Discussion\
**Created:** [January 26, 2025, 10:38pm UTC](https://community.freefem.org/t/partial-boundary-integration/3711 "2025-01-26T22:38:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sruget](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sruget](https://community.freefem.org/u/sruget)\
**Post date:** [January 26, 2025, 10:38pm UTC](https://community.freefem.org/t/partial-boundary-integration/3711/1 "2025-01-26T22:38:41Z")

</div>

Hello,

I am trying to integrate over a portion of my domain’s boundary but I am facing some weird results. To sum up, let’s say that my domain is [0,1]^2, and that I want to integrate over the part (y=0, x \in [0.25, 0.75]). Here is my code :

1. int N = 100;
2. mesh Th=square(N, N, [x,y]);
3. fespace Vh(Th,P1);
4. Vh u;
5. border bottom(t=0, 1) {x =t; y = 0; label = 1;}
6. cout \<\< “test :” \<\< int1d(Th, 1)(u) \<\< endl;

The associated output is 1 (as expected)…  
Now, if I turn the line 5. into  
5’. border bottom(t=0.25, 0.75) {x =t; y = 0; label = 1;}  
or  
5’'. border bottom(t=0, 1) {x =0.25+0.5\*t; y = 0; label = 1;}  
Then the output remains 1 instead of 0.5 (which is the expected output).

What did I miss ?

Thanks for your help,

Simon

---

<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 27, 2025, 8:17am UTC](https://community.freefem.org/t/partial-boundary-integration/3711/2 "2025-01-27T08:17:13Z")

</div>

You don’t compute your bottom border

> cout \<\< “test :” \<\< int1d(Th, 1)(u) \<\< endl;

you compute the bottom border of the square mesh see [https://doc.freefem.org/documentation/mesh-generation.html](https://doc.freefem.org/documentation/mesh-generation.html)

---

<div class="post-metadata">

**Author:** ![sruget](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sruget](https://community.freefem.org/u/sruget)\
**Post date:** [January 27, 2025, 10:23am UTC](https://community.freefem.org/t/partial-boundary-integration/3711/3 "2025-01-27T10:23:02Z")

</div>

I don’t get it. How can I compute the integral over (x\in[0.25, 0.75], y=0) then. I try defining the whole boundary as suggested in the docs you are referring to (see below), but it did not work either.  
Here is the code :

1. int N = 100;
2. mesh Th=square(N, N, [x,y]);
3. fespace Vh(Th,P1);
4. Vh u;
5. border bottom1(t=0, 1) {x =0.25\*t; y = 0; label = 1;}
6. border bottom2(t=0, 1) {x =0.25+0.5\*t; y = 0; label = 1;}
7. border bottom3(t=0, 1) {x =0.75+0.25\*t; y = 0; label = 1;}
8. border right(t=0, 1) {x = 1; y = t; label = 2;}
9. border top(t=0, 1) {x = 1-t; y = 1; label = 3;}
10. border left(t=0, 1) {x = 0; y = 1-t; label = 4;}
11. cout \<\< “test :” \<\< int1d(Th, bottom2)(u) \<\< endl;

Again, the output is 1instead of 0.5…

---

<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 27, 2025, 11:28am UTC](https://community.freefem.org/t/partial-boundary-integration/3711/4 "2025-01-27T11:28:35Z")

</div>

try this

> Vh u;  
> border bottom1(t=0, 1) {x =0.25_t; y = 0; label = 10;}  
> border bottom2(t=0, 1) {x =0.25+0.5_t; y = 0; label = 11;}  
> border bottom3(t=0, 1) {x =0.75+0.25\*t; y = 0; label = 12;}  
> border right(t=0, 1) {x = 1; y = t; label = 2;}  
> border top(t=0, 1) {x = 1-t; y = 1; label = 3;}  
> border left(t=0, 1) {x = 0; y = 1-t; label = 4;}  
> cout \<\< “test :” \<\< int1d(Th, 11)(1.0) \<\< endl;

Note that

> cout \<\< “test :” \<\< int1d(Th, 11)(1.0) \<\< endl;

integrates over the boundary whose label is `11`, that is `bottom2`

---

<div class="post-metadata">

**Author:** ![sruget](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sruget](https://community.freefem.org/u/sruget)\
**Post date:** [January 27, 2025, 12:30pm UTC](https://community.freefem.org/t/partial-boundary-integration/3711/5 "2025-01-27T12:30:43Z")

</div>

Does it work on your computer ?  
I try your code :

```auto
int N = 100;
mesh Th=square(N, N, [x,y]);
fespace Vh(Th,P1);
Vh u = 1;
border bottom1(t=0, 1) {x =0.25*t; y = 0; label = 10;}
border bottom2(t=0, 1) {x =0.25+0.5*t; y = 0; label = 11;}
border bottom3(t=0, 1) {x =0.75+0.25*t; y = 0; label = 12;}
border right(t=0, 1) {x = 1; y = t; label = 2;}
border top(t=0, 1) {x = 1-t; y = 1; label = 3;}
border left(t=0, 1) {x = 0; y = 1-t; label = 4;}
cout << "integrate over 11 : " << int1d(Th, 11)(u) << endl;
cout << "integrate over bottom2 : " << int1d(Th, bottom2)(u) << endl;

```

First output is 0… Second output is 1…

---

<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 27, 2025, 5:13pm UTC](https://community.freefem.org/t/partial-boundary-integration/3711/6 "2025-01-27T17:13:10Z")

</div>

you do not use `border` properly. You must use `buildmesh` instead of `square`. all info is here [https://doc.freefem.org/documentation/mesh-generation.html#the-command-buildmesh](https://doc.freefem.org/documentation/mesh-generation.html#the-command-buildmesh)

> int NN=10;  
> mesh Th2 = buildmesh( bottom1(NN/4) + bottom2(NN/2) +bottom3(NN/4) + right(NN) + top(NN)+left(NN) );  
> cout \<\< "integrate over 11 : " \<\< int1d(Th2, 11)(1.0) \<\< endl;

---

<div class="post-metadata">

**Author:** ![sruget](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@sruget](https://community.freefem.org/u/sruget)\
**Post date:** [January 29, 2025, 3:35pm UTC](https://community.freefem.org/t/partial-boundary-integration/3711/7 "2025-01-29T15:35:29Z")

</div>

Ok, I get it ! Using buildmesh works fine.

Thanks for your help !

Simon
