Import Geant4 11.3.1 source tree
This commit is contained in:
@@ -113,7 +113,7 @@ G4GeometryManager::~G4GeometryManager()
|
||||
fgInstance = nullptr;
|
||||
fIsClosed = false;
|
||||
|
||||
if( fWallClockTimer && G4Threading::IsMasterThread() )
|
||||
if( (fWallClockTimer != nullptr) && G4Threading::IsMasterThread() )
|
||||
{
|
||||
delete fWallClockTimer;
|
||||
fWallClockTimer= nullptr;
|
||||
@@ -240,11 +240,9 @@ G4bool G4GeometryManager::BuildOptimisations(G4bool allOpts, G4bool verbose)
|
||||
fOptimiseInParallelConfigured = fParallelVoxelOptimisationRequested
|
||||
&& G4Threading::IsMultithreadedApplication();
|
||||
|
||||
static unsigned int NumCallsBuildOptimisations = 0; // WORKAROUND - TODO fix
|
||||
if( fOptimiseInParallelConfigured && (NumCallsBuildOptimisations==0) )
|
||||
if( fOptimiseInParallelConfigured )
|
||||
{
|
||||
PrepareParallelOptimisation(allOpts, verbose);
|
||||
++NumCallsBuildOptimisations;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -285,7 +283,7 @@ void G4GeometryManager::BuildOptimisationsSequential(G4bool allOpts,
|
||||
|
||||
for (auto & n : *Store)
|
||||
{
|
||||
if (verbose) timer.Start();
|
||||
if (verbose) { timer.Start(); }
|
||||
volume=n;
|
||||
// For safety, check if there are any existing voxels and
|
||||
// delete before replacement
|
||||
@@ -374,7 +372,7 @@ void
|
||||
G4GeometryManager::CreateListOfVolumesToOptimise(G4bool allOpts, G4bool verbose)
|
||||
{
|
||||
// Prepare the work - must be called only in one thread !!
|
||||
|
||||
|
||||
G4LogicalVolumeStore* Store = G4LogicalVolumeStore::GetInstance();
|
||||
|
||||
if( !fVolumesToOptimise.empty() )
|
||||
@@ -416,9 +414,11 @@ G4GeometryManager::CreateListOfVolumesToOptimise(G4bool allOpts, G4bool verbose)
|
||||
}
|
||||
|
||||
if(verbose)
|
||||
G4cout << "** G4GeometryManager::PrepareOptimisationWork: "
|
||||
{
|
||||
G4cout << "** G4GeometryManager::CreateListOfVolumesToOptimise: "
|
||||
<< " Number of volumes for voxelisation = "
|
||||
<< fVolumesToOptimise.size() << G4endl;
|
||||
}
|
||||
|
||||
fLogVolumeIterator = fVolumesToOptimise.cbegin();
|
||||
}
|
||||
@@ -482,9 +482,13 @@ void G4GeometryManager::RequestParallelOptimisation(G4bool flag, G4bool verbose)
|
||||
//
|
||||
void G4GeometryManager::ConfigureParallelOptimisation(G4bool verbose)
|
||||
{
|
||||
static G4ThreadLocal unsigned int numCallsConfig = 0;
|
||||
++numCallsConfig;
|
||||
|
||||
if(verbose)
|
||||
{
|
||||
G4cout << "** G4GeometryManager::ConfigureParallelOptimisation() called. "
|
||||
G4cout << "** G4GeometryManager::ConfigureParallelOptimisation() called "
|
||||
<< " for the " << numCallsConfig << " time. "
|
||||
<< " LEAVING all the work (of voxel optimisation) to the threads/tasks !"
|
||||
<< G4endl;
|
||||
}
|
||||
@@ -501,6 +505,9 @@ void G4GeometryManager::ConfigureParallelOptimisation(G4bool verbose)
|
||||
fTotalNumberVolumesOptimised = 0; // Number of volumes done
|
||||
|
||||
fWallClockStarted = false; // Will need to restart it!
|
||||
|
||||
fLogVolumeIterator = fVolumesToOptimise.cbegin();
|
||||
// Reset the iterator -- else to be sure that work is done correctly
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
@@ -528,8 +535,8 @@ void G4GeometryManager::UndertakeOptimisation()
|
||||
G4bool verbose = fVerboseParallel;
|
||||
G4LogicalVolume* logVolume = nullptr;
|
||||
|
||||
fParallelVoxelOptimisationUnderway = true;
|
||||
|
||||
fParallelVoxelOptimisationUnderway = true;
|
||||
|
||||
// Start timer - if not already done
|
||||
if( ( !fWallClockStarted ) && verbose )
|
||||
{
|
||||
@@ -546,7 +553,7 @@ void G4GeometryManager::UndertakeOptimisation()
|
||||
|
||||
while( (logVolume = ObtainVolumeToOptimise()) != nullptr )
|
||||
{
|
||||
if (verbose) fetimer.Start();
|
||||
if (verbose) { fetimer.Start(); }
|
||||
|
||||
G4SmartVoxelHeader* head = logVolume->GetVoxelHeader();
|
||||
delete head;
|
||||
@@ -601,7 +608,7 @@ void G4GeometryManager::UndertakeOptimisation()
|
||||
<< "but found that voxels headers are missing in "
|
||||
<< badVolumes << " volumes.";
|
||||
G4Exception("G4GeometryManager::UndertakeOptimisation()",
|
||||
"GeomMng002", FatalException, errmsg);
|
||||
"GeomMgt002", FatalException, errmsg);
|
||||
}
|
||||
|
||||
// Create report
|
||||
@@ -688,18 +695,80 @@ G4int G4GeometryManager::CheckOptimisation()
|
||||
// ***************************************************************************
|
||||
//
|
||||
G4int
|
||||
G4GeometryManager::ReportWorkerIsDoneOptimising(unsigned int numVolumesOptimised)
|
||||
G4GeometryManager::ReportWorkerIsDoneOptimising(unsigned int nVolOptimised)
|
||||
{
|
||||
// Check that all are done and, if so, signal that optimisation is finished
|
||||
G4int orderReporting;
|
||||
|
||||
G4AutoLock lock(statResultsMutex);
|
||||
orderReporting = ++fNumberThreadsReporting;
|
||||
fTotalNumberVolumesOptimised += numVolumesOptimised;
|
||||
fTotalNumberVolumesOptimised += nVolOptimised;
|
||||
|
||||
if (fNumberThreadsReporting == G4Threading::GetNumberOfRunningWorkerThreads())
|
||||
if( fVerboseParallel )
|
||||
{
|
||||
InformOptimisationIsFinished(fVerboseParallel);
|
||||
std::cout << "G4GeometryManager: the " << orderReporting
|
||||
<< " worker has finished. "
|
||||
<< " Total volumes voxelised = "
|
||||
<< fTotalNumberVolumesOptimised
|
||||
<< " out of " << fVolumesToOptimise.size() << G4endl;
|
||||
}
|
||||
|
||||
if ( fNumberThreadsReporting == G4Threading::GetNumberOfRunningWorkerThreads()
|
||||
|| fTotalNumberVolumesOptimised == fVolumesToOptimise.size() )
|
||||
{
|
||||
const auto TotalThreads = G4Threading::GetNumberOfRunningWorkerThreads();
|
||||
auto tid= G4Threading::G4GetThreadId();
|
||||
|
||||
// -- Some Checks
|
||||
if( fTotalNumberVolumesOptimised != fVolumesToOptimise.size() )
|
||||
{
|
||||
G4ExceptionDescription errmsg;
|
||||
errmsg << " [thread " << tid << " ] "
|
||||
<< " ERROR: Number of volumes 'voxelised' = "
|
||||
<< fTotalNumberVolumesOptimised
|
||||
<< " is not equal to the total number requested "
|
||||
<< fVolumesToOptimise.size() << " !! " << G4endl;
|
||||
G4Exception("G4GeometryManager::ReportWorkerIsDoneOptimising()",
|
||||
"GeomMgt0003", FatalException, errmsg);
|
||||
}
|
||||
|
||||
if( fVerboseParallel )
|
||||
{
|
||||
if( fNumberThreadsReporting > TotalThreads )
|
||||
{
|
||||
G4ExceptionDescription errmsg;
|
||||
errmsg << " [thread " << tid << " ] "
|
||||
<< " WARNING: Number of threads 'reporting' = "
|
||||
<< fNumberThreadsReporting
|
||||
<< " exceeds the total number of threads "
|
||||
<< TotalThreads << " !! " << G4endl
|
||||
<< " *Missed* calling ConfigureParallelOptimisation() to reset. ";
|
||||
G4Exception("G4GeometryManager::ReportWorkerIsDoneOptimising()",
|
||||
"GeomMgt1002", JustWarning, errmsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( fTotalNumberVolumesOptimised == fVolumesToOptimise.size()
|
||||
&& ( fNumberThreadsReporting < TotalThreads ) )
|
||||
{
|
||||
G4ExceptionDescription errmsg;
|
||||
errmsg << " [thread " << tid << " ] "
|
||||
<< " WARNING: All volumes optimised, yet only "
|
||||
<< fNumberThreadsReporting << " threads reported out of "
|
||||
<< TotalThreads;
|
||||
G4Exception("G4GeometryManager::ReportWorkerIsDoneOptimising()",
|
||||
"GeomMgt1002", JustWarning, errmsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
// -- End of Checks
|
||||
|
||||
// Report the end
|
||||
if( fNumberThreadsReporting <= G4Threading::GetNumberOfRunningWorkerThreads() )
|
||||
{
|
||||
// Close the work, and (if verbosity is on) report statistics
|
||||
InformOptimisationIsFinished(fVerboseParallel);
|
||||
}
|
||||
}
|
||||
|
||||
return orderReporting;
|
||||
@@ -859,8 +928,7 @@ void G4GeometryManager::SetWorldMaximumExtent(G4double extent)
|
||||
//
|
||||
void
|
||||
G4GeometryManager::ReportVoxelStats( std::vector<G4SmartVoxelStat> & stats,
|
||||
G4double totalCpuTime,
|
||||
std::ostream &os )
|
||||
G4double totalCpuTime, std::ostream &os )
|
||||
{
|
||||
os << "--------------------------------------------------------------------------------"
|
||||
<< G4endl;
|
||||
|
||||
@@ -218,7 +218,8 @@ G4double G4VSolid::GetCubicVolume()
|
||||
G4double G4VSolid::EstimateCubicVolume(G4int nStat, G4double epsilon) const
|
||||
{
|
||||
G4int iInside=0;
|
||||
G4double px,py,pz,minX,maxX,minY,maxY,minZ,maxZ,volume,halfepsilon;
|
||||
G4double px, py, pz, volume, halfepsilon;
|
||||
G4double minX=0., maxX=0., minY=0., maxY=0., minZ=0., maxZ=0.;
|
||||
G4ThreeVector p;
|
||||
EInside in;
|
||||
|
||||
@@ -235,8 +236,8 @@ G4double G4VSolid::EstimateCubicVolume(G4int nStat, G4double epsilon) const
|
||||
|
||||
// limits
|
||||
|
||||
if(nStat < 100) nStat = 100;
|
||||
if(epsilon > 0.01) epsilon = 0.01;
|
||||
if(nStat < 100) { nStat = 100; }
|
||||
if(epsilon > 0.01) { epsilon = 0.01; }
|
||||
halfepsilon = 0.5*epsilon;
|
||||
|
||||
for(auto i = 0; i < nStat; ++i )
|
||||
@@ -246,7 +247,7 @@ G4double G4VSolid::EstimateCubicVolume(G4int nStat, G4double epsilon) const
|
||||
pz = minZ-halfepsilon+(maxZ-minZ+epsilon)*G4QuickRand();
|
||||
p = G4ThreeVector(px,py,pz);
|
||||
in = Inside(p);
|
||||
if(in != kOutside) ++iInside;
|
||||
if(in != kOutside) { ++iInside; }
|
||||
}
|
||||
volume = (maxX-minX+epsilon)*(maxY-minY+epsilon)
|
||||
* (maxZ-minZ+epsilon)*iInside/nStat;
|
||||
@@ -360,15 +361,15 @@ G4double G4VSolid::EstimateSurfaceArea(G4int nstat, G4double ell) const
|
||||
G4double dist = 0;
|
||||
if (in == kInside)
|
||||
{
|
||||
if (DistanceToOut(p) >= eps) continue;
|
||||
if (DistanceToOut(p) >= eps) { continue; }
|
||||
G4int icase = 0;
|
||||
if (Inside(G4ThreeVector(px-del, py, pz)) != kInside) icase += 1;
|
||||
if (Inside(G4ThreeVector(px+del, py, pz)) != kInside) icase += 2;
|
||||
if (Inside(G4ThreeVector(px, py-del, pz)) != kInside) icase += 4;
|
||||
if (Inside(G4ThreeVector(px, py+del, pz)) != kInside) icase += 8;
|
||||
if (Inside(G4ThreeVector(px, py, pz-del)) != kInside) icase += 16;
|
||||
if (Inside(G4ThreeVector(px, py, pz+del)) != kInside) icase += 32;
|
||||
if (icase == 0) continue;
|
||||
if (Inside(G4ThreeVector(px-del, py, pz)) != kInside) { icase += 1; }
|
||||
if (Inside(G4ThreeVector(px+del, py, pz)) != kInside) { icase += 2; }
|
||||
if (Inside(G4ThreeVector(px, py-del, pz)) != kInside) { icase += 4; }
|
||||
if (Inside(G4ThreeVector(px, py+del, pz)) != kInside) { icase += 8; }
|
||||
if (Inside(G4ThreeVector(px, py, pz-del)) != kInside) { icase += 16; }
|
||||
if (Inside(G4ThreeVector(px, py, pz+del)) != kInside) { icase += 32; }
|
||||
if (icase == 0) { continue; }
|
||||
G4ThreeVector v = directions[icase];
|
||||
dist = DistanceToOut(p, v);
|
||||
G4ThreeVector n = SurfaceNormal(p + v*dist);
|
||||
@@ -376,22 +377,22 @@ G4double G4VSolid::EstimateSurfaceArea(G4int nstat, G4double ell) const
|
||||
}
|
||||
else if (in == kOutside)
|
||||
{
|
||||
if (DistanceToIn(p) >= eps) continue;
|
||||
if (DistanceToIn(p) >= eps) { continue; }
|
||||
G4int icase = 0;
|
||||
if (Inside(G4ThreeVector(px-del, py, pz)) != kOutside) icase += 1;
|
||||
if (Inside(G4ThreeVector(px+del, py, pz)) != kOutside) icase += 2;
|
||||
if (Inside(G4ThreeVector(px, py-del, pz)) != kOutside) icase += 4;
|
||||
if (Inside(G4ThreeVector(px, py+del, pz)) != kOutside) icase += 8;
|
||||
if (Inside(G4ThreeVector(px, py, pz-del)) != kOutside) icase += 16;
|
||||
if (Inside(G4ThreeVector(px, py, pz+del)) != kOutside) icase += 32;
|
||||
if (icase == 0) continue;
|
||||
if (Inside(G4ThreeVector(px-del, py, pz)) != kOutside) { icase += 1; }
|
||||
if (Inside(G4ThreeVector(px+del, py, pz)) != kOutside) { icase += 2; }
|
||||
if (Inside(G4ThreeVector(px, py-del, pz)) != kOutside) { icase += 4; }
|
||||
if (Inside(G4ThreeVector(px, py+del, pz)) != kOutside) { icase += 8; }
|
||||
if (Inside(G4ThreeVector(px, py, pz-del)) != kOutside) { icase += 16; }
|
||||
if (Inside(G4ThreeVector(px, py, pz+del)) != kOutside) { icase += 32; }
|
||||
if (icase == 0) { continue; }
|
||||
G4ThreeVector v = directions[icase];
|
||||
dist = DistanceToIn(p, v);
|
||||
if (dist == kInfinity) continue;
|
||||
if (dist == kInfinity) { continue; }
|
||||
G4ThreeVector n = SurfaceNormal(p + v*dist);
|
||||
dist *= -(v.dot(n));
|
||||
}
|
||||
if (dist < eps) ++icount;
|
||||
if (dist < eps) { ++icount; }
|
||||
}
|
||||
return dX*dY*dZ*icount/npoints/dd;
|
||||
}
|
||||
@@ -567,14 +568,14 @@ void G4VSolid::ClipPolygon( G4ThreeVectorList& pPolygon,
|
||||
|
||||
pPolygon.clear();
|
||||
|
||||
if ( outputPolygon.empty() ) return;
|
||||
if ( outputPolygon.empty() ) { return; }
|
||||
|
||||
G4VoxelLimits simpleLimit2;
|
||||
simpleLimit2.AddLimit(kXAxis,-kInfinity,pVoxelLimit.GetMaxXExtent());
|
||||
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
|
||||
|
||||
if ( pPolygon.empty() ) return;
|
||||
else outputPolygon.clear();
|
||||
if ( pPolygon.empty() ) { return; }
|
||||
outputPolygon.clear();
|
||||
}
|
||||
if ( pVoxelLimit.IsYLimited() ) // && pAxis != kYAxis)
|
||||
{
|
||||
@@ -587,14 +588,14 @@ void G4VSolid::ClipPolygon( G4ThreeVectorList& pPolygon,
|
||||
|
||||
pPolygon.clear();
|
||||
|
||||
if ( outputPolygon.empty() ) return;
|
||||
if ( outputPolygon.empty() ) { return; }
|
||||
|
||||
G4VoxelLimits simpleLimit2;
|
||||
simpleLimit2.AddLimit(kYAxis,-kInfinity,pVoxelLimit.GetMaxYExtent());
|
||||
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
|
||||
|
||||
if ( pPolygon.empty() ) return;
|
||||
else outputPolygon.clear();
|
||||
if ( pPolygon.empty() ) { return; }
|
||||
outputPolygon.clear();
|
||||
}
|
||||
if ( pVoxelLimit.IsZLimited() ) // && pAxis != kZAxis)
|
||||
{
|
||||
@@ -607,7 +608,7 @@ void G4VSolid::ClipPolygon( G4ThreeVectorList& pPolygon,
|
||||
|
||||
pPolygon.clear();
|
||||
|
||||
if ( outputPolygon.empty() ) return;
|
||||
if ( outputPolygon.empty() ) { return; }
|
||||
|
||||
G4VoxelLimits simpleLimit2;
|
||||
simpleLimit2.AddLimit(kZAxis,-kInfinity,pVoxelLimit.GetMaxZExtent());
|
||||
@@ -635,8 +636,8 @@ G4VSolid::ClipPolygonToSimpleLimits( G4ThreeVectorList& pPolygon,
|
||||
for (i = 0 ; i < noVertices ; ++i )
|
||||
{
|
||||
vStart = pPolygon[i];
|
||||
if ( i == noVertices-1 ) vEnd = pPolygon[0];
|
||||
else vEnd = pPolygon[i+1];
|
||||
if ( i == noVertices-1 ) { vEnd = pPolygon[0]; }
|
||||
else { vEnd = pPolygon[i+1]; }
|
||||
|
||||
if ( pVoxelLimit.Inside(vStart) )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user