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);
157 GetPhiUAtX(xx,phi,u) ;
190 static const G4double pihalf = pi/2 ;
193 G4bool IsParallel = false ;
194 G4bool IsConverged = false ;
215 distance[j] = kInfinity;
218 gxx[j].
set(kInfinity, kInfinity, kInfinity);
237 G4bool tmpisvalid = false ;
239 std::vector<Intersection> xbuf ;
246 G4double phixz = fPhiTwist * ( p.
x() * v.
z() - p.
z() * v.
x() ) ;
247 G4double phiyz = fPhiTwist * ( p.
y() * v.
z() - p.
z() * v.
y() ) ;
254 if ( std::fabs(p.
z()) <= L )
256 phi = p.
z() * fPhiTwist / L ;
257 u = (fDy1*(4*(-(fdeltaY*phi*v.
x()) + fPhiTwist*p.
y()*v.
x()
258 + fdeltaX*phi*v.
y() - fPhiTwist*p.
x()*v.
y())
259 + ((fDx3plus1 + fDx4plus2)*fPhiTwist
260 + 2*(fDx3minus1 + fDx4minus2)*phi)
261 *(v.
y()*std::cos(phi) - v.
x()*std::sin(phi))))
262 /(fPhiTwist*(4*fDy1* v.
x() - (fa1md1 + 4*fDy1*fTAlph)*v.
y())
263 *std::cos(phi) + fPhiTwist*(fa1md1*v.
x()
264 + 4*fDy1*(fTAlph*v.
x() + v.
y()))*std::sin(phi));
271 xbuf.push_back(xbuftmp) ;
275 distance[0] = kInfinity;
276 gxx[0].
set(kInfinity,kInfinity,kInfinity);
280 areacode[0], isvalid[0],
281 0, validate, &gp, &gv);
292 fDy1*(-4*phixz + 4*fTAlph*phiyz
293 + (fDx3plus1 + fDx4plus2)*fPhiTwist*v.
z())) ;
295 fDy1*(4*fDy1*(phiyz + 2*fDz*v.
x() + fTAlph*(phixz - 2*fDz*v.
y()))
296 - 2*fDy1*(2*fdeltaX + fDx3minus1 + fDx4minus2
297 - 2*fdeltaY*fTAlph)*v.
z()
298 + fa1md1*(phixz - 2*fDz*v.
y() + fdeltaY*v.
z()));
300 fDy1*(fa1md1*(-5*phiyz - 24*fDz*v.
x() + 12*fdeltaX*v.
z()) +
301 fDy1*(20*phixz - 4*(5*fTAlph*phiyz + 24*fDz*fTAlph*v.
x()
302 + 24*fDz*v.
y()) + (48*fdeltaY + (fDx3plus1 + fDx4plus2)
303 *fPhiTwist + 48*fdeltaX*fTAlph)*v.
z()));
305 fDy1*(fa1md1*(phixz - 10*fDz*v.
y() + 5*fdeltaY*v.
z())
306 + 2*fDy1*(2*phiyz + 20*fDz*v.
x()
307 + (-10*fdeltaX + fDx3minus1 + fDx4minus2)*v.
z()
308 + 2*fTAlph*(phixz - 10*fDz*v.
y() + 5*fdeltaY*v.
z())));
310 fDy1*(-(fa1md1*(phiyz + 100*fDz*v.
x() - 50*fdeltaX*v.
z()))
311 + fDy1*(4*phixz - 400*fDz*v.
y()
312 + (200*fdeltaY - (fDx3plus1 + fDx4plus2)*fPhiTwist)*v.
z()
313 - 4*fTAlph*(phiyz + 100*fDz*v.
x() - 50*fdeltaX*v.
z())));
315 fDy1*(4*fDy1*(7*fTAlph*phixz + 7*phiyz - 6*fDz*v.
x() + 6*fDz*fTAlph*v.
y())
316 + 6*fDy1*(2*fdeltaX+fDx3minus1+fDx4minus2-2*fdeltaY*fTAlph)*v.
z()
317 + fa1md1*(7*phixz + 6*fDz*v.
y() - 3*fdeltaY*v.
z()));
319 fDy1*(fa1md1*(-9*phiyz - 56*fDz*v.
x() + 28*fdeltaX*v.
z())
320 + 4*fDy1*(9*phixz - 9*fTAlph*phiyz - 56*fDz*fTAlph*v.
x()
321 - 56*fDz*v.
y() + 28*(fdeltaY + fdeltaX*fTAlph)*v.
z()));
323 fDy1*(fa1md1*(2*fDz*v.
y() - fdeltaY*v.
z())
324 + fDy1*(-8*fDz*v.
x() + 8*fDz*fTAlph*v.
y()
325 + 4*fdeltaX*v.
z() - 4*fdeltaY*fTAlph*v.
z()));
328 G4cout <<
"coef = " << c[0] <<
" "
341 for (
G4int i = 0 ; i<num ; i++ )
346 G4cout <<
"Solution " << i <<
" : " << srd[i] <<
G4endl ;
348 phi = std::fmod(srd[i] , pihalf) ;
349 u = (fDy1*(4*(phiyz + 2*fDz*phi*v.
y() - fdeltaY*phi*v.
z())
350 - ((fDx3plus1 + fDx4plus2)*fPhiTwist
351 + 2*(fDx3minus1 + fDx4minus2)*phi)*v.
z()*std::sin(phi)))
352 /(fPhiTwist*v.
z()*(4*fDy1*std::cos(phi)
353 + (fa1md1 + 4*fDy1*fTAlph)*std::sin(phi)));
360 xbuf.push_back(xbuftmp) ;
363 G4cout <<
"solution " << i <<
" = " << phi <<
" , " << u <<
G4endl ;
369 nxx = (
G4int)xbuf.size() ;
378 for (
auto & k : xbuf)
381 G4cout <<
"Solution " << k <<
" : "
382 <<
"reconstructed phiR = " << xbuf[k].phi
383 <<
", uR = " << xbuf[k].u <<
G4endl ;
389 IsConverged = false ;
391 for (
G4int i = 1 ; i<maxint ; ++i )
393 xxonsurface = SurfacePoint(phi,u) ;
394 surfacenormal = NormAng(phi,u) ;
397 deltaX = ( tmpxx - xxonsurface ).mag() ;
398 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
410 G4cout <<
"Step i = " << i <<
", distance = " << tmpdist
411 <<
", " << deltaX <<
G4endl ;
415 GetPhiUAtX(tmpxx, phi, u) ;
419 G4cout <<
"approximated phi = " << phi <<
", u = " << u <<
G4endl ;
422 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
426 if ( std::fabs(tmpdist)<ctol ) { tmpdist = 0 ; }
429 G4cout <<
"refined solution " << phi <<
" , " << u <<
G4endl ;
440 tmpareacode = GetAreaCode(tmpxx);
443 if (tmpdist >= 0) tmpisvalid =
true;
448 tmpareacode = GetAreaCode(tmpxx,
false);
451 if (tmpdist >= 0) { tmpisvalid =
true; }
456 G4Exception(
"G4TwistTrapAlphaSide::DistanceToSurface()",
458 "Feature NOT implemented !");
470 k.distance = tmpdist ;
471 k.areacode = tmpareacode ;
472 k.isvalid = tmpisvalid ;
491 auto nxxtmp = (
G4int)xbuf.size() ;
493 if ( nxxtmp<2 || IsParallel )
509 xbuf.push_back(xbuftmp) ;
524 xbuf.push_back(xbuftmp) ;
526 for ( std::size_t k = nxxtmp ; k<xbuf.size() ; ++k )
530 G4cout <<
"Solution " << k <<
" : "
531 <<
"reconstructed phiR = " << xbuf[k].phi
532 <<
", uR = " << xbuf[k].u <<
G4endl ;
538 IsConverged = false ;
540 for (
G4int i = 1 ; i<maxint ; ++i )
542 xxonsurface = SurfacePoint(phi,u) ;
543 surfacenormal = NormAng(phi,u) ;
545 deltaX = ( tmpxx - xxonsurface ).mag();
546 theta = std::fabs(std::acos(v*surfacenormal) - pihalf);
557 G4cout <<
"Step i = " << i <<
", distance = " << tmpdist
558 <<
", " << deltaX <<
G4endl
559 <<
"X = " << tmpxx <<
G4endl ;
562 GetPhiUAtX(tmpxx, phi, u) ;
566 G4cout <<
"approximated phi = " << phi <<
", u = " << u <<
G4endl ;
569 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
573 if ( std::fabs(tmpdist)<ctol ) { tmpdist = 0; }
576 G4cout <<
"refined solution " << phi <<
" , " << u <<
G4endl ;
587 tmpareacode = GetAreaCode(tmpxx);
590 if (tmpdist >= 0) { tmpisvalid =
true; }
595 tmpareacode = GetAreaCode(tmpxx,
false);
598 if (tmpdist >= 0) { tmpisvalid =
true; }
603 G4Exception(
"G4TwistedBoxSide::DistanceToSurface()",
605 "Feature NOT implemented !");
617 xbuf[k].distance = tmpdist ;
618 xbuf[k].areacode = tmpareacode ;
619 xbuf[k].isvalid = tmpisvalid ;
636 nxx = (
G4int)xbuf.size() ;
638 for (
G4int i = 0 ; i<(
G4int)xbuf.size() ; ++i )
640 distance[i] = xbuf[i].distance;
642 areacode[i] = xbuf[i].areacode ;
643 isvalid[i] = xbuf[i].isvalid ;
646 isvalid[i], nxx, validate, &gp, &gv);
648 G4cout <<
"element Nr. " << i
649 <<
", local Intersection = " << xbuf[i].xx
650 <<
", distance = " << xbuf[i].distance
651 <<
", u = " << xbuf[i].u
652 <<
", phi = " << xbuf[i].phi
653 <<
", isvalid = " << xbuf[i].isvalid
661 G4cout << nxx <<
" possible physical solutions found" <<
G4endl ;
662 for (
G4int k= 0 ; k< nxx ; k++ )
664 G4cout <<
"global intersection Point found: " << gxx[k] <<
G4endl ;
701 distance[i] = kInfinity;
703 gxx[i].
set(kInfinity, kInfinity, kInfinity);
720 for (
G4int i = 1 ; i<20 ; ++i )
722 xxonsurface = SurfacePoint(phiR,uR) ;
723 surfacenormal = NormAng(phiR,uR) ;
725 deltaX = ( xx - xxonsurface ).mag() ;
728 G4cout <<
"i = " << i <<
", distance = " << distance[0]
729 <<
", " << deltaX <<
G4endl
730 <<
"X = " << xx <<
G4endl ;
735 GetPhiUAtX(xx, phiR, uR) ;
737 if ( deltaX <= ctol ) { break ; }
742 uMax = GetBoundaryMax(phiR) ;
744 if ( phiR > halfphi ) { phiR = halfphi ; }
745 if ( phiR < -halfphi ) { phiR = -halfphi ; }
746 if ( uR > uMax ) { uR = uMax ; }
747 if ( uR < -uMax ) { uR = -uMax ; }
749 xxonsurface = SurfacePoint(phiR,uR) ;
750 distance[0] = ( p - xx ).mag() ;
751 if ( distance[0] <= ctol ) { distance[0] = 0 ; }
756 G4cout <<
"refined solution " << phiR <<
" , " << uR <<
" , " <<
G4endl ;
765 G4cout <<
"intersection Point found: " << gxx[0] <<
G4endl ;
788 GetPhiUAtX(xx, phi,yprime ) ;
790 G4double fYAxisMax = GetBoundaryMax(phi) ;
791 G4double fYAxisMin = GetBoundaryMin(phi) ;
795 G4cout <<
"GetAreaCode: yprime = " << yprime <<
G4endl ;
796 G4cout <<
"Intervall is " << fYAxisMin <<
" to " << fYAxisMax <<
G4endl ;
811 if (yprime < fYAxisMin + ctol)
814 if (yprime <= fYAxisMin - ctol) { isoutside =
true; }
817 else if (yprime > fYAxisMax - ctol)
820 if (yprime >= fYAxisMax + ctol) { isoutside =
true; }
834 if (xx.
z() <=
fAxisMin[zaxis] - ctol) { isoutside =
true; }
836 else if (xx.
z() >
fAxisMax[zaxis] - ctol)
844 if (xx.
z() >=
fAxisMax[zaxis] + ctol) { isoutside =
true; }
852 G4int tmpareacode = areacode & (~sInside);
853 areacode = tmpareacode;
865 if (yprime < fYAxisMin )
869 else if (yprime > fYAxisMax)
904 "Feature NOT implemented !");
912void G4TwistTrapAlphaSide::SetCorners()
924 x = -fdeltaX/2. + (fDx1 - fDy1*fTAlph)*std::cos(fPhiTwist/2.)
925 - fDy1*std::sin(fPhiTwist/2.);
926 y = -fdeltaY/2. - fDy1*std::cos(fPhiTwist/2.)
927 + (-fDx1 + fDy1*fTAlph)*std::sin(fPhiTwist/2.);
936 x = -fdeltaX/2. + (fDx2 + fDy1*fTAlph)*std::cos(fPhiTwist/2.)
937 + fDy1*std::sin(fPhiTwist/2.);
938 y = -fdeltaY/2. + fDy1*std::cos(fPhiTwist/2.)
939 - (fDx2 + fDy1*fTAlph)*std::sin(fPhiTwist/2.);
948 x = fdeltaX/2. + (fDx4 + fDy2*fTAlph)*std::cos(fPhiTwist/2.)
949 - fDy2*std::sin(fPhiTwist/2.);
950 y = fdeltaY/2. + fDy2*std::cos(fPhiTwist/2.)
951 + (fDx4 + fDy2*fTAlph)*std::sin(fPhiTwist/2.);
959 x = fdeltaX/2. + (fDx3 - fDy2*fTAlph)*std::cos(fPhiTwist/2.)
960 + fDy2*std::sin(fPhiTwist/2.) ;
961 y = fdeltaY/2. - fDy2*std::cos(fPhiTwist/2.)
962 + (fDx3 - fDy2*fTAlph)*std::sin(fPhiTwist/2.) ;
974 "Method NOT implemented !");
981void G4TwistTrapAlphaSide::SetBoundaries()
992 direction = direction.
unit();
998 direction = direction.
unit();
1004 direction = direction.
unit();
1010 direction = direction.
unit();
1019 "Feature NOT implemented !");
1035 phi = p.
z()/(2*fDz)*fPhiTwist ;
1036 u = (fPhiTwist*(2*fDx1*fDx1 - 2*fDx2*fDx2 - fa1md1*(fDx3 + fDx4)
1037 - 4*(fDx3plus1 + fDx4plus2)*fDy1*fTAlph)
1038 - 2*(2*fDx1*fDx1 - 2*fDx2*fDx2 + fa1md1*(fDx3 + fDx4)
1039 + 4*(fDx3minus1 + fDx4minus2)*fDy1*fTAlph)*phi
1040 - 4*(fa1md1*(fdeltaX*phi - fPhiTwist*p.
x())
1041 + 4*fDy1*(fdeltaY*phi + fdeltaX*fTAlph*phi
1042 - fPhiTwist*(fTAlph*p.
x() + p.
y())))*std::cos(phi)
1043 - 4*(fa1md1*fdeltaY*phi - 4*fdeltaX*fDy1*phi
1044 + 4*fdeltaY*fDy1*fTAlph*phi + 4*fDy1*fPhiTwist*p.
x()
1045 - fPhiTwist*(fa1md1 + 4*fDy1*fTAlph)*p.
y())*std::sin(phi))
1046 /(fDy1* fPhiTwist*((std::fabs(((fa1md1 + 4*fDy1*fTAlph)*std::cos(phi))
1047 /fDy1 - 4*std::sin(phi)))
1048 *(std::fabs(((fa1md1 + 4*fDy1*fTAlph)*std::cos(phi))
1049 /fDy1 - 4*std::sin(phi)))
1050 + (std::fabs(4*std::cos(phi)
1051 + ((fa1md1 + 4*fDy1*fTAlph)*std::sin(phi))/fDy1))
1052 * (std::fabs(4*std::cos(phi)
1053 + ((fa1md1 + 4*fDy1*fTAlph)*std::sin(phi))/fDy1)))) ;
1077 GetPhiUAtX( tmpp, phi, u ) ;
1112 for (
G4int i = 0 ; i<
n ; ++i )
1114 z = -fDz+i*(2.*fDz)/(n-1) ;
1115 phi = z*fPhiTwist/(2*fDz) ;
1116 b = GetValueB(phi) ;
1118 for (
G4int j = 0 ; j<k ; ++j )
1120 nnode =
GetNode(i,j,k,n,iside) ;
1121 u = -b/2 +j*b/(k-1) ;
1122 p = SurfacePoint(phi,u,
true) ;
1124 xyz[nnode][0] = p.
x() ;
1125 xyz[nnode][1] = p.
y() ;
1126 xyz[nnode][2] = p.
z() ;
1128 if ( i<n-1 && j<k-1 )
1130 nface =
GetFace(i,j,k,n,iside) ;
1132 * (
GetNode(i ,j ,k,n,iside)+1) ;
1134 * (
GetNode(i ,j+1,k,n,iside)+1) ;
1136 * (
GetNode(i+1,j+1,k,n,iside)+1) ;
1138 * (
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)
~G4TwistTrapAlphaSide() override
G4int DistanceToSurface(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol) override
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)
G4ThreeVector GetNormal(const G4ThreeVector &xx, G4bool isGlobal=false) override
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