86 fTAlph = std::tan(fAlph) ;
92 fDx4plus2 = fDx4 + fDx2 ;
93 fDx4minus2 = fDx4 - fDx2 ;
94 fDx3plus1 = fDx3 + fDx1 ;
95 fDx3minus1 = fDx3 - fDx1 ;
96 fDy2plus1 = fDy2 + fDy1 ;
97 fDy2minus1 = fDy2 - fDy1 ;
99 fa1md1 = 2*fDx2 - 2*fDx1 ;
100 fa2md2 = 2*fDx4 - 2*fDx3 ;
102 fPhiTwist = PhiTwist ;
103 fAngleSide = AngleSide ;
105 fdeltaX = 2 * fDz * std::tan(fTheta) * std::cos(fPhi);
107 fdeltaY = 2 * fDz * std::tan(fTheta) * std::sin(fPhi);
125 :
G4VTwistSurface(a), fTheta(0.), fPhi(0.), fDy1(0.), fDx1(0.), fDx2(0.),
126 fDy2(0.), fDx3(0.), fDx4(0.), fDz(0.), fAlph(0.), fTAlph(0.), fPhiTwist(0.),
127 fAngleSide(0.), fDx4plus2(0.), fDx4minus2(0.), fDx3plus1(0.), fDx3minus1(0.),
128 fDy2plus1(0.), fDy2minus1(0.), fa1md1(0.), fa2md2(0.), fdeltaX(0.),
175 GetPhiUAtX(xx,phi,u) ;
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 ;
738 for (
G4int i = 1 ; i<20 ; i++ )
740 xxonsurface = SurfacePoint(phiR,uR) ;
741 surfacenormal = NormAng(phiR,uR) ;
743 deltaX = ( xx - xxonsurface ).mag() ;
746 G4cout <<
"i = " << i <<
", distance = " << distance[0]
747 <<
", " << deltaX <<
G4endl
748 <<
"X = " << xx <<
G4endl ;
753 GetPhiUAtX(xx, phiR, uR) ;
755 if ( deltaX <= ctol ) { break ; }
760 uMax = GetBoundaryMax(phiR) ;
762 if ( phiR > halfphi ) { phiR = halfphi ; }
763 if ( phiR < -halfphi ) { phiR = -halfphi ; }
764 if ( uR > uMax ) { uR = uMax ; }
765 if ( uR < -uMax ) { uR = -uMax ; }
767 xxonsurface = SurfacePoint(phiR,uR) ;
768 distance[0] = ( p - xx ).mag() ;
769 if ( distance[0] <= ctol ) { distance[0] = 0 ; }
774 G4cout <<
"refined solution " << phiR <<
" , " << uR <<
" , " <<
G4endl ;
783 G4cout <<
"intersection Point found: " << gxx[0] <<
G4endl ;
806 GetPhiUAtX(xx, phi,yprime ) ;
808 G4double fYAxisMax = GetBoundaryMax(phi) ;
809 G4double fYAxisMin = GetBoundaryMin(phi) ;
813 G4cout <<
"GetAreaCode: yprime = " << yprime <<
G4endl ;
814 G4cout <<
"Intervall is " << fYAxisMin <<
" to " << fYAxisMax <<
G4endl ;
829 if (yprime < fYAxisMin + ctol)
832 if (yprime <= fYAxisMin - ctol) { isoutside =
true; }
835 else if (yprime > fYAxisMax - ctol)
838 if (yprime >= fYAxisMax + ctol) { isoutside =
true; }
852 if (xx.
z() <=
fAxisMin[zaxis] - ctol) { isoutside =
true; }
854 else if (xx.
z() >
fAxisMax[zaxis] - ctol)
858 if (areacode & sBoundary)
862 if (xx.
z() >=
fAxisMax[zaxis] + ctol) { isoutside =
true; }
871 areacode = tmpareacode;
873 else if ((areacode & sBoundary) !=
sBoundary)
883 if (yprime < fYAxisMin )
887 else if (yprime > fYAxisMax)
897 if (areacode & sBoundary)
905 if (areacode & sBoundary)
922 "Feature NOT implemented !");
930 void G4TwistTrapAlphaSide::SetCorners()
942 x = -fdeltaX/2. + (fDx1 - fDy1*fTAlph)*std::cos(fPhiTwist/2.)
943 - fDy1*std::sin(fPhiTwist/2.);
944 y = -fdeltaY/2. - fDy1*std::cos(fPhiTwist/2.)
945 + (-fDx1 + fDy1*fTAlph)*std::sin(fPhiTwist/2.);
954 x = -fdeltaX/2. + (fDx2 + fDy1*fTAlph)*std::cos(fPhiTwist/2.)
955 + fDy1*std::sin(fPhiTwist/2.);
956 y = -fdeltaY/2. + fDy1*std::cos(fPhiTwist/2.)
957 - (fDx2 + fDy1*fTAlph)*std::sin(fPhiTwist/2.);
966 x = fdeltaX/2. + (fDx4 + fDy2*fTAlph)*std::cos(fPhiTwist/2.)
967 - fDy2*std::sin(fPhiTwist/2.);
968 y = fdeltaY/2. + fDy2*std::cos(fPhiTwist/2.)
969 + (fDx4 + fDy2*fTAlph)*std::sin(fPhiTwist/2.);
977 x = fdeltaX/2. + (fDx3 - fDy2*fTAlph)*std::cos(fPhiTwist/2.)
978 + fDy2*std::sin(fPhiTwist/2.) ;
979 y = fdeltaY/2. - fDy2*std::cos(fPhiTwist/2.)
980 + (fDx3 - fDy2*fTAlph)*std::sin(fPhiTwist/2.) ;
992 "Method NOT implemented !");
999 void G4TwistTrapAlphaSide::SetBoundaries()
1010 direction = direction.
unit();
1016 direction = direction.
unit();
1022 direction = direction.
unit();
1028 direction = direction.
unit();
1037 "Feature NOT implemented !");
1053 phi = p.
z()/(2*fDz)*fPhiTwist ;
1054 u = (fPhiTwist*(2*fDx1*fDx1 - 2*fDx2*fDx2 - fa1md1*(fDx3 + fDx4)
1055 - 4*(fDx3plus1 + fDx4plus2)*fDy1*fTAlph)
1056 - 2*(2*fDx1*fDx1 - 2*fDx2*fDx2 + fa1md1*(fDx3 + fDx4)
1057 + 4*(fDx3minus1 + fDx4minus2)*fDy1*fTAlph)*phi
1058 - 4*(fa1md1*(fdeltaX*phi - fPhiTwist*p.
x())
1059 + 4*fDy1*(fdeltaY*phi + fdeltaX*fTAlph*phi
1060 - fPhiTwist*(fTAlph*p.
x() + p.
y())))*std::cos(phi)
1061 - 4*(fa1md1*fdeltaY*phi - 4*fdeltaX*fDy1*phi
1062 + 4*fdeltaY*fDy1*fTAlph*phi + 4*fDy1*fPhiTwist*p.
x()
1063 - fPhiTwist*(fa1md1 + 4*fDy1*fTAlph)*p.
y())*std::sin(phi))
1064 /(fDy1* fPhiTwist*((std::fabs(((fa1md1 + 4*fDy1*fTAlph)*std::cos(phi))
1065 /fDy1 - 4*std::sin(phi)))
1066 *(std::fabs(((fa1md1 + 4*fDy1*fTAlph)*std::cos(phi))
1067 /fDy1 - 4*std::sin(phi)))
1068 + (std::fabs(4*std::cos(phi)
1069 + ((fa1md1 + 4*fDy1*fTAlph)*std::sin(phi))/fDy1))
1070 * (std::fabs(4*std::cos(phi)
1071 + ((fa1md1 + 4*fDy1*fTAlph)*std::sin(phi))/fDy1)))) ;
1095 GetPhiUAtX( tmpp, phi, u ) ;
1130 for (
G4int i = 0 ; i<
n ; i++ )
1132 z = -fDz+i*(2.*fDz)/(n-1) ;
1133 phi = z*fPhiTwist/(2*fDz) ;
1134 b = GetValueB(phi) ;
1136 for (
G4int j = 0 ; j<k ; j++ )
1138 nnode =
GetNode(i,j,k,n,iside) ;
1139 u = -b/2 +j*b/(k-1) ;
1140 p = SurfacePoint(phi,u,
true) ;
1142 xyz[nnode][0] = p.
x() ;
1143 xyz[nnode][1] = p.
y() ;
1144 xyz[nnode][2] = p.
z() ;
1146 if ( i<n-1 && j<k-1 )
1148 nface =
GetFace(i,j,k,n,iside) ;
1150 * (
GetNode(i ,j ,k,n,iside)+1) ;
1152 * (
GetNode(i ,j+1,k,n,iside)+1) ;
1154 * (
GetNode(i+1,j+1,k,n,iside)+1) ;
1156 * (
GetNode(i+1,j ,k,n,iside)+1) ;
static const G4int sAxisZ
void set(double x, double y, double z)
G4int GetAreacode(G4int i) const
void SetCorner(G4int areacode, G4double x, G4double y, G4double z)
static const G4int sC0Min1Max
static const G4double kInfinity
G4ThreeVector ComputeGlobalDirection(const G4ThreeVector &lp) const
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const
G4SurfCurNormal fCurrentNormal
G4double DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4ThreeVector GetCorner(G4int areacode) const
static const G4int sOutside
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const
virtual ~G4TwistTrapAlphaSide()
HepRotation inverse() const
static double normal(HepRandomEngine *eptr)
static const G4int sC0Min1Min
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)
G4GLOB_DLL std::ostream G4cout
G4bool IsOutside(G4int areacode) const
G4double GetDistance(G4int i) const
static const G4int sAxis1
static const G4int sC0Max1Max
static const G4int sBoundary
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
G4double DistanceToPlane(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
static const G4int sAxis0
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const
static const G4int sAxisMin
virtual G4ThreeVector GetNormal(const G4ThreeVector &xx, G4bool isGlobal=false)
static const G4int sAxisY
static const G4int sInside
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
static const G4int sCorner
G4int GetNode(G4int i, G4int j, G4int m, G4int n, G4int iside)
static const G4int sAxisMax
virtual G4int DistanceToSurface(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol)
G4ThreeVector GetXX(G4int i) const
virtual void SetBoundary(const G4int &axiscode, const G4ThreeVector &direction, const G4ThreeVector &x0, const G4int &boundarytype)
HepRotation & rotateZ(double delta)
G4bool EqualIntersection(const Intersection &a, const Intersection &b)
G4int GetFace(G4int i, G4int j, G4int m, G4int n, G4int iside)
static constexpr double pi
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const
G4int GetEdgeVisibility(G4int i, G4int j, G4int m, G4int n, G4int number, G4int orientation)
static constexpr double L
G4bool DistanceSort(const Intersection &a, const Intersection &b)
static const G4int sC0Max1Min
G4int FindRoots(G4double *op, G4int degree, G4double *zeror, G4double *zeroi)
CurrentStatus fCurStatWithV
void ResetfDone(EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=0)