74G4bool G4GeometryManager::fParallelVoxelOptimisationRequested =
true;
77G4bool G4GeometryManager::fOptimiseInParallelConfigured =
false;
85G4GeometryManager::G4GeometryManager()
93 if( fParallelVoxeliser ==
nullptr )
95 fParallelVoxeliser=
new G4VoxelisationHelper();
105 fgInstance =
nullptr;
113 if( fParallelVoxeliser !=
nullptr )
115 delete fParallelVoxeliser;
116 fParallelVoxeliser =
nullptr;
134 if (pVolume !=
nullptr)
136 workDone= BuildOptimisations(pOptimise, pVolume);
140 workDone= BuildOptimisations(pOptimise, verbose);
142 fIsClosed = workDone;
153 if( fOptimiseInParallelConfigured )
155 fIsClosed= fParallelVoxeliser->IsParallelOptimisationFinished();
170 if (pVolume !=
nullptr)
172 DeleteOptimisations(pVolume);
176 DeleteOptimisations();
190 if (fgInstance ==
nullptr)
192 fgInstance =
new G4GeometryManager;
221 return fParallelVoxeliser->IsParallelOptimisationFinished();
231 return fOptimiseInParallelConfigured;
242 G4bool finishedOptimisation =
false;
244 fOptimiseInParallelConfigured = fParallelVoxelOptimisationRequested
247 if( fOptimiseInParallelConfigured )
253 BuildOptimisationsSequential(allOpts, verbose);
254 finishedOptimisation=
true;
258 return finishedOptimisation;
270void G4GeometryManager::BuildOptimisationsSequential(
G4bool allOpts,
275 std::vector<G4SmartVoxelStat> stats;
277 if (verbose) { allTimer.
Start(); }
280 G4LogicalVolume* volume;
281 G4SmartVoxelHeader* head;
283#ifdef G4GEOMETRY_VOXELDEBUG
285 <<
"*** G4GeometryManager::BuildOptimisationsSequential() called on tid "
289 for (
auto & n : *Store)
291 if (verbose) { timer.
Start(); }
305#ifdef G4GEOMETRY_VOXELDEBUG
306 G4cout <<
"** G4GeometryManager::BuildOptimisationsSequential()"
307 <<
" Examining logical volume name = '" << volume->
GetName()
310 head =
new G4SmartVoxelHeader(volume);
318 std::ostringstream message;
319 message <<
"VoxelHeader allocation error." <<
G4endl
320 <<
"Allocation of new VoxelHeader" <<
G4endl
321 <<
" for volume '" << volume->
GetName() <<
"' failed.";
322 G4Exception(
"G4GeometryManager::BuildOptimisations()",
"GeomMgt0003",
328 stats.emplace_back( volume, head,
336#ifdef G4GEOMETRY_VOXELDEBUG
338 G4cout <<
"- Skipping logical volume with " << numDaughters
339 <<
" daughters and name = '" << volume->
GetName() <<
"' " <<
G4endl;
340 if( numDaughters > 1 )
346 if( numDaughters == 1 )
371 fParallelVoxelOptimisationRequested = flag;
374 fParallelVoxeliser->SetVerbosity(verbose);
384 fParallelVoxeliser->UndertakeOptimisation();
393G4bool G4GeometryManager::BuildOptimisations(
G4bool allOpts,
396 if (pVolume ==
nullptr) {
return false; }
402 if (tVolume ==
nullptr)
404 G4bool done=BuildOptimisations(allOpts,
false);
416 head =
new G4SmartVoxelHeader(tVolume);
423 std::ostringstream message;
424 message <<
"VoxelHeader allocation error." <<
G4endl
425 <<
"Allocation of new VoxelHeader" <<
G4endl
426 <<
" for volume " << tVolume->
GetName() <<
" failed.";
427 G4Exception(
"G4GeometryManager::BuildOptimisations()",
"GeomMgt0003",
434#ifdef G4GEOMETRY_VOXELDEBUG
435 G4cout <<
"** G4GeometryManager::BuildOptimisations()" <<
G4endl
436 <<
" Skipping logical volume name = " << tVolume->
GetName()
446 BuildOptimisations(allOpts, tVolume->
GetDaughter(0));
457void G4GeometryManager::DeleteOptimisations()
459 G4LogicalVolume* tVolume =
nullptr;
461 for (
auto & n : *Store)
476 if (pVolume ==
nullptr) {
return; }
482 if (tVolume ==
nullptr) {
return DeleteOptimisations(); }
507 G4Exception(
"G4GeometryManager::SetMaximumExtent()",
509 "Extent can be set only BEFORE creating any geometry object!");
G4TemplateAutoLock< G4Mutex > G4AutoLock
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4bool IsReplicated() const override
#define G4MUTEX_INITIALIZER
G4GLOB_DLL std::ostream G4cout
G4GeometryManager is a singleton class responsible for high level geometrical functions,...
G4bool IsGeometryClosed()
static G4GeometryManager * GetInstance()
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
void SetWorldMaximumExtent(G4double worldExtent)
void OptimiseInParallel(G4bool val=true)
void RequestParallelOptimisation(G4bool val=true, G4bool verbose=true)
G4bool IsParallelOptimisationConfigured()
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
void UndertakeOptimisation()
static G4GeometryManager * GetInstanceIfExist()
G4bool IsParallelOptimisationFinished()
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
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4LogicalVolume * GetMotherLogical() const
virtual G4bool IsReplicated() const =0
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetRegularStructureId() const =0
G4VoxelisationHelper is a helper class to undertake voxelisation in parallel, aiding and off-loading ...
static void ReportVoxelStats(std::vector< G4SmartVoxelStat > &stats, G4double totalCpuTime, std::ostream &os=G4cout)
void PrepareParallelOptimisation(G4bool allOpts, G4bool verbose)
G4bool IsMultithreadedApplication()
const G4int kMinVoxelVolumesLevel1