Import Geant4 10.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-12-09 12:35:28 +01:00
parent 4ec577e5c4
commit a3452e42ac
3514 changed files with 210500 additions and 89628 deletions
@@ -44,6 +44,11 @@
#include "G4PolyconeSide.hh"
#include "G4PolyPhiFace.hh"
#include "G4GeomTools.hh"
#include "G4VoxelLimits.hh"
#include "G4AffineTransform.hh"
#include "G4BoundingEnvelope.hh"
#include "Randomize.hh"
#include "G4Polyhedron.hh"
@@ -100,9 +105,10 @@ void G4GenericPolycone::Create( G4double phiStart,
G4double rzArea = rz->Area();
if (rzArea < -kCarTolerance)
{
rz->ReverseOrder();
else if (rzArea < -kCarTolerance)
}
else if (rzArea < kCarTolerance)
{
std::ostringstream message;
message << "Illegal input parameters - " << GetName() << G4endl
@@ -281,7 +287,8 @@ G4GenericPolycone::G4GenericPolycone( const G4GenericPolycone &source )
//
// Assignment operator
//
G4GenericPolycone &G4GenericPolycone::operator=( const G4GenericPolycone &source )
G4GenericPolycone&
G4GenericPolycone::operator=( const G4GenericPolycone &source )
{
if (this == &source) return *this;
@@ -399,6 +406,194 @@ G4double G4GenericPolycone::DistanceToIn( const G4ThreeVector &p ) const
return G4VCSGfaceted::DistanceToIn(p);
}
//////////////////////////////////////////////////////////////////////////
//
// Get bounding box
void
G4GenericPolycone::Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const
{
G4double rmin = kInfinity, rmax = -kInfinity;
G4double zmin = kInfinity, zmax = -kInfinity;
for (G4int i=0; i<GetNumRZCorner(); ++i)
{
G4PolyconeSideRZ corner = GetCorner(i);
if (corner.r < rmin) rmin = corner.r;
if (corner.r > rmax) rmax = corner.r;
if (corner.z < zmin) zmin = corner.z;
if (corner.z > zmax) zmax = corner.z;
}
if (IsOpen())
{
G4TwoVector vmin,vmax;
G4GeomTools::DiskExtent(rmin,rmax,
GetSinStartPhi(),GetCosStartPhi(),
GetSinEndPhi(),GetCosEndPhi(),
vmin,vmax);
pMin.set(vmin.x(),vmin.y(),zmin);
pMax.set(vmax.x(),vmax.y(),zmax);
}
else
{
pMin.set(-rmax,-rmax, zmin);
pMax.set( rmax, rmax, zmax);
}
// Check correctness of the bounding box
//
if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
{
std::ostringstream message;
message << "Bad bounding box (min >= max) for solid: "
<< GetName() << " !"
<< "\npMin = " << pMin
<< "\npMax = " << pMax;
G4Exception("GenericG4Polycone::Extent()", "GeomMgt0001",
JustWarning, message);
DumpInfo();
}
}
//////////////////////////////////////////////////////////////////////////
//
// Calculate extent under transform and specified limit
G4bool
G4GenericPolycone::CalculateExtent(const EAxis pAxis,
const G4VoxelLimits& pVoxelLimit,
const G4AffineTransform& pTransform,
G4double& pMin, G4double& pMax) const
{
G4ThreeVector bmin, bmax;
G4bool exist;
// Check bounding box (bbox)
//
Extent(bmin,bmax);
G4BoundingEnvelope bbox(bmin,bmax);
#ifdef G4BBOX_EXTENT
if (true) return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
#endif
if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
{
return exist = (pMin < pMax) ? true : false;
}
// To find the extent, RZ contour of the polycone is subdivided
// in triangles. The extent is calculated as cumulative extent of
// all sub-polycones formed by rotation of triangles around Z
//
G4TwoVectorList contourRZ;
G4TwoVectorList triangles;
G4double eminlim = pVoxelLimit.GetMinExtent(pAxis);
G4double emaxlim = pVoxelLimit.GetMaxExtent(pAxis);
// get RZ contour, ensure anticlockwise order of corners
for (G4int i=0; i<GetNumRZCorner(); ++i)
{
G4PolyconeSideRZ corner = GetCorner(i);
contourRZ.push_back(G4TwoVector(corner.r,corner.z));
}
G4double area = G4GeomTools::PolygonArea(contourRZ);
if (area < 0.) std::reverse(contourRZ.begin(),contourRZ.end());
// triangulate RZ countour
if (!G4GeomTools::TriangulatePolygon(contourRZ,triangles))
{
std::ostringstream message;
message << "Triangulation of RZ contour has failed for solid: "
<< GetName() << " !"
<< "\nExtent has been calculated using boundary box";
G4Exception("G4GenericPolycone::CalculateExtent()",
"GeomMgt1002", JustWarning, message);
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
}
// set trigonometric values
const G4int NSTEPS = 24; // number of steps for whole circle
G4double astep = (360/NSTEPS)*deg; // max angle for one step
G4double sphi = GetStartPhi();
G4double ephi = GetEndPhi();
G4double dphi = IsOpen() ? ephi-sphi : twopi;
G4int ksteps = (dphi <= astep) ? 1 : (G4int)((dphi-deg)/astep) + 1;
G4double ang = dphi/ksteps;
G4double sinHalf = std::sin(0.5*ang);
G4double cosHalf = std::cos(0.5*ang);
G4double sinStep = 2.*sinHalf*cosHalf;
G4double cosStep = 1. - 2.*sinHalf*sinHalf;
G4double sinStart = GetSinStartPhi();
G4double cosStart = GetCosStartPhi();
G4double sinEnd = GetSinEndPhi();
G4double cosEnd = GetCosEndPhi();
// define vectors and arrays
std::vector<const G4ThreeVectorList *> polygons;
polygons.resize(ksteps+2);
G4ThreeVectorList pols[NSTEPS+2];
for (G4int k=0; k<ksteps+2; ++k) pols[k].resize(6);
for (G4int k=0; k<ksteps+2; ++k) polygons[k] = &pols[k];
G4double r0[6],z0[6]; // contour with original edges of triangle
G4double r1[6]; // shifted radii of external edges of triangle
// main loop along triangles
pMin = kInfinity;
pMax =-kInfinity;
G4int ntria = triangles.size()/3;
for (G4int i=0; i<ntria; ++i)
{
G4int i3 = i*3;
for (G4int k=0; k<3; ++k)
{
G4int e0 = i3+k, e1 = (k<2) ? e0+1 : i3;
G4int k2 = k*2;
// set contour with original edges of triangle
r0[k2+0] = triangles[e0].x(); z0[k2+0] = triangles[e0].y();
r0[k2+1] = triangles[e1].x(); z0[k2+1] = triangles[e1].y();
// set shifted radii
r1[k2+0] = r0[k2+0];
r1[k2+1] = r0[k2+1];
if (z0[k2+1] - z0[k2+0] <= 0) continue;
r1[k2+0] /= cosHalf;
r1[k2+1] /= cosHalf;
}
// rotate countour, set sequence of 6-sided polygons
G4double sinCur = sinStart*cosHalf + cosStart*sinHalf;
G4double cosCur = cosStart*cosHalf - sinStart*sinHalf;
for (G4int j=0; j<6; ++j)
{
pols[0][j].set(r0[j]*cosStart,r0[j]*sinStart,z0[j]);
}
for (G4int k=1; k<ksteps+1; ++k)
{
for (G4int j=0; j<6; ++j)
{
pols[k][j].set(r1[j]*cosCur,r1[j]*sinCur,z0[j]);
}
G4double sinTmp = sinCur;
sinCur = sinCur*cosStep + cosCur*sinStep;
cosCur = cosCur*cosStep - sinTmp*sinStep;
}
for (G4int j=0; j<6; ++j)
{
pols[ksteps+1][j].set(r0[j]*cosEnd,r0[j]*sinEnd,z0[j]);
}
// set sub-envelope and adjust extent
G4double emin,emax;
G4BoundingEnvelope benv(polygons);
if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax)) continue;
if (emin < pMin) pMin = emin;
if (emax > pMax) pMax = emax;
if (eminlim > pMin && emaxlim < pMax) return true; // max possible extent
}
return (pMin < pMax);
}
//
// ComputeDimensions
@@ -732,10 +927,10 @@ G4Polyhedron* G4GenericPolycone::CreatePolyhedron() const
}
}
G4Polyhedron* polyhedron = new G4Polyhedron;
G4int problem = polyhedron->createPolyhedron(nNodes, nFaces, xyz, faces_vec);
G4int prob = polyhedron->createPolyhedron(nNodes, nFaces, xyz, faces_vec);
delete [] faces_vec;
delete [] xyz;
if (problem)
if (prob)
{
std::ostringstream message;
message << "Problem creating G4Polyhedron for: " << GetName();