Message: Infinite loop in G4SubtractionSolid::DistanceToIn() Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Warning Infinite loop in G4SubtractionSolid::DistanceToIn() 

Forum: Geometry
Date: 09 Mar, 2009
From: Svetlana Biktemerova <Svetlana Biktemerova>

The next code leads Geant4 to the infinite loop.

//___________________________________________________________________________________________________________________________
void test(){
     const char* nms[]={"kOutside","kSurface","kInside"};

     double t_dz=0.3392505000;
     double t_rad=85.94;
     double p_rmz=85.9400000000;
     double p_rpz=99.2300000000;
     double p_hz=0.3392505000;

     G4Paraboloid* par = new G4Paraboloid("par",p_hz,p_rmz,p_rpz);
     G4DisplacedSolid* pard=new G4DisplacedSolid("disp_par",par,new G4RotationMatrix(0.,180.*deg,0.),G4ThreeVector(0.,0.,0.));
     G4Tubs* t=new G4Tubs("absorber",0.,t_rad,t_dz,0.*deg,360.*deg);
     G4SubtractionSolid* seg1 = new G4SubtractionSolid("par1_i",pard,t,0,0);

     G4ThreeVector v(-82.1262056167, 40.0738142048, 0.0732052691);
     G4ThreeVector dir(-0.00013143732014871606, 0.00006413537198823375,-0.99999998930544242715);
     dir=dir.unit();

     printf("%20.10f %20s %20.10f\n",v.x(),nms[t->Inside(v)],t->DistanceToOut(v,dir));
     printf("%20.10f %20s %20.10f\n",v.x(),nms[pard->Inside(v)],pard->DistanceToIn(v,dir));

     G4ThreeVector v0(-81.97424905536260553163, 39.99966638606156266178, 1156.18746249999981046130);
     printf("infinite_loop...\n");
     seg1->DistanceToIn(v0,dir);
     printf("finished...\n");
}
//___________________________________________________________________________________________________________________________

The reason is printed to the output: both constituents solid say that point "v" is outside, and both of them return 0.0 as distance to in/out.

G4SubtractionSolid::DistanceToIn() uses the "while" loop:
//___________________________________________________________________________________________________________________________
while( Inside(p+dist*v) == kOutside )  // pushing loop
{
  disTmp = fPtrSolidB->DistanceToOut(p+dist*v,v) ;
  dist += disTmp ;

  if( Inside(p+dist*v) == kOutside ){ 
    disTmp = fPtrSolidA->DistanceToIn(p+dist*v,v) ;
    if(disTmp == kInfinity){return kInfinity;}                 
    dist += disTmp ;
  }
}
//___________________________________________________________________________________________________________________________

as "disTmp" is always 0., this loop is infinite. I suggest to add a simple check: if both "disTmp" are zeroes, move them manually by a small number, like 1.e-9.

It also seems that other G4BooleanSolids are also "dangerous", but I do not have exact examples for them.

best regards, Svetlana Biktemerova

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Question: Re: Infinite loop in G4SubtractionSolid::DistanceToIn()   (Gabriele Cosmo - 09 Mar, 2009)
(_ Question: Re: Infinite loop in G4SubtractionSolid::DistanceToIn()   (Linda Schnorrenberger - 03 Sep, 2010)
1 None: RE: Infinite loop in G4SubtractionSolid::DistanceToIn()   (Asai, Makoto - 03 Sep, 2010)
2 More: Re: Infinite loop in G4SubtractionSolid::DistanceToIn()   (Gabriele Cosmo - 03 Sep, 2010)
1 Question: Re: Infinite loop in G4SubtractionSolid::DistanceToIn()   (Linda Schnorrenberger - 12 Nov, 2010)
... 5 Message(s)
 Add Message Add Message
to: "Infinite loop in G4SubtractionSolid::DistanceToIn()"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]