Import Geant4 10.5.1 source tree

This commit is contained in:
Gabriele Cosmo
2019-04-17 10:39:02 +02:00
parent a7fdc52004
commit 28a70706e0
661 changed files with 55791 additions and 106984 deletions
+18
View File
@@ -16,6 +16,24 @@ committal in the source repository !
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
15-February-2019 E.Tcherniaev (geom-specific-V10-04-16)
- Accurate calculation of radical in G4IntersectingCone.
It addresses the problem report #2111.
4-February-2019 G.Cosmo
- Fix in G4EllipticalTube::CheckParameters() for typo in condition.
30-January-2019 G.Cosmo
- Disabled precise computation of extent and use simple bounding-box
in CalculateExtent() for G4Tet and G4TessellatedSolid, to speed up
intialisation in setups with relatively complex meshes.
- Apply bounding-box calculation for extent also for corresponding
VecGeom wrappers.
24-January-2019 E.Tcherniaev
- Completely revised, more robust and performant G4EllipticalTube;
new exhaustive test/testEllipticalTube.cc based on Shape Conventions.
20-September-2018 G.Cosmo (geom-specific-V10-04-15)
- Make G4UPolycone wrapper inheriting from vecgeom::GenericUnplacedPolycone,
following the latest changes in VecGeom.
@@ -34,16 +34,20 @@
//
// Declaration of a CSG volume representing a tube with elliptical
// cross section (geant3 solid 'ELTU'):
//
// G4EllipticalTube( const G4String& name,
//
// G4EllipticalTube( const G4String& name,
// G4double Dx,
// G4double Dy,
// G4double Dz )
//
// The equation of the surface in x/y is 1.0 = (x/dx)**2 + (y/dy)**2
// The equation of the lateral surface : (x/dx)^2 + (y/dy)^2 = 1
// Author:
// First implementation:
// David C. Williams (davidw@scipp.ucsc.edu)
//
// Revision:
// Evgueni Tcherniaev (evgueni.tcherniaev@cern.ch), 23.12.2019
//
// --------------------------------------------------------------------
#ifndef G4EllipticalTube_hh
@@ -56,34 +60,37 @@ class G4EllipticalTube : public G4VSolid
{
public: // with description
G4EllipticalTube( const G4String &name,
G4double theDx,
G4double theDy,
G4double theDz );
G4EllipticalTube( const G4String &name,
G4double Dx,
G4double Dy,
G4double Dz );
virtual ~G4EllipticalTube();
// Standard solid methods
void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const;
// Standard methods
//
void BoundingLimits( G4ThreeVector& pMin, G4ThreeVector& pMax ) const;
G4bool CalculateExtent( const EAxis pAxis,
const G4VoxelLimits& pVoxelLimit,
const G4AffineTransform& pTransform,
G4double& pmin, G4double& pmax ) const;
EInside Inside( const G4ThreeVector& p ) const;
G4ThreeVector SurfaceNormal( const G4ThreeVector& p ) const;
G4double DistanceToIn( const G4ThreeVector& p,
const G4ThreeVector& v ) const;
G4double DistanceToIn( const G4ThreeVector& p ) const;
G4double DistanceToOut( const G4ThreeVector& p,
const G4ThreeVector& v,
const G4bool calcNorm=false,
G4bool *validNorm=0,
G4ThreeVector *n=0 ) const;
G4double DistanceToOut( const G4ThreeVector& p ) const;
G4GeometryType GetEntityType() const;
@@ -98,57 +105,67 @@ class G4EllipticalTube : public G4VSolid
G4ThreeVector GetPointOnSurface() const;
// Visualisation methods
//
G4Polyhedron* CreatePolyhedron() const;
G4Polyhedron* GetPolyhedron () const;
void DescribeYourselfTo( G4VGraphicsScene& scene ) const;
G4VisExtent GetExtent() const;
// Accessors
//
inline G4double GetDx() const;
inline G4double GetDy() const;
inline G4double GetDz() const;
inline void SetDx( const G4double newDx );
inline void SetDy( const G4double newDy );
inline void SetDz( const G4double newDz );
inline void SetDx( G4double Dx );
inline void SetDy( G4double Dy );
inline void SetDz( G4double Dz );
public: // without description
G4EllipticalTube(__void__&);
// Fake default constructor for usage restricted to direct object
// persistency for clients requiring preallocation of memory for
// persistifiable objects.
// persistifiable objects
G4EllipticalTube(const G4EllipticalTube& rhs);
G4EllipticalTube& operator=(const G4EllipticalTube& rhs);
// Copy constructor and assignment operator.
protected: // without description
G4double dx, dy, dz;
// Utility
inline G4double CheckXY( const G4double x,
const G4double y,
const G4double toler ) const;
inline G4double CheckXY( const G4double x, const G4double y ) const;
G4int IntersectXY( const G4ThreeVector &p,
const G4ThreeVector &v, G4double s[2] ) const;
G4EllipticalTube& operator=(const G4EllipticalTube& rhs);
// Copy constructor and assignment operator
private:
void CheckParameters();
// Check parameters and set pre-calculated values
G4ThreeVector ApproxSurfaceNormal( const G4ThreeVector& p ) const;
// Algorithm for SurfaceNormal() following the original
// specification for points not on the surface.
// specification for points not on the surface
G4double halfTol;
G4double GetCachedSurfaceArea() const;
// Calculate surface area and cache it
private:
G4double halfTolerance;
G4double fDx; // semi-axis in X
G4double fDy; // semi-axis in Y
G4double fDz; // half length in Z
G4double fCubicVolume; // volume
G4double fSurfaceArea; // surface area
// Cached pre-calculated values
G4double fRsph; // R of bounding sphere
G4double fDDx; // Dx squared
G4double fDDy; // Dy squared
G4double fSx; // X scale factor
G4double fSy; // Y scale factor
G4double fR; // resulting Radius, after scaling elipse to circle
G4double fQ1; // distance approximation : dist = Q1*(x^2 + y^2) - Q2
G4double fQ2; // distance approximation : dist = Q1*(x^2 + y^2) - Q2
G4double fScratch; // half length of scratching segment squared
G4double fCubicVolume;
G4double fSurfaceArea;
mutable G4bool fRebuildPolyhedron;
mutable G4Polyhedron* fpPolyhedron;
};
@@ -36,57 +36,47 @@
inline
G4double G4EllipticalTube::GetDx() const
{
return dx;
return fDx;
}
inline
G4double G4EllipticalTube::GetDy() const
{
return dy;
return fDy;
}
inline
G4double G4EllipticalTube::GetDz() const
{
return dz;
return fDz;
}
inline
void G4EllipticalTube::SetDx( const G4double newDx )
inline
void G4EllipticalTube::SetDx(G4double Dx)
{
dx = newDx;
fDx = Dx;
CheckParameters();
fCubicVolume = 0.;
fSurfaceArea = 0.;
fRebuildPolyhedron = true;
}
inline
void G4EllipticalTube::SetDy( const G4double newDy )
void G4EllipticalTube::SetDy( G4double Dy )
{
dy = newDy;
fDy = Dy;
CheckParameters();
fCubicVolume = 0.;
fSurfaceArea = 0.;
fRebuildPolyhedron = true;
}
inline
void G4EllipticalTube::SetDz( const G4double newDz )
void G4EllipticalTube::SetDz( G4double Dz )
{
dz = newDz;
fDz = Dz;
CheckParameters();
fCubicVolume = 0.;
fSurfaceArea = 0.;
fRebuildPolyhedron = true;
}
inline
G4double G4EllipticalTube::CheckXY( const G4double x,
const G4double y,
const G4double toler ) const
{
G4double rx = x/(dx+toler), ry = y/(dy+toler);
return rx*rx + ry*ry;
}
inline
G4double G4EllipticalTube::CheckXY( const G4double x, const G4double y ) const
{
G4double rx = x/dx, ry = y/dy;
return rx*rx + ry*ry;
}
@@ -132,7 +132,7 @@ class G4Tet : public G4VSolid
// Copy constructor and assignment operator.
const char* CVSHeaderVers()
{ return "$Id: G4Tet.hh 113723 2018-12-06 14:12:07Z gunter $"; }
{ return "$Id$"; }
const char* CVSFileVers()
{ return CVSVers; }
void PrintWarnings(G4bool flag)
File diff suppressed because it is too large Load Diff
@@ -25,7 +25,7 @@
//
//
//
//
//
// --------------------------------------------------------------------
// GEANT 4 class source file
//
@@ -44,45 +44,31 @@
//
G4IntersectingCone::G4IntersectingCone( const G4double r[2],
const G4double z[2] )
{
{
const G4double halfCarTolerance
= 0.5 * G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
//
// What type of cone are we?
//
type1 = (std::fabs(z[1]-z[0]) > std::fabs(r[1]-r[0]));
if (type1)
type1 = (std::abs(z[1]-z[0]) > std::abs(r[1]-r[0]));
if (type1) // tube like
{
B = (r[1]-r[0])/(z[1]-z[0]); // tube like
A = 0.5*( r[1]+r[0] - B*(z[1]+z[0]) );
B = (r[1] - r[0]) / (z[1] - z[0]);
A = (r[0]*z[1] - r[1]*z[0]) / (z[1] -z[0]);
}
else
else // disk like
{
B = (z[1]-z[0])/(r[1]-r[0]); // disk like
A = 0.5*( z[1]+z[0] - B*(r[1]+r[0]) );
B = (z[1] - z[0]) / (r[1] - r[0]);
A = (z[0]*r[1] - z[1]*r[0]) / (r[1] - r[0]);
}
//
// Calculate extent
//
if (r[0] < r[1])
{
rLo = r[0]-halfCarTolerance; rHi = r[1]+halfCarTolerance;
}
else
{
rLo = r[1]-halfCarTolerance; rHi = r[0]+halfCarTolerance;
}
if (z[0] < z[1])
{
zLo = z[0]-halfCarTolerance; zHi = z[1]+halfCarTolerance;
}
else
{
zLo = z[1]-halfCarTolerance; zHi = z[0]+halfCarTolerance;
}
rLo = std::min(r[0], r[1]) - halfCarTolerance;
rHi = std::max(r[0], r[1]) + halfCarTolerance;
zLo = std::min(z[0], z[1]) - halfCarTolerance;
zHi = std::max(z[0], z[1]) + halfCarTolerance;
}
@@ -171,11 +157,11 @@ G4int G4IntersectingCone::LineHitsCone( const G4ThreeVector &p,
//
// where:
//
// a = x0**2 + y0**2 - (A + B*z0)**2
// a = tx**2 + ty**2 - (B*tz)**2
//
// b = 2*( x0*tx + y0*ty - (A*B - B*B*z0)*tz)
// b = 2*( px*vx + py*vy - B*(A + B*pz)*vz )
//
// c = tx**2 + ty**2 - (B*tz)**2
// c = x0**2 + y0**2 - (A + B*z0)**2
//
// Notice, that if a < 0, this indicates that the two solutions (assuming
// they exist) are in opposite cones (that is, given z0 = -A/B, one z < z0
@@ -191,7 +177,7 @@ G4int G4IntersectingCone::LineHitsCone( const G4ThreeVector &p,
// This should be rare.
//
// For b*b - 4*a*c = 0, we also have one solution, which is almost always
// a line just grazing the surface of a the cone, which we want to ignore.
// a line just grazing the surface of a the cone, which we want to ignore.
// However, there are two other, very rare, possibilities:
// a line intersecting the z axis and either:
// 1. At the same angle std::atan(B) to just miss one side of the cone, or
@@ -204,12 +190,12 @@ G4int G4IntersectingCone::LineHitsCone( const G4ThreeVector &p,
//
// Now: x0*tx + y0*ty = 0 in terms of roundoff error. We can write:
// Delta = x0*tx + y0*ty
// b = 2*( Delta - (A*B + B*B*z0)*tz )
// b = 2*( Delta - B*(A + B*z0)*tz )
// For:
// b*b - 4*a*c = epsilon
// where epsilon is small, then:
// Delta = epsilon/2/B
//
//
G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
const G4ThreeVector &v,
G4double *s1, G4double *s2 )
@@ -219,14 +205,34 @@ G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
G4double x0 = p.x(), y0 = p.y(), z0 = p.z();
G4double tx = v.x(), ty = v.y(), tz = v.z();
G4double a = tx*tx + ty*ty - sqr(B*tz);
G4double b = 2*( x0*tx + y0*ty - (A*B + B*B*z0)*tz);
G4double c = x0*x0 + y0*y0 - sqr(A + B*z0);
G4double radical = b*b - 4*a*c;
if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
// Value of radical can be inaccurate due to loss of precision
// if to calculate the coefficiets a,b,c like the following:
// G4double a = tx*tx + ty*ty - sqr(B*tz);
// G4double b = 2*( x0*tx + y0*ty - B*(A + B*z0)*tz);
// G4double c = x0*x0 + y0*y0 - sqr(A + B*z0);
//
// For more accurate calculation of radical the coefficients
// are splitted in two components, radial and along z-axis
//
G4double ar = tx*tx + ty*ty;
G4double az = sqr(B*tz);
G4double br = 2*(x0*tx + y0*ty);
G4double bz = 2*B*(A + B*z0)*tz;
G4double cr = x0*x0 + y0*y0;
G4double cz = sqr(A + B*z0);
// Instead radical = b*b - 4*a*c
G4double arcz = 4*ar*cz;
G4double azcr = 4*az*cr;
G4double radical = (br*br - 4*ar*cr) + ((std::max(arcz,azcr) - 2*bz*br) + std::min(arcz,azcr));
// Find the coefficients
G4double a = ar - az;
G4double b = br - bz;
G4double c = cr - cz;
if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
if (radical < EPS*std::fabs(b))
{
//
@@ -247,7 +253,7 @@ G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
{
radical = std::sqrt(radical);
}
if (a > 1/kInfinity)
{
G4double sa, sb, q = -0.5*( b + (b < 0 ? -radical : +radical) );
@@ -277,7 +283,7 @@ G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
}
}
//
// LineHitsCone2
//
@@ -297,7 +303,7 @@ G4int G4IntersectingCone::LineHitsCone1( const G4ThreeVector &p,
//
// a > 0 now means we intersect only once in the correct hemisphere.
//
// a > 0 ? We only want solution which produces R > 0.
// a > 0 ? We only want solution which produces R > 0.
// since R = (z0+s*tz-A)/B, for tz/B > 0, this is the largest s
// for tz/B < 0, this is the smallest s
// thus, same as in case 1 ( since sign(tz/B) = sign(tz*B) )
@@ -310,27 +316,47 @@ G4int G4IntersectingCone::LineHitsCone2( const G4ThreeVector &p,
// originally it was 1E-6
G4double x0 = p.x(), y0 = p.y(), z0 = p.z();
G4double tx = v.x(), ty = v.y(), tz = v.z();
// Special case which might not be so rare: B = 0 (precisely)
//
if (B==0)
{
if (std::fabs(tz) < 1/kInfinity) { return 0; }
*s1 = (A-z0)/tz;
return 1;
}
// Value of radical can be inaccurate due to loss of precision
// if to calculate the coefficiets a,b,c like the following:
// G4double a = tz*tz - B2*(tx*tx + ty*ty);
// G4double b = 2*( (z0-A)*tz - B2*(x0*tx + y0*ty) );
// G4double c = sqr(z0-A) - B2*( x0*x0 + y0*y0 );
//
// For more accurate calculation of radical the coefficients
// are splitted in two components, radial and along z-axis
//
G4double B2 = B*B;
G4double a = tz*tz - B2*(tx*tx + ty*ty);
G4double b = 2*( (z0-A)*tz - B2*(x0*tx + y0*ty) );
G4double c = sqr(z0-A) - B2*( x0*x0 + y0*y0 );
G4double radical = b*b - 4*a*c;
if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
G4double az = tz*tz;
G4double ar = B2*(tx*tx + ty*ty);
G4double bz = 2*(z0-A)*tz;
G4double br = 2*B2*(x0*tx + y0*ty);
G4double cz = sqr(z0-A);
G4double cr = B2*(x0*x0 + y0*y0);
// Instead radical = b*b - 4*a*c
G4double arcz = 4*ar*cz;
G4double azcr = 4*az*cr;
G4double radical = (br*br - 4*ar*cr) + ((std::max(arcz,azcr) - 2*bz*br) + std::min(arcz,azcr));
// Find the coefficients
G4double a = az - ar;
G4double b = bz - br;
G4double c = cz - cr;
if (radical < -EPS*std::fabs(b)) { return 0; } // No solution
if (radical < EPS*std::fabs(b))
{
//
@@ -350,7 +376,7 @@ G4int G4IntersectingCone::LineHitsCone2( const G4ThreeVector &p,
{
radical = std::sqrt(radical);
}
if (a < -1/kInfinity)
{
G4double sa, sb, q = -0.5*( b + (b < 0 ? -radical : +radical) );
@@ -1859,18 +1859,22 @@ G4TessellatedSolid::CalculateExtent(const EAxis pAxis,
G4double& pMin, G4double& pMax) const
{
G4ThreeVector bmin, bmax;
G4bool exist;
// Check bounding box (bbox)
//
BoundingLimits(bmin,bmax);
G4BoundingEnvelope bbox(bmin,bmax);
#ifdef G4BBOX_EXTENT
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#endif
// Use simple bounding-box to help in the case of complex meshes
//
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#if 0
// Precise extent computation (disabled by default for this shape)
//
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
{
return exist = (pMin < pMax) ? true : false;
return (pMin < pMax) ? true : false;
}
// The extent is calculated as cumulative extent of the pyramids
@@ -1907,6 +1911,7 @@ G4TessellatedSolid::CalculateExtent(const EAxis pAxis,
if (eminlim > pMin && emaxlim < pMax) break; // max possible extent
}
return (pMin < pMax);
#endif
}
///////////////////////////////////////////////////////////////////////////////
+12 -7
View File
@@ -58,7 +58,7 @@
//#if !defined(G4GEOM_USE_UTET)
const char G4Tet::CVSVers[]="$Id: G4Tet.cc 113723 2018-12-06 14:12:07Z gunter $";
const char G4Tet::CVSVers[]="$Id$";
#include "G4VoxelLimits.hh"
#include "G4AffineTransform.hh"
@@ -328,15 +328,20 @@ G4bool G4Tet::CalculateExtent(const EAxis pAxis,
G4double& pMin, G4double& pMax) const
{
G4ThreeVector bmin, bmax;
G4bool exist;
// Check bounding box (bbox)
//
BoundingLimits(bmin,bmax);
G4BoundingEnvelope bbox(bmin,bmax);
#ifdef G4BBOX_EXTENT
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#endif
// Use simple bounding-box to help in the case of complex 3D meshes
//
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#if 0
// Precise extent computation (disabled by default for this shape)
//
G4bool exist;
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
{
return exist = (pMin < pMax) ? true : false;
@@ -359,8 +364,8 @@ G4bool G4Tet::CalculateExtent(const EAxis pAxis,
polygons[1] = &base;
G4BoundingEnvelope benv(bmin,bmax,polygons);
exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
return exist;
return exists = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#endif
}
/////////////////////////////////////////////////////////////////////////
@@ -326,19 +326,23 @@ G4UTessellatedSolid::CalculateExtent(const EAxis pAxis,
G4double& pMin, G4double& pMax) const
{
G4ThreeVector bmin, bmax;
G4bool exist;
G4double kCarToleranceHalf = 0.5*kCarTolerance;
// Check bounding box (bbox)
//
BoundingLimits(bmin,bmax);
G4BoundingEnvelope bbox(bmin,bmax);
#ifdef G4BBOX_EXTENT
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#endif
// Use simple bounding-box to help in the case of complex meshes
//
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#if 0
// Precise extent computation (disabled by default for this shape)
//
G4double kCarToleranceHalf = 0.5*kCarTolerance;
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
{
return exist = (pMin < pMax) ? true : false;
return (pMin < pMax) ? true : false;
}
// The extent is calculated as cumulative extent of the pyramids
@@ -373,6 +377,7 @@ G4UTessellatedSolid::CalculateExtent(const EAxis pAxis,
if (eminlim > pMin && emaxlim < pMax) break; // max possible extent
}
return (pMin < pMax);
#endif
}
+11 -6
View File
@@ -188,15 +188,20 @@ G4UTet::CalculateExtent(const EAxis pAxis,
G4double& pMin, G4double& pMax) const
{
G4ThreeVector bmin, bmax;
G4bool exist;
// Check bounding box (bbox)
//
BoundingLimits(bmin,bmax);
G4BoundingEnvelope bbox(bmin,bmax);
#ifdef G4BBOX_EXTENT
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#endif
// Use simple bounding-box to help in the case of complex 3D meshes
//
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#if 0
// Precise extent computation (disabled by default for this shape)
//
G4bool exist;
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
{
return exist = (pMin < pMax) ? true : false;
@@ -219,8 +224,8 @@ G4UTet::CalculateExtent(const EAxis pAxis,
polygons[1] = &base;
G4BoundingEnvelope benv(bmin,bmax,polygons);
exist = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
return exist;
return exists = benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#endif
}
////////////////////////////////////////////////////////////////////////