50 axis0min, axis1min, axis0max, axis1max),
55 G4Exception(
"G4TwistTubsSide::G4TwistTubsSide()",
"GeomSolids0002",
90 SetCorners( EndInnerRadius, EndOuterRadius, EndPhi, EndZ) ;
215 for (
auto i=0; i<2; ++i)
217 distance[i] = kInfinity;
220 gxx[i].
set(kInfinity, kInfinity, kInfinity);
239 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
240 isvalid[0], 0, validate, &gp, &gv);
249 G4double b = fKappa * (v.
x() * p.
z() + v.
z() * p.
x()) - v.
y();
260 distance[0] = - c / b;
261 xx[0] = p + distance[0]*v;
266 areacode[0] = GetAreaCode(xx[0]);
269 if (distance[0] >= 0) { isvalid[0] =
true; }
274 areacode[0] = GetAreaCode(xx[0],
false);
277 if (distance[0] >= 0) { isvalid[0] =
true; }
286 if (distance[0] >= 0) { isvalid[0] =
true; }
290 distance[0] = kInfinity;
292 areacode[0], isvalid[0],
293 0, validate, &gp, &gv);
298 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
299 isvalid[0], 1, validate, &gp, &gv);
311 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
312 isvalid[0], 0, validate, &gp, &gv);
321 G4double tmpdist[2] = {kInfinity, kInfinity};
324 G4bool tmpisvalid[2] = {
false,
false};
326 for (
auto i=0; i<2; ++i)
333 if ( b *
D < 0 && std::fabs(bminusD /
D) < protection )
336 tmpdist[i] = - c/b * ( 1 - acovbb * (1 + 2*acovbb));
340 tmpdist[i] = factor * bminusD;
344 tmpxx[i] = p + tmpdist[i]*v;
348 tmpareacode[i] = GetAreaCode(tmpxx[i]);
351 if (tmpdist[i] >= 0) { tmpisvalid[i] =
true; }
357 tmpareacode[i] = GetAreaCode(tmpxx[i],
false);
360 if (tmpdist[i] >= 0) { tmpisvalid[i] =
true; }
367 if (tmpxx[i].x() > 0)
370 if (tmpdist[i] >= 0) { tmpisvalid[i] =
true; }
374 tmpdist[i] = kInfinity;
379 if (tmpdist[0] <= tmpdist[1])
381 distance[0] = tmpdist[0];
382 distance[1] = tmpdist[1];
387 areacode[0] = tmpareacode[0];
388 areacode[1] = tmpareacode[1];
389 isvalid[0] = tmpisvalid[0];
390 isvalid[1] = tmpisvalid[1];
394 distance[0] = tmpdist[1];
395 distance[1] = tmpdist[0];
400 areacode[0] = tmpareacode[1];
401 areacode[1] = tmpareacode[0];
402 isvalid[0] = tmpisvalid[1];
403 isvalid[1] = tmpisvalid[0];
406 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
407 isvalid[0], 2, validate, &gp, &gv);
408 fCurStatWithV.SetCurrentStatus(1, gxx[1], distance[1], areacode[1],
409 isvalid[1], 2, validate, &gp, &gv);
413 for (
G4int k=0; k<2; ++k)
415 if (!isvalid[k]) {
continue; }
417 G4ThreeVector xxonsurface(xx[k].x(), fKappa * std::fabs(xx[k].x())
418 * xx[k].z() , xx[k].z());
419 G4double deltaY = (xx[k] - xxonsurface).mag();
426 for (l=0; l<maxcount; ++l)
430 surfacenormal, xx[k]);
431 deltaY = (xx[k] - xxonsurface).mag();
432 if (deltaY > lastdeltaY) { }
436 xxonsurface.
set(xx[k].x(),
437 fKappa * std::fabs(xx[k].x()) * xx[k].z(),
442 std::ostringstream message;
443 message <<
"Exceeded maxloop count!" <<
G4endl
444 <<
" maxloop count " << maxcount;
445 G4Exception(
"G4TwistTubsFlatSide::DistanceToSurface(p,v)",
457 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
458 isvalid[0], 0, validate, &gp, &gv);
478 distance[i] =
fCurStat.GetDistance(i);
479 areacode[i] =
fCurStat.GetAreacode(i);
485 for (
auto i=0; i<2; ++i)
487 distance[i] = kInfinity;
489 gxx[i].
set(kInfinity, kInfinity, kInfinity);
496 G4int parity = (fKappa >= 0 ? 1 : -1);
506 for (
auto i=0; i<2; ++i)
511 if ((gp - lastgxx[0]).mag() < halftol
512 || (gp - lastgxx[1]).mag() < halftol)
520 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
543 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
572 else if (p.
z() <
C.z())
583 else if (p.
z() <
A.z())
593 for (
auto i=0; i<2; ++i)
598 B = x0[i] + ((
A.z() - x0[i].z()) / d[i].z()) * d[i];
604 D = x0[i] + ((
C.z() - x0[i].z()) / d[i].z()) * d[i];
613 G4double test = (
A.z() -
C.z()) * parity * pside;
625 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
636 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
664 xxacb, nacb) * parity;
666 xxcad, ncad) * parity;
669 if (std::fabs(distToACB) <= halftol || std::fabs(distToCAD) <= halftol)
671 xx = (std::fabs(distToACB) < std::fabs(distToCAD) ? xxacb : xxcad);
676 fCurStat.SetCurrentStatus(0, gxx[0], distance[0] , areacode[0],
681 if (distToACB * distToCAD > 0 && distToACB < 0)
686 distance[0] = DistanceToPlane(p,
A,
B,
C,
D, parity, xx, normal);
690 if (distToACB * distToCAD > 0)
694 if (distToACB <= distToCAD)
696 distance[0] = distToACB;
701 distance[0] = distToCAD;
711 distance[0] = distToACB;
716 distance[0] = distToCAD;
724 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
751 xxanm, nanm) * parity;
753 xxcmn, ncmn) * parity;
756 if (distToanm * distTocmn > 0 && distToanm < 0)
760 "Point p is behind the surfaces.");
764 if (std::fabs(distToanm) <= halftol)
770 if (std::fabs(distTocmn) <= halftol)
777 if (distToanm <= distTocmn)
787 return DistanceToPlane(p,
A,
M,
N,
D, parity, xx, n);
798 return DistanceToPlane(p,
C,
N,
M,
B, parity, xx, n);
827 if (xx.
x() <=
fAxisMin[xaxis] - ctol) { isoutside =
true; }
829 else if (xx.
x() >
fAxisMax[xaxis] - ctol)
832 if (xx.
x() >=
fAxisMax[xaxis] + ctol) { isoutside =
true; }
849 if (xx.
z() <=
fAxisMin[zaxis] - ctol) { isoutside =
true; }
851 else if (xx.
z() >
fAxisMax[zaxis] - ctol)
875 areacode = tmpareacode;
932 "Feature NOT implemented !");
940void G4TwistTubsSide::SetCorners(
G4double endInnerRad[2],
955 x = endInnerRad[zmin]*std::cos(endPhi[zmin]);
956 y = endInnerRad[zmin]*std::sin(endPhi[zmin]);
961 x = endOuterRad[zmin]*std::cos(endPhi[zmin]);
962 y = endOuterRad[zmin]*std::sin(endPhi[zmin]);
967 x = endOuterRad[zmax]*std::cos(endPhi[zmax]);
968 y = endOuterRad[zmax]*std::sin(endPhi[zmax]);
973 x = endInnerRad[zmax]*std::cos(endPhi[zmax]);
974 y = endInnerRad[zmax]*std::sin(endPhi[zmax]);
981 std::ostringstream message;
982 message <<
"Feature NOT implemented !" <<
G4endl
984 <<
" fAxis[1] = " <<
fAxis[1];
993void G4TwistTubsSide::SetCorners()
997 "Method NOT implemented !");
1003void G4TwistTubsSide::SetBoundaries()
1013 direction = direction.
unit();
1019 direction = direction.
unit();
1025 direction = direction.
unit();
1031 direction = direction.
unit();
1038 std::ostringstream message;
1039 message <<
"Feature NOT implemented !" <<
G4endl
1041 <<
" fAxis[1] = " <<
fAxis[1];
1063 for (
G4int i = 0 ; i<
n ; ++i )
1067 for (
G4int j = 0 ; j<k ; ++j )
1069 nnode =
GetNode(i,j,k,n,iside) ;
1071 xmin = GetBoundaryMin(z) ;
1072 xmax = GetBoundaryMax(z) ;
1076 x = xmin + j*(xmax-xmin)/(k-1) ;
1080 x = xmax - j*(xmax-xmin)/(k-1) ;
1083 p = SurfacePoint(x,z,
true) ;
1085 xyz[nnode][0] = p.
x() ;
1086 xyz[nnode][1] = p.
y() ;
1087 xyz[nnode][2] = p.
z() ;
1089 if ( i<n-1 && j<k-1 )
1091 nface =
GetFace(i,j,k,n,iside) ;
1094 * (
GetNode(i ,j ,k,n,iside)+1) ;
1096 * (
GetNode(i+1,j ,k,n,iside)+1) ;
1098 * (
GetNode(i+1,j+1,k,n,iside)+1) ;
1100 * (
GetNode(i ,j+1,k,n,iside)+1) ;
const G4double kCarTolerance
G4double C(G4double temp)
G4double B(G4double temperature)
G4double D(G4double temp)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::HepRotation G4RotationMatrix
CLHEP::Hep3Vector G4ThreeVector
Hep3Vector cross(const Hep3Vector &) const
void set(double x, double y, double z)
G4ThreeVector GetNormal(const G4ThreeVector &p, G4bool isGlobal=false) override
G4TwistTubsSide(const G4String &name, const G4RotationMatrix &rot, const G4ThreeVector &tlate, G4int handedness, const G4double kappa, const EAxis axis0=kXAxis, const EAxis axis1=kZAxis, G4double axis0min=-kInfinity, G4double axis1min=-kInfinity, G4double axis0max=kInfinity, G4double axis1max=kInfinity)
G4int DistanceToSurface(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol) override
virtual G4int AmIOnLeftSide(const G4ThreeVector &me, const G4ThreeVector &vec, G4bool withTol=true)
static const G4int sC0Min1Min
static const G4int sC0Min1Max
G4VTwistSurface(const G4String &name)
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)
G4double DistanceToLine(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &d, G4ThreeVector &xx)
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const
static const G4int sAxisMin
static const G4int sC0Max1Max
static const G4int sAxis1
virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode, const G4ThreeVector &p) const
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
virtual G4double DistanceToBoundary(G4int areacode, G4ThreeVector &xx, const G4ThreeVector &p)
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
virtual void GetBoundaryParameters(const G4int &areacode, G4ThreeVector &d, G4ThreeVector &x0, G4int &boundarytype) const