75 fTAlph = std::tan(fAlph) ;
81 fDx4plus2 = fDx4 + fDx2 ;
82 fDx4minus2 = fDx4 - fDx2 ;
83 fDx3plus1 = fDx3 + fDx1 ;
84 fDx3minus1 = fDx3 - fDx1 ;
85 fDy2plus1 = fDy2 + fDy1 ;
86 fDy2minus1 = fDy2 - fDy1 ;
88 fa1md1 = 2*fDx2 - 2*fDx1 ;
89 fa2md2 = 2*fDx4 - 2*fDx3 ;
91 fPhiTwist = PhiTwist ;
92 fAngleSide = AngleSide ;
94 fdeltaX = 2 * fDz * std::tan(fTheta) * std::cos(fPhi);
96 fdeltaY = 2 * fDz * std::tan(fTheta) * std::sin(fPhi);
113 :
G4VTwistSurface(a), fTheta(0.), fPhi(0.), fDy1(0.), fDx1(0.), fDx2(0.),
114 fDy2(0.), fDx3(0.), fDx4(0.), fDz(0.), fAlph(0.), fTAlph(0.), fPhiTwist(0.),
115 fAngleSide(0.), fDx4plus2(0.), fDx4minus2(0.), fDx3plus1(0.), fDx3minus1(0.),
116 fDy2plus1(0.), fDy2minus1(0.), fa1md1(0.), fa2md2(0.), fdeltaX(0.),
163 GetPhiUAtX(xx,phi,u) ;
196 static const G4double pihalf = pi/2 ;
199 G4bool IsParallel = false ;
200 G4bool IsConverged = false ;
221 distance[j] = kInfinity;
224 gxx[j].
set(kInfinity, kInfinity, kInfinity);
243 G4bool tmpisvalid = false ;
245 std::vector<Intersection> xbuf ;
252 G4double phixz = fPhiTwist * ( p.
x() * v.
z() - p.
z() * v.
x() ) ;
253 G4double phiyz = fPhiTwist * ( p.
y() * v.
z() - p.
z() * v.
y() ) ;
260 if ( std::fabs(p.
z()) <= L )
262 phi = p.
z() * fPhiTwist / L ;
263 u = (fDy1*(4*(-(fdeltaY*phi*v.
x()) + fPhiTwist*p.
y()*v.
x()
264 + fdeltaX*phi*v.
y() - fPhiTwist*p.
x()*v.
y())
265 + ((fDx3plus1 + fDx4plus2)*fPhiTwist
266 + 2*(fDx3minus1 + fDx4minus2)*phi)
267 *(v.
y()*std::cos(phi) - v.
x()*std::sin(phi))))
268 /(fPhiTwist*(4*fDy1* v.
x() - (fa1md1 + 4*fDy1*fTAlph)*v.
y())
269 *std::cos(phi) + fPhiTwist*(fa1md1*v.
x()
270 + 4*fDy1*(fTAlph*v.
x() + v.
y()))*std::sin(phi));
277 xbuf.push_back(xbuftmp) ;
281 distance[0] = kInfinity;
282 gxx[0].
set(kInfinity,kInfinity,kInfinity);
286 areacode[0], isvalid[0],
287 0, validate, &gp, &gv);
298 fDy1*(-4*phixz + 4*fTAlph*phiyz
299 + (fDx3plus1 + fDx4plus2)*fPhiTwist*v.
z())) ;
301 fDy1*(4*fDy1*(phiyz + 2*fDz*v.
x() + fTAlph*(phixz - 2*fDz*v.
y()))
302 - 2*fDy1*(2*fdeltaX + fDx3minus1 + fDx4minus2
303 - 2*fdeltaY*fTAlph)*v.
z()
304 + fa1md1*(phixz - 2*fDz*v.
y() + fdeltaY*v.
z()));
306 fDy1*(fa1md1*(-5*phiyz - 24*fDz*v.
x() + 12*fdeltaX*v.
z()) +
307 fDy1*(20*phixz - 4*(5*fTAlph*phiyz + 24*fDz*fTAlph*v.
x()
308 + 24*fDz*v.
y()) + (48*fdeltaY + (fDx3plus1 + fDx4plus2)
309 *fPhiTwist + 48*fdeltaX*fTAlph)*v.
z()));
311 fDy1*(fa1md1*(phixz - 10*fDz*v.
y() + 5*fdeltaY*v.
z())
312 + 2*fDy1*(2*phiyz + 20*fDz*v.
x()
313 + (-10*fdeltaX + fDx3minus1 + fDx4minus2)*v.
z()
314 + 2*fTAlph*(phixz - 10*fDz*v.
y() + 5*fdeltaY*v.
z())));
316 fDy1*(-(fa1md1*(phiyz + 100*fDz*v.
x() - 50*fdeltaX*v.
z()))
317 + fDy1*(4*phixz - 400*fDz*v.
y()
318 + (200*fdeltaY - (fDx3plus1 + fDx4plus2)*fPhiTwist)*v.
z()
319 - 4*fTAlph*(phiyz + 100*fDz*v.
x() - 50*fdeltaX*v.
z())));
321 fDy1*(4*fDy1*(7*fTAlph*phixz + 7*phiyz - 6*fDz*v.
x() + 6*fDz*fTAlph*v.
y())
322 + 6*fDy1*(2*fdeltaX+fDx3minus1+fDx4minus2-2*fdeltaY*fTAlph)*v.
z()
323 + fa1md1*(7*phixz + 6*fDz*v.
y() - 3*fdeltaY*v.
z()));
325 fDy1*(fa1md1*(-9*phiyz - 56*fDz*v.
x() + 28*fdeltaX*v.
z())
326 + 4*fDy1*(9*phixz - 9*fTAlph*phiyz - 56*fDz*fTAlph*v.
x()
327 - 56*fDz*v.
y() + 28*(fdeltaY + fdeltaX*fTAlph)*v.
z()));
329 fDy1*(fa1md1*(2*fDz*v.
y() - fdeltaY*v.
z())
330 + fDy1*(-8*fDz*v.
x() + 8*fDz*fTAlph*v.
y()
331 + 4*fdeltaX*v.
z() - 4*fdeltaY*fTAlph*v.
z()));
334 G4cout <<
"coef = " << c[0] <<
" "
347 for (
G4int i = 0 ; i<num ; i++ )
352 G4cout <<
"Solution " << i <<
" : " << srd[i] <<
G4endl ;
354 phi = std::fmod(srd[i] , pihalf) ;
355 u = (fDy1*(4*(phiyz + 2*fDz*phi*v.
y() - fdeltaY*phi*v.
z())
356 - ((fDx3plus1 + fDx4plus2)*fPhiTwist
357 + 2*(fDx3minus1 + fDx4minus2)*phi)*v.
z()*std::sin(phi)))
358 /(fPhiTwist*v.
z()*(4*fDy1*std::cos(phi)
359 + (fa1md1 + 4*fDy1*fTAlph)*std::sin(phi)));
366 xbuf.push_back(xbuftmp) ;
369 G4cout <<
"solution " << i <<
" = " << phi <<
" , " << u <<
G4endl ;
384 for (
size_t k = 0 ; k<xbuf.size() ; ++k )
387 G4cout <<
"Solution " << k <<
" : "
388 <<
"reconstructed phiR = " << xbuf[k].phi
389 <<
", uR = " << xbuf[k].u <<
G4endl ;
395 IsConverged = false ;
397 for (
G4int i = 1 ; i<maxint ; ++i )
399 xxonsurface = SurfacePoint(phi,u) ;
400 surfacenormal = NormAng(phi,u) ;
403 deltaX = ( tmpxx - xxonsurface ).mag() ;
404 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
416 G4cout <<
"Step i = " << i <<
", distance = " << tmpdist
417 <<
", " << deltaX <<
G4endl ;
421 GetPhiUAtX(tmpxx, phi, u) ;
425 G4cout <<
"approximated phi = " << phi <<
", u = " << u <<
G4endl ;
428 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
432 if ( std::fabs(tmpdist)<ctol ) { tmpdist = 0 ; }
435 G4cout <<
"refined solution " << phi <<
" , " << u <<
G4endl ;
446 tmpareacode = GetAreaCode(tmpxx);
449 if (tmpdist >= 0) tmpisvalid =
true;
454 tmpareacode = GetAreaCode(tmpxx,
false);
457 if (tmpdist >= 0) { tmpisvalid =
true; }
462 G4Exception(
"G4TwistTrapAlphaSide::DistanceToSurface()",
464 "Feature NOT implemented !");
476 xbuf[k].distance = tmpdist ;
477 xbuf[k].areacode = tmpareacode ;
478 xbuf[k].isvalid = tmpisvalid ;
497 G4int nxxtmp = xbuf.size() ;
499 if ( nxxtmp<2 || IsParallel )
515 xbuf.push_back(xbuftmp) ;
530 xbuf.push_back(xbuftmp) ;
532 for (
size_t k = nxxtmp ; k<xbuf.size() ; ++k )
536 G4cout <<
"Solution " << k <<
" : "
537 <<
"reconstructed phiR = " << xbuf[k].phi
538 <<
", uR = " << xbuf[k].u <<
G4endl ;
544 IsConverged = false ;
546 for (
G4int i = 1 ; i<maxint ; ++i )
548 xxonsurface = SurfacePoint(phi,u) ;
549 surfacenormal = NormAng(phi,u) ;
551 deltaX = ( tmpxx - xxonsurface ).mag();
552 theta = std::fabs(std::acos(v*surfacenormal) - pihalf);
563 G4cout <<
"Step i = " << i <<
", distance = " << tmpdist
564 <<
", " << deltaX <<
G4endl
565 <<
"X = " << tmpxx <<
G4endl ;
568 GetPhiUAtX(tmpxx, phi, u) ;
572 G4cout <<
"approximated phi = " << phi <<
", u = " << u <<
G4endl ;
575 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
579 if ( std::fabs(tmpdist)<ctol ) { tmpdist = 0; }
582 G4cout <<
"refined solution " << phi <<
" , " << u <<
G4endl ;
593 tmpareacode = GetAreaCode(tmpxx);
596 if (tmpdist >= 0) { tmpisvalid =
true; }
601 tmpareacode = GetAreaCode(tmpxx,
false);
604 if (tmpdist >= 0) { tmpisvalid =
true; }
609 G4Exception(
"G4TwistedBoxSide::DistanceToSurface()",
611 "Feature NOT implemented !");
623 xbuf[k].distance = tmpdist ;
624 xbuf[k].areacode = tmpareacode ;
625 xbuf[k].isvalid = tmpisvalid ;
644 for (
size_t i = 0 ; i<xbuf.size() ; ++i )
646 distance[i] = xbuf[i].distance;
648 areacode[i] = xbuf[i].areacode ;
649 isvalid[i] = xbuf[i].isvalid ;
652 isvalid[i], nxx, validate, &gp, &gv);
654 G4cout <<
"element Nr. " << i
655 <<
", local Intersection = " << xbuf[i].xx
656 <<
", distance = " << xbuf[i].distance
657 <<
", u = " << xbuf[i].u
658 <<
", phi = " << xbuf[i].phi
659 <<
", isvalid = " << xbuf[i].isvalid
667 G4cout << nxx <<
" possible physical solutions found" <<
G4endl ;
668 for (
G4int k= 0 ; k< nxx ; k++ )
670 G4cout <<
"global intersection Point found: " << gxx[k] <<
G4endl ;
707 distance[i] = kInfinity;
709 gxx[i].
set(kInfinity, kInfinity, kInfinity);
726 for (
G4int i = 1 ; i<20 ; ++i )
728 xxonsurface = SurfacePoint(phiR,uR) ;
729 surfacenormal = NormAng(phiR,uR) ;
731 deltaX = ( xx - xxonsurface ).mag() ;
734 G4cout <<
"i = " << i <<
", distance = " << distance[0]
735 <<
", " << deltaX <<
G4endl
736 <<
"X = " << xx <<
G4endl ;
741 GetPhiUAtX(xx, phiR, uR) ;
743 if ( deltaX <= ctol ) { break ; }
748 uMax = GetBoundaryMax(phiR) ;
750 if ( phiR > halfphi ) { phiR = halfphi ; }
751 if ( phiR < -halfphi ) { phiR = -halfphi ; }
752 if ( uR > uMax ) { uR = uMax ; }
753 if ( uR < -uMax ) { uR = -uMax ; }
755 xxonsurface = SurfacePoint(phiR,uR) ;
756 distance[0] = ( p - xx ).mag() ;
757 if ( distance[0] <= ctol ) { distance[0] = 0 ; }
762 G4cout <<
"refined solution " << phiR <<
" , " << uR <<
" , " <<
G4endl ;
771 G4cout <<
"intersection Point found: " << gxx[0] <<
G4endl ;
794 GetPhiUAtX(xx, phi,yprime ) ;
796 G4double fYAxisMax = GetBoundaryMax(phi) ;
797 G4double fYAxisMin = GetBoundaryMin(phi) ;
801 G4cout <<
"GetAreaCode: yprime = " << yprime <<
G4endl ;
802 G4cout <<
"Intervall is " << fYAxisMin <<
" to " << fYAxisMax <<
G4endl ;
817 if (yprime < fYAxisMin + ctol)
820 if (yprime <= fYAxisMin - ctol) { isoutside =
true; }
823 else if (yprime > fYAxisMax - ctol)
826 if (yprime >= fYAxisMax + ctol) { isoutside =
true; }
840 if (xx.
z() <=
fAxisMin[zaxis] - ctol) { isoutside =
true; }
842 else if (xx.
z() >
fAxisMax[zaxis] - ctol)
850 if (xx.
z() >=
fAxisMax[zaxis] + ctol) { isoutside =
true; }
858 G4int tmpareacode = areacode & (~sInside);
859 areacode = tmpareacode;
871 if (yprime < fYAxisMin )
875 else if (yprime > fYAxisMax)
910 "Feature NOT implemented !");
918void G4TwistTrapAlphaSide::SetCorners()
930 x = -fdeltaX/2. + (fDx1 - fDy1*fTAlph)*std::cos(fPhiTwist/2.)
931 - fDy1*std::sin(fPhiTwist/2.);
932 y = -fdeltaY/2. - fDy1*std::cos(fPhiTwist/2.)
933 + (-fDx1 + fDy1*fTAlph)*std::sin(fPhiTwist/2.);
942 x = -fdeltaX/2. + (fDx2 + fDy1*fTAlph)*std::cos(fPhiTwist/2.)
943 + fDy1*std::sin(fPhiTwist/2.);
944 y = -fdeltaY/2. + fDy1*std::cos(fPhiTwist/2.)
945 - (fDx2 + fDy1*fTAlph)*std::sin(fPhiTwist/2.);
954 x = fdeltaX/2. + (fDx4 + fDy2*fTAlph)*std::cos(fPhiTwist/2.)
955 - fDy2*std::sin(fPhiTwist/2.);
956 y = fdeltaY/2. + fDy2*std::cos(fPhiTwist/2.)
957 + (fDx4 + fDy2*fTAlph)*std::sin(fPhiTwist/2.);
965 x = fdeltaX/2. + (fDx3 - fDy2*fTAlph)*std::cos(fPhiTwist/2.)
966 + fDy2*std::sin(fPhiTwist/2.) ;
967 y = fdeltaY/2. - fDy2*std::cos(fPhiTwist/2.)
968 + (fDx3 - fDy2*fTAlph)*std::sin(fPhiTwist/2.) ;
980 "Method NOT implemented !");
987void G4TwistTrapAlphaSide::SetBoundaries()
998 direction = direction.
unit();
1004 direction = direction.
unit();
1010 direction = direction.
unit();
1016 direction = direction.
unit();
1025 "Feature NOT implemented !");
1041 phi = p.
z()/(2*fDz)*fPhiTwist ;
1042 u = (fPhiTwist*(2*fDx1*fDx1 - 2*fDx2*fDx2 - fa1md1*(fDx3 + fDx4)
1043 - 4*(fDx3plus1 + fDx4plus2)*fDy1*fTAlph)
1044 - 2*(2*fDx1*fDx1 - 2*fDx2*fDx2 + fa1md1*(fDx3 + fDx4)
1045 + 4*(fDx3minus1 + fDx4minus2)*fDy1*fTAlph)*phi
1046 - 4*(fa1md1*(fdeltaX*phi - fPhiTwist*p.
x())
1047 + 4*fDy1*(fdeltaY*phi + fdeltaX*fTAlph*phi
1048 - fPhiTwist*(fTAlph*p.
x() + p.
y())))*std::cos(phi)
1049 - 4*(fa1md1*fdeltaY*phi - 4*fdeltaX*fDy1*phi
1050 + 4*fdeltaY*fDy1*fTAlph*phi + 4*fDy1*fPhiTwist*p.
x()
1051 - fPhiTwist*(fa1md1 + 4*fDy1*fTAlph)*p.
y())*std::sin(phi))
1052 /(fDy1* fPhiTwist*((std::fabs(((fa1md1 + 4*fDy1*fTAlph)*std::cos(phi))
1053 /fDy1 - 4*std::sin(phi)))
1054 *(std::fabs(((fa1md1 + 4*fDy1*fTAlph)*std::cos(phi))
1055 /fDy1 - 4*std::sin(phi)))
1056 + (std::fabs(4*std::cos(phi)
1057 + ((fa1md1 + 4*fDy1*fTAlph)*std::sin(phi))/fDy1))
1058 * (std::fabs(4*std::cos(phi)
1059 + ((fa1md1 + 4*fDy1*fTAlph)*std::sin(phi))/fDy1)))) ;
1083 GetPhiUAtX( tmpp, phi, u ) ;
1118 for (
G4int i = 0 ; i<
n ; ++i )
1120 z = -fDz+i*(2.*fDz)/(n-1) ;
1121 phi = z*fPhiTwist/(2*fDz) ;
1122 b = GetValueB(phi) ;
1124 for (
G4int j = 0 ; j<k ; ++j )
1126 nnode =
GetNode(i,j,k,n,iside) ;
1127 u = -b/2 +j*b/(k-1) ;
1128 p = SurfacePoint(phi,u,
true) ;
1130 xyz[nnode][0] = p.
x() ;
1131 xyz[nnode][1] = p.
y() ;
1132 xyz[nnode][2] = p.
z() ;
1134 if ( i<n-1 && j<k-1 )
1136 nface =
GetFace(i,j,k,n,iside) ;
1138 * (
GetNode(i ,j ,k,n,iside)+1) ;
1140 * (
GetNode(i ,j+1,k,n,iside)+1) ;
1142 * (
GetNode(i+1,j+1,k,n,iside)+1) ;
1144 * (
GetNode(i+1,j ,k,n,iside)+1) ;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4bool DistanceSort(const Intersection &a, const Intersection &b)
G4bool EqualIntersection(const Intersection &a, const Intersection &b)
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
HepRotation inverse() const
HepRotation & rotateZ(double delta)
G4int FindRoots(G4double *op, G4int degree, G4double *zeror, G4double *zeroi)
virtual G4int DistanceToSurface(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol)
virtual ~G4TwistTrapAlphaSide()
G4TwistTrapAlphaSide(const G4String &name, G4double PhiTwist, G4double pDz, G4double pTheta, G4double pPhi, G4double pDy1, G4double pDx1, G4double pDx2, G4double pDy2, G4double pDx3, G4double pDx4, G4double pAlph, G4double AngleSide)
virtual G4ThreeVector GetNormal(const G4ThreeVector &xx, G4bool isGlobal=false)
G4int GetAreacode(G4int i) const
G4double GetDistance(G4int i) const
G4bool IsValid(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=nullptr)
G4ThreeVector GetXX(G4int i) const
void ResetfDone(EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=nullptr)
static const G4int sC0Min1Min
static const G4int sC0Min1Max
G4double DistanceToPlane(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4int GetNode(G4int i, G4int j, G4int m, G4int n, G4int iside)
static const G4int sOutside
G4ThreeVector ComputeGlobalDirection(const G4ThreeVector &lp) const
static const G4int sAxisMax
static const G4int sAxis0
G4int GetFace(G4int i, G4int j, G4int m, G4int n, G4int iside)
G4int GetEdgeVisibility(G4int i, G4int j, G4int m, G4int n, G4int number, G4int orientation)
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const
static const G4int sAxisMin
static const G4int sC0Max1Max
static const G4int sAxis1
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const
virtual void SetBoundary(const G4int &axiscode, const G4ThreeVector &direction, const G4ThreeVector &x0, const G4int &boundarytype)
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const
void SetCorner(G4int areacode, G4double x, G4double y, G4double z)
G4ThreeVector GetCorner(G4int areacode) const
static const G4int sBoundary
static const G4int sAxisZ
G4bool IsOutside(G4int areacode) const
static const G4int sCorner
static const G4int sC0Max1Min
static const G4int sInside
CurrentStatus fCurStatWithV
static const G4int sAxisY
G4double DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const
G4SurfCurNormal fCurrentNormal