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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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