Import Geant4 11.3.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2024-06-28 13:08:51 +02:00
parent f7b23877ed
commit e58e650b32
5232 changed files with 239416 additions and 244360 deletions
@@ -47,7 +47,7 @@ class G4ErrorTarget
{
public:
G4ErrorTarget();
G4ErrorTarget() = default;
virtual ~G4ErrorTarget() = default;
virtual G4double GetDistanceFromPoint( const G4ThreeVector&,
@@ -35,9 +35,10 @@
// Member data:
//
// - fgInstance
// Ptr to the unique instance of class
// Ptr to the unique instance of class (per Thread)
// 26.07.95, P.Kent - Initial version, including optimisation build
// 12.06.24, J.Apostolakis - Added parallel optimisation in workers
// --------------------------------------------------------------------
#ifndef G4GEOMETRYMANAGER_HH
#define G4GEOMETRYMANAGER_HH 1
@@ -46,8 +47,10 @@
#include "G4Types.hh"
#include "G4SmartVoxelStat.hh"
#include "G4ios.hh"
class G4VPhysicalVolume;
class G4Timer;
class G4GeometryManager
{
@@ -78,26 +81,115 @@ class G4GeometryManager
static G4GeometryManager* GetInstanceIfExist();
// Return ptr to singleton instance.
public:
static void OptimizeInParallel(G4bool val = true);
// Request optimization using threads (if MT is enabled & used ).
void UndertakeOptimisation();
// Method that contributes to (Voxel) optimisation until all work is done.
// Must be called by Worker thread initialisation - not a user callable
// method.
static void RequestParallelOptimisation(G4bool val = true,
G4bool verbose = true);
// Detailed method for user to request parallel Optimisation
// (if verbosity is required). Calling this is enough to ask for it.
// It will be used if Geant4 is built with MT/tasks.
static void ChooseSequentialOptimisation(G4bool verbose = false);
// Simple way to avoid parallel optimisation.
static G4bool IsParallelOptimisationConfigured();
// Check whether parallel optimisation was requested.
static G4bool IsParallelOptimisationFinished();
// Report whether parallel optimisation is done.
~G4GeometryManager();
// Destructor.
protected:
G4GeometryManager() = default;
// Protected constructor. Set the geometry to be open
// Destructor; called by G4RunManagerKernel.
private:
void BuildOptimisations(G4bool allOpt, G4bool verbose = false);
G4GeometryManager() = default;
// Private constructor. Set the geometry to be open.
G4bool BuildOptimisations(G4bool allOpt, G4bool verbose = false);
// Optimise all or just multi-volumes (parameterisations, .. ).
void BuildOptimisations(G4bool allOpt, G4VPhysicalVolume* vol);
// Optimise one volume or subtree only.
void DeleteOptimisations();
void DeleteOptimisations(G4VPhysicalVolume* vol);
static void ReportVoxelStats( std::vector<G4SmartVoxelStat>& stats,
G4double totalCpuTime );
void ReportVoxelStats( std::vector<G4SmartVoxelStat>& stats,
G4double totalCpuTime,
std::ostream &os = G4cout );
void ReportVoxelInfo(G4LogicalVolume * logVolume, std::ostream& os);
void PrepareParallelOptimisation(G4bool allOpts, G4bool verbose = true);
void BuildOptimisationsSequential(G4bool allOpts, G4bool verbose = true);
// Methods for parallel initialization
void CreateListOfVolumesToOptimise(G4bool allOpts, G4bool verbose);
// Build vector of relevant volumes.
G4LogicalVolume* ObtainVolumeToOptimize();
static G4ThreadLocal G4GeometryManager* fgInstance;
static G4ThreadLocal G4bool fIsClosed;
static std::vector<G4LogicalVolume*> fVolumesToOptimize;
// The list of volumes which threads need to optimize.
static std::vector<G4LogicalVolume*>::iterator fLogVolumeIterator;
// Iterator used by UndertakeOptimisation().
static std::vector<G4SmartVoxelStat> fGlobVoxelStats;
// Statistics container shared by all workers
static void ConfigureParallelOptimisation(G4bool verbose);
// Prepare for parallel optimisation.
G4int ReportWorkerIsDoneOptimising(unsigned int numVolumesOptimized);
// Thread-safe method for worker to report it's finished its work.
// It counts the number of workers that finished, and returns count.
// It counts the number of volumes optimised; if all workers have
// reported, it results in a 'Finished' state.
static void InformOptimisationIsFinished(G4bool verbose);
// Returns true if all workers are finished (or all work is done).
static void ResetListOfVolumesToOptimise();
// Resets (empties) the list of candidate volumes for optimisation.
// Must be called when Optimisation is finished.
G4int CheckOptimisation();
// Check volumes marked to optimised are done, and report number
// that are missing voxel header.
void WaitForVoxelisationFinish(G4bool verbose = false);
// Wait until the voxelisation is all done.
private:
// Flags for parallel initialization
// ---------------------------------
static G4bool fVerboseParallel;
static G4bool fParallelVoxelOptimisationRequested;
// Flag to register it was requested.
static G4bool fOptimizeInParallelConfigured;
// Not just requested, but adopted (i.e. also in MT/tasking mode).
static G4bool fParallelVoxelOptimisationUnderway; // It has started
static G4bool fParallelVoxelOptimisationFinished; // It is done
static G4bool fUsingExistingWorkers;
// Fact: can and will use existing MT/tasks.
// Statistics for parallel Optimisation - used in 'verbose' mode
// ------------------------------------
static G4double fSumVoxelTime;
static G4int fNumberThreadsReporting;
static unsigned int fTotalNumberVolumesOptimized;
// Counters.
// For Wall Clock time in parallel mode ...
//
static G4Timer* fWallClockTimer; // Owned by master thread
static G4bool fWallClockStarted;
};
#endif
@@ -86,6 +86,10 @@ class G4ReflectedSolid : public G4VSolid
G4ThreeVector GetPointOnSurface() const override;
G4int GetNumOfConstituents() const override;
G4bool IsFaceted() const override;
G4VSolid* Clone() const override;
G4GeometryType GetEntityType() const override;
@@ -51,7 +51,6 @@
#include "geomwdefs.hh"
#include "G4Types.hh"
#include "G4Allocator.hh"
using G4SliceVector = std::vector<G4int>;
@@ -102,11 +101,6 @@ class G4SmartVoxelNode
G4bool operator == (const G4SmartVoxelNode& v) const;
// Equality operator.
inline void* operator new(std::size_t);
// Override "new" for "G4Allocator".
inline void operator delete(void* aNode);
// Override "delete" for "G4Allocator".
private:
G4int fminEquivalent;
@@ -27,25 +27,6 @@
//
// --------------------------------------------------------------------
extern G4GEOM_DLL G4Allocator<G4SmartVoxelNode>*& aNodeAllocator();
// --------------------------------------------------------------------
inline
void* G4SmartVoxelNode::operator new(std::size_t)
{
if(aNodeAllocator() == nullptr)
{
aNodeAllocator() = new G4Allocator<G4SmartVoxelNode>;
}
return (void*) aNodeAllocator()->MallocSingle();
}
// --------------------------------------------------------------------
inline
void G4SmartVoxelNode::operator delete(void* aNode)
{
aNodeAllocator()->FreeSingle((G4SmartVoxelNode*) aNode);
}
// --------------------------------------------------------------------
inline
@@ -43,7 +43,6 @@
#include "geomwdefs.hh"
#include "G4Types.hh"
#include "G4Allocator.hh"
class G4SmartVoxelNode;
class G4SmartVoxelHeader;
@@ -80,11 +79,6 @@ class G4SmartVoxelProxy
// Equality operator.
// True when objects share same address.
inline void* operator new(std::size_t);
// Override "new" for "G4Allocator".
inline void operator delete(void* aProxy);
// Override "delete" for "G4Allocator".
private:
G4SmartVoxelHeader* fHeader = nullptr;
@@ -27,26 +27,6 @@
//
// --------------------------------------------------------------------
extern G4GEOM_DLL G4Allocator<G4SmartVoxelProxy>*& aProxyAllocator();
// --------------------------------------------------------------------
inline
void* G4SmartVoxelProxy::operator new(std::size_t)
{
if(aProxyAllocator() == nullptr)
{
aProxyAllocator() = new G4Allocator<G4SmartVoxelProxy>;
}
return (void*) aProxyAllocator()->MallocSingle();
}
// --------------------------------------------------------------------
inline
void G4SmartVoxelProxy::operator delete(void* aProxy)
{
aProxyAllocator()->FreeSingle((G4SmartVoxelProxy*) aProxy);
}
// --------------------------------------------------------------------
inline
G4bool G4SmartVoxelProxy::IsHeader() const
@@ -165,6 +165,13 @@ class G4UAdapter : public G4VSolid, protected UnplacedVolume_t
virtual G4ThreeVector GetPointOnSurface() const override;
// Returns a random point located on the surface of the solid.
virtual G4int GetNumOfConstituents() const override;
// Returns the number of constituents used for construction of the solid.
// For non-Boolean solids the return value is one.
virtual G4bool IsFaceted() const override;
// Returns true if the solid has only planar faces, false otherwise.
virtual G4GeometryType GetEntityType() const override;
// Provide identification of the class of an object.
// (required for persistency)
@@ -412,6 +419,18 @@ G4ThreeVector G4UAdapter<UnplacedVolume_t>::GetPointOnSurface() const
return G4ThreeVector(p.x(), p.y(), p.z());
}
template <class UnplacedVolume_t>
G4int G4UAdapter<UnplacedVolume_t>::GetNumOfConstituents() const
{
return 1;
}
template <class UnplacedVolume_t>
G4bool G4UAdapter<UnplacedVolume_t>::IsFaceted() const
{
return false;
}
// Inline visualization adapters
namespace
@@ -161,7 +161,7 @@ class G4VSolid
virtual void ComputeDimensions(G4VPVParameterisation* p,
const G4int n,
const G4VPhysicalVolume* pRep);
// Throw exception if ComputeDimensions called frrom an illegal
// Throw exception if ComputeDimensions called from an illegal
// derived class.
virtual G4double GetCubicVolume();
@@ -186,6 +186,13 @@ class G4VSolid
// Returns a random point located on the surface of the solid.
// Points returned are not necessarily uniformly distributed.
virtual G4int GetNumOfConstituents() const;
// Returns the number of constituents of the solid.
// For non-Boolean solids the return value is one.
virtual G4bool IsFaceted() const;
// Returns true if the solid has only planar faces, false otherwise.
virtual G4VSolid* Clone() const;
// Returns a pointer of a dynamically allocated copy of the solid.
// Returns NULL pointer with warning in case the concrete solid does not