G4TwistTrapFlatSide Class Reference

#include <G4TwistTrapFlatSide.hh>

Inheritance diagram for G4TwistTrapFlatSide:

G4VTwistSurface

Public Member Functions

 G4TwistTrapFlatSide (const G4String &name, G4double PhiTwist, G4double pDx1, G4double pDx2, G4double pDy, G4double pDz, G4double pAlpha, G4double pPhi, G4double pTheta, G4int handedness)
virtual ~G4TwistTrapFlatSide ()
virtual G4ThreeVector GetNormal (const G4ThreeVector &, G4bool isGlobal=false)
virtual G4int DistanceToSurface (const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol)
virtual G4int DistanceToSurface (const G4ThreeVector &gp, G4ThreeVector gxx[], G4double distance[], G4int areacode[])
virtual G4ThreeVector SurfacePoint (G4double x, G4double y, G4bool isGlobal=false)
virtual G4double GetBoundaryMin (G4double u)
virtual G4double GetBoundaryMax (G4double u)
virtual G4double GetSurfaceArea ()
virtual void GetFacets (G4int m, G4int n, G4double xyz[][3], G4int faces[][4], G4int iside)
 G4TwistTrapFlatSide (__void__ &)

Protected Member Functions

virtual G4int GetAreaCode (const G4ThreeVector &xx, G4bool withTol=true)

Detailed Description

Definition at line 50 of file G4TwistTrapFlatSide.hh.


Constructor & Destructor Documentation

G4TwistTrapFlatSide::G4TwistTrapFlatSide ( const G4String name,
G4double  PhiTwist,
G4double  pDx1,
G4double  pDx2,
G4double  pDy,
G4double  pDz,
G4double  pAlpha,
G4double  pPhi,
G4double  pTheta,
G4int  handedness 
)

Definition at line 46 of file G4TwistTrapFlatSide.cc.

References G4VTwistSurface::fAxis, G4VTwistSurface::fAxisMax, G4VTwistSurface::fAxisMin, G4VTwistSurface::fCurrentNormal, G4VTwistSurface::fHandedness, G4VTwistSurface::fIsValidNorm, G4VTwistSurface::fRot, G4VTwistSurface::fTrans, kXAxis, and kYAxis.

00057   : G4VTwistSurface(name)
00058 {
00059    fHandedness = handedness;   // +z = +ve, -z = -ve
00060 
00061    fDx1 = pDx1 ;
00062    fDx2 = pDx2 ;
00063    fDy = pDy ;
00064    fDz = pDz ;
00065    fAlpha = pAlpha ;
00066    fTAlph = std::tan(fAlpha) ;
00067    fPhi  = pPhi ;
00068    fTheta = pTheta ;
00069 
00070    fdeltaX = 2 * fDz * std::tan(fTheta) * std::cos(fPhi)  ;
00071      // dx in surface equation
00072    fdeltaY = 2 * fDz * std::tan(fTheta) * std::sin(fPhi)  ;
00073      // dy in surface equation
00074 
00075    fPhiTwist = PhiTwist ;
00076 
00077    fCurrentNormal.normal.set( 0, 0, (fHandedness < 0 ? -1 : 1)); 
00078          // Unit vector, in local coordinate system
00079    fRot.rotateZ( fHandedness > 0 
00080                  ? 0.5 * fPhiTwist
00081                  : -0.5 * fPhiTwist );
00082 
00083    fTrans.set(
00084               fHandedness > 0 ? 0.5*fdeltaX : -0.5*fdeltaX , 
00085               fHandedness > 0 ? 0.5*fdeltaY : -0.5*fdeltaY ,
00086               fHandedness > 0 ? fDz : -fDz ) ;
00087 
00088    fIsValidNorm = true;
00089 
00090 
00091    fAxis[0] = kXAxis ;
00092    fAxis[1] = kYAxis ;
00093    fAxisMin[0] = kInfinity ;  // x-Axis cannot be fixed, because it 
00094    fAxisMax[0] =  kInfinity ; // depends on y
00095    fAxisMin[1] = -fDy ;  // y - axis
00096    fAxisMax[1] =  fDy ;
00097 
00098    SetCorners();
00099    SetBoundaries();
00100 }

G4TwistTrapFlatSide::~G4TwistTrapFlatSide (  )  [virtual]

Definition at line 116 of file G4TwistTrapFlatSide.cc.

00117 {
00118 }

G4TwistTrapFlatSide::G4TwistTrapFlatSide ( __void__ &   ) 

Definition at line 106 of file G4TwistTrapFlatSide.cc.

00107   : G4VTwistSurface(a), fDx1(0.), fDx2(0.), fDy(0.), fDz(0.), fPhiTwist(0.), 
00108     fAlpha(0.), fTAlph(0.), fPhi(0.), fTheta(0.), fdeltaX(0.), fdeltaY(0.)
00109 {
00110 }


Member Function Documentation

G4int G4TwistTrapFlatSide::DistanceToSurface ( const G4ThreeVector gp,
G4ThreeVector  gxx[],
G4double  distance[],
G4int  areacode[] 
) [virtual]

Implements G4VTwistSurface.

Definition at line 246 of file G4TwistTrapFlatSide.cc.

References G4VTwistSurface::ComputeGlobalPoint(), G4VTwistSurface::ComputeLocalPoint(), G4VTwistSurface::fCurStat, G4VTwistSurface::kCarTolerance, G4VTwistSurface::kDontValidate, G4VTwistSurface::sInside, and G4VTwistSurface::sOutside.

00250 {
00251    // Calculate distance to plane in local coordinate,
00252    // then return distance and global intersection points.
00253    //  
00254 
00255    fCurStat.ResetfDone(kDontValidate, &gp);
00256 
00257    if (fCurStat.IsDone()) {
00258       G4int i;
00259       for (i=0; i<fCurStat.GetNXX(); i++) {
00260          gxx[i] = fCurStat.GetXX(i);
00261          distance[i] = fCurStat.GetDistance(i);
00262          areacode[i] = fCurStat.GetAreacode(i);
00263       }
00264       return fCurStat.GetNXX();
00265    } else {
00266       // initialize
00267       G4int i;
00268       for (i=0; i<2; i++) {
00269          distance[i] = kInfinity;
00270          areacode[i] = sOutside;
00271          gxx[i].set(kInfinity, kInfinity, kInfinity);
00272       }
00273    }
00274    
00275    G4ThreeVector p = ComputeLocalPoint(gp);
00276    G4ThreeVector xx;
00277 
00278    // The plane is placed on origin with making its normal 
00279    // parallel to z-axis. 
00280    if (std::fabs(p.z()) <= 0.5 * kCarTolerance)
00281    {   // if p is on the plane, return 1
00282       distance[0] = 0;
00283       xx = p;
00284    } else {
00285       distance[0] = std::fabs(p.z());
00286       xx.set(p.x(), p.y(), 0);  
00287    }
00288 
00289    gxx[0] = ComputeGlobalPoint(xx);
00290    areacode[0] = sInside;
00291    G4bool isvalid = true;
00292    fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
00293                              isvalid, 1, kDontValidate, &gp);
00294    return 1;
00295 
00296 }

G4int G4TwistTrapFlatSide::DistanceToSurface ( const G4ThreeVector gp,
const G4ThreeVector gv,
G4ThreeVector  gxx[],
G4double  distance[],
G4int  areacode[],
G4bool  isvalid[],
EValidate  validate = kValidateWithTol 
) [virtual]

Definition at line 136 of file G4TwistTrapFlatSide.cc.

References G4VTwistSurface::ComputeGlobalPoint(), G4VTwistSurface::ComputeLocalDirection(), G4VTwistSurface::ComputeLocalPoint(), G4VTwistSurface::fCurStatWithV, G4cerr, G4endl, GetAreaCode(), G4VTwistSurface::GetName(), G4VTwistSurface::IsInside(), G4VTwistSurface::IsOutside(), G4VTwistSurface::kValidateWithoutTol, G4VTwistSurface::kValidateWithTol, G4VTwistSurface::sInside, and G4VTwistSurface::sOutside.

00143 {
00144    fCurStatWithV.ResetfDone(validate, &gp, &gv);
00145    
00146    if (fCurStatWithV.IsDone()) {
00147       G4int i;
00148       for (i=0; i<fCurStatWithV.GetNXX(); i++) {
00149          gxx[i] = fCurStatWithV.GetXX(i);
00150          distance[i] = fCurStatWithV.GetDistance(i);
00151          areacode[i] = fCurStatWithV.GetAreacode(i);
00152          isvalid[i]  = fCurStatWithV.IsValid(i);
00153       }
00154       return fCurStatWithV.GetNXX();
00155    } else {
00156       // initialize
00157       G4int i;
00158       for (i=0; i<2; i++) {
00159          distance[i] = kInfinity;
00160          areacode[i] = sOutside;
00161          isvalid[i]  = false;
00162          gxx[i].set(kInfinity, kInfinity, kInfinity);
00163       }
00164    }
00165 
00166    G4ThreeVector p = ComputeLocalPoint(gp);
00167    G4ThreeVector v = ComputeLocalDirection(gv);
00168 
00169    //
00170    // special case!
00171    // if p is on surface, distance = 0. 
00172    //
00173 
00174    if (std::fabs(p.z()) == 0.) {   // if p is on the plane
00175       distance[0] = 0;
00176       G4ThreeVector xx = p;
00177       gxx[0] = ComputeGlobalPoint(xx);
00178       
00179       if (validate == kValidateWithTol) {
00180          areacode[0] = GetAreaCode(xx);
00181          if (!IsOutside(areacode[0])) {
00182             isvalid[0] = true;
00183          }
00184       } else if (validate == kValidateWithoutTol) {
00185          areacode[0] = GetAreaCode(xx, false);
00186          if (IsInside(areacode[0])) {
00187             isvalid[0] = true;
00188          }
00189       } else { // kDontValidate
00190          areacode[0] = sInside;
00191          isvalid[0] = true;
00192       }
00193 
00194       return 1;
00195    }
00196    //
00197    // special case end
00198    //
00199    
00200    if (v.z() == 0) { 
00201 
00202       fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0], 
00203                                      isvalid[0], 0, validate, &gp, &gv);
00204       return 0;
00205    }
00206    
00207    distance[0] = - (p.z() / v.z());
00208       
00209    G4ThreeVector xx = p + distance[0]*v;
00210    gxx[0] = ComputeGlobalPoint(xx);
00211 
00212    if (validate == kValidateWithTol) {
00213       areacode[0] = GetAreaCode(xx);
00214       if (!IsOutside(areacode[0])) {
00215          if (distance[0] >= 0) isvalid[0] = true;
00216       }
00217    } else if (validate == kValidateWithoutTol) {
00218       areacode[0] = GetAreaCode(xx, false);
00219       if (IsInside(areacode[0])) {
00220          if (distance[0] >= 0) isvalid[0] = true;
00221       }
00222    } else { // kDontValidate
00223       areacode[0] = sInside;
00224          if (distance[0] >= 0) isvalid[0] = true;
00225    }
00226 
00227 
00228    fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], areacode[0],
00229                                   isvalid[0], 1, validate, &gp, &gv);
00230 
00231 #ifdef G4TWISTDEBUG
00232    G4cerr << "ERROR - G4TwistTrapFlatSide::DistanceToSurface(p,v)" << G4endl;
00233    G4cerr << "        Name        : " << GetName() << G4endl;
00234    G4cerr << "        xx          : " << xx << G4endl;
00235    G4cerr << "        gxx[0]      : " << gxx[0] << G4endl;
00236    G4cerr << "        dist[0]     : " << distance[0] << G4endl;
00237    G4cerr << "        areacode[0] : " << areacode[0] << G4endl;
00238    G4cerr << "        isvalid[0]  : " << isvalid[0]  << G4endl;
00239 #endif
00240    return 1;
00241 }

G4int G4TwistTrapFlatSide::GetAreaCode ( const G4ThreeVector xx,
G4bool  withTol = true 
) [protected, virtual]

Implements G4VTwistSurface.

Definition at line 298 of file G4TwistTrapFlatSide.cc.

References FatalException, G4VTwistSurface::fAxis, G4VTwistSurface::fAxisMax, G4VTwistSurface::fAxisMin, G4Exception(), G4VTwistSurface::kCarTolerance, kXAxis, kYAxis, G4VTwistSurface::sAxis0, G4VTwistSurface::sAxis1, G4VTwistSurface::sAxisMax, G4VTwistSurface::sAxisMin, G4VTwistSurface::sAxisX, G4VTwistSurface::sAxisY, G4VTwistSurface::sBoundary, G4VTwistSurface::sCorner, and G4VTwistSurface::sInside.

Referenced by DistanceToSurface().

00300 {
00301 
00302   static const G4double ctol = 0.5 * kCarTolerance;
00303   G4int areacode = sInside;
00304   
00305   if (fAxis[0] == kXAxis && fAxis[1] == kYAxis) {
00306 
00307     G4int yaxis = 1;
00308     
00309     G4double wmax = xAxisMax(xx.y(), fTAlph ) ;
00310     G4double wmin = -xAxisMax(xx.y(), -fTAlph ) ;
00311 
00312     if (withTol) {
00313       
00314       G4bool isoutside   = false;
00315       
00316       // test boundary of x-axis
00317       
00318       if (xx.x() < wmin + ctol) {
00319         areacode |= (sAxis0 & (sAxisX | sAxisMin)) | sBoundary; 
00320         if (xx.x() <= wmin - ctol) isoutside = true;
00321         
00322       } else if (xx.x() > wmax - ctol) {
00323         areacode |= (sAxis0 & (sAxisX | sAxisMax)) | sBoundary;
00324         if (xx.x() >= wmax + ctol)  isoutside = true;
00325       }
00326       
00327       // test boundary of y-axis
00328       
00329       if (xx.y() < fAxisMin[yaxis] + ctol) {
00330         areacode |= (sAxis1 & (sAxisY | sAxisMin)); 
00331         
00332         if   (areacode & sBoundary) areacode |= sCorner;  // xx is on the corner.
00333         else                        areacode |= sBoundary;
00334         if (xx.y() <= fAxisMin[yaxis] - ctol) isoutside = true;
00335         
00336       } else if (xx.y() > fAxisMax[yaxis] - ctol) {
00337         areacode |= (sAxis1 & (sAxisY | sAxisMax));
00338         
00339         if   (areacode & sBoundary) areacode |= sCorner;  // xx is on the corner.
00340         else                        areacode |= sBoundary; 
00341         if (xx.y() >= fAxisMax[yaxis] + ctol) isoutside = true;
00342       }
00343       
00344       // if isoutside = true, clear inside bit.             
00345       // if not on boundary, add axis information.             
00346       
00347       if (isoutside) {
00348         G4int tmpareacode = areacode & (~sInside);
00349         areacode = tmpareacode;
00350       } else if ((areacode & sBoundary) != sBoundary) {
00351         areacode |= (sAxis0 & sAxisX) | (sAxis1 & sAxisY);
00352       }           
00353       
00354     } else {
00355       
00356       // boundary of x-axis
00357       
00358       if (xx.x() < wmin ) {
00359         areacode |= (sAxis0 & (sAxisX | sAxisMin)) | sBoundary;
00360       } else if (xx.x() > wmax) {
00361         areacode |= (sAxis0 & (sAxisX | sAxisMax)) | sBoundary;
00362       }
00363       
00364       // boundary of y-axis
00365       
00366       if (xx.y() < fAxisMin[yaxis]) {
00367         areacode |= (sAxis1 & (sAxisY | sAxisMin));
00368         if   (areacode & sBoundary) areacode |= sCorner;  // xx is on the corner.
00369         else                        areacode |= sBoundary; 
00370         
00371       } else if (xx.y() > fAxisMax[yaxis]) {
00372         areacode |= (sAxis1 & (sAxisY | sAxisMax)) ;
00373         if   (areacode & sBoundary) areacode |= sCorner;  // xx is on the corner.
00374         else                        areacode |= sBoundary; 
00375       }
00376       
00377       if ((areacode & sBoundary) != sBoundary) {
00378         areacode |= (sAxis0 & sAxisX) | (sAxis1 & sAxisY);
00379       }           
00380     }
00381     return areacode;
00382   } else {
00383     G4Exception("G4TwistTrapFlatSide::GetAreaCode()",
00384                 "GeomSolids0001", FatalException,
00385                 "Feature NOT implemented !");
00386   }
00387   
00388   return areacode;
00389 }

G4double G4TwistTrapFlatSide::GetBoundaryMax ( G4double  u  )  [inline, virtual]

Implements G4VTwistSurface.

Definition at line 150 of file G4TwistTrapFlatSide.hh.

Referenced by GetFacets().

00151 {
00152   return xAxisMax(y, fTAlph ) ; 
00153 }

G4double G4TwistTrapFlatSide::GetBoundaryMin ( G4double  u  )  [inline, virtual]

Implements G4VTwistSurface.

Definition at line 144 of file G4TwistTrapFlatSide.hh.

Referenced by GetFacets().

00145 {
00146   return -xAxisMax(y, -fTAlph ) ;
00147 }

void G4TwistTrapFlatSide::GetFacets ( G4int  m,
G4int  n,
G4double  xyz[][3],
G4int  faces[][4],
G4int  iside 
) [virtual]

Implements G4VTwistSurface.

Definition at line 486 of file G4TwistTrapFlatSide.cc.

References G4VTwistSurface::fHandedness, GetBoundaryMax(), GetBoundaryMin(), G4VTwistSurface::GetEdgeVisibility(), G4VTwistSurface::GetFace(), G4VTwistSurface::GetNode(), and SurfacePoint().

00488 {
00489 
00490   G4double x,y    ;     // the two parameters for the surface equation
00491   G4ThreeVector p ;  // a point on the surface, given by (z,u)
00492 
00493   G4int nnode ;
00494   G4int nface ;
00495 
00496   G4double xmin,xmax ;
00497 
00498   // calculate the (n-1)*(k-1) vertices
00499 
00500   G4int i,j ;
00501 
00502   for ( i = 0 ; i<n ; i++ ) {
00503 
00504     y = -fDy + i*(2*fDy)/(n-1) ;
00505 
00506     for ( j = 0 ; j<k ; j++ ) {
00507 
00508       xmin = GetBoundaryMin(y) ;
00509       xmax = GetBoundaryMax(y) ;
00510       x = xmin + j*(xmax-xmin)/(k-1) ;
00511 
00512       nnode = GetNode(i,j,k,n,iside) ;
00513       p = SurfacePoint(x,y,true) ;  // surface point in global coordinate system
00514 
00515       xyz[nnode][0] = p.x() ;
00516       xyz[nnode][1] = p.y() ;
00517       xyz[nnode][2] = p.z() ;
00518 
00519       if ( i<n-1 && j<k-1 ) {   
00520 
00521         nface = GetFace(i,j,k,n,iside) ;
00522 
00523         if (fHandedness < 0) {  // lower side 
00524           faces[nface][0] = GetEdgeVisibility(i,j,k,n,0,1) * ( GetNode(i  ,j  ,k,n,iside)+1) ;  
00525           faces[nface][1] = GetEdgeVisibility(i,j,k,n,1,1) * ( GetNode(i+1,j  ,k,n,iside)+1) ;
00526           faces[nface][2] = GetEdgeVisibility(i,j,k,n,2,1) * ( GetNode(i+1,j+1,k,n,iside)+1) ;
00527           faces[nface][3] = GetEdgeVisibility(i,j,k,n,3,1) * ( GetNode(i  ,j+1,k,n,iside)+1) ;
00528         } else {                // upper side
00529           faces[nface][0] = GetEdgeVisibility(i,j,k,n,0,-1) * ( GetNode(i  ,j  ,k,n,iside)+1) ;  
00530           faces[nface][1] = GetEdgeVisibility(i,j,k,n,1,-1) * ( GetNode(i  ,j+1,k,n,iside)+1) ;
00531           faces[nface][2] = GetEdgeVisibility(i,j,k,n,2,-1) * ( GetNode(i+1,j+1,k,n,iside)+1) ;
00532           faces[nface][3] = GetEdgeVisibility(i,j,k,n,3,-1) * ( GetNode(i+1,j  ,k,n,iside)+1) ;
00533         }
00534 
00535       }
00536     }
00537   }
00538 }

G4ThreeVector G4TwistTrapFlatSide::GetNormal ( const G4ThreeVector ,
G4bool  isGlobal = false 
) [virtual]

Implements G4VTwistSurface.

Definition at line 123 of file G4TwistTrapFlatSide.cc.

References G4VTwistSurface::ComputeGlobalDirection(), and G4VTwistSurface::fCurrentNormal.

00125 {
00126    if (isGlobal) {
00127       return ComputeGlobalDirection(fCurrentNormal.normal);
00128    } else {
00129       return fCurrentNormal.normal;
00130    }
00131 }

G4double G4TwistTrapFlatSide::GetSurfaceArea (  )  [inline, virtual]

Implements G4VTwistSurface.

Definition at line 156 of file G4TwistTrapFlatSide.hh.

00157 {
00158   return 2*(fDx1 + fDx2)*fDy ;
00159 }

G4ThreeVector G4TwistTrapFlatSide::SurfacePoint ( G4double  x,
G4double  y,
G4bool  isGlobal = false 
) [inline, virtual]

Implements G4VTwistSurface.

Definition at line 135 of file G4TwistTrapFlatSide.hh.

References G4VTwistSurface::fRot, and G4VTwistSurface::fTrans.

Referenced by GetFacets().

00136 {
00137   G4ThreeVector SurfPoint ( x,y,0);
00138 
00139   if (isGlobal) { return (fRot*SurfPoint + fTrans); }
00140   return SurfPoint;
00141 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:35 2013 for Geant4 by  doxygen 1.4.7