36#ifdef G4GEOMETRY_VOXELDEBUG
90 if (pVolume !=
nullptr)
92 BuildOptimisations(pOptimise, pVolume);
96 BuildOptimisations(pOptimise, verbose);
113 if (pVolume !=
nullptr)
115 DeleteOptimisations(pVolume);
119 DeleteOptimisations();
141 if (fgInstance ==
nullptr)
162void G4GeometryManager::BuildOptimisations(
G4bool allOpts,
G4bool verbose)
166 std::vector<G4SmartVoxelStat> stats;
167 if (verbose) { allTimer.
Start(); }
173 for (
size_t n=0;
n<Store->size(); ++
n)
175 if (verbose) timer.
Start();
189#ifdef G4GEOMETRY_VOXELDEBUG
190 G4cout <<
"**** G4GeometryManager::BuildOptimisations" <<
G4endl
191 <<
" Examining logical volume name = "
201 std::ostringstream message;
202 message <<
"VoxelHeader allocation error." <<
G4endl
203 <<
"Allocation of new VoxelHeader" <<
G4endl
204 <<
" for volume " << volume->
GetName() <<
" failed.";
205 G4Exception(
"G4GeometryManager::BuildOptimisations()",
"GeomMgt0003",
219#ifdef G4GEOMETRY_VOXELDEBUG
220 G4cout <<
"**** G4GeometryManager::BuildOptimisations" <<
G4endl
221 <<
" Skipping logical volume name = " << volume->
GetName()
238void G4GeometryManager::BuildOptimisations(
G4bool allOpts,
241 if (pVolume ==
nullptr) {
return; }
247 if (tVolume ==
nullptr) {
return BuildOptimisations(allOpts,
false); }
264 std::ostringstream message;
265 message <<
"VoxelHeader allocation error." <<
G4endl
266 <<
"Allocation of new VoxelHeader" <<
G4endl
267 <<
" for volume " << tVolume->
GetName() <<
" failed.";
268 G4Exception(
"G4GeometryManager::BuildOptimisations()",
"GeomMgt0003",
275#ifdef G4GEOMETRY_VOXELDEBUG
276 G4cout <<
"**** G4GeometryManager::BuildOptimisations" <<
G4endl
277 <<
" Skipping logical volume name = " << tVolume->
GetName()
287 BuildOptimisations(allOpts, tVolume->
GetDaughter(0));
296void G4GeometryManager::DeleteOptimisations()
300 for (
size_t n=0;
n<Store->size(); ++
n)
315 if (!pVolume) {
return; }
321 if (tVolume ==
nullptr) {
return DeleteOptimisations(); }
346 G4Exception(
"G4GeometryManager::SetMaximumExtent()",
348 "Extent can be set only BEFORE creating any geometry object!");
358G4GeometryManager::ReportVoxelStats( std::vector<G4SmartVoxelStat> & stats,
361 G4cout <<
"G4GeometryManager::ReportVoxelStats -- Voxel Statistics"
367 G4int i, nStat = stats.size();
370 for( i=0; i<nStat; ++i ) { totalMemory += stats[i].GetMemoryUse(); }
372 G4cout <<
" Total memory consumed for geometry optimisation: "
373 << totalMemory/1024 <<
" kByte" <<
G4endl;
374 G4cout <<
" Total CPU time elapsed for geometry optimisation: "
375 << std::setprecision(2) << totalCpuTime <<
" seconds"
376 << std::setprecision(6) <<
G4endl;
381 std::sort( stats.begin(), stats.end(),
384 return a.GetTotalTime() > b.GetTotalTime();
387 G4int nPrint = nStat > 10 ? 10 : nStat;
392 G4cout <<
" Percent Total CPU System CPU Memory Volume\n"
393 <<
" ------- ---------- ---------- -------- ----------"
398 for(i=0; i<nPrint; ++i)
401 G4double system = stats[i].GetSysTime();
404 if (system < 0) { system = 0.0; }
405 if ((total < 0) || (totalCpuTime < perMillion))
408 { perc =
total*100/totalCpuTime; }
410 G4cout << std::setprecision(2)
411 << std::setiosflags(std::ios::fixed|std::ios::right)
412 << std::setw(11) << perc
413 << std::setw(13) <<
total
414 << std::setw(13) << system
415 << std::setw(13) << (stats[i].GetMemoryUse()+512)/1024
416 <<
"k " << std::setiosflags(std::ios::left)
417 << stats[i].GetVolume()->GetName()
418 << std::resetiosflags(std::ios::floatfield|std::ios::adjustfield)
419 << std::setprecision(6)
426 std::sort( stats.begin(), stats.end(),
429 return a.GetMemoryUse() > b.GetMemoryUse();
434 G4cout <<
"\n Voxelisation: top memory users:" <<
G4endl;
435 G4cout <<
" Percent Memory Heads Nodes Pointers Total CPU Volume\n"
436 <<
" ------- -------- ------ ------ -------- ---------- ----------"
441 for(i=0; i<nPrint; ++i)
443 G4long memory = stats[i].GetMemoryUse();
444 G4double totTime = stats[i].GetTotalTime();
445 if (totTime < 0) { totTime = 0.0; }
447 G4cout << std::setprecision(2)
448 << std::setiosflags(std::ios::fixed|std::ios::right)
450 << std::setw(11) << memory/1024 <<
"k "
451 << std::setw( 9) << stats[i].GetNumberHeads()
452 << std::setw( 9) << stats[i].GetNumberNodes()
453 << std::setw(11) << stats[i].GetNumberPointers()
454 << std::setw(13) << totTime <<
" "
455 << std::setiosflags(std::ios::left)
456 << stats[i].GetVolume()->GetName()
457 << std::resetiosflags(std::ios::floatfield|std::ios::adjustfield)
458 << std::setprecision(6)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
static G4bool IsGeometryClosed()
static G4GeometryManager * GetInstance()
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
void SetWorldMaximumExtent(G4double worldExtent)
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
static G4GeometryManager * GetInstanceIfExist()
void SetSurfaceTolerance(G4double worldExtent)
static G4GeometryTolerance * GetInstance()
static G4LogicalVolumeStore * GetInstance()
void SetVoxelHeader(G4SmartVoxelHeader *pVoxel)
size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
G4bool IsToOptimise() const
const G4String & GetName() const
G4SmartVoxelHeader * GetVoxelHeader() const
static G4SolidStore * GetInstance()
G4double GetSystemElapsed() const
G4double GetUserElapsed() const
G4LogicalVolume * GetMotherLogical() const
virtual G4bool IsReplicated() const =0
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetRegularStructureId() const =0
G4double total(Particle const *const p1, Particle const *const p2)
const G4int kMinVoxelVolumesLevel1