# Integral over an ImplicitRegion

I often need to do integrals over surfaces of different geometries ( in my case it's fermi surfaces ). To do so i use the following code

s1 = ImplicitRegion[G[x, y]== 0 , {{x, -pi, pi}, {y, -pi, pi}}];
NIntegrate[F[x], {x, y} \[Element] s1]


Which is simple. i first define a region over which to integrate and then integrate over that region.

I obtain a very confusing and intriguing error in some ( not all) cases.

Thread::tdlen: Objects of unequal length in
{NIntegrateSimplexQuadratureDumpP$176172}->{(1/2)(NIntegrateSimplexQuadratureDump S$176172$176174+NIntegrateSimplexQuadratur eDumpS$176172$176176),(NIntegrateSimplexQuadratureDump S$176172\$176175+<<48>>)/2} cannot be combined.


Now this error only happen for some geometries and some functions. to be more specific i tried the following :

   G[x_, y_] = 2*t (Cos[x] + Cos[y] ) ;
F[x]=1


it works

   G[x_, y_] = 2*t (Cos[x] + Cos[y] ) ;
F[x]=x


it works ( here t=1 ).

But for

   G[x_, y_] = 2*t (Cos[x] + Cos[y] ) ;
F[x]=Cos[x] ;


it doesn't work

What's the problem, and what does this error mean ?

this is the exact code i wrote :

F[x_, y_] = 2*(Cos[x] + Cos[y]);
s1 = ImplicitRegion[F[x, y] == 1, {{x, -Pi, Pi}, {y, -Pi, Pi}}];
NIntegrate[Cos[x], Element[{x, y}, s1]]


PS: exactly the same happens with or without using DiscretizeRegion

Version Number:11.0.0.0 Platform:Microsoft Windows (64-bit)

• What values are you using for t and u? Also, you need to be consistent between F and f. – Bob Hanlon Nov 27 '16 at 0:13
• Please post the actual code you used. What is posted does not generate the errors you report. You may find this meta Q&A helpful – Michael E2 Nov 27 '16 at 13:48
• Well i am not surprised that you didn't have the error since apparently according to this post. in some cases it doesn't happen which is very confusing. – lakehal Nov 27 '16 at 18:08

I filed a bug report for you. Here is a workaround:

Needs["NDSolveFEM"]
F[x_, y_] = 2*(Cos[x] + Cos[y]);
s1 = ImplicitRegion[F[x, y] == 1, {{x, -Pi, Pi}, {y, -Pi, Pi}}];
bmesh = ToBoundaryMesh[s1, "MeshOrder" -> 2];
FEMNBoundaryIntegrate[Cos[x], {x, y}, bmesh]
3.131461968054968


update:

You can also use this:

Needs["NDSolveFEM"]
F[x_, y_] = 2*(Cos[x] + Cos[y]);
s1 = ImplicitRegion[F[x, y] == 1, {{x, -Pi, Pi}, {y, -Pi, Pi}}];
bmesh = ToBoundaryMesh[s1, "MeshOrder" -> 2];
NIntegrate[Cos[x], {x, y} \[Element] bmesh]


Generate a boundary element mesh (see ToBoundaryMesh) from the region. NIntegrate than figures out that it should do a surface integral.

• Thank you very much, it seems to be working. on the other hand i have no idea what the code means is it possible to have more details the code ? – lakehal Nov 28 '16 at 17:18
• @lakehal, I hope this is better? – user21 Nov 28 '16 at 17:24
• well yes now it's much better. although i still want to understand the code better. can you give refrence on the FEMNBoundaryIntegrate. i tried to look it up i didn't have a result on this as a function. there is something that describes the methode but not it as a function and it's options. from what i understood it's a methode to do integral by descritisation so i would like to know what are the options to increse the precision. and thanks again. – lakehal Nov 29 '16 at 17:17
• @lakehal, there is no reference on FEMNBoundaryIntegrate` - It uses the finite element method to evaluate the argument over the (curved) boundary and then sums things up. To only way to control it is through the boundary mesh, and then is documented in ToBoundaryMesh – user21 Nov 30 '16 at 8:01
• Now things are clear. thank you. – lakehal Dec 4 '16 at 13:47