8
$\begingroup$

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 
{NIntegrate`SimplexQuadratureDump`P$176172[1]}->{(1/2)(NIntegrate`SimplexQuadratureDump
`S$176172$176174+NIntegrate`SimplexQuadratur
eDump`S$176172$176176),(NIntegrate`SimplexQuadratureDump
`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)

$\endgroup$
3
  • 1
    $\begingroup$ What values are you using for t and u? Also, you need to be consistent between F and f. $\endgroup$
    – Bob Hanlon
    Nov 27, 2016 at 0:13
  • 1
    $\begingroup$ 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 $\endgroup$
    – Michael E2
    Nov 27, 2016 at 13:48
  • $\begingroup$ 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. $\endgroup$
    – lakehal
    Nov 27, 2016 at 18:08

2 Answers 2

5
$\begingroup$

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

Needs["NDSolve`FEM`"]
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["NDSolve`FEM`"]
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.

$\endgroup$
5
  • $\begingroup$ 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 ? $\endgroup$
    – lakehal
    Nov 28, 2016 at 17:18
  • $\begingroup$ @lakehal, I hope this is better? $\endgroup$
    – user21
    Nov 28, 2016 at 17:24
  • $\begingroup$ 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. $\endgroup$
    – lakehal
    Nov 29, 2016 at 17:17
  • $\begingroup$ @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 $\endgroup$
    – user21
    Nov 30, 2016 at 8:01
  • $\begingroup$ Now things are clear. thank you. $\endgroup$
    – lakehal
    Dec 4, 2016 at 13:47
0
$\begingroup$

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]

enter image description here

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?

Addition. I'd like to add that

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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – cvgmt
    Apr 12, 2022 at 9:32
  • $\begingroup$ 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. $\endgroup$
    – cvgmt
    Apr 12, 2022 at 9:38
  • $\begingroup$ @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. $\endgroup$
    – user64494
    Apr 12, 2022 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.