How to 1D integrate along a path inside mesh

Suppose I have a mesh Th defined in the square from x = 0 to 1, y = 0 to 1. I solve a PDE on this mesh, getting solution u. Now I want to know the line integral of u along the straight path from (0, 1/2) to (1, 1/2), that is, along a horizontal line that goes through the center of the square. What is the correct syntax for this?

I tried defining a border “bb” that runs from (0, 1/2) to (1, 1/2), then calling

   int1d(Th, bb)(u),

but this gives zero. I assume this fails because bb is not an actual border of Th.

I think you should use levelset keyword for the integration. something like

int1d(Th, levelset=phi)(...)

see doc here

Hi. I looked at the documentation, but I didn’t really understand what “levelset” does. How would adding this flag allow me to integrate along a given path?

take this example.

func r = sqrt(xx +yy);
real lc = int1d(Th,levelset=r-1.)(1.) ;

here it integrates along the circle of radius one. Basically the phi in
int1d(Th, levelset=phi)(...) is the parametric equation along which you integrate.


I managed to get two domains: one big domain and inside that big domain, I have a small domain. I need to get line integral around the small domain as well as area integral. I am getting some value as one d line integral but the area integral is zero. Can you suggest what is the best way of doing that? Thankyou.

see it:

Thanks, but in my case, I have the labels available. I have a problem in getting area integral for f(u)dxdy in the smaller domain (black mesh). Mesh Th is defined for the whole domain (green+black) and int2d(Th,1)(f(u)) doen’t give me any result. 1 is the labels of inner boundary (black).