38#ifdef G4GEOMETRY_VOXELDEBUG
84 if (pVolume !=
nullptr)
86 BuildOptimisations(pOptimise, pVolume);
90 BuildOptimisations(pOptimise, verbose);
107 if (pVolume !=
nullptr)
109 DeleteOptimisations(pVolume);
113 DeleteOptimisations();
135 if (fgInstance ==
nullptr)
156void G4GeometryManager::BuildOptimisations(
G4bool allOpts,
G4bool verbose)
160 std::vector<G4SmartVoxelStat> stats;
161 if (verbose) { allTimer.
Start(); }
167 for (
auto & n : *Store)
169 if (verbose) timer.
Start();
183#ifdef G4GEOMETRY_VOXELDEBUG
184 G4cout <<
"**** G4GeometryManager::BuildOptimisations" <<
G4endl
185 <<
" Examining logical volume name = "
195 std::ostringstream message;
196 message <<
"VoxelHeader allocation error." <<
G4endl
197 <<
"Allocation of new VoxelHeader" <<
G4endl
198 <<
" for volume " << volume->
GetName() <<
" failed.";
199 G4Exception(
"G4GeometryManager::BuildOptimisations()",
"GeomMgt0003",
205 stats.emplace_back( volume, head,
213#ifdef G4GEOMETRY_VOXELDEBUG
214 G4cout <<
"**** G4GeometryManager::BuildOptimisations" <<
G4endl
215 <<
" Skipping logical volume name = " << volume->
GetName()
232void G4GeometryManager::BuildOptimisations(
G4bool allOpts,
235 if (pVolume ==
nullptr) {
return; }
241 if (tVolume ==
nullptr) {
return BuildOptimisations(allOpts,
false); }
258 std::ostringstream message;
259 message <<
"VoxelHeader allocation error." <<
G4endl
260 <<
"Allocation of new VoxelHeader" <<
G4endl
261 <<
" for volume " << tVolume->
GetName() <<
" failed.";
262 G4Exception(
"G4GeometryManager::BuildOptimisations()",
"GeomMgt0003",
269#ifdef G4GEOMETRY_VOXELDEBUG
270 G4cout <<
"**** G4GeometryManager::BuildOptimisations" <<
G4endl
271 <<
" Skipping logical volume name = " << tVolume->
GetName()
281 BuildOptimisations(allOpts, tVolume->
GetDaughter(0));
290void G4GeometryManager::DeleteOptimisations()
294 for (
auto & n : *Store)
309 if (pVolume ==
nullptr) {
return; }
315 if (tVolume ==
nullptr) {
return DeleteOptimisations(); }
340 G4Exception(
"G4GeometryManager::SetMaximumExtent()",
342 "Extent can be set only BEFORE creating any geometry object!");
352G4GeometryManager::ReportVoxelStats( std::vector<G4SmartVoxelStat> & stats,
355 G4cout <<
"G4GeometryManager::ReportVoxelStats -- Voxel Statistics"
364 for( i=0; i<nStat; ++i ) { totalMemory += stats[i].GetMemoryUse(); }
366 G4cout <<
" Total memory consumed for geometry optimisation: "
367 << totalMemory/1024 <<
" kByte" <<
G4endl;
368 G4cout <<
" Total CPU time elapsed for geometry optimisation: "
369 << std::setprecision(2) << totalCpuTime <<
" seconds"
370 << std::setprecision(6) <<
G4endl;
375 std::sort( stats.begin(), stats.end(),
378 return a.GetTotalTime() > b.GetTotalTime();
381 G4int nPrint = nStat > 10 ? 10 : nStat;
386 G4cout <<
" Percent Total CPU System CPU Memory Volume\n"
387 <<
" ------- ---------- ---------- -------- ----------"
392 for(i=0; i<nPrint; ++i)
395 G4double system = stats[i].GetSysTime();
398 if (system < 0) { system = 0.0; }
399 if ((total < 0) || (totalCpuTime < perMillion))
402 { perc =
total*100/totalCpuTime; }
404 G4cout << std::setprecision(2)
405 << std::setiosflags(std::ios::fixed|std::ios::right)
406 << std::setw(11) << perc
407 << std::setw(13) <<
total
408 << std::setw(13) << system
409 << std::setw(13) << (stats[i].GetMemoryUse()+512)/1024
410 <<
"k " << std::setiosflags(std::ios::left)
411 << stats[i].GetVolume()->GetName()
412 << std::resetiosflags(std::ios::floatfield|std::ios::adjustfield)
413 << std::setprecision(6)
420 std::sort( stats.begin(), stats.end(),
423 return a.GetMemoryUse() > b.GetMemoryUse();
428 G4cout <<
"\n Voxelisation: top memory users:" <<
G4endl;
429 G4cout <<
" Percent Memory Heads Nodes Pointers Total CPU Volume\n"
430 <<
" ------- -------- ------ ------ -------- ---------- ----------"
435 for(i=0; i<nPrint; ++i)
437 G4long memory = stats[i].GetMemoryUse();
438 G4double totTime = stats[i].GetTotalTime();
439 if (totTime < 0) { totTime = 0.0; }
441 G4cout << std::setprecision(2)
442 << std::setiosflags(std::ios::fixed|std::ios::right)
444 << std::setw(11) << memory/1024 <<
"k "
445 << std::setw( 9) << stats[i].GetNumberHeads()
446 << std::setw( 9) << stats[i].GetNumberNodes()
447 << std::setw(11) << stats[i].GetNumberPointers()
448 << std::setw(13) << totTime <<
" "
449 << std::setiosflags(std::ios::left)
450 << stats[i].GetVolume()->GetName()
451 << std::resetiosflags(std::ios::floatfield|std::ios::adjustfield)
452 << std::setprecision(6)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
G4GeometryManager()=default
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)
std::size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const std::size_t 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