75 fTAlph = std::tan(fAlph) ;
82 fDx4plus2 = fDx4 + fDx2 ;
83 fDx4minus2 = fDx4 - fDx2 ;
84 fDx3plus1 = fDx3 + fDx1 ;
85 fDx3minus1 = fDx3 - fDx1 ;
86 fDy2plus1 = fDy2 + fDy1 ;
87 fDy2minus1 = fDy2 - fDy1 ;
89 fa1md1 = 2*fDx2 - 2*fDx1 ;
90 fa2md2 = 2*fDx4 - 2*fDx3 ;
92 fPhiTwist = PhiTwist ;
93 fAngleSide = AngleSide ;
95 fdeltaX = 2*fDz*std::tan(fTheta)*std::cos(fPhi);
96 fdeltaY = 2*fDz*std::tan(fTheta)*std::sin(fPhi);
152 GetPhiUAtX(xx,phi,u) ;
185 static const G4double pihalf = pi/2 ;
188 G4bool IsParallel = false ;
189 G4bool IsConverged = false ;
210 distance[i] = kInfinity;
213 gxx[i].
set(kInfinity, kInfinity, kInfinity);
232 G4bool tmpisvalid = false ;
234 std::vector<Intersection> xbuf ;
241 G4double phixz = fPhiTwist * ( p.
x() * v.
z() - p.
z() * v.
x() ) ;
242 G4double phiyz = fPhiTwist * ( p.
y() * v.
z() - p.
z() * v.
y() ) ;
248 if ( std::fabs(p.
z()) <= L )
250 phi = p.
z() * fPhiTwist / L ;
252 u = (2*(fdeltaY*phi*v.
x() - fPhiTwist*p.
y()*v.
x() - fdeltaX*phi*v.
y()
253 + fPhiTwist*p.
x()*v.
y()) + (fDy2plus1*fPhiTwist
254 + 2*fDy2minus1*phi)*(v.
x()*std::cos(phi) + v.
y()*std::sin(phi)))
255 / (2.* fPhiTwist*(v.
y()*std::cos(phi) - v.
x()*std::sin(phi)));
263 xbuf.push_back(xbuftmp) ;
267 distance[0] = kInfinity;
268 gxx[0].
set(kInfinity,kInfinity,kInfinity);
272 areacode[0], isvalid[0],
273 0, validate, &gp, &gv);
282 c[8] = -3600*(-2*phiyz + fDy2plus1*fPhiTwist*v.
z()) ;
283 c[7] = -7200*(phixz - 2*fDz*v.
y() + (fdeltaY + fDy2minus1)*v.
z()) ;
284 c[6] = 120*(-52*phiyz - 120*fDz*v.
x() + 60*fdeltaX*v.
z()
285 + 11*fDy2plus1*fPhiTwist*v.
z()) ;
286 c[5] = 240*(16*phixz - 52*fDz*v.
y() + 26*fdeltaY*v.
z()
287 + 11*fDy2minus1*v.
z()) ;
288 c[4] = 12*(127*phiyz + 640*fDz*v.
x() - 320*fdeltaX*v.
z()
289 + 4*fDy2plus1*fPhiTwist*v.
z()) ;
290 c[3] = -404*phixz + 3048*fDz*v.
y() - 1524*fdeltaY*v.
z()
291 + 96*fDy2minus1*v.
z() ;
292 c[2] = -72*phiyz + 404*(-2*fDz*v.
x() + fdeltaX*v.
z()) ;
293 c[1] = 12*(phixz - 12*fDz*v.
y() + 6*fdeltaY*v.
z()) ;
294 c[0] = 24*fDz*v.
x() - 12*fdeltaX*v.
z() ;
298 G4cout <<
"coef = " << c[0] <<
" "
312 for (
G4int i = 0 ; i<num ; ++i )
317 G4cout <<
"Solution " << i <<
" : " << srd[i] <<
G4endl ;
319 phi = std::fmod(srd[i] , pihalf) ;
320 u = (1/std::cos(phi)*(2*phixz + 4*fDz*phi*v.
x()
321 - 2*fdeltaX*phi*v.
z() + (fDy2plus1*fPhiTwist
322 + 2*fDy2minus1*phi)*v.
z()* std::sin(phi)))/(2.*fPhiTwist*v.
z()) ;
330 xbuf.push_back(xbuftmp) ;
333 G4cout <<
"solution " << i <<
" = " << phi <<
" , " << u <<
G4endl ;
340 nxx = (
G4int)xbuf.size() ;
350 for (
auto & k : xbuf)
353 G4cout <<
"Solution " << k <<
" : "
354 <<
"reconstructed phiR = " << xbuf[k].phi
355 <<
", uR = " << xbuf[k].u <<
G4endl ;
361 IsConverged = false ;
363 for (
G4int i = 1 ; i<maxint ; ++i )
365 xxonsurface = SurfacePoint(phi,u) ;
366 surfacenormal = NormAng(phi,u) ;
368 deltaX = ( tmpxx - xxonsurface ).mag() ;
369 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
381 G4cout <<
"Step i = " << i <<
", distance = "
382 << tmpdist <<
", " << deltaX <<
G4endl ;
386 GetPhiUAtX(tmpxx, phi, u);
389 G4cout <<
"approximated phi = " << phi <<
", u = " << u <<
G4endl ;
392 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
395 if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 ;
398 G4cout <<
"refined solution " << phi <<
" , " << u <<
G4endl ;
409 tmpareacode = GetAreaCode(tmpxx);
412 if (tmpdist >= 0) tmpisvalid =
true;
417 tmpareacode = GetAreaCode(tmpxx,
false);
420 if (tmpdist >= 0) tmpisvalid =
true;
425 G4Exception(
"G4TwistTrapParallelSide::DistanceToSurface()",
427 "Feature NOT implemented !");
438 k.distance = tmpdist ;
439 k.areacode = tmpareacode ;
440 k.isvalid = tmpisvalid ;
456 auto nxxtmp = (
G4int)xbuf.size() ;
458 if ( nxxtmp<2 || IsParallel )
474 xbuf.push_back(xbuftmp) ;
489 xbuf.push_back(xbuftmp) ;
491 for ( std::size_t k = nxxtmp ; k<xbuf.size() ; ++k )
494 G4cout <<
"Solution " << k <<
" : "
495 <<
"reconstructed phiR = " << xbuf[k].phi
496 <<
", uR = " << xbuf[k].u <<
G4endl ;
502 IsConverged = false ;
504 for (
G4int i = 1 ; i<maxint ; ++i )
506 xxonsurface = SurfacePoint(phi,u) ;
507 surfacenormal = NormAng(phi,u) ;
509 deltaX = ( tmpxx - xxonsurface ).mag() ;
510 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ;
521 G4cout <<
"Step i = " << i <<
", distance = "
522 << tmpdist <<
", " << deltaX <<
G4endl ;
526 GetPhiUAtX(tmpxx, phi, u) ;
529 G4cout <<
"approximated phi = " << phi <<
", u = " << u <<
G4endl ;
532 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; }
535 if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 ;
538 G4cout <<
"refined solution " << phi <<
" , " << u <<
G4endl ;
549 tmpareacode = GetAreaCode(tmpxx);
552 if (tmpdist >= 0) tmpisvalid =
true;
557 tmpareacode = GetAreaCode(tmpxx,
false);
560 if (tmpdist >= 0) tmpisvalid =
true;
565 G4Exception(
"G4TwistedBoxSide::DistanceToSurface()",
567 "Feature NOT implemented !");
579 xbuf[k].distance = tmpdist ;
580 xbuf[k].areacode = tmpareacode ;
581 xbuf[k].isvalid = tmpisvalid ;
597 nxx = (
G4int)xbuf.size() ;
599 for (
G4int i = 0 ; i<(
G4int)xbuf.size() ; ++i )
601 distance[i] = xbuf[i].distance;
603 areacode[i] = xbuf[i].areacode ;
604 isvalid[i] = xbuf[i].isvalid ;
607 isvalid[i], nxx, validate, &gp, &gv);
609 G4cout <<
"element Nr. " << i
610 <<
", local Intersection = " << xbuf[i].xx
611 <<
", distance = " << xbuf[i].distance
612 <<
", u = " << xbuf[i].u
613 <<
", phi = " << xbuf[i].phi
614 <<
", isvalid = " << xbuf[i].isvalid
620 G4cout <<
"G4TwistTrapParallelSide finished " <<
G4endl ;
621 G4cout << nxx <<
" possible physical solutions found" <<
G4endl ;
622 for (
G4int k= 0 ; k< nxx ; ++k )
624 G4cout <<
"global intersection Point found: " << gxx[k] <<
G4endl ;
659 distance[i] = kInfinity;
661 gxx[i].
set(kInfinity, kInfinity, kInfinity);
678 for (
G4int i = 1 ; i<maxint ; ++i )
680 xxonsurface = SurfacePoint(phiR,uR) ;
681 surfacenormal = NormAng(phiR,uR) ;
683 deltaX = ( xx - xxonsurface ).mag() ;
686 G4cout <<
"i = " << i <<
", distance = "
687 << distance[0] <<
", " << deltaX <<
G4endl ;
692 GetPhiUAtX(xx, phiR, uR) ;
694 if ( deltaX <= ctol ) { break ; }
700 G4double uMax = GetBoundaryMax(phiR) ;
701 G4double uMin = GetBoundaryMin(phiR) ;
703 if ( phiR > halfphi ) phiR = halfphi ;
704 if ( phiR < -halfphi ) phiR = -halfphi ;
705 if ( uR > uMax ) uR = uMax ;
706 if ( uR < uMin ) uR = uMin ;
708 xxonsurface = SurfacePoint(phiR,uR) ;
709 distance[0] = ( p - xx ).mag() ;
710 if ( distance[0] <= ctol ) { distance[0] = 0 ; }
715 G4cout <<
"refined solution " << phiR <<
" , " << uR <<
" , " <<
G4endl ;
724 G4cout <<
"intersection Point found: " << gxx[0] <<
G4endl ;
746 GetPhiUAtX(xx, phi,yprime ) ;
748 G4double fXAxisMax = GetBoundaryMax(phi) ;
749 G4double fXAxisMin = GetBoundaryMin(phi) ;
753 G4cout <<
"GetAreaCode: yprime = " << yprime <<
G4endl ;
754 G4cout <<
"Intervall is " << fXAxisMin <<
" to " << fXAxisMax <<
G4endl ;
769 if (yprime < fXAxisMin + ctol)
772 if (yprime <= fXAxisMin - ctol) isoutside =
true;
775 else if (yprime > fXAxisMax - ctol)
778 if (yprime >= fXAxisMax + ctol) isoutside =
true;
789 if (xx.
z() <=
fAxisMin[zaxis] - ctol) isoutside =
true;
792 else if (xx.
z() >
fAxisMax[zaxis] - ctol)
798 if (xx.
z() >=
fAxisMax[zaxis] + ctol) isoutside =
true;
806 G4int tmpareacode = areacode & (~sInside);
807 areacode = tmpareacode;
819 if (yprime < fXAxisMin )
823 else if (yprime > fXAxisMax)
853 G4Exception(
"G4TwistTrapParallelSide::GetAreaCode()",
855 "Feature NOT implemented !");
863void G4TwistTrapParallelSide::SetCorners()
874 x = -fdeltaX/2. + (-fDx2 + fDy1*fTAlph)*std::cos(fPhiTwist/2.)
875 + fDy1*std::sin(fPhiTwist/2.) ;
876 y = -fdeltaY/2. + fDy1*std::cos(fPhiTwist/2.)
877 + (fDx2 - fDy1*fTAlph)*std::sin(fPhiTwist/2.) ;
884 x = -fdeltaX/2. + (fDx2 + fDy1*fTAlph)*std::cos(fPhiTwist/2.)
885 + fDy1*std::sin(fPhiTwist/2.) ;
886 y = -fdeltaY/2. + fDy1*std::cos(fPhiTwist/2.)
887 - (fDx2 + fDy1*fTAlph)*std::sin(fPhiTwist/2.) ;
893 x = fdeltaX/2. + (fDx4 + fDy2*fTAlph)*std::cos(fPhiTwist/2.)
894 - fDy2*std::sin(fPhiTwist/2.) ;
895 y = fdeltaY/2. + fDy2*std::cos(fPhiTwist/2.)
896 + (fDx4 + fDy2*fTAlph)*std::sin(fPhiTwist/2.) ;
902 x = fdeltaX/2. + (-fDx4 + fDy2*fTAlph)*std::cos(fPhiTwist/2.)
903 - fDy2*std::sin(fPhiTwist/2.) ;
904 y = fdeltaY/2. + fDy2*std::cos(fPhiTwist/2.)
905 + (-fDx4 + fDy2*fTAlph)*std::sin(fPhiTwist/2.) ;
912 G4Exception(
"G4TwistTrapParallelSide::SetCorners()",
914 "Method NOT implemented !");
921void G4TwistTrapParallelSide::SetBoundaries()
932 direction = direction.
unit();
938 direction = direction.
unit();
944 direction = direction.
unit();
950 direction = direction.
unit();
956 G4Exception(
"G4TwistTrapParallelSide::SetCorners()",
958 "Feature NOT implemented !");
975 phi = p.
z()/(2*fDz)*fPhiTwist ;
977 u = ((-(fdeltaX*phi) + fPhiTwist*p.
x())* std::cos(phi)
978 + (-(fdeltaY*phi) + fPhiTwist*p.
y())*std::sin(phi))/fPhiTwist ;
1001 GetPhiUAtX( tmpp, phi, u ) ;
1032 for (
G4int i = 0 ; i<
n ; ++i )
1034 z = -fDz+i*(2.*fDz)/(n-1) ;
1035 phi = z*fPhiTwist/(2*fDz) ;
1036 umin = GetBoundaryMin(phi) ;
1037 umax = GetBoundaryMax(phi) ;
1039 for (
G4int j = 0 ; j<k ; ++j )
1041 nnode =
GetNode(i,j,k,n,iside) ;
1042 u = umax - j*(umax-umin)/(k-1) ;
1043 p = SurfacePoint(phi,u,
true) ;
1045 xyz[nnode][0] = p.
x() ;
1046 xyz[nnode][1] = p.
y() ;
1047 xyz[nnode][2] = p.
z() ;
1049 if ( i<n-1 && j<k-1 )
1051 nface =
GetFace(i,j,k,n,iside) ;
1053 * (
GetNode(i ,j ,k,n,iside)+1) ;
1055 * (
GetNode(i ,j+1,k,n,iside)+1) ;
1057 * (
GetNode(i+1,j+1,k,n,iside)+1) ;
1059 * (
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)
G4int DistanceToSurface(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol) override
G4TwistTrapParallelSide(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)
~G4TwistTrapParallelSide() override
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 sAxisX
G4double DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const
G4SurfCurNormal fCurrentNormal