Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4TwistBoxSide implementation << 27 // 23 // 28 // Author: 18/03/2005 - O.Link (Oliver.Link@ce << 24 // $Id: G4TwistBoxSide.cc,v 1.3 2005/12/06 09:22:13 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-08-00 $ >> 26 // >> 27 // >> 28 // -------------------------------------------------------------------- >> 29 // GEANT 4 class source file >> 30 // >> 31 // >> 32 // G4TwistBoxSide.cc >> 33 // >> 34 // Author: >> 35 // >> 36 // 18/03/2005 - O.Link (Oliver.Link@cern.ch) >> 37 // 29 // ------------------------------------------- 38 // -------------------------------------------------------------------- 30 39 31 #include <cmath> 40 #include <cmath> 32 41 33 #include "G4TwistBoxSide.hh" 42 #include "G4TwistBoxSide.hh" 34 #include "G4PhysicalConstants.hh" << 35 #include "G4JTPolynomialSolver.hh" 43 #include "G4JTPolynomialSolver.hh" 36 44 37 //============================================ 45 //===================================================================== 38 //* constructors ----------------------------- 46 //* constructors ------------------------------------------------------ 39 47 40 G4TwistBoxSide::G4TwistBoxSide(const G4String& << 48 G4TwistBoxSide::G4TwistBoxSide(const G4String &name, 41 G4double PhiTw 49 G4double PhiTwist, // twist angle 42 G4double pDz, 50 G4double pDz, // half z lenght 43 G4double pThet 51 G4double pTheta, // direction between end planes 44 G4double pPhi, 52 G4double pPhi, // defined by polar and azimutal angles. 45 G4double pDy1, 53 G4double pDy1, // half y length at -pDz 46 G4double pDx1, 54 G4double pDx1, // half x length at -pDz,-pDy 47 G4double pDx2, 55 G4double pDx2, // half x length at -pDz,+pDy 48 G4double pDy2, 56 G4double pDy2, // half y length at +pDz 49 G4double pDx3, 57 G4double pDx3, // half x length at +pDz,-pDy 50 G4double pDx4, 58 G4double pDx4, // half x length at +pDz,+pDy 51 G4double pAlph 59 G4double pAlph, // tilt angle at +pDz 52 G4double Angle 60 G4double AngleSide // parity 53 61 ) : G4VTwistSurface(name) 54 { 62 { 55 63 56 64 57 fAxis[0] = kYAxis; // in local coordinate 65 fAxis[0] = kYAxis; // in local coordinate system 58 fAxis[1] = kZAxis; 66 fAxis[1] = kZAxis; 59 fAxisMin[0] = -kInfinity ; // Y Axis bounda 67 fAxisMin[0] = -kInfinity ; // Y Axis boundary 60 fAxisMax[0] = kInfinity ; // depends on 68 fAxisMax[0] = kInfinity ; // depends on z !! 61 fAxisMin[1] = -pDz ; // Z Axis boundary 69 fAxisMin[1] = -pDz ; // Z Axis boundary 62 fAxisMax[1] = pDz ; 70 fAxisMax[1] = pDz ; 63 71 64 fDx1 = pDx1 ; 72 fDx1 = pDx1 ; 65 fDx2 = pDx2 ; // box 73 fDx2 = pDx2 ; // box 66 fDx3 = pDx3 ; 74 fDx3 = pDx3 ; 67 fDx4 = pDx4 ; // box 75 fDx4 = pDx4 ; // box 68 76 69 // this is an overhead. But the parameter na 77 // this is an overhead. But the parameter naming scheme fits to the other surfaces. 70 78 71 if ( fDx1 != fDx2 || fDx3 != fDx4 ) << 79 if ( ! (fDx1 == fDx2 && fDx3 == fDx4 ) ) { 72 { << 80 G4cerr << "ERROR - G4TwistBoxSide::G4TwistBoxSide(): " 73 std::ostringstream message; << 81 << GetName() << G4endl 74 message << "TwistedTrapBoxSide is not used << 82 << " Not a box ! - " << G4endl ; 75 << GetName() << G4endl << 83 G4Exception("G4TwistBoxSide::G4TwistBoxSide()", "InvalidSetup", 76 << " Not a box !"; << 84 FatalException, "TwistedTrapBoxSide is not used as a the side of a box."); 77 G4Exception("G4TwistBoxSide::G4TwistBoxSid << 78 FatalException, message); << 79 } 85 } 80 86 81 fDy1 = pDy1 ; 87 fDy1 = pDy1 ; 82 fDy2 = pDy2 ; 88 fDy2 = pDy2 ; 83 89 84 fDz = pDz ; 90 fDz = pDz ; 85 91 86 fAlph = pAlph ; 92 fAlph = pAlph ; 87 fTAlph = std::tan(fAlph) ; 93 fTAlph = std::tan(fAlph) ; 88 94 89 fTheta = pTheta ; 95 fTheta = pTheta ; 90 fPhi = pPhi ; 96 fPhi = pPhi ; 91 97 92 // precalculate frequently used parameters << 98 // precalculate frequently used parameters 93 << 94 fDx4plus2 = fDx4 + fDx2 ; 99 fDx4plus2 = fDx4 + fDx2 ; 95 fDx4minus2 = fDx4 - fDx2 ; 100 fDx4minus2 = fDx4 - fDx2 ; 96 fDx3plus1 = fDx3 + fDx1 ; 101 fDx3plus1 = fDx3 + fDx1 ; 97 fDx3minus1 = fDx3 - fDx1 ; 102 fDx3minus1 = fDx3 - fDx1 ; 98 fDy2plus1 = fDy2 + fDy1 ; 103 fDy2plus1 = fDy2 + fDy1 ; 99 fDy2minus1 = fDy2 - fDy1 ; 104 fDy2minus1 = fDy2 - fDy1 ; 100 105 101 fa1md1 = 2*fDx2 - 2*fDx1 ; << 106 fa1md1 = 2*fDx2 - 2*fDx1 ; 102 fa2md2 = 2*fDx4 - 2*fDx3 ; 107 fa2md2 = 2*fDx4 - 2*fDx3 ; 103 108 104 109 105 fPhiTwist = PhiTwist ; // dphi 110 fPhiTwist = PhiTwist ; // dphi 106 fAngleSide = AngleSide ; // 0,90,180,270 de 111 fAngleSide = AngleSide ; // 0,90,180,270 deg 107 112 108 fdeltaX = 2*fDz * std::tan(fTheta) * std::co << 113 fdeltaX = 2 * fDz * std::tan(fTheta) * std::cos(fPhi) ; // dx in surface equation 109 fdeltaY = 2*fDz * std::tan(fTheta) * std::si << 114 fdeltaY = 2 * fDz * std::tan(fTheta) * std::sin(fPhi) ; // dy in surface equation 110 115 111 fRot.rotateZ( AngleSide ) ; 116 fRot.rotateZ( AngleSide ) ; 112 117 113 fTrans.set(0, 0, 0); // No Translation 118 fTrans.set(0, 0, 0); // No Translation 114 fIsValidNorm = false; 119 fIsValidNorm = false; 115 120 116 SetCorners(); << 121 SetCorners() ; 117 SetBoundaries(); << 122 SetBoundaries() ; >> 123 118 } 124 } 119 125 120 126 121 //============================================ 127 //===================================================================== 122 //* Fake default constructor ----------------- 128 //* Fake default constructor ------------------------------------------ 123 129 124 G4TwistBoxSide::G4TwistBoxSide( __void__& a ) 130 G4TwistBoxSide::G4TwistBoxSide( __void__& a ) 125 : G4VTwistSurface(a) 131 : G4VTwistSurface(a) 126 { 132 { 127 } 133 } 128 134 129 135 130 //============================================ 136 //===================================================================== 131 //* destructor ------------------------------- 137 //* destructor -------------------------------------------------------- 132 138 133 G4TwistBoxSide::~G4TwistBoxSide() = default; << 139 G4TwistBoxSide::~G4TwistBoxSide() >> 140 { >> 141 } 134 142 135 //============================================ 143 //===================================================================== 136 //* GetNormal -------------------------------- 144 //* GetNormal --------------------------------------------------------- 137 145 138 G4ThreeVector G4TwistBoxSide::GetNormal(const << 146 G4ThreeVector G4TwistBoxSide::GetNormal(const G4ThreeVector &tmpxx, 139 << 147 G4bool isGlobal) 140 { 148 { 141 // GetNormal returns a normal vector at a s 149 // GetNormal returns a normal vector at a surface (or very close 142 // to surface) point at tmpxx. 150 // to surface) point at tmpxx. 143 // If isGlobal=true, it returns the normal 151 // If isGlobal=true, it returns the normal in global coordinate. 144 // 152 // 145 153 146 G4ThreeVector xx; 154 G4ThreeVector xx; 147 if (isGlobal) << 155 if (isGlobal) { 148 { << 149 xx = ComputeLocalPoint(tmpxx); 156 xx = ComputeLocalPoint(tmpxx); 150 if ((xx - fCurrentNormal.p).mag() < 0.5 << 157 if ((xx - fCurrentNormal.p).mag() < 0.5 * kCarTolerance) { 151 { << 152 return ComputeGlobalDirection(fCurren 158 return ComputeGlobalDirection(fCurrentNormal.normal); 153 } 159 } 154 } << 160 } else { 155 else << 156 { << 157 xx = tmpxx; 161 xx = tmpxx; 158 if (xx == fCurrentNormal.p) << 162 if (xx == fCurrentNormal.p) { 159 { << 160 return fCurrentNormal.normal; 163 return fCurrentNormal.normal; 161 } 164 } 162 } 165 } 163 166 164 G4double phi ; 167 G4double phi ; 165 G4double u ; 168 G4double u ; 166 169 167 GetPhiUAtX(xx,phi,u) ; // phi,u for point 170 GetPhiUAtX(xx,phi,u) ; // phi,u for point xx close to surface 168 171 169 G4ThreeVector normal = NormAng(phi,u) ; // << 172 G4ThreeVector normal = NormAng(phi,u) ; // the normal vector at phi,u 170 173 171 #ifdef G4TWISTDEBUG << 174 #ifdef G4SPECSDEBUG 172 G4cout << "normal vector = " << normal << 175 G4cout << "normal vector = " << normal << G4endl ; 173 G4cout << "phi = " << phi << " , u = " << u 176 G4cout << "phi = " << phi << " , u = " << u << G4endl ; 174 #endif 177 #endif 175 178 176 // normal = normal/normal.mag() ; 179 // normal = normal/normal.mag() ; 177 180 178 if (isGlobal) << 181 if (isGlobal) { 179 { << 180 fCurrentNormal.normal = ComputeGlobalDir 182 fCurrentNormal.normal = ComputeGlobalDirection(normal.unit()); 181 } << 183 } else { 182 else << 183 { << 184 fCurrentNormal.normal = normal.unit(); 184 fCurrentNormal.normal = normal.unit(); 185 } 185 } 186 return fCurrentNormal.normal; 186 return fCurrentNormal.normal; 187 } 187 } 188 188 189 //============================================ 189 //===================================================================== 190 //* DistanceToSurface ------------------------ 190 //* DistanceToSurface ------------------------------------------------- 191 191 192 G4int G4TwistBoxSide::DistanceToSurface(const << 192 G4int G4TwistBoxSide::DistanceToSurface(const G4ThreeVector &gp, 193 const << 193 const G4ThreeVector &gv, 194 194 G4ThreeVector gxx[], 195 195 G4double distance[], 196 196 G4int areacode[], 197 197 G4bool isvalid[], 198 198 EValidate validate) 199 { 199 { 200 200 >> 201 static const G4double ctol = 0.5 * kCarTolerance; 201 static const G4double pihalf = pi/2 ; 202 static const G4double pihalf = pi/2 ; 202 const G4double ctol = 0.5 * kCarTolerance; << 203 203 204 G4bool IsParallel = false ; 204 G4bool IsParallel = false ; 205 G4bool IsConverged = false ; << 205 G4bool IsConverged = false ; 206 206 207 G4int nxx = 0 ; // number of physical solut 207 G4int nxx = 0 ; // number of physical solutions 208 208 209 fCurStatWithV.ResetfDone(validate, &gp, &gv) 209 fCurStatWithV.ResetfDone(validate, &gp, &gv); 210 210 211 if (fCurStatWithV.IsDone()) << 211 if (fCurStatWithV.IsDone()) { 212 { << 212 G4int i; 213 for (G4int i=0; i<fCurStatWithV.GetNXX(); << 213 for (i=0; i<fCurStatWithV.GetNXX(); i++) { 214 { << 215 gxx[i] = fCurStatWithV.GetXX(i); 214 gxx[i] = fCurStatWithV.GetXX(i); 216 distance[i] = fCurStatWithV.GetDistance( 215 distance[i] = fCurStatWithV.GetDistance(i); 217 areacode[i] = fCurStatWithV.GetAreacode( 216 areacode[i] = fCurStatWithV.GetAreacode(i); 218 isvalid[i] = fCurStatWithV.IsValid(i); 217 isvalid[i] = fCurStatWithV.IsValid(i); 219 } 218 } 220 return fCurStatWithV.GetNXX(); 219 return fCurStatWithV.GetNXX(); 221 } << 220 } else { 222 else // initialize << 221 223 { << 222 // initialize 224 for (G4int i=0; i<G4VSURFACENXX ; ++i) << 223 G4int i; 225 { << 224 for (i=0; i<G4VSURFACENXX ; i++) { 226 distance[i] = kInfinity; 225 distance[i] = kInfinity; 227 areacode[i] = sOutside; 226 areacode[i] = sOutside; 228 isvalid[i] = false; 227 isvalid[i] = false; 229 gxx[i].set(kInfinity, kInfinity, kInfini 228 gxx[i].set(kInfinity, kInfinity, kInfinity); 230 } 229 } 231 } 230 } 232 231 233 G4ThreeVector p = ComputeLocalPoint(gp); 232 G4ThreeVector p = ComputeLocalPoint(gp); 234 G4ThreeVector v = ComputeLocalDirection(gv); 233 G4ThreeVector v = ComputeLocalDirection(gv); 235 234 236 #ifdef G4TWISTDEBUG << 235 #ifdef G4SPECSDEBUG 237 G4cout << "Local point p = " << p << G4endl 236 G4cout << "Local point p = " << p << G4endl ; 238 G4cout << "Local direction v = " << v << G4e 237 G4cout << "Local direction v = " << v << G4endl ; 239 #endif 238 #endif 240 239 241 G4double phi=0.,u=0.,q=0.; // parameters << 240 G4double phi,u ; // parameters 242 241 243 // temporary variables 242 // temporary variables 244 243 245 G4double tmpdist = kInfinity ; 244 G4double tmpdist = kInfinity ; 246 G4ThreeVector tmpxx; 245 G4ThreeVector tmpxx; 247 G4int tmpareacode = sOutside ; 246 G4int tmpareacode = sOutside ; 248 G4bool tmpisvalid = false ; 247 G4bool tmpisvalid = false ; 249 248 250 std::vector<Intersection> xbuf ; 249 std::vector<Intersection> xbuf ; 251 Intersection xbuftmp ; 250 Intersection xbuftmp ; 252 251 253 // prepare some variables for the intersecti 252 // prepare some variables for the intersection finder 254 253 255 G4double L = 2*fDz ; 254 G4double L = 2*fDz ; 256 255 257 G4double phixz = fPhiTwist * ( p.x() * v.z() 256 G4double phixz = fPhiTwist * ( p.x() * v.z() - p.z() * v.x() ) ; 258 G4double phiyz = fPhiTwist * ( p.y() * v.z() 257 G4double phiyz = fPhiTwist * ( p.y() * v.z() - p.z() * v.y() ) ; 259 258 260 // special case vz = 0 259 // special case vz = 0 261 260 262 if ( v.z() == 0. ) << 261 if ( v.z() == 0. ) { 263 { << 264 if ( (std::fabs(p.z()) <= L) && (fPhiTwist << 265 { << 266 phi = p.z() * fPhiTwist / L ; // phi is << 267 262 268 q = (2.* fPhiTwist*((v.x() - fTAlph*v.y( << 263 if ( std::fabs(p.z()) <= L ) { // intersection possible in z 269 + (fTAlph*v.x() + << 270 264 271 if (q != 0.0) << 265 phi = p.z() * fPhiTwist / L ; // phi is determined by the z-position 272 { << 266 273 u = (2*(-(fdeltaY*phi*v.x()) + fPhiTwi << 267 u = (2*(-(fdeltaY*phi*v.x()) + fPhiTwist*p.y()*v.x() + fdeltaX*phi*v.y() - fPhiTwist*p.x()*v.y()) + (fDx4plus2*fPhiTwist + 2*fDx4minus2*phi)*(v.y()*std::cos(phi) - v.x()*std::sin(phi)))/(2.* fPhiTwist*((v.x() - fTAlph*v.y())*std::cos(phi) + (fTAlph*v.x() + v.y())*std::sin(phi))) ; 274 + fdeltaX*phi*v.y() - fPhiTwis << 268 275 + (fDx4plus2*fPhiTwist + 2*fDx4mi << 276 * (v.y()*std::cos(phi) - v.x()*st << 277 } << 278 xbuftmp.phi = phi ; 269 xbuftmp.phi = phi ; 279 xbuftmp.u = u ; 270 xbuftmp.u = u ; 280 xbuftmp.areacode = sOutside ; 271 xbuftmp.areacode = sOutside ; 281 xbuftmp.distance = kInfinity ; 272 xbuftmp.distance = kInfinity ; 282 xbuftmp.isvalid = false ; 273 xbuftmp.isvalid = false ; 283 274 284 xbuf.push_back(xbuftmp) ; // store it t 275 xbuf.push_back(xbuftmp) ; // store it to xbuf >> 276 285 } 277 } 286 else // no interse << 278 287 { << 279 else { // no intersection possible >> 280 288 distance[0] = kInfinity; 281 distance[0] = kInfinity; 289 gxx[0].set(kInfinity,kInfinity,kInfinity 282 gxx[0].set(kInfinity,kInfinity,kInfinity); 290 isvalid[0] = false ; 283 isvalid[0] = false ; 291 areacode[0] = sOutside ; 284 areacode[0] = sOutside ; 292 fCurStatWithV.SetCurrentStatus(0, gxx[0] 285 fCurStatWithV.SetCurrentStatus(0, gxx[0], distance[0], 293 areacode[ 286 areacode[0], isvalid[0], 294 0, valida 287 0, validate, &gp, &gv); 295 288 296 return 0; 289 return 0; 297 } // end std::fabs(p.z() <= L << 290 >> 291 >> 292 } // end std::fabs(p.z() <= L >> 293 298 } // end v.z() == 0 294 } // end v.z() == 0 299 else // general solution for non-zero vz << 295 300 { << 296 301 G4double c[8],srd[7],si[7] ; << 297 // general solution for non-zero vz >> 298 >> 299 else { >> 300 >> 301 G4double c[8],sr[7],si[7] ; 302 302 303 c[7] = -14400*(-2*phixz + 2*fTAlph*phiyz + 303 c[7] = -14400*(-2*phixz + 2*fTAlph*phiyz + fDx4plus2*fPhiTwist*v.z()) ; 304 c[6] = 28800*(phiyz + 2*fDz*v.x() - (fdelt 304 c[6] = 28800*(phiyz + 2*fDz*v.x() - (fdeltaX + fDx4minus2)*v.z() + fTAlph*(phixz - 2*fDz*v.y() + fdeltaY*v.z())) ; 305 c[5] = -1200*(10*phixz - 48*fDz*v.y() + 24 305 c[5] = -1200*(10*phixz - 48*fDz*v.y() + 24*fdeltaY*v.z() + fDx4plus2*fPhiTwist*v.z() - 2*fTAlph*(5*phiyz + 24*fDz*v.x() - 12*fdeltaX*v.z())) ; 306 c[4] = -2400*(phiyz + 10*fDz*v.x() - 5*fde 306 c[4] = -2400*(phiyz + 10*fDz*v.x() - 5*fdeltaX*v.z() + fDx4minus2*v.z() + fTAlph*(phixz - 10*fDz*v.y() + 5*fdeltaY*v.z())) ; 307 c[3] = 24*(2*phixz - 200*fDz*v.y() + 100*f 307 c[3] = 24*(2*phixz - 200*fDz*v.y() + 100*fdeltaY*v.z() - fDx4plus2*fPhiTwist*v.z() - 2*fTAlph*(phiyz + 100*fDz*v.x() - 50*fdeltaX*v.z())) ; 308 c[2] = -16*(7*fTAlph* phixz + 7*phiyz - 6* 308 c[2] = -16*(7*fTAlph* phixz + 7*phiyz - 6*fDz*v.x() + 6*fDz*fTAlph*v.y() + 3*(fdeltaX + fDx4minus2 - fdeltaY*fTAlph)*v.z()) ; 309 c[1] = 4*(9*phixz - 9*fTAlph*phiyz - 56*fD 309 c[1] = 4*(9*phixz - 9*fTAlph*phiyz - 56*fDz*fTAlph*v.x() - 56*fDz*v.y() + 28*(fdeltaY + fdeltaX*fTAlph)*v.z()) ; 310 c[0] = 36*(2* fDz*(v.x() - fTAlph*v.y()) - 310 c[0] = 36*(2* fDz*(v.x() - fTAlph*v.y()) - fdeltaX*v.z() + fdeltaY*fTAlph*v.z()) ; 311 311 312 #ifdef G4TWISTDEBUG << 312 >> 313 #ifdef G4SPECSDEBUG 313 G4cout << "coef = " << c[0] << " " 314 G4cout << "coef = " << c[0] << " " 314 << c[1] << " " 315 << c[1] << " " 315 << c[2] << " " 316 << c[2] << " " 316 << c[3] << " " 317 << c[3] << " " 317 << c[4] << " " 318 << c[4] << " " 318 << c[5] << " " 319 << c[5] << " " 319 << c[6] << " " 320 << c[6] << " " 320 << c[7] << G4endl ; 321 << c[7] << G4endl ; 321 #endif 322 #endif 322 323 323 G4JTPolynomialSolver trapEq ; 324 G4JTPolynomialSolver trapEq ; 324 G4int num = trapEq.FindRoots(c,7,srd,si); << 325 G4int num = trapEq.FindRoots(c,7,sr,si); >> 326 >> 327 >> 328 for (G4int i = 0 ; i<num ; i++ ) { // loop over all mathematical solutions >> 329 if ( si[i]==0.0 ) { // only real solutions >> 330 #ifdef G4SPECSDEBUG >> 331 G4cout << "Solution " << i << " : " << sr[i] << G4endl ; >> 332 #endif >> 333 phi = std::fmod(sr[i] , pihalf) ; 325 334 326 for (G4int i = 0 ; i<num ; ++i ) // loo << 335 u = (2*phiyz + 4*fDz*phi*v.y() - 2*fdeltaY*phi*v.z() - fDx4plus2*fPhiTwist*v.z()*std::sin(phi) - 2*fDx4minus2*phi*v.z()*std::sin(phi))/(2*fPhiTwist*v.z()*std::cos(phi) + 2*fPhiTwist*fTAlph*v.z()*std::sin(phi)) ; 327 { << 328 if ( (si[i]==0.0) && (fPhiTwist != 0.0) << 329 { << 330 #ifdef G4TWISTDEBUG << 331 G4cout << "Solution " << i << " : " << << 332 #endif << 333 phi = std::fmod(srd[i], pihalf) ; << 334 << 335 u = (2*phiyz + 4*fDz*phi*v.y() - 2*f << 336 - fDx4plus2*fPhiTwist*v.z()*std:: << 337 - 2*fDx4minus2*phi*v.z()*std::sin << 338 /(2*fPhiTwist*v.z()*std::cos(phi) << 339 + 2*fPhiTwist*fTAlph*v.z()*std: << 340 336 341 xbuftmp.phi = phi ; 337 xbuftmp.phi = phi ; 342 xbuftmp.u = u ; 338 xbuftmp.u = u ; 343 xbuftmp.areacode = sOutside ; 339 xbuftmp.areacode = sOutside ; 344 xbuftmp.distance = kInfinity ; 340 xbuftmp.distance = kInfinity ; 345 xbuftmp.isvalid = false ; 341 xbuftmp.isvalid = false ; 346 342 347 xbuf.push_back(xbuftmp) ; // store it 343 xbuf.push_back(xbuftmp) ; // store it to xbuf 348 344 349 #ifdef G4TWISTDEBUG << 345 #ifdef G4SPECSDEBUG 350 G4cout << "solution " << i << " = " << 346 G4cout << "solution " << i << " = " << phi << " , " << u << G4endl ; 351 #endif 347 #endif >> 348 352 } // end if real solution 349 } // end if real solution 353 } // end loop i 350 } // end loop i 354 } // end general case << 351 >> 352 } // end general case 355 353 356 354 357 nxx = (G4int)xbuf.size() ; // save the numb << 355 nxx = xbuf.size() ; // save the number of solutions 358 356 359 G4ThreeVector xxonsurface ; // point 357 G4ThreeVector xxonsurface ; // point on surface 360 G4ThreeVector surfacenormal ; // normal 358 G4ThreeVector surfacenormal ; // normal vector 361 G4double deltaX ; // distan << 359 G4double deltaX ; // distance between intersection point and point on surface 362 // point << 363 G4double theta ; // angle 360 G4double theta ; // angle between track and surfacenormal 364 G4double factor ; // a scal 361 G4double factor ; // a scaling factor 365 G4int maxint = 30 ; // number 362 G4int maxint = 30 ; // number of iterations 366 363 367 364 368 for (auto & k : xbuf) << 365 for ( size_t k = 0 ; k<xbuf.size() ; k++ ) { 369 { << 366 370 #ifdef G4TWISTDEBUG << 367 #ifdef G4SPECSDEBUG 371 G4cout << "Solution " << k << " : " 368 G4cout << "Solution " << k << " : " 372 << "reconstructed phiR = " << xbuf[ 369 << "reconstructed phiR = " << xbuf[k].phi 373 << ", uR = " << xbuf[k].u << G4endl 370 << ", uR = " << xbuf[k].u << G4endl ; 374 #endif 371 #endif 375 372 376 phi = k.phi ; // get the stored values fo << 373 phi = xbuf[k].phi ; // get the stored values for phi and u 377 u = k.u ; << 374 u = xbuf[k].u ; 378 375 379 IsConverged = false ; // no convergence 376 IsConverged = false ; // no convergence at the beginning 380 377 381 for ( G4int i = 1 ; i<maxint ; ++i ) << 378 for ( G4int i = 1 ; i<maxint ; i++ ) { 382 { << 379 383 xxonsurface = SurfacePoint(phi,u) ; 380 xxonsurface = SurfacePoint(phi,u) ; 384 surfacenormal = NormAng(phi,u) ; 381 surfacenormal = NormAng(phi,u) ; 385 tmpdist = DistanceToPlaneWithV(p, v, xxo 382 tmpdist = DistanceToPlaneWithV(p, v, xxonsurface, surfacenormal, tmpxx); 386 deltaX = ( tmpxx - xxonsurface ).mag() ; 383 deltaX = ( tmpxx - xxonsurface ).mag() ; 387 theta = std::fabs(std::acos(v*surfacenor 384 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ; 388 if ( theta < 0.001 ) << 385 if ( theta < 0.001 ) { 389 { << 390 factor = 50 ; 386 factor = 50 ; 391 IsParallel = true ; 387 IsParallel = true ; 392 } 388 } 393 else << 389 else { 394 { << 395 factor = 1 ; 390 factor = 1 ; 396 } 391 } 397 392 398 #ifdef G4TWISTDEBUG << 393 #ifdef G4SPECSDEBUG 399 G4cout << "Step i = " << i << ", distanc 394 G4cout << "Step i = " << i << ", distance = " << tmpdist << ", " << deltaX << G4endl ; 400 G4cout << "X = " << tmpxx << G4endl ; 395 G4cout << "X = " << tmpxx << G4endl ; 401 #endif 396 #endif 402 397 403 GetPhiUAtX(tmpxx, phi, u) ; // the new p 398 GetPhiUAtX(tmpxx, phi, u) ; // the new point xx is accepted and phi/u replaced 404 399 405 #ifdef G4TWISTDEBUG << 400 #ifdef G4SPECSDEBUG 406 G4cout << "approximated phi = " << phi < 401 G4cout << "approximated phi = " << phi << ", u = " << u << G4endl ; 407 #endif 402 #endif 408 403 409 if ( deltaX <= factor*ctol ) { IsConverg 404 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; } 410 405 411 } // end iterative loop (i) 406 } // end iterative loop (i) >> 407 412 408 413 if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 << 409 // new code 21.09.05 O.Link >> 410 if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 ; 414 411 415 #ifdef G4TWISTDEBUG << 412 #ifdef G4SPECSDEBUG 416 G4cout << "refined solution " << phi << " 413 G4cout << "refined solution " << phi << " , " << u << G4endl ; 417 G4cout << "distance = " << tmpdist << G4en 414 G4cout << "distance = " << tmpdist << G4endl ; 418 G4cout << "local X = " << tmpxx << G4endl 415 G4cout << "local X = " << tmpxx << G4endl ; 419 #endif 416 #endif 420 417 421 tmpisvalid = false ; // init 418 tmpisvalid = false ; // init 422 419 423 if ( IsConverged ) << 420 if ( IsConverged ) { 424 { << 421 425 if (validate == kValidateWithTol) << 422 if (validate == kValidateWithTol) { 426 { << 427 tmpareacode = GetAreaCode(tmpxx); 423 tmpareacode = GetAreaCode(tmpxx); 428 if (!IsOutside(tmpareacode)) << 424 if (!IsOutside(tmpareacode)) { 429 { << 430 if (tmpdist >= 0) tmpisvalid = true; 425 if (tmpdist >= 0) tmpisvalid = true; 431 } 426 } 432 } << 427 } else if (validate == kValidateWithoutTol) { 433 else if (validate == kValidateWithoutTol << 434 { << 435 tmpareacode = GetAreaCode(tmpxx, false 428 tmpareacode = GetAreaCode(tmpxx, false); 436 if (IsInside(tmpareacode)) << 429 if (IsInside(tmpareacode)) { 437 { << 438 if (tmpdist >= 0) tmpisvalid = true; 430 if (tmpdist >= 0) tmpisvalid = true; 439 } 431 } 440 } << 432 } else { // kDontValidate 441 else // kDontValidate << 442 { << 443 G4Exception("G4TwistBoxSide::DistanceT 433 G4Exception("G4TwistBoxSide::DistanceToSurface()", 444 "GeomSolids0001", FatalExc << 434 "NotImplemented kDontValidate", FatalException, 445 "Feature NOT implemented ! 435 "Feature NOT implemented !"); 446 } 436 } 447 } << 437 448 else << 438 } 449 { << 439 else { 450 tmpdist = kInfinity; // no convergen 440 tmpdist = kInfinity; // no convergence after 10 steps 451 tmpisvalid = false ; // solution is 441 tmpisvalid = false ; // solution is not vaild 452 } 442 } 453 443 >> 444 454 // store the found values 445 // store the found values 455 k.xx = tmpxx ; << 446 xbuf[k].xx = tmpxx ; 456 k.distance = tmpdist ; << 447 xbuf[k].distance = tmpdist ; 457 k.areacode = tmpareacode ; << 448 xbuf[k].areacode = tmpareacode ; 458 k.isvalid = tmpisvalid ; << 449 xbuf[k].isvalid = tmpisvalid ; >> 450 459 451 460 } // end loop over physical solutions (vari 452 } // end loop over physical solutions (variable k) 461 453 >> 454 462 std::sort(xbuf.begin() , xbuf.end(), Distanc 455 std::sort(xbuf.begin() , xbuf.end(), DistanceSort ) ; // sorting 463 456 464 #ifdef G4TWISTDEBUG << 457 #ifdef G4SPECSDEBUG 465 G4cout << G4endl << "list xbuf after sorting 458 G4cout << G4endl << "list xbuf after sorting : " << G4endl ; 466 G4cout << G4endl << G4endl ; 459 G4cout << G4endl << G4endl ; 467 #endif 460 #endif 468 461 >> 462 469 // erase identical intersection (within kCar 463 // erase identical intersection (within kCarTolerance) 470 xbuf.erase(std::unique(xbuf.begin(),xbuf.end << 464 xbuf.erase( std::unique(xbuf.begin(), xbuf.end() , EqualIntersection ) , xbuf.end() ) ; >> 465 471 466 472 // add guesses 467 // add guesses 473 468 474 auto nxxtmp = (G4int)xbuf.size() ; << 469 G4int nxxtmp = xbuf.size() ; >> 470 >> 471 if ( nxxtmp<2 || IsParallel ) { 475 472 476 if ( nxxtmp<2 || IsParallel ) << 477 { << 478 // positive end 473 // positive end 479 #ifdef G4TWISTDEBUG << 474 #ifdef G4SPECSDEBUG 480 G4cout << "add guess at +z/2 .. " << G4end 475 G4cout << "add guess at +z/2 .. " << G4endl ; 481 #endif 476 #endif 482 477 483 phi = fPhiTwist/2 ; 478 phi = fPhiTwist/2 ; 484 u = 0. ; << 479 u = 0 ; >> 480 >> 481 >> 482 485 xbuftmp.phi = phi ; 483 xbuftmp.phi = phi ; 486 xbuftmp.u = u ; 484 xbuftmp.u = u ; 487 xbuftmp.areacode = sOutside ; 485 xbuftmp.areacode = sOutside ; 488 xbuftmp.distance = kInfinity ; 486 xbuftmp.distance = kInfinity ; 489 xbuftmp.isvalid = false ; 487 xbuftmp.isvalid = false ; 490 488 491 xbuf.push_back(xbuftmp) ; // store it to 489 xbuf.push_back(xbuftmp) ; // store it to xbuf 492 490 493 #ifdef G4TWISTDEBUG << 491 >> 492 #ifdef G4SPECSDEBUG 494 G4cout << "add guess at -z/2 .. " << G4end 493 G4cout << "add guess at -z/2 .. " << G4endl ; 495 #endif 494 #endif 496 495 497 phi = -fPhiTwist/2 ; 496 phi = -fPhiTwist/2 ; 498 u = 0. ; << 497 u = 0 ; 499 498 500 xbuftmp.phi = phi ; 499 xbuftmp.phi = phi ; 501 xbuftmp.u = u ; 500 xbuftmp.u = u ; 502 xbuftmp.areacode = sOutside ; 501 xbuftmp.areacode = sOutside ; 503 xbuftmp.distance = kInfinity ; 502 xbuftmp.distance = kInfinity ; 504 xbuftmp.isvalid = false ; 503 xbuftmp.isvalid = false ; 505 504 506 xbuf.push_back(xbuftmp) ; // store it to 505 xbuf.push_back(xbuftmp) ; // store it to xbuf 507 506 508 for ( std::size_t k = nxxtmp ; k<xbuf.size << 507 for ( size_t k = nxxtmp ; k<xbuf.size() ; k++ ) { 509 { << 508 510 #ifdef G4TWISTDEBUG << 509 #ifdef G4SPECSDEBUG 511 G4cout << "Solution " << k << " : " 510 G4cout << "Solution " << k << " : " 512 << "reconstructed phiR = " << xbu 511 << "reconstructed phiR = " << xbuf[k].phi 513 << ", uR = " << xbuf[k].u << G4en 512 << ", uR = " << xbuf[k].u << G4endl ; 514 #endif 513 #endif 515 514 516 phi = xbuf[k].phi ; // get the stored v 515 phi = xbuf[k].phi ; // get the stored values for phi and u 517 u = xbuf[k].u ; 516 u = xbuf[k].u ; 518 517 519 IsConverged = false ; // no convergenc 518 IsConverged = false ; // no convergence at the beginning 520 519 521 for ( G4int i = 1 ; i<maxint ; ++i ) << 520 for ( G4int i = 1 ; i<maxint ; i++ ) { 522 { << 521 523 xxonsurface = SurfacePoint(phi,u) ; 522 xxonsurface = SurfacePoint(phi,u) ; 524 surfacenormal = NormAng(phi,u) ; 523 surfacenormal = NormAng(phi,u) ; 525 tmpdist = DistanceToPlaneWithV(p, v, x << 524 tmpdist = DistanceToPlaneWithV(p, v, xxonsurface, surfacenormal, tmpxx); 526 deltaX = ( tmpxx - xxonsurface ).mag() 525 deltaX = ( tmpxx - xxonsurface ).mag() ; 527 theta = std::fabs(std::acos(v*surfacen 526 theta = std::fabs(std::acos(v*surfacenormal) - pihalf) ; 528 if ( theta < 0.001 ) << 527 if ( theta < 0.001 ) { 529 { << 530 factor = 50 ; 528 factor = 50 ; 531 } 529 } 532 else << 530 else { 533 { << 534 factor = 1 ; 531 factor = 1 ; 535 } 532 } 536 533 537 #ifdef G4TWISTDEBUG << 534 #ifdef G4SPECSDEBUG 538 G4cout << "Step i = " << i << ", dista << 535 G4cout << "Step i = " << i << ", distance = " << tmpdist << ", " << deltaX << G4endl ; 539 << tmpdist << ", " << deltaX << << 540 G4cout << "X = " << tmpxx << G4endl ; 536 G4cout << "X = " << tmpxx << G4endl ; 541 #endif 537 #endif 542 538 543 GetPhiUAtX(tmpxx, phi, u) ; << 539 GetPhiUAtX(tmpxx, phi, u) ; // the new point xx is accepted and phi/u replaced 544 // the new point xx is accepted and << 545 540 546 #ifdef G4TWISTDEBUG << 541 #ifdef G4SPECSDEBUG 547 G4cout << "approximated phi = " << phi 542 G4cout << "approximated phi = " << phi << ", u = " << u << G4endl ; 548 #endif 543 #endif 549 544 550 if ( deltaX <= factor*ctol ) { IsConve 545 if ( deltaX <= factor*ctol ) { IsConverged = true ; break ; } 551 546 552 } // end iterative loop (i) 547 } // end iterative loop (i) >> 548 553 549 554 if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 << 550 // new code 21.09.05 O.Link >> 551 if ( std::fabs(tmpdist)<ctol ) tmpdist = 0 ; 555 552 556 #ifdef G4TWISTDEBUG << 553 #ifdef G4SPECSDEBUG 557 G4cout << "refined solution " << phi << 554 G4cout << "refined solution " << phi << " , " << u << G4endl ; 558 G4cout << "distance = " << tmpdist << G4 555 G4cout << "distance = " << tmpdist << G4endl ; 559 G4cout << "local X = " << tmpxx << G4end 556 G4cout << "local X = " << tmpxx << G4endl ; 560 #endif 557 #endif 561 558 562 tmpisvalid = false ; // init 559 tmpisvalid = false ; // init 563 560 564 if ( IsConverged ) << 561 if ( IsConverged ) { 565 { << 562 566 if (validate == kValidateWithTol) << 563 if (validate == kValidateWithTol) { 567 { << 568 tmpareacode = GetAreaCode(tmpxx); 564 tmpareacode = GetAreaCode(tmpxx); 569 if (!IsOutside(tmpareacode)) << 565 if (!IsOutside(tmpareacode)) { 570 { << 571 if (tmpdist >= 0) tmpisvalid = tru 566 if (tmpdist >= 0) tmpisvalid = true; 572 } 567 } 573 } << 568 } else if (validate == kValidateWithoutTol) { 574 else if (validate == kValidateWithoutT << 575 { << 576 tmpareacode = GetAreaCode(tmpxx, fal 569 tmpareacode = GetAreaCode(tmpxx, false); 577 if (IsInside(tmpareacode)) << 570 if (IsInside(tmpareacode)) { 578 { << 579 if (tmpdist >= 0) tmpisvalid = tru 571 if (tmpdist >= 0) tmpisvalid = true; 580 } 572 } 581 } << 573 } else { // kDontValidate 582 else // kDontValidate << 583 { << 584 G4Exception("G4TwistedBoxSide::Dista 574 G4Exception("G4TwistedBoxSide::DistanceToSurface()", 585 "GeomSolids0001", FatalE << 575 "NotImplemented kDontValidate", FatalException, 586 "Feature NOT implemented 576 "Feature NOT implemented !"); 587 } 577 } 588 } << 578 589 else << 579 } 590 { << 580 else { 591 tmpdist = kInfinity; // no converg 581 tmpdist = kInfinity; // no convergence after 10 steps 592 tmpisvalid = false ; // solution i 582 tmpisvalid = false ; // solution is not vaild 593 } 583 } 594 << 584 >> 585 595 // store the found values 586 // store the found values 596 xbuf[k].xx = tmpxx ; 587 xbuf[k].xx = tmpxx ; 597 xbuf[k].distance = tmpdist ; 588 xbuf[k].distance = tmpdist ; 598 xbuf[k].areacode = tmpareacode ; 589 xbuf[k].areacode = tmpareacode ; 599 xbuf[k].isvalid = tmpisvalid ; 590 xbuf[k].isvalid = tmpisvalid ; >> 591 >> 592 600 } // end loop over physical solutions 593 } // end loop over physical solutions >> 594 >> 595 601 } // end less than 2 solutions 596 } // end less than 2 solutions 602 597 >> 598 603 // sort again 599 // sort again 604 std::sort(xbuf.begin() , xbuf.end(), Distanc 600 std::sort(xbuf.begin() , xbuf.end(), DistanceSort ) ; // sorting 605 601 606 // erase identical intersection (within kCar 602 // erase identical intersection (within kCarTolerance) 607 xbuf.erase(std::unique(xbuf.begin(),xbuf.end << 603 xbuf.erase( std::unique(xbuf.begin(), xbuf.end() , EqualIntersection ) , xbuf.end() ) ; 608 604 609 #ifdef G4TWISTDEBUG << 605 #ifdef G4SPECSDEBUG 610 G4cout << G4endl << "list xbuf after sorting 606 G4cout << G4endl << "list xbuf after sorting : " << G4endl ; 611 G4cout << G4endl << G4endl ; 607 G4cout << G4endl << G4endl ; 612 #endif 608 #endif 613 609 614 nxx = (G4int)xbuf.size() ; // determine nu << 610 nxx = xbuf.size() ; // determine number of solutions again. 615 611 616 for ( G4int i = 0 ; i<(G4int)xbuf.size() ; + << 612 for ( size_t i = 0 ; i<xbuf.size() ; i++ ) { 617 { << 613 618 distance[i] = xbuf[i].distance; 614 distance[i] = xbuf[i].distance; 619 gxx[i] = ComputeGlobalPoint(xbuf[i].x 615 gxx[i] = ComputeGlobalPoint(xbuf[i].xx); 620 areacode[i] = xbuf[i].areacode ; 616 areacode[i] = xbuf[i].areacode ; 621 isvalid[i] = xbuf[i].isvalid ; 617 isvalid[i] = xbuf[i].isvalid ; 622 618 623 fCurStatWithV.SetCurrentStatus(i, gxx[i], 619 fCurStatWithV.SetCurrentStatus(i, gxx[i], distance[i], areacode[i], 624 isvalid[i 620 isvalid[i], nxx, validate, &gp, &gv); 625 621 626 #ifdef G4TWISTDEBUG << 622 #ifdef G4SPECSDEBUG 627 G4cout << "element Nr. " << i 623 G4cout << "element Nr. " << i 628 << ", local Intersection = " << xbu 624 << ", local Intersection = " << xbuf[i].xx 629 << ", distance = " << xbuf[i].dista 625 << ", distance = " << xbuf[i].distance 630 << ", u = " << xbuf[i].u 626 << ", u = " << xbuf[i].u 631 << ", phi = " << xbuf[i].phi 627 << ", phi = " << xbuf[i].phi 632 << ", isvalid = " << xbuf[i].isvali 628 << ", isvalid = " << xbuf[i].isvalid 633 << G4endl ; 629 << G4endl ; 634 #endif 630 #endif 635 631 636 } // end for( i ) loop 632 } // end for( i ) loop 637 633 638 #ifdef G4TWISTDEBUG << 634 >> 635 #ifdef G4SPECSDEBUG 639 G4cout << "G4TwistBoxSide finished " << G4en 636 G4cout << "G4TwistBoxSide finished " << G4endl ; 640 G4cout << nxx << " possible physical solutio 637 G4cout << nxx << " possible physical solutions found" << G4endl ; 641 for ( G4int k= 0 ; k< nxx ; ++k ) << 638 for ( G4int k= 0 ; k< nxx ; k++ ) { 642 { << 643 G4cout << "global intersection Point found 639 G4cout << "global intersection Point found: " << gxx[k] << G4endl ; 644 G4cout << "distance = " << distance[k] << 640 G4cout << "distance = " << distance[k] << G4endl ; 645 G4cout << "isvalid = " << isvalid[k] << G4 641 G4cout << "isvalid = " << isvalid[k] << G4endl ; 646 } 642 } 647 #endif 643 #endif 648 644 649 return nxx ; 645 return nxx ; >> 646 650 } 647 } 651 648 >> 649 652 //============================================ 650 //===================================================================== 653 //* DistanceToSurface ------------------------ 651 //* DistanceToSurface ------------------------------------------------- 654 652 655 G4int G4TwistBoxSide::DistanceToSurface(const << 653 G4int G4TwistBoxSide::DistanceToSurface(const G4ThreeVector &gp, 656 << 654 G4ThreeVector gxx[], 657 << 655 G4double distance[], 658 << 656 G4int areacode[]) 659 { 657 { 660 const G4double ctol = 0.5 * kCarTolerance; << 658 // to do >> 659 >> 660 static const G4double ctol = 0.5 * kCarTolerance; 661 661 662 fCurStat.ResetfDone(kDontValidate, &gp); 662 fCurStat.ResetfDone(kDontValidate, &gp); 663 663 664 if (fCurStat.IsDone()) << 664 if (fCurStat.IsDone()) { 665 { << 665 G4int i; 666 for (G4int i=0; i<fCurStat.GetNXX(); ++i << 666 for (i=0; i<fCurStat.GetNXX(); i++) { 667 { << 668 gxx[i] = fCurStat.GetXX(i); 667 gxx[i] = fCurStat.GetXX(i); 669 distance[i] = fCurStat.GetDistance(i) 668 distance[i] = fCurStat.GetDistance(i); 670 areacode[i] = fCurStat.GetAreacode(i) 669 areacode[i] = fCurStat.GetAreacode(i); 671 } 670 } 672 return fCurStat.GetNXX(); 671 return fCurStat.GetNXX(); 673 } << 672 } else { 674 else // initialize << 673 // initialize 675 { << 674 G4int i; 676 for (G4int i=0; i<G4VSURFACENXX; ++i) << 675 for (i=0; i<G4VSURFACENXX; i++) { 677 { << 678 distance[i] = kInfinity; 676 distance[i] = kInfinity; 679 areacode[i] = sOutside; 677 areacode[i] = sOutside; 680 gxx[i].set(kInfinity, kInfinity, kInf 678 gxx[i].set(kInfinity, kInfinity, kInfinity); 681 } 679 } 682 } 680 } 683 681 684 G4ThreeVector p = ComputeLocalPoint(gp); 682 G4ThreeVector p = ComputeLocalPoint(gp); 685 G4ThreeVector xx; // intersection point 683 G4ThreeVector xx; // intersection point 686 G4ThreeVector xxonsurface ; // interpolated 684 G4ThreeVector xxonsurface ; // interpolated intersection point 687 685 688 // the surfacenormal at that surface point 686 // the surfacenormal at that surface point 689 G4double phiR = 0. ; << 687 G4double phiR = 0 ; // 690 G4double uR = 0. ; << 688 G4double uR = 0 ; 691 689 692 G4ThreeVector surfacenormal ; 690 G4ThreeVector surfacenormal ; 693 G4double deltaX ; 691 G4double deltaX ; 694 692 695 G4int maxint = 20 ; 693 G4int maxint = 20 ; 696 694 697 for ( G4int i = 1 ; i<maxint ; ++i ) << 695 for ( G4int i = 1 ; i<maxint ; i++ ) { 698 { << 696 699 xxonsurface = SurfacePoint(phiR,uR) ; 697 xxonsurface = SurfacePoint(phiR,uR) ; 700 surfacenormal = NormAng(phiR,uR) ; 698 surfacenormal = NormAng(phiR,uR) ; 701 distance[0] = DistanceToPlane(p, xxonsurf 699 distance[0] = DistanceToPlane(p, xxonsurface, surfacenormal, xx); // new XX 702 deltaX = ( xx - xxonsurface ).mag() ; 700 deltaX = ( xx - xxonsurface ).mag() ; 703 701 704 #ifdef G4TWISTDEBUG << 702 #ifdef G4SPECSDEBUG 705 G4cout << "i = " << i << ", distance = " << 703 G4cout << "i = " << i << ", distance = " << distance[0] << ", " << deltaX << G4endl ; 706 << ", " << deltaX << G4endl ; << 707 G4cout << "X = " << xx << G4endl ; 704 G4cout << "X = " << xx << G4endl ; 708 #endif 705 #endif 709 706 710 // the new point xx is accepted and phi/p 707 // the new point xx is accepted and phi/psi replaced 711 GetPhiUAtX(xx, phiR, uR) ; 708 GetPhiUAtX(xx, phiR, uR) ; 712 709 713 if ( deltaX <= ctol ) { break ; } 710 if ( deltaX <= ctol ) { break ; } >> 711 714 } 712 } 715 713 716 // check validity of solution ( valid phi,p 714 // check validity of solution ( valid phi,psi ) 717 715 718 G4double halfphi = 0.5*fPhiTwist ; 716 G4double halfphi = 0.5*fPhiTwist ; 719 G4double uMax = GetBoundaryMax(phiR) ; 717 G4double uMax = GetBoundaryMax(phiR) ; 720 718 721 if ( phiR > halfphi ) phiR = halfphi ; 719 if ( phiR > halfphi ) phiR = halfphi ; 722 if ( phiR < -halfphi ) phiR = -halfphi ; 720 if ( phiR < -halfphi ) phiR = -halfphi ; 723 if ( uR > uMax ) uR = uMax ; 721 if ( uR > uMax ) uR = uMax ; 724 if ( uR < -uMax ) uR = -uMax ; 722 if ( uR < -uMax ) uR = -uMax ; 725 723 726 xxonsurface = SurfacePoint(phiR,uR) ; 724 xxonsurface = SurfacePoint(phiR,uR) ; 727 distance[0] = ( p - xx ).mag() ; 725 distance[0] = ( p - xx ).mag() ; 728 if ( distance[0] <= ctol ) { distance[0] = 726 if ( distance[0] <= ctol ) { distance[0] = 0 ; } 729 727 730 // end of validity 728 // end of validity 731 729 732 #ifdef G4TWISTDEBUG << 730 #ifdef G4SPECSDEBUG 733 G4cout << "refined solution " << phiR << " 731 G4cout << "refined solution " << phiR << " , " << uR << " , " << G4endl ; 734 G4cout << "distance = " << distance[0] << G 732 G4cout << "distance = " << distance[0] << G4endl ; 735 G4cout << "X = " << xx << G4endl ; 733 G4cout << "X = " << xx << G4endl ; 736 #endif 734 #endif 737 735 738 G4bool isvalid = true; 736 G4bool isvalid = true; 739 gxx[0] = ComputeGlobalPoint(xx); << 737 gxx[0] = ComputeGlobalPoint(xx); 740 738 741 #ifdef G4TWISTDEBUG << 739 #ifdef G4SPECSDEBUG 742 G4cout << "intersection Point found: " << g 740 G4cout << "intersection Point found: " << gxx[0] << G4endl ; 743 G4cout << "distance = " << distance[0] << G 741 G4cout << "distance = " << distance[0] << G4endl ; 744 #endif 742 #endif 745 743 746 fCurStat.SetCurrentStatus(0, gxx[0], distan 744 fCurStat.SetCurrentStatus(0, gxx[0], distance[0], areacode[0], 747 isvalid, 1, kDontV 745 isvalid, 1, kDontValidate, &gp); 748 return 1; 746 return 1; >> 747 >> 748 749 } 749 } 750 750 >> 751 751 //============================================ 752 //===================================================================== 752 //* GetAreaCode ------------------------------ 753 //* GetAreaCode ------------------------------------------------------- 753 754 754 G4int G4TwistBoxSide::GetAreaCode(const G4Thre << 755 G4int G4TwistBoxSide::GetAreaCode(const G4ThreeVector &xx, 755 G4bool << 756 G4bool withTol) 756 { 757 { 757 // We must use the function in local coordi 758 // We must use the function in local coordinate system. 758 // See the description of DistanceToSurface 759 // See the description of DistanceToSurface(p,v). 759 760 760 const G4double ctol = 0.5 * kCarTolerance; << 761 static const G4double ctol = 0.5 * kCarTolerance; 761 762 762 G4double phi ; 763 G4double phi ; 763 G4double yprime ; 764 G4double yprime ; 764 GetPhiUAtX(xx, phi,yprime ) ; 765 GetPhiUAtX(xx, phi,yprime ) ; 765 766 766 G4double fYAxisMax = GetBoundaryMax(phi) ; 767 G4double fYAxisMax = GetBoundaryMax(phi) ; // Boundaries are symmetric 767 G4double fYAxisMin = - fYAxisMax ; 768 G4double fYAxisMin = - fYAxisMax ; 768 769 769 #ifdef G4TWISTDEBUG << 770 #ifdef G4SPECSDEBUG 770 G4cout << "GetAreaCode: phi = " << phi << G 771 G4cout << "GetAreaCode: phi = " << phi << G4endl ; 771 G4cout << "GetAreaCode: yprime = " << yprim 772 G4cout << "GetAreaCode: yprime = " << yprime << G4endl ; 772 G4cout << "Intervall is " << fYAxisMin << " 773 G4cout << "Intervall is " << fYAxisMin << " to " << fYAxisMax << G4endl ; 773 #endif 774 #endif 774 775 775 G4int areacode = sInside; 776 G4int areacode = sInside; 776 777 777 if (fAxis[0] == kYAxis && fAxis[1] == kZAxi << 778 if (fAxis[0] == kYAxis && fAxis[1] == kZAxis) { 778 { << 779 779 G4int zaxis = 1; 780 G4int zaxis = 1; 780 781 781 if (withTol) << 782 if (withTol) { 782 { << 783 783 G4bool isoutside = false; << 784 G4bool isoutside = false; 784 785 785 // test boundary of yaxis 786 // test boundary of yaxis 786 787 787 if (yprime < fYAxisMin + ctol) << 788 if (yprime < fYAxisMin + ctol) { 788 { << 789 areacode |= (sAxis0 & (sAxisY | sA 789 areacode |= (sAxis0 & (sAxisY | sAxisMin)) | sBoundary; 790 if (yprime <= fYAxisMin - ctol) is 790 if (yprime <= fYAxisMin - ctol) isoutside = true; 791 791 792 } << 792 } else if (yprime > fYAxisMax - ctol) { 793 else if (yprime > fYAxisMax - ctol) << 794 { << 795 areacode |= (sAxis0 & (sAxisY | sA 793 areacode |= (sAxis0 & (sAxisY | sAxisMax)) | sBoundary; 796 if (yprime >= fYAxisMax + ctol) i 794 if (yprime >= fYAxisMax + ctol) isoutside = true; 797 } 795 } 798 796 799 // test boundary of z-axis 797 // test boundary of z-axis 800 798 801 if (xx.z() < fAxisMin[zaxis] + ctol) << 799 if (xx.z() < fAxisMin[zaxis] + ctol) { 802 { << 803 areacode |= (sAxis1 & (sAxisZ | sA 800 areacode |= (sAxis1 & (sAxisZ | sAxisMin)); 804 801 805 if ((areacode & sBoundary) != 0) << 802 if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner. 806 else areaco 803 else areacode |= sBoundary; 807 if (xx.z() <= fAxisMin[zaxis] - ct 804 if (xx.z() <= fAxisMin[zaxis] - ctol) isoutside = true; 808 805 809 } << 806 } else if (xx.z() > fAxisMax[zaxis] - ctol) { 810 else if (xx.z() > fAxisMax[zaxis] - c << 811 { << 812 areacode |= (sAxis1 & (sAxisZ | sA 807 areacode |= (sAxis1 & (sAxisZ | sAxisMax)); 813 808 814 if ((areacode & sBoundary) != 0) << 809 if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner. 815 else areaco 810 else areacode |= sBoundary; 816 if (xx.z() >= fAxisMax[zaxis] + ct 811 if (xx.z() >= fAxisMax[zaxis] + ctol) isoutside = true; 817 } 812 } 818 813 819 // if isoutside = true, clear inside 814 // if isoutside = true, clear inside bit. 820 // if not on boundary, add axis infor 815 // if not on boundary, add axis information. 821 816 822 if (isoutside) << 817 if (isoutside) { 823 { << 824 G4int tmpareacode = areacode & (~s 818 G4int tmpareacode = areacode & (~sInside); 825 areacode = tmpareacode; 819 areacode = tmpareacode; 826 } << 820 } else if ((areacode & sBoundary) != sBoundary) { 827 else if ((areacode & sBoundary) != sB << 828 { << 829 areacode |= (sAxis0 & sAxisY) | (s 821 areacode |= (sAxis0 & sAxisY) | (sAxis1 & sAxisZ); 830 } 822 } 831 823 832 } << 824 } else { 833 else << 825 834 { << 835 // boundary of y-axis 826 // boundary of y-axis 836 827 837 if (yprime < fYAxisMin ) << 828 if (yprime < fYAxisMin ) { 838 { << 839 areacode |= (sAxis0 & (sAxisY | sA 829 areacode |= (sAxis0 & (sAxisY | sAxisMin)) | sBoundary; 840 } << 830 } else if (yprime > fYAxisMax) { 841 else if (yprime > fYAxisMax) << 842 { << 843 areacode |= (sAxis0 & (sAxisY | sA 831 areacode |= (sAxis0 & (sAxisY | sAxisMax)) | sBoundary; 844 } 832 } 845 833 846 // boundary of z-axis 834 // boundary of z-axis 847 835 848 if (xx.z() < fAxisMin[zaxis]) << 836 if (xx.z() < fAxisMin[zaxis]) { 849 { << 850 areacode |= (sAxis1 & (sAxisZ | sA 837 areacode |= (sAxis1 & (sAxisZ | sAxisMin)); 851 if ((areacode & sBoundary) != 0) << 838 if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner. 852 else areaco 839 else areacode |= sBoundary; 853 840 854 } << 841 } else if (xx.z() > fAxisMax[zaxis]) { 855 else if (xx.z() > fAxisMax[zaxis]) << 856 { << 857 areacode |= (sAxis1 & (sAxisZ | sA 842 areacode |= (sAxis1 & (sAxisZ | sAxisMax)) ; 858 if ((areacode & sBoundary) != 0) << 843 if (areacode & sBoundary) areacode |= sCorner; // xx is on the corner. 859 else areaco 844 else areacode |= sBoundary; 860 } 845 } 861 846 862 if ((areacode & sBoundary) != sBounda << 847 if ((areacode & sBoundary) != sBoundary) { 863 { << 864 areacode |= (sAxis0 & sAxisY) | (s 848 areacode |= (sAxis0 & sAxisY) | (sAxis1 & sAxisZ); 865 } 849 } 866 } 850 } 867 return areacode; 851 return areacode; 868 } << 852 } else { 869 else << 870 { << 871 G4Exception("G4TwistBoxSide::GetAreaCode 853 G4Exception("G4TwistBoxSide::GetAreaCode()", 872 "GeomSolids0001", FatalExcep << 854 "NotImplemented", FatalException, 873 "Feature NOT implemented !") 855 "Feature NOT implemented !"); 874 } 856 } 875 return areacode; 857 return areacode; 876 } 858 } 877 859 878 //============================================ 860 //===================================================================== 879 //* SetCorners() ----------------------------- 861 //* SetCorners() ------------------------------------------------------ 880 862 881 void G4TwistBoxSide::SetCorners() 863 void G4TwistBoxSide::SetCorners() 882 { 864 { 883 865 884 // Set Corner points in local coodinate. 866 // Set Corner points in local coodinate. 885 867 886 if (fAxis[0] == kYAxis && fAxis[1] == kZAxis << 868 if (fAxis[0] == kYAxis && fAxis[1] == kZAxis) { 887 { << 869 888 G4double x, y, z; 870 G4double x, y, z; 889 871 890 // corner of Axis0min and Axis1min 872 // corner of Axis0min and Axis1min 891 873 892 x = -fdeltaX/2. + (fDx2 - fDy1*fTAlph)*std 874 x = -fdeltaX/2. + (fDx2 - fDy1*fTAlph)*std::cos(fPhiTwist/2.) - fDy1*std::sin(fPhiTwist/2.) ; 893 y = -fdeltaY/2. - fDy1*std::cos(fPhiTwist/ 875 y = -fdeltaY/2. - fDy1*std::cos(fPhiTwist/2.) + (-fDx2 + fDy1*fTAlph)*std::sin(fPhiTwist/2.) ; 894 z = -fDz ; 876 z = -fDz ; 895 877 896 SetCorner(sC0Min1Min, x, y, z); 878 SetCorner(sC0Min1Min, x, y, z); 897 879 898 // corner of Axis0max and Axis1min 880 // corner of Axis0max and Axis1min 899 881 900 x = -fdeltaX/2. + (fDx2 + fDy1*fTAlph)*std 882 x = -fdeltaX/2. + (fDx2 + fDy1*fTAlph)*std::cos(fPhiTwist/2.) + fDy1*std::sin(fPhiTwist/2.) ; 901 y = -fdeltaY/2. + fDy1*std::cos(fPhiTwist/ 883 y = -fdeltaY/2. + fDy1*std::cos(fPhiTwist/2.) - (fDx2 + fDy1*fTAlph)*std::sin(fPhiTwist/2.) ; 902 z = -fDz ; 884 z = -fDz ; 903 885 904 SetCorner(sC0Max1Min, x, y, z); 886 SetCorner(sC0Max1Min, x, y, z); 905 887 906 // corner of Axis0max and Axis1max 888 // corner of Axis0max and Axis1max 907 889 908 x = fdeltaX/2. + (fDx4 + fDy2*fTAlph)*std: 890 x = fdeltaX/2. + (fDx4 + fDy2*fTAlph)*std::cos(fPhiTwist/2.) - fDy2*std::sin(fPhiTwist/2.) ; 909 y = fdeltaY/2. + fDy2*std::cos(fPhiTwist/2 891 y = fdeltaY/2. + fDy2*std::cos(fPhiTwist/2.) + (fDx4 + fDy2*fTAlph)*std::sin(fPhiTwist/2.) ; 910 z = fDz ; 892 z = fDz ; 911 893 912 SetCorner(sC0Max1Max, x, y, z); 894 SetCorner(sC0Max1Max, x, y, z); 913 895 914 // corner of Axis0min and Axis1max 896 // corner of Axis0min and Axis1max 915 897 916 x = fdeltaX/2. + (fDx4 - fDy2*fTAlph)*std: 898 x = fdeltaX/2. + (fDx4 - fDy2*fTAlph)*std::cos(fPhiTwist/2.) + fDy2*std::sin(fPhiTwist/2.) ; 917 y = fdeltaY/2. - fDy2*std::cos(fPhiTwist/2 899 y = fdeltaY/2. - fDy2*std::cos(fPhiTwist/2.) + (fDx4 - fDy2*fTAlph)*std::sin(fPhiTwist/2.) ; 918 z = fDz ; 900 z = fDz ; 919 901 920 SetCorner(sC0Min1Max, x, y, z); 902 SetCorner(sC0Min1Max, x, y, z); 921 903 922 } << 904 } else { 923 else << 905 924 { << 925 G4Exception("G4TwistBoxSide::SetCorners()" 906 G4Exception("G4TwistBoxSide::SetCorners()", 926 "GeomSolids0001", FatalExcepti << 907 "NotImplemented", FatalException, 927 "Method NOT implemented !"); 908 "Method NOT implemented !"); 928 } 909 } 929 } 910 } 930 911 931 //============================================ 912 //===================================================================== 932 //* SetBoundaries() -------------------------- 913 //* SetBoundaries() --------------------------------------------------- 933 914 934 void G4TwistBoxSide::SetBoundaries() 915 void G4TwistBoxSide::SetBoundaries() 935 { 916 { 936 // Set direction-unit vector of boundary-li << 917 // Set direction-unit vector of boundary-lines in local coodinate. >> 918 // 937 919 938 G4ThreeVector direction; 920 G4ThreeVector direction; 939 921 940 if (fAxis[0] == kYAxis && fAxis[1] == kZAxis << 922 if (fAxis[0] == kYAxis && fAxis[1] == kZAxis) { 941 { << 923 942 // sAxis0 & sAxisMin 924 // sAxis0 & sAxisMin 943 direction = GetCorner(sC0Min1Max) - GetCor 925 direction = GetCorner(sC0Min1Max) - GetCorner(sC0Min1Min); 944 direction = direction.unit(); 926 direction = direction.unit(); 945 SetBoundary(sAxis0 & (sAxisY | sAxisMin), 927 SetBoundary(sAxis0 & (sAxisY | sAxisMin), direction, 946 GetCorner(sC0Min1Min), sAxisZ) 928 GetCorner(sC0Min1Min), sAxisZ) ; 947 929 948 // sAxis0 & sAxisMax 930 // sAxis0 & sAxisMax 949 direction = GetCorner(sC0Max1Max) - GetCor 931 direction = GetCorner(sC0Max1Max) - GetCorner(sC0Max1Min); 950 direction = direction.unit(); 932 direction = direction.unit(); 951 SetBoundary(sAxis0 & (sAxisY | sAxisMax), 933 SetBoundary(sAxis0 & (sAxisY | sAxisMax), direction, 952 GetCorner(sC0Max1Min), sAxisZ) 934 GetCorner(sC0Max1Min), sAxisZ); 953 935 954 // sAxis1 & sAxisMin 936 // sAxis1 & sAxisMin 955 direction = GetCorner(sC0Max1Min) - GetCor 937 direction = GetCorner(sC0Max1Min) - GetCorner(sC0Min1Min); 956 direction = direction.unit(); 938 direction = direction.unit(); 957 SetBoundary(sAxis1 & (sAxisZ | sAxisMin), 939 SetBoundary(sAxis1 & (sAxisZ | sAxisMin), direction, 958 GetCorner(sC0Min1Min), sAxisY) 940 GetCorner(sC0Min1Min), sAxisY); 959 941 960 // sAxis1 & sAxisMax 942 // sAxis1 & sAxisMax 961 direction = GetCorner(sC0Max1Max) - GetCor 943 direction = GetCorner(sC0Max1Max) - GetCorner(sC0Min1Max); 962 direction = direction.unit(); 944 direction = direction.unit(); 963 SetBoundary(sAxis1 & (sAxisZ | sAxisMax), 945 SetBoundary(sAxis1 & (sAxisZ | sAxisMax), direction, 964 GetCorner(sC0Min1Max), sAxisY) 946 GetCorner(sC0Min1Max), sAxisY); 965 947 966 } << 948 } else { 967 else << 949 968 { << 950 G4Exception("G4TwistBoxSide::SetCorners()", 969 G4Exception("G4TwistBoxSide::SetCorners()" << 951 "NotImplemented", FatalException, 970 "GeomSolids0001", FatalExcepti << 952 "Feature NOT implemented !"); 971 "Feature NOT implemented !"); << 972 } 953 } 973 } 954 } 974 955 975 956 976 void G4TwistBoxSide::GetPhiUAtX( const G4Three << 957 void G4TwistBoxSide::GetPhiUAtX( G4ThreeVector p, G4double &phi, G4double &u) 977 { 958 { 978 // find closest point XX on surface for a gi 959 // find closest point XX on surface for a given point p 979 // X0 is a point on the surface, d is the d << 960 // X0 is a point on the surface, d is the direction ( both for a fixed z = pz) 980 // ( both for a fixed z = pz) << 981 961 982 // phi is given by the z coordinate of p 962 // phi is given by the z coordinate of p 983 963 984 phi = p.z()/(2*fDz)*fPhiTwist ; 964 phi = p.z()/(2*fDz)*fPhiTwist ; 985 965 986 u = -(fTAlph*(fDx4plus2*fPhiTwist + 2*fDx4m << 966 u = -(fTAlph*(fDx4plus2*fPhiTwist + 2*fDx4minus2*phi) + 2*(fdeltaY*phi + fdeltaX*fTAlph*phi - fPhiTwist*(fTAlph*p.x() + p.y()))* std::cos(phi) + 2*(-(fdeltaX*phi) + fdeltaY*fTAlph*phi + fPhiTwist*(p.x() - fTAlph*p.y()))*std::sin(phi))/(2.*(fPhiTwist + fPhiTwist*fTAlph*fTAlph)) ; 987 + 2*(fdeltaY*phi + fdeltaX*fTAlph*phi << 967 988 - fPhiTwist*(fTAlph*p.x() + p.y()))* << 968 989 + 2*(-(fdeltaX*phi) + fdeltaY*fTAlph* << 990 - fTAlph*p.y()))*std::sin(phi))/(2.*( << 991 + fPhiTwist*fTAlph*fTAlph)) ; << 992 } 969 } 993 970 994 971 995 G4ThreeVector G4TwistBoxSide::ProjectPoint(con << 972 G4ThreeVector G4TwistBoxSide::ProjectPoint(const G4ThreeVector &p, 996 << 973 G4bool isglobal) 997 { 974 { 998 // Get Rho at p.z() on Hyperbolic Surface. 975 // Get Rho at p.z() on Hyperbolic Surface. 999 G4ThreeVector tmpp; 976 G4ThreeVector tmpp; 1000 if (isglobal) << 977 if (isglobal) { 1001 { << 1002 tmpp = fRot.inverse()*p - fTrans; 978 tmpp = fRot.inverse()*p - fTrans; 1003 } << 979 } else { 1004 else << 1005 { << 1006 tmpp = p; 980 tmpp = p; 1007 } 981 } 1008 982 1009 G4double phi ; 983 G4double phi ; 1010 G4double u ; 984 G4double u ; 1011 985 1012 GetPhiUAtX( tmpp, phi, u ) ; << 986 GetPhiUAtX( tmpp, phi, u ) ; // calculate (phi, u) for a point p close the surface 1013 // calculate (phi, u) for a point p close << 1014 987 1015 G4ThreeVector xx = SurfacePoint(phi,u) ; << 988 G4ThreeVector xx = SurfacePoint(phi,u) ; // transform back to cartesian coordinates 1016 // transform back to cartesian coordinate << 1017 989 1018 if (isglobal) << 990 if (isglobal) { 1019 { << 1020 return (fRot * xx + fTrans); 991 return (fRot * xx + fTrans); 1021 } << 992 } else { 1022 else << 1023 { << 1024 return xx; 993 return xx; 1025 } 994 } 1026 } 995 } 1027 996 1028 void G4TwistBoxSide::GetFacets( G4int k, G4in << 997 void G4TwistBoxSide::GetFacets( G4int m, G4int n, G4double xyz[][3], G4int faces[][4], G4int iside ) 1029 G4int faces[] << 1030 { 998 { >> 999 1031 G4double phi ; 1000 G4double phi ; 1032 G4double b ; 1001 G4double b ; 1033 1002 1034 G4double z, u ; // the two parameters f 1003 G4double z, u ; // the two parameters for the surface equation 1035 G4ThreeVector p ; // a point on the surfac 1004 G4ThreeVector p ; // a point on the surface, given by (z,u) 1036 1005 1037 G4int nnode ; 1006 G4int nnode ; 1038 G4int nface ; 1007 G4int nface ; 1039 1008 1040 // calculate the (n-1)*(k-1) vertices << 1009 // calculate the (n-1)*(m-1) vertices 1041 1010 1042 G4int i,j ; 1011 G4int i,j ; 1043 1012 1044 for ( i = 0 ; i<n ; ++i ) << 1013 for ( i = 0 ; i<n ; i++ ) { 1045 { << 1014 1046 z = -fDz+i*(2.*fDz)/(n-1) ; 1015 z = -fDz+i*(2.*fDz)/(n-1) ; 1047 phi = z*fPhiTwist/(2*fDz) ; 1016 phi = z*fPhiTwist/(2*fDz) ; 1048 b = GetValueB(phi) ; 1017 b = GetValueB(phi) ; 1049 1018 1050 for ( j = 0 ; j<k ; ++j ) << 1019 for ( j = 0 ; j<m ; j++ ) { 1051 { << 1020 1052 nnode = GetNode(i,j,k,n,iside) ; << 1021 nnode = GetNode(i,j,m,n,iside) ; 1053 u = -b/2 +j*b/(k-1) ; << 1022 u = -b/2 +j*b/(m-1) ; 1054 p = SurfacePoint(phi,u,true) ; << 1023 p = SurfacePoint(phi,u,true) ; // surface point in global coordinate system 1055 // surface point in global coordinate << 1056 1024 1057 xyz[nnode][0] = p.x() ; 1025 xyz[nnode][0] = p.x() ; 1058 xyz[nnode][1] = p.y() ; 1026 xyz[nnode][1] = p.y() ; 1059 xyz[nnode][2] = p.z() ; 1027 xyz[nnode][2] = p.z() ; 1060 1028 1061 if ( i<n-1 && j<k-1 ) // contercloc << 1029 if ( i<n-1 && j<m-1 ) { // conterclock wise filling 1062 { << 1030 1063 nface = GetFace(i,j,k,n,iside) ; << 1031 nface = GetFace(i,j,m,n,iside) ; 1064 faces[nface][0] = GetEdgeVisibility(i << 1032 faces[nface][0] = GetNode(i ,j ,m,n,iside)+1 ; // fortran numbering 1065 faces[nface][1] = GetEdgeVisibility(i << 1033 faces[nface][1] = GetNode(i ,j+1,m,n,iside)+1 ; 1066 faces[nface][2] = GetEdgeVisibility(i << 1034 faces[nface][2] = GetNode(i+1,j+1,m,n,iside)+1 ; 1067 faces[nface][3] = GetEdgeVisibility(i << 1035 faces[nface][3] = GetNode(i+1,j ,m,n,iside)+1 ; 1068 } 1036 } 1069 } 1037 } 1070 } 1038 } 1071 } 1039 } 1072 1040