source: trunk/source/geometry/solids/specific/include/G4TwistedTubs.hh@ 1350

Last change on this file since 1350 was 1337, checked in by garnier, 15 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 15.6 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4TwistedTubs.hh,v 1.14 2007/05/23 09:32:35 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30//
31// --------------------------------------------------------------------
32// GEANT 4 class header file
33//
34//
35// G4TwistedTubs
36//
37// Class description:
38//
39// G4TwistedTubs is a sort of twisted cylinder.
40// A twisted cylinder which is placed along with z-axis and is
41// separated into phi-segments should become a hyperboloid, and
42// its each segmented piece should be tilted with a stereo angle.
43// G4TwistedTubs is a G4VSolid.
44// It can have inner & outer surfaces as well as G4TwistedTubs,
45// but cannot has different stereo angles between the inner surface
46// and outer surface.
47
48// Author:
49// 01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp)
50//
51// History:
52// 13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
53// from original version in Jupiter-2.5.02 application.
54// --------------------------------------------------------------------
55#ifndef __G4TWISTEDTUBS__
56#define __G4TWISTEDTUBS__
57
58#include "G4VSolid.hh"
59#include "G4TwistTubsFlatSide.hh"
60#include "G4TwistTubsSide.hh"
61#include "G4TwistTubsHypeSide.hh"
62
63class G4SolidExtentList;
64class G4ClippablePolygon;
65
66class G4TwistedTubs : public G4VSolid
67{
68 public: // with description
69
70 G4TwistedTubs(const G4String &pname, // Name of instance
71 G4double twistedangle, // Twisted angle
72 G4double endinnerrad, // Inner radius at endcap
73 G4double endouterrad, // Outer radius at endcap
74 G4double halfzlen, // half z length
75 G4double dphi); // Phi angle of a segment
76
77 G4TwistedTubs(const G4String &pname, // Name of instance
78 G4double twistedangle, // Stereo angle
79 G4double endinnerrad, // Inner radius at endcap
80 G4double endouterrad, // Outer radius at endcap
81 G4double halfzlen, // half z length
82 G4int nseg, // Number of segments in totalPhi
83 G4double totphi); // Total angle of all segments
84
85 G4TwistedTubs(const G4String &pname, // Name of instance
86 G4double twistedangle, // Twisted angle
87 G4double innerrad, // Inner radius at z=0
88 G4double outerrad, // Outer radius at z=0
89 G4double negativeEndz, // -ve z endplate
90 G4double positiveEndz, // +ve z endplate
91 G4double dphi); // Phi angle of a segment
92
93 G4TwistedTubs(const G4String &pname, // Name of instance
94 G4double twistedangle, // Stereo angle
95 G4double innerrad, // Inner radius at z=0
96 G4double outerrad, // Outer radius at z=0
97 G4double negativeEndz, // -ve z endplate
98 G4double positiveEndz, // +ve z endplate
99 G4int nseg, // Number of segments in totalPhi
100 G4double totphi); // Total angle of all segments
101
102 virtual ~G4TwistedTubs();
103
104 void ComputeDimensions(G4VPVParameterisation * /* p */ ,
105 const G4int /* n */ ,
106 const G4VPhysicalVolume * /* prep */ );
107
108 G4bool CalculateExtent(const EAxis paxis,
109 const G4VoxelLimits &pvoxellimit,
110 const G4AffineTransform &ptransform,
111 G4double &pmin,
112 G4double &pmax ) const;
113
114 G4double DistanceToIn (const G4ThreeVector &p,
115 const G4ThreeVector &v ) const;
116
117 G4double DistanceToIn (const G4ThreeVector &p ) const;
118
119 G4double DistanceToOut(const G4ThreeVector &p,
120 const G4ThreeVector &v,
121 const G4bool calcnorm=G4bool(false),
122 G4bool *validnorm=0,
123 G4ThreeVector *n=0 ) const;
124
125 G4double DistanceToOut(const G4ThreeVector &p) const;
126
127 EInside Inside (const G4ThreeVector &p) const;
128
129 G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const;
130
131 void DescribeYourselfTo (G4VGraphicsScene &scene) const;
132 G4Polyhedron *CreatePolyhedron () const;
133 G4NURBS *CreateNURBS () const;
134 G4Polyhedron *GetPolyhedron () const;
135
136 std::ostream &StreamInfo(std::ostream& os) const;
137
138 // accessors
139
140 inline G4double GetDPhi () const { return fDPhi ; }
141 inline G4double GetPhiTwist () const { return fPhiTwist ; }
142 inline G4double GetInnerRadius () const { return fInnerRadius; }
143 inline G4double GetOuterRadius () const { return fOuterRadius; }
144 inline G4double GetInnerStereo () const { return fInnerStereo; }
145 inline G4double GetOuterStereo () const { return fOuterStereo; }
146 inline G4double GetZHalfLength () const { return fZHalfLength; }
147 inline G4double GetKappa () const { return fKappa ; }
148
149 inline G4double GetTanInnerStereo () const { return fTanInnerStereo ; }
150 inline G4double GetTanInnerStereo2() const { return fTanInnerStereo2 ; }
151 inline G4double GetTanOuterStereo () const { return fTanOuterStereo ; }
152 inline G4double GetTanOuterStereo2() const { return fTanOuterStereo2 ; }
153
154 inline G4double GetEndZ (G4int i) const { return fEndZ[i] ; }
155 inline G4double GetEndPhi (G4int i) const { return fEndPhi[i]; }
156 inline G4double GetEndInnerRadius (G4int i) const
157 { return fEndInnerRadius[i]; }
158 inline G4double GetEndOuterRadius (G4int i) const
159 { return fEndOuterRadius[i]; }
160 inline G4double GetEndInnerRadius () const
161 { return (fEndInnerRadius[0] > fEndInnerRadius[1] ?
162 fEndInnerRadius[0] : fEndInnerRadius[1]); }
163 inline G4double GetEndOuterRadius () const
164 { return (fEndOuterRadius[0] > fEndOuterRadius[1] ?
165 fEndOuterRadius[0] : fEndOuterRadius[1]); }
166
167 G4VisExtent GetExtent () const;
168 G4GeometryType GetEntityType() const;
169
170 G4double GetCubicVolume();
171 // Returns an estimation of the geometrical cubic volume of the
172 // solid. Caches the computed value once computed the first time.
173 G4double GetSurfaceArea();
174 // Returns an estimation of the geometrical surface area of the
175 // solid. Caches the computed value once computed the first time.
176
177 G4ThreeVector GetPointOnSurface() const ;
178
179 public: // without description
180
181 G4TwistedTubs(__void__&);
182 // Fake default constructor for usage restricted to direct object
183 // persistency for clients requiring preallocation of memory for
184 // persistifiable objects.
185
186#ifdef G4TWISTDEBUG
187 G4VTwistSurface * GetOuterHype() const { return fOuterHype; }
188#endif
189
190 private:
191
192 inline void SetFields(G4double phitwist, G4double innerrad,
193 G4double outerrad,
194 G4double negativeEndz, G4double positiveEndz);
195
196 void CreateSurfaces();
197
198 static void AddPolyToExtent( const G4ThreeVector &v0,
199 const G4ThreeVector &v1,
200 const G4ThreeVector &w1,
201 const G4ThreeVector &w0,
202 const G4VoxelLimits &voxellimit,
203 const EAxis axis,
204 G4SolidExtentList &extentlist );
205 private:
206
207 G4double fPhiTwist; // Twist angle from -fZHalfLength to fZHalfLength
208 G4double fInnerRadius; // Inner-hype radius at z=0
209 G4double fOuterRadius; // Outer-hype radius at z=0
210 G4double fEndZ[2]; // z at endcaps, [0] = -ve z, [1] = +ve z
211 G4double fDPhi; // Phi-width of a segment fDPhi > 0
212 G4double fZHalfLength; // Half length along z-axis
213
214 G4double fInnerStereo; // Inner-hype stereo angle
215 G4double fOuterStereo; // Outer-hype stereo angle
216 G4double fTanInnerStereo; // std::tan(innerStereoAngle)
217 G4double fTanOuterStereo; // std::tan(outerStereoAngle)
218 G4double fKappa; // std::tan(fPhiTwist/2)/fZHalfLen;
219 G4double fEndInnerRadius[2]; // Inner-hype radii endcaps [0] -ve z, [1] +ve z
220 G4double fEndOuterRadius[2]; // Outer-hype radii endcaps [0] -ve z, [1] +ve z
221 G4double fEndPhi[2]; // Phi endcaps, [0] = -ve z, [1] = +ve z
222
223 G4double fInnerRadius2; // fInnerRadius * fInnerRadius
224 G4double fOuterRadius2; // fOuterRadius * fOuterRadius
225 G4double fTanInnerStereo2; // fInnerRadius * fInnerRadius
226 G4double fTanOuterStereo2; // fInnerRadius * fInnerRadius
227 G4double fEndZ2[2]; // fEndZ * fEndZ
228
229 G4VTwistSurface *fLowerEndcap; // Surface of -ve z
230 G4VTwistSurface *fUpperEndcap; // Surface of +ve z
231 G4VTwistSurface *fLatterTwisted; // Surface of -ve phi
232 G4VTwistSurface *fFormerTwisted; // Surface of +ve phi
233 G4VTwistSurface *fInnerHype; // Surface of -ve r
234 G4VTwistSurface *fOuterHype; // Surface of +ve r
235
236 G4double fCubicVolume; // Cached value for cubic volume
237 G4double fSurfaceArea; // Cached value for surface area
238
239 mutable G4Polyhedron* fpPolyhedron; // pointer to polyhedron for vis
240
241 class LastState // last Inside result
242 {
243 public:
244 LastState()
245 {
246 p.set(kInfinity,kInfinity,kInfinity);
247 inside = kOutside;
248 }
249 ~LastState(){}
250 public:
251 G4ThreeVector p;
252 EInside inside;
253 };
254
255 class LastVector // last SurfaceNormal result
256 {
257 public:
258 LastVector()
259 {
260 p.set(kInfinity,kInfinity,kInfinity);
261 vec.set(kInfinity,kInfinity,kInfinity);
262 surface = new G4VTwistSurface*[1];
263 }
264 ~LastVector()
265 {
266 delete [] surface;
267 }
268 public:
269 G4ThreeVector p;
270 G4ThreeVector vec;
271 G4VTwistSurface **surface;
272 };
273
274 class LastValue // last G4double value
275 {
276 public:
277 LastValue()
278 {
279 p.set(kInfinity,kInfinity,kInfinity);
280 value = DBL_MAX;
281 }
282 ~LastValue(){}
283 public:
284 G4ThreeVector p;
285 G4double value;
286 };
287
288 class LastValueWithDoubleVector // last G4double value
289 {
290 public:
291 LastValueWithDoubleVector()
292 {
293 p.set(kInfinity,kInfinity,kInfinity);
294 vec.set(kInfinity,kInfinity,kInfinity);
295 value = DBL_MAX;
296 }
297 ~LastValueWithDoubleVector(){}
298 public:
299 G4ThreeVector p;
300 G4ThreeVector vec;
301 G4double value;
302 };
303
304 LastState fLastInside;
305 LastVector fLastNormal;
306 LastValue fLastDistanceToIn;
307 LastValue fLastDistanceToOut;
308 LastValueWithDoubleVector fLastDistanceToInWithV;
309 LastValueWithDoubleVector fLastDistanceToOutWithV;
310
311 };
312
313//=====================================================================
314
315//---------------------
316// inline functions
317//---------------------
318
319inline
320void G4TwistedTubs::SetFields(G4double phitwist, G4double innerrad,
321 G4double outerrad, G4double negativeEndz,
322 G4double positiveEndz)
323{
324 fCubicVolume = 0.;
325 fPhiTwist = phitwist;
326 fEndZ[0] = negativeEndz;
327 fEndZ[1] = positiveEndz;
328 fEndZ2[0] = fEndZ[0] * fEndZ[0];
329 fEndZ2[1] = fEndZ[1] * fEndZ[1];
330 fInnerRadius = innerrad;
331 fOuterRadius = outerrad;
332 fInnerRadius2 = fInnerRadius * fInnerRadius;
333 fOuterRadius2 = fOuterRadius * fOuterRadius;
334
335 G4int maxi;
336 if (std::fabs(fEndZ[0]) >= std::fabs(fEndZ[1])) {
337 fZHalfLength = std::fabs(fEndZ[0]);
338 maxi = 0;
339 } else {
340 fZHalfLength = std::fabs(fEndZ[1]);
341 maxi = 1;
342 }
343
344 G4double parity = (fPhiTwist > 0 ? 1 : -1);
345 G4double tanHalfTwist = std::tan(0.5 * fPhiTwist);
346 G4double innerNumerator = std::fabs(fInnerRadius * tanHalfTwist) * parity;
347 G4double outerNumerator = std::fabs(fOuterRadius * tanHalfTwist) * parity;
348
349 fTanInnerStereo = innerNumerator / fZHalfLength;
350 fTanOuterStereo = outerNumerator / fZHalfLength;
351 fTanInnerStereo2 = fTanInnerStereo * fTanInnerStereo;
352 fTanOuterStereo2 = fTanOuterStereo * fTanOuterStereo;
353 fInnerStereo = std::atan2(innerNumerator, fZHalfLength);
354 fOuterStereo = std::atan2(outerNumerator, fZHalfLength);
355 fEndInnerRadius[0] = std::sqrt(fInnerRadius2 + fEndZ2[0] * fTanInnerStereo2);
356 fEndInnerRadius[1] = std::sqrt(fInnerRadius2 + fEndZ2[1] * fTanInnerStereo2);
357 fEndOuterRadius[0] = std::sqrt(fOuterRadius2 + fEndZ2[0] * fTanOuterStereo2);
358 fEndOuterRadius[1] = std::sqrt(fOuterRadius2 + fEndZ2[1] * fTanOuterStereo2);
359
360 fKappa = tanHalfTwist / fZHalfLength;
361 fEndPhi[0] = std::atan2(fEndZ[0] * tanHalfTwist, fZHalfLength);
362 fEndPhi[1] = std::atan2(fEndZ[1] * tanHalfTwist, fZHalfLength);
363
364#ifdef G4TWISTDEBUG
365 G4cout << "/********* G4TwistedTubs::SetFields() Field Parameters ***************** " << G4endl;
366 G4cout << "/* fPhiTwist : " << fPhiTwist << G4endl;
367 G4cout << "/* fEndZ(0, 1) : " << fEndZ[0] << " , " << fEndZ[1] << G4endl;
368 G4cout << "/* fEndPhi(0, 1) : " << fEndPhi[0] << " , " << fEndPhi[1] << G4endl;
369 G4cout << "/* fInnerRadius, fOuterRadius : " << fInnerRadius << " , " << fOuterRadius << G4endl;
370 G4cout << "/* fEndInnerRadius(0, 1) : " << fEndInnerRadius[0] << " , "
371 << fEndInnerRadius[1] << G4endl;
372 G4cout << "/* fEndOuterRadius(0, 1) : " << fEndOuterRadius[0] << " , "
373 << fEndOuterRadius[1] << G4endl;
374 G4cout << "/* fInnerStereo, fOuterStereo : " << fInnerStereo << " , " << fOuterStereo << G4endl;
375 G4cout << "/* tanHalfTwist, fKappa : " << tanHalfTwist << " , " << fKappa << G4endl;
376 G4cout << "/*********************************************************************** " << G4endl;
377#endif
378}
379
380#endif
Note: See TracBrowser for help on using the repository browser.