Geant4-11
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Static Private Attributes
G4GeometryManager Class Reference

#include <G4GeometryManager.hh>

Public Member Functions

G4bool CloseGeometry (G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
 
void OpenGeometry (G4VPhysicalVolume *vol=nullptr)
 
void SetWorldMaximumExtent (G4double worldExtent)
 
 ~G4GeometryManager ()
 

Static Public Member Functions

static G4GeometryManagerGetInstance ()
 
static G4GeometryManagerGetInstanceIfExist ()
 
static G4bool IsGeometryClosed ()
 

Protected Member Functions

 G4GeometryManager ()=default
 

Private Member Functions

void BuildOptimisations (G4bool allOpt, G4bool verbose=false)
 
void BuildOptimisations (G4bool allOpt, G4VPhysicalVolume *vol)
 
void DeleteOptimisations ()
 
void DeleteOptimisations (G4VPhysicalVolume *vol)
 

Static Private Member Functions

static void ReportVoxelStats (std::vector< G4SmartVoxelStat > &stats, G4double totalCpuTime)
 

Static Private Attributes

static G4ThreadLocal G4GeometryManagerfgInstance = nullptr
 
static G4ThreadLocal G4bool fIsClosed = false
 

Detailed Description

Definition at line 52 of file G4GeometryManager.hh.

Constructor & Destructor Documentation

◆ ~G4GeometryManager()

G4GeometryManager::~G4GeometryManager ( )

Definition at line 65 of file G4GeometryManager.cc.

66{
67 fgInstance = nullptr;
68 fIsClosed = false;
69}
static G4ThreadLocal G4GeometryManager * fgInstance
static G4ThreadLocal G4bool fIsClosed

References fgInstance, and fIsClosed.

◆ G4GeometryManager()

G4GeometryManager::G4GeometryManager ( )
protecteddefault

Referenced by GetInstance().

Member Function Documentation

◆ BuildOptimisations() [1/2]

void G4GeometryManager::BuildOptimisations ( G4bool  allOpt,
G4bool  verbose = false 
)
private

Definition at line 155 of file G4GeometryManager.cc.

156{
157 G4Timer timer;
158 G4Timer allTimer;
159 std::vector<G4SmartVoxelStat> stats;
160 if (verbose) { allTimer.Start(); }
161
163 G4LogicalVolume* volume;
164 G4SmartVoxelHeader* head;
165
166 for (size_t n=0; n<Store->size(); ++n)
167 {
168 if (verbose) timer.Start();
169 volume=(*Store)[n];
170 // For safety, check if there are any existing voxels and
171 // delete before replacement
172 //
173 head = volume->GetVoxelHeader();
174 delete head;
175 volume->SetVoxelHeader(nullptr);
176 if ( ( (volume->IsToOptimise())
177 && (volume->GetNoDaughters()>=kMinVoxelVolumesLevel1&&allOpts) )
178 || ( (volume->GetNoDaughters()==1)
179 && (volume->GetDaughter(0)->IsReplicated()==true)
180 && (volume->GetDaughter(0)->GetRegularStructureId()!=1) ) )
181 {
182#ifdef G4GEOMETRY_VOXELDEBUG
183 G4cout << "**** G4GeometryManager::BuildOptimisations" << G4endl
184 << " Examining logical volume name = "
185 << volume->GetName() << G4endl;
186#endif
187 head = new G4SmartVoxelHeader(volume);
188 if (head != nullptr)
189 {
190 volume->SetVoxelHeader(head);
191 }
192 else
193 {
194 std::ostringstream message;
195 message << "VoxelHeader allocation error." << G4endl
196 << "Allocation of new VoxelHeader" << G4endl
197 << " for volume " << volume->GetName() << " failed.";
198 G4Exception("G4GeometryManager::BuildOptimisations()", "GeomMgt0003",
199 FatalException, message);
200 }
201 if (verbose)
202 {
203 timer.Stop();
204 stats.push_back( G4SmartVoxelStat( volume, head,
205 timer.GetSystemElapsed(),
206 timer.GetUserElapsed() ) );
207 }
208 }
209 else
210 {
211 // Don't create voxels for this node
212#ifdef G4GEOMETRY_VOXELDEBUG
213 G4cout << "**** G4GeometryManager::BuildOptimisations" << G4endl
214 << " Skipping logical volume name = " << volume->GetName()
215 << G4endl;
216#endif
217 }
218 }
219 if (verbose)
220 {
221 allTimer.Stop();
222 ReportVoxelStats( stats, allTimer.GetSystemElapsed()
223 + allTimer.GetUserElapsed() );
224 }
225}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static void ReportVoxelStats(std::vector< G4SmartVoxelStat > &stats, G4double totalCpuTime)
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
void Stop()
G4double GetSystemElapsed() const
Definition: G4Timer.cc:132
G4double GetUserElapsed() const
Definition: G4Timer.cc:143
void Start()
virtual G4bool IsReplicated() const =0
virtual G4int GetRegularStructureId() const =0
const G4int kMinVoxelVolumesLevel1
Definition: voxeldefs.hh:39

References FatalException, G4cout, G4endl, G4Exception(), G4LogicalVolume::GetDaughter(), G4LogicalVolumeStore::GetInstance(), G4LogicalVolume::GetName(), G4LogicalVolume::GetNoDaughters(), G4VPhysicalVolume::GetRegularStructureId(), G4Timer::GetSystemElapsed(), G4Timer::GetUserElapsed(), G4LogicalVolume::GetVoxelHeader(), G4VPhysicalVolume::IsReplicated(), G4LogicalVolume::IsToOptimise(), kMinVoxelVolumesLevel1, CLHEP::detail::n, ReportVoxelStats(), G4LogicalVolume::SetVoxelHeader(), G4Timer::Start(), and G4Timer::Stop().

Referenced by BuildOptimisations(), and CloseGeometry().

◆ BuildOptimisations() [2/2]

void G4GeometryManager::BuildOptimisations ( G4bool  allOpt,
G4VPhysicalVolume vol 
)
private

Definition at line 231 of file G4GeometryManager.cc.

233{
234 if (pVolume == nullptr) { return; }
235
236 // Retrieve the mother logical volume, if not NULL,
237 // otherwise apply global optimisation for the world volume
238 //
239 G4LogicalVolume* tVolume = pVolume->GetMotherLogical();
240 if (tVolume == nullptr) { return BuildOptimisations(allOpts, false); }
241
242 G4SmartVoxelHeader* head = tVolume->GetVoxelHeader();
243 delete head;
244 tVolume->SetVoxelHeader(nullptr);
245 if ( ( (tVolume->IsToOptimise())
246 && (tVolume->GetNoDaughters()>=kMinVoxelVolumesLevel1&&allOpts) )
247 || ( (tVolume->GetNoDaughters()==1)
248 && (tVolume->GetDaughter(0)->IsReplicated()==true) ) )
249 {
250 head = new G4SmartVoxelHeader(tVolume);
251 if (head != nullptr)
252 {
253 tVolume->SetVoxelHeader(head);
254 }
255 else
256 {
257 std::ostringstream message;
258 message << "VoxelHeader allocation error." << G4endl
259 << "Allocation of new VoxelHeader" << G4endl
260 << " for volume " << tVolume->GetName() << " failed.";
261 G4Exception("G4GeometryManager::BuildOptimisations()", "GeomMgt0003",
262 FatalException, message);
263 }
264 }
265 else
266 {
267 // Don't create voxels for this node
268#ifdef G4GEOMETRY_VOXELDEBUG
269 G4cout << "**** G4GeometryManager::BuildOptimisations" << G4endl
270 << " Skipping logical volume name = " << tVolume->GetName()
271 << G4endl;
272#endif
273 }
274
275 // Scan recursively the associated logical volume tree
276 //
277 tVolume = pVolume->GetLogicalVolume();
278 if (tVolume->GetNoDaughters())
279 {
280 BuildOptimisations(allOpts, tVolume->GetDaughter(0));
281 }
282}
void BuildOptimisations(G4bool allOpt, G4bool verbose=false)

References BuildOptimisations(), FatalException, G4cout, G4endl, G4Exception(), G4LogicalVolume::GetDaughter(), G4VPhysicalVolume::GetLogicalVolume(), G4VPhysicalVolume::GetMotherLogical(), G4LogicalVolume::GetName(), G4LogicalVolume::GetNoDaughters(), G4LogicalVolume::GetVoxelHeader(), G4VPhysicalVolume::IsReplicated(), G4LogicalVolume::IsToOptimise(), kMinVoxelVolumesLevel1, and G4LogicalVolume::SetVoxelHeader().

◆ CloseGeometry()

G4bool G4GeometryManager::CloseGeometry ( G4bool  pOptimise = true,
G4bool  verbose = false,
G4VPhysicalVolume vol = nullptr 
)

◆ DeleteOptimisations() [1/2]

void G4GeometryManager::DeleteOptimisations ( )
private

Definition at line 289 of file G4GeometryManager.cc.

290{
291 G4LogicalVolume* tVolume = nullptr;
293 for (size_t n=0; n<Store->size(); ++n)
294 {
295 tVolume=(*Store)[n];
296 delete tVolume->GetVoxelHeader();
297 tVolume->SetVoxelHeader(nullptr);
298 }
299}

References G4LogicalVolumeStore::GetInstance(), G4LogicalVolume::GetVoxelHeader(), CLHEP::detail::n, and G4LogicalVolume::SetVoxelHeader().

Referenced by DeleteOptimisations(), and OpenGeometry().

◆ DeleteOptimisations() [2/2]

void G4GeometryManager::DeleteOptimisations ( G4VPhysicalVolume vol)
private

Definition at line 306 of file G4GeometryManager.cc.

307{
308 if (!pVolume) { return; }
309
310 // Retrieve the mother logical volume, if not NULL,
311 // otherwise global deletion to world volume.
312 //
313 G4LogicalVolume* tVolume = pVolume->GetMotherLogical();
314 if (tVolume == nullptr) { return DeleteOptimisations(); }
315 delete tVolume->GetVoxelHeader();
316 tVolume->SetVoxelHeader(nullptr);
317
318 // Scan recursively the associated logical volume tree
319 //
320 tVolume = pVolume->GetLogicalVolume();
321 if (tVolume->GetNoDaughters())
322 {
323 DeleteOptimisations(tVolume->GetDaughter(0));
324 }
325}

References DeleteOptimisations(), G4LogicalVolume::GetDaughter(), G4VPhysicalVolume::GetLogicalVolume(), G4VPhysicalVolume::GetMotherLogical(), G4LogicalVolume::GetNoDaughters(), G4LogicalVolume::GetVoxelHeader(), and G4LogicalVolume::SetVoxelHeader().

◆ GetInstance()

G4GeometryManager * G4GeometryManager::GetInstance ( )
static

◆ GetInstanceIfExist()

G4GeometryManager * G4GeometryManager::GetInstanceIfExist ( )
static

Definition at line 145 of file G4GeometryManager.cc.

146{
147 return fgInstance;
148}

References fgInstance.

Referenced by G4RunManagerKernel::~G4RunManagerKernel().

◆ IsGeometryClosed()

G4bool G4GeometryManager::IsGeometryClosed ( )
static

◆ OpenGeometry()

void G4GeometryManager::OpenGeometry ( G4VPhysicalVolume vol = nullptr)

◆ ReportVoxelStats()

void G4GeometryManager::ReportVoxelStats ( std::vector< G4SmartVoxelStat > &  stats,
G4double  totalCpuTime 
)
staticprivate

Definition at line 351 of file G4GeometryManager.cc.

353{
354 G4cout << "G4GeometryManager::ReportVoxelStats -- Voxel Statistics"
355 << G4endl << G4endl;
356
357 //
358 // Get total memory use
359 //
360 G4int i, nStat = stats.size();
361 G4long totalMemory = 0;
362
363 for( i=0; i<nStat; ++i ) { totalMemory += stats[i].GetMemoryUse(); }
364
365 G4cout << " Total memory consumed for geometry optimisation: "
366 << totalMemory/1024 << " kByte" << G4endl;
367 G4cout << " Total CPU time elapsed for geometry optimisation: "
368 << std::setprecision(2) << totalCpuTime << " seconds"
369 << std::setprecision(6) << G4endl;
370
371 //
372 // First list: sort by total CPU time
373 //
374 std::sort( stats.begin(), stats.end(),
375 [](const G4SmartVoxelStat& a, const G4SmartVoxelStat& b)
376 {
377 return a.GetTotalTime() > b.GetTotalTime();
378 } );
379
380 G4int nPrint = nStat > 10 ? 10 : nStat;
381
382 if (nPrint)
383 {
384 G4cout << "\n Voxelisation: top CPU users:" << G4endl;
385 G4cout << " Percent Total CPU System CPU Memory Volume\n"
386 << " ------- ---------- ---------- -------- ----------"
387 << G4endl;
388 // 12345678901.234567890123.234567890123.234567890123k .
389 }
390
391 for(i=0; i<nPrint; ++i)
392 {
393 G4double total = stats[i].GetTotalTime();
394 G4double system = stats[i].GetSysTime();
395 G4double perc = 0.0;
396
397 if (system < 0) { system = 0.0; }
398 if ((total < 0) || (totalCpuTime < perMillion))
399 { total = 0; }
400 else
401 { perc = total*100/totalCpuTime; }
402
403 G4cout << std::setprecision(2)
404 << std::setiosflags(std::ios::fixed|std::ios::right)
405 << std::setw(11) << perc
406 << std::setw(13) << total
407 << std::setw(13) << system
408 << std::setw(13) << (stats[i].GetMemoryUse()+512)/1024
409 << "k " << std::setiosflags(std::ios::left)
410 << stats[i].GetVolume()->GetName()
411 << std::resetiosflags(std::ios::floatfield|std::ios::adjustfield)
412 << std::setprecision(6)
413 << G4endl;
414 }
415
416 //
417 // Second list: sort by memory use
418 //
419 std::sort( stats.begin(), stats.end(),
420 [](const G4SmartVoxelStat& a, const G4SmartVoxelStat& b)
421 {
422 return a.GetMemoryUse() > b.GetMemoryUse();
423 } );
424
425 if (nPrint)
426 {
427 G4cout << "\n Voxelisation: top memory users:" << G4endl;
428 G4cout << " Percent Memory Heads Nodes Pointers Total CPU Volume\n"
429 << " ------- -------- ------ ------ -------- ---------- ----------"
430 << G4endl;
431 // 12345678901.2345678901k .23456789.23456789.2345678901.234567890123. .
432 }
433
434 for(i=0; i<nPrint; ++i)
435 {
436 G4long memory = stats[i].GetMemoryUse();
437 G4double totTime = stats[i].GetTotalTime();
438 if (totTime < 0) { totTime = 0.0; }
439
440 G4cout << std::setprecision(2)
441 << std::setiosflags(std::ios::fixed|std::ios::right)
442 << std::setw(11) << G4double(memory*100)/G4double(totalMemory)
443 << std::setw(11) << memory/1024 << "k "
444 << std::setw( 9) << stats[i].GetNumberHeads()
445 << std::setw( 9) << stats[i].GetNumberNodes()
446 << std::setw(11) << stats[i].GetNumberPointers()
447 << std::setw(13) << totTime << " "
448 << std::setiosflags(std::ios::left)
449 << stats[i].GetVolume()->GetName()
450 << std::resetiosflags(std::ios::floatfield|std::ios::adjustfield)
451 << std::setprecision(6)
452 << G4endl;
453 }
454}
static constexpr double perMillion
Definition: G4SIunits.hh:327
double G4double
Definition: G4Types.hh:83
long G4long
Definition: G4Types.hh:87
int G4int
Definition: G4Types.hh:85
G4double total(Particle const *const p1, Particle const *const p2)

References G4cout, G4endl, perMillion, and G4INCL::CrossSections::total().

Referenced by BuildOptimisations().

◆ SetWorldMaximumExtent()

void G4GeometryManager::SetWorldMaximumExtent ( G4double  worldExtent)

Definition at line 332 of file G4GeometryManager.cc.

333{
334 if (G4SolidStore::GetInstance()->size())
335 {
336 // Sanity check to assure that extent is fixed BEFORE creating
337 // any geometry object (solids in this case)
338 //
339 G4Exception("G4GeometryManager::SetMaximumExtent()",
340 "GeomMgt0003", FatalException,
341 "Extent can be set only BEFORE creating any geometry object!");
342 }
344}
void SetSurfaceTolerance(G4double worldExtent)
static G4GeometryTolerance * GetInstance()
static G4SolidStore * GetInstance()

References FatalException, G4Exception(), G4SolidStore::GetInstance(), G4GeometryTolerance::GetInstance(), and G4GeometryTolerance::SetSurfaceTolerance().

Referenced by export_G4GeometryManager().

Field Documentation

◆ fgInstance

G4ThreadLocal G4GeometryManager * G4GeometryManager::fgInstance = nullptr
staticprivate

Definition at line 99 of file G4GeometryManager.hh.

Referenced by GetInstance(), GetInstanceIfExist(), and ~G4GeometryManager().

◆ fIsClosed

G4ThreadLocal G4bool G4GeometryManager::fIsClosed = false
staticprivate

The documentation for this class was generated from the following files: