211   G4bool IsParallel = false ;
 
  212   G4bool IsConverged =  false ;
 
  255   G4bool        tmpisvalid  = false ;
 
  257   std::vector<Intersection> xbuf ;
 
  264   G4double phixz = fPhiTwist * ( p.
x() * v.
z() - p.
z() * v.
x() ) ;
 
  265   G4double phiyz = fPhiTwist * ( p.
y() * v.
z() - p.
z() * v.
y() ) ;
 
  272     if ( std::fabs(p.
z()) <= L )   
 
  274       phi = p.
z() * fPhiTwist / 
L ;  
 
  275       u = (fDy1*(4*(-(fdeltaY*phi*v.
x()) + fPhiTwist*p.
y()*v.
x()
 
  276                     + fdeltaX*phi*v.
y() - fPhiTwist*p.
x()*v.
y())
 
  277                  + ((fDx3plus1 + fDx4plus2)*fPhiTwist
 
  278                  +  2*(fDx3minus1 + fDx4minus2)*phi)
 
  279                      *(v.
y()*std::cos(phi) - v.
x()*std::sin(phi))))
 
  280          /(fPhiTwist*(4*fDy1* v.
x() - (fa1md1 + 4*fDy1*fTAlph)*v.
y())
 
  281                     *std::cos(phi) + fPhiTwist*(fa1md1*v.
x()
 
  282                        + 4*fDy1*(fTAlph*v.
x() + v.
y()))*std::sin(phi));
 
  289       xbuf.push_back(xbuftmp) ;  
 
  298                                      areacode[0], isvalid[0],
 
  299                                      0, validate, &gp, &gv);
 
  310             fDy1*(-4*phixz + 4*fTAlph*phiyz
 
  311                  + (fDx3plus1 + fDx4plus2)*fPhiTwist*v.
z())) ;
 
  313       fDy1*(4*fDy1*(phiyz + 2*fDz*v.
x() + fTAlph*(phixz - 2*fDz*v.
y()))
 
  314           - 2*fDy1*(2*fdeltaX + fDx3minus1 + fDx4minus2
 
  315                   - 2*fdeltaY*fTAlph)*v.
z()
 
  316           + fa1md1*(phixz - 2*fDz*v.
y() + fdeltaY*v.
z()));
 
  318       fDy1*(fa1md1*(-5*phiyz - 24*fDz*v.
x() + 12*fdeltaX*v.
z()) + 
 
  319             fDy1*(20*phixz - 4*(5*fTAlph*phiyz + 24*fDz*fTAlph*v.
x()
 
  320                    + 24*fDz*v.
y()) + (48*fdeltaY + (fDx3plus1 + fDx4plus2)
 
  321                                     *fPhiTwist + 48*fdeltaX*fTAlph)*v.
z()));
 
  323       fDy1*(fa1md1*(phixz - 10*fDz*v.
y() + 5*fdeltaY*v.
z())
 
  324           + 2*fDy1*(2*phiyz + 20*fDz*v.
x()
 
  325                    + (-10*fdeltaX + fDx3minus1 + fDx4minus2)*v.
z()
 
  326                    + 2*fTAlph*(phixz - 10*fDz*v.
y() + 5*fdeltaY*v.
z())));
 
  328       fDy1*(-(fa1md1*(phiyz + 100*fDz*v.
x() - 50*fdeltaX*v.
z()))
 
  329           + fDy1*(4*phixz - 400*fDz*v.
y()
 
  330                   + (200*fdeltaY - (fDx3plus1 + fDx4plus2)*fPhiTwist)*v.
z()
 
  331                   - 4*fTAlph*(phiyz + 100*fDz*v.
x() - 50*fdeltaX*v.
z())));
 
  333       fDy1*(4*fDy1*(7*fTAlph*phixz + 7*phiyz - 6*fDz*v.
x() + 6*fDz*fTAlph*v.
y())
 
  334           + 6*fDy1*(2*fdeltaX+fDx3minus1+fDx4minus2-2*fdeltaY*fTAlph)*v.
z()
 
  335           + fa1md1*(7*phixz + 6*fDz*v.
y() - 3*fdeltaY*v.
z()));
 
  337       fDy1*(fa1md1*(-9*phiyz - 56*fDz*v.
x() + 28*fdeltaX*v.
z())
 
  338           + 4*fDy1*(9*phixz - 9*fTAlph*phiyz - 56*fDz*fTAlph*v.
x()
 
  339                   - 56*fDz*v.
y() + 28*(fdeltaY + fdeltaX*fTAlph)*v.
z()));
 
  341       fDy1*(fa1md1*(2*fDz*v.
y() - fdeltaY*v.
z())
 
  342           + fDy1*(-8*fDz*v.
x() + 8*fDz*fTAlph*v.
y()
 
  343                 + 4*fdeltaX*v.
z() - 4*fdeltaY*fTAlph*v.
z()));
 
  346     G4cout << 
"coef = " << c[0] << 
" "  
  359     for (
G4int i = 0 ; i<num ; i++ )   
 
  364         G4cout << 
"Solution " << i << 
" : " << srd[i] << 
G4endl ;
 
  366         phi = std::fmod(srd[i] , pihalf)  ;
 
  367         u   = (fDy1*(4*(phiyz + 2*fDz*phi*v.
y() - fdeltaY*phi*v.
z())
 
  368                      - ((fDx3plus1 + fDx4plus2)*fPhiTwist
 
  369                        + 2*(fDx3minus1 + fDx4minus2)*phi)*v.
z()*std::sin(phi)))
 
  370              /(fPhiTwist*v.
z()*(4*fDy1*std::cos(phi)
 
  371                              + (fa1md1 + 4*fDy1*fTAlph)*std::sin(phi)));        
 
  378         xbuf.push_back(xbuftmp) ;  
 
  381         G4cout << 
"solution " << i << 
" = " << phi << 
" , " << u  << 
G4endl ;
 
  396   for ( 
size_t k = 0 ; k<xbuf.size() ; k++ )
 
  399     G4cout << 
"Solution " << k << 
" : "  
  400            << 
"reconstructed phiR = " << xbuf[k].phi
 
  401            << 
", uR = " << xbuf[k].u << 
G4endl ; 
 
  407     IsConverged = false ;   
 
  409     for ( 
G4int i = 1 ; i<maxint ; i++ )
 
  411       xxonsurface = SurfacePoint(phi,u) ;
 
  412       surfacenormal = NormAng(phi,u) ;
 
  415       deltaX = ( tmpxx - xxonsurface ).mag() ; 
 
  416       theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
 
  428       G4cout << 
"Step i = " << i << 
", distance = " << tmpdist
 
  429              << 
", " << deltaX << 
G4endl ;
 
  433       GetPhiUAtX(tmpxx, phi, u) ;
 
  437       G4cout << 
"approximated phi = " << phi << 
", u = " << u << 
G4endl ; 
 
  440       if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
 
  444     if ( std::fabs(tmpdist)<ctol ) { tmpdist = 0 ; }
 
  447     G4cout << 
"refined solution "  << phi << 
" , " << u  <<  
G4endl ;
 
  458         tmpareacode = GetAreaCode(tmpxx);
 
  461           if (tmpdist >= 0) tmpisvalid = 
true;
 
  466         tmpareacode = GetAreaCode(tmpxx, 
false);
 
  469           if (tmpdist >= 0) { tmpisvalid = 
true; }
 
  474         G4Exception(
"G4TwistTrapAlphaSide::DistanceToSurface()",
 
  476                     "Feature NOT implemented !");
 
  488     xbuf[k].distance = tmpdist ;
 
  489     xbuf[k].areacode = tmpareacode ;
 
  490     xbuf[k].isvalid = tmpisvalid ;
 
  497   G4cout << G4endl << 
"list xbuf after sorting : " << 
G4endl ;
 
  509   G4int nxxtmp = xbuf.size() ;
 
  511   if ( nxxtmp<2 || IsParallel  )  
 
  527     xbuf.push_back(xbuftmp) ;  
 
  542     xbuf.push_back(xbuftmp) ;  
 
  544     for ( 
size_t k = nxxtmp ; k<xbuf.size() ; k++ )
 
  548       G4cout << 
"Solution " << k << 
" : "  
  549              << 
"reconstructed phiR = " << xbuf[k].phi
 
  550              << 
", uR = " << xbuf[k].u << 
G4endl ; 
 
  556       IsConverged = false ;   
 
  558       for ( 
G4int i = 1 ; i<maxint ; i++ )
 
  560         xxonsurface = SurfacePoint(phi,u) ;
 
  561         surfacenormal = NormAng(phi,u) ;
 
  563         deltaX = ( tmpxx - xxonsurface ).mag();
 
  564         theta = std::fabs(std::acos(v*surfacenormal) - pihalf);
 
  575         G4cout << 
"Step i = " << i << 
", distance = " << tmpdist
 
  576                << 
", " << deltaX << G4endl
 
  577                << 
"X = " << tmpxx << 
G4endl ;
 
  580         GetPhiUAtX(tmpxx, phi, u) ;
 
  584         G4cout << 
"approximated phi = " << phi << 
", u = " << u << 
G4endl ; 
 
  587         if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
 
  591       if ( std::fabs(tmpdist)<ctol )  { tmpdist = 0; }
 
  594       G4cout << 
"refined solution "  << phi << 
" , " << u  <<  
G4endl ;
 
  605           tmpareacode = GetAreaCode(tmpxx);
 
  608             if (tmpdist >= 0)  { tmpisvalid = 
true; }
 
  613           tmpareacode = GetAreaCode(tmpxx, 
false);
 
  616             if (tmpdist >= 0)  { tmpisvalid = 
true; }
 
  621           G4Exception(
"G4TwistedBoxSide::DistanceToSurface()",
 
  623                       "Feature NOT implemented !");
 
  635       xbuf[k].distance = tmpdist ;
 
  636       xbuf[k].areacode = tmpareacode ;
 
  637       xbuf[k].isvalid = tmpisvalid ;
 
  650   G4cout << G4endl << 
"list xbuf after sorting : " << 
G4endl ;
 
  656   for ( 
size_t i = 0 ; i<xbuf.size() ; i++ )
 
  658     distance[i] = xbuf[i].distance;
 
  660     areacode[i] = xbuf[i].areacode ;
 
  661     isvalid[i]  = xbuf[i].isvalid ;
 
  664                                      isvalid[i], nxx, validate, &gp, &gv);
 
  666     G4cout << 
"element Nr. " << i 
 
  667            << 
", local Intersection = " << xbuf[i].xx 
 
  668            << 
", distance = " << xbuf[i].distance 
 
  669            << 
", u = " << xbuf[i].u 
 
  670            << 
", phi = " << xbuf[i].phi 
 
  671            << 
", isvalid = " << xbuf[i].isvalid 
 
  679   G4cout << nxx << 
" possible physical solutions found" << 
G4endl ;
 
  680   for ( 
G4int k= 0 ; k< nxx ; k++ )
 
  682     G4cout << 
"global intersection Point found: " << gxx[k] << 
G4endl ;
 
void set(double x, double y, double z)
 
G4int GetAreacode(G4int i) const 
 
static const G4double kInfinity
 
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const 
 
G4double DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
 
static const G4int sOutside
 
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const 
 
G4GLOB_DLL std::ostream G4cout
 
G4bool IsOutside(G4int areacode) const 
 
G4double GetDistance(G4int i) const 
 
void SetCurrentStatus(G4int i, G4ThreeVector &xx, G4double &dist, G4int &areacode, G4bool &isvalid, G4int nxx, EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=0)
 
G4bool IsValid(G4int i) const 
 
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const 
 
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
 
G4ThreeVector GetXX(G4int i) const 
 
G4bool EqualIntersection(const Intersection &a, const Intersection &b)
 
static constexpr double pi
 
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const 
 
static constexpr double L
 
G4bool DistanceSort(const Intersection &a, const Intersection &b)
 
G4int FindRoots(G4double *op, G4int degree, G4double *zeror, G4double *zeroi)
 
CurrentStatus fCurStatWithV
 
void ResetfDone(EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=0)