Integration over a part of the big domain

I have a mesh defined on x as (-20,20) and y as (-20,20). The mesh space is defined on this domain lengths. However I would like to integrate a P2 variable over a certain part of the domain given by x’=(-2,10) and y’=(-2,2). Is there a specific way to integrate over this specific part of domain? Any help is appreciated.

fespace Ph(Th, P0);
Ph chi = (x > -2 && x < 10 && y > -2 && y < 2);
real myInt = int2d(Th)(chi * u);
1 Like

It works. Thank you very much @prj

@prj Continuing on the above question, I would like to ask if there is also a way to obtain a solution variable over a certain part of the domain? I have the 2-dimensional solution field over the entire domain but I would like to store the 2-dimensional solution on a part of the domain given by x’=(-2,10) and y’=(-2,2). Thanks in advance.

I’d advise you to read the documentation. It can be easily achieved, for example by using the trunc function, followed by an interpolation from your orginal fespace to a newly defined fespace on your trunc'ed mesh.

Thanks @prj for pointing out the reference.