# 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]}->{(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. Nov 27, 2016 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 Nov 27, 2016 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. Nov 27, 2016 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 ? Nov 28, 2016 at 17:18
• @lakehal, I hope this is better? Nov 28, 2016 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. Nov 29, 2016 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 Nov 30, 2016 at 8:01
• Now things are clear. thank you. Dec 4, 2016 at 13:47

Some things change to better. In version 13 on Windows 10

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]]


3.13146

Region[s1]


It should be noticed that the notation Integrate[Cos[x], Element[{x, y}, s1]] is unclear. Is this a line integral? if so, of which kind?

Integrate[Cos[x]*Boole[2*(Cos[x] + Cos[y]) == 1], {x, -Pi, Pi}, {y, -Pi, Pi}]

0
in order to explain why the notation Integrate[Cos[x], Element[{x, y}, s1]] is unclear.
• NIntegrate[1, Element[{x, y}, s1]] is arclength, It is a line integrate, Cos[x] is a function on a one-dimensional sub-manifold on plane, so we can not use double integrate. Your can read something about Hausdorff measure. Apr 12, 2022 at 9:32
• Distinguish between the integral of a function on a manifold and the integral of a vector field on a manifold. Here just a function Cos[x] on a 1-dimensional sub-manifold. Apr 12, 2022 at 9:38
• @cvgmt: Thank you for your interest to the answer. Where is "NIntegrate[1, Element[{x, y}, s1]]` is arclength" documented? I am aware about Hausdorff measure. Apr 12, 2022 at 9:40