Partial Boundary Integration

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

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

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…

try this

Vh u;
border bottom1(t=0, 1) {x =0.25t; 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

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

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…

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

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;

1 Like

Ok, I get it ! Using buildmesh works fine.

Thanks for your help !

Simon