Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4CachedMagneticField Class Reference

G4CachedMagneticField is a specialisation of G4MagneticField and is used to cache the Magnetic Field value, for fields whose evaluation is expensive. More...

#include <G4CachedMagneticField.hh>

Inheritance diagram for G4CachedMagneticField:

Public Member Functions

 G4CachedMagneticField (G4MagneticField *pMagField, G4double distance)
 ~G4CachedMagneticField () override=default
 G4CachedMagneticField (const G4CachedMagneticField &r)
G4CachedMagneticFieldoperator= (const G4CachedMagneticField &p)
void GetFieldValue (const G4double Point[4], G4double *Bfield) const override
G4double GetConstDistance () const
void SetConstDistance (G4double dist)
G4int GetCountCalls () const
G4int GetCountEvaluations () const
void ClearCounts ()
void ReportStatistics ()
G4FieldClone () const override
Public Member Functions inherited from G4MagneticField
 G4MagneticField ()
 ~G4MagneticField () override=default
 G4MagneticField (const G4MagneticField &r)
G4MagneticFieldoperator= (const G4MagneticField &p)
G4bool DoesFieldChangeEnergy () const override
G4FieldType GetFieldType () const override
Public Member Functions inherited from G4Field
 G4Field (G4bool gravityOn=false)
virtual ~G4Field ()=default
 G4Field (const G4Field &p)=default
G4Fieldoperator= (const G4Field &p)
G4bool IsGravityActive () const
void SetGravityActive (G4bool OnOffFlag)

Protected Attributes

G4int fCountCalls = 0
G4int fCountEvaluations = 0

Additional Inherited Members

Static Public Attributes inherited from G4Field
static constexpr G4int MAX_NUMBER_OF_COMPONENTS = 24

Detailed Description

G4CachedMagneticField is a specialisation of G4MagneticField and is used to cache the Magnetic Field value, for fields whose evaluation is expensive.

Definition at line 47 of file G4CachedMagneticField.hh.

Constructor & Destructor Documentation

◆ G4CachedMagneticField() [1/2]

G4CachedMagneticField::G4CachedMagneticField ( G4MagneticField * pMagField,
G4double distance )

Constructor for G4CachedMagneticField.

Parameters
[in]pMagFieldPointer to the original magnetic field.
[in]distanceDistance for field evaluation, within which the field does not change.

Definition at line 33 of file G4CachedMagneticField.cc.

35 : fpMagneticField(pMagField), fDistanceConst(distance),
36 fLastLocation(DBL_MAX,DBL_MAX,DBL_MAX), fLastValue(DBL_MAX,DBL_MAX,DBL_MAX)
37{
38 ClearCounts();
39}
#define DBL_MAX
Definition templates.hh:62

Referenced by Clone(), G4CachedMagneticField(), operator=(), and ~G4CachedMagneticField().

◆ ~G4CachedMagneticField()

G4CachedMagneticField::~G4CachedMagneticField ( )
overridedefault

Default Destructor.

◆ G4CachedMagneticField() [2/2]

G4CachedMagneticField::G4CachedMagneticField ( const G4CachedMagneticField & r)

Copy constructor and assignment operator.

Definition at line 61 of file G4CachedMagneticField.cc.

63 : G4MagneticField(rightCMF)
64{
65 fpMagneticField= rightCMF.fpMagneticField; // NOTE: sharing pointer here!
66 fDistanceConst = rightCMF.fDistanceConst;
67 fLastLocation = rightCMF.fLastLocation;
68 fLastValue = rightCMF.fLastValue;
69 ClearCounts();
70}

Member Function Documentation

◆ ClearCounts()

void G4CachedMagneticField::ClearCounts ( )
inline

◆ Clone()

G4Field * G4CachedMagneticField::Clone ( ) const
overridevirtual

Returns a pointer of an allocated clone of the field.

Reimplemented from G4Field.

Definition at line 41 of file G4CachedMagneticField.cc.

42{
43 // Cannot use copy constructor: need to clone the associated magnetic field
44
45 auto aF = static_cast<G4MagneticField*>(fpMagneticField->Clone());
46 auto cloned = new G4CachedMagneticField(aF, fDistanceConst);
47
48 cloned->fLastLocation = fLastLocation;
49 cloned->fLastValue = fLastValue;
50 return cloned;
51}
G4CachedMagneticField(G4MagneticField *pMagField, G4double distance)

◆ GetConstDistance()

G4double G4CachedMagneticField::GetConstDistance ( ) const
inline

Getter and setter for the distance within which field is constant.

Definition at line 81 of file G4CachedMagneticField.hh.

81{ return fDistanceConst; }

◆ GetCountCalls()

G4int G4CachedMagneticField::GetCountCalls ( ) const
inline

Accessors.

Definition at line 87 of file G4CachedMagneticField.hh.

87{ return fCountCalls; }

◆ GetCountEvaluations()

G4int G4CachedMagneticField::GetCountEvaluations ( ) const
inline

Definition at line 88 of file G4CachedMagneticField.hh.

88{ return fCountEvaluations; }

◆ GetFieldValue()

void G4CachedMagneticField::GetFieldValue ( const G4double Point[4],
G4double * Bfield ) const
overridevirtual

Returns the value of the field at the give 'Point'.

Parameters
[in]PointThe given position time vector (x,y,z,t).
[out]BfieldThe returned field array.

Implements G4MagneticField.

Definition at line 86 of file G4CachedMagneticField.cc.

88{
89 G4ThreeVector newLocation( Point[0], Point[1], Point[2] );
90
91 G4double distSq= (newLocation-fLastLocation).mag2();
93 if( distSq < fDistanceConst*fDistanceConst )
94 {
95 Bfield[0] = fLastValue.x();
96 Bfield[1] = fLastValue.y();
97 Bfield[2] = fLastValue.z();
98 }
99 else
100 {
101 fpMagneticField->GetFieldValue( Point, Bfield );
103 fLastLocation = G4ThreeVector( Point[0], Point[1], Point[2] );
104 fLastValue = G4ThreeVector( Bfield[0], Bfield[1], Bfield[2] );
105 }
106}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83

◆ operator=()

G4CachedMagneticField & G4CachedMagneticField::operator= ( const G4CachedMagneticField & p)

Definition at line 73 of file G4CachedMagneticField.cc.

74{
75 if (&p == this) { return *this; }
77 fpMagneticField= p.fpMagneticField; // NOTE: sharing pointer here!
78 fDistanceConst = p.fDistanceConst;
79 fLastLocation = p.fLastLocation;
80 fLastValue = p.fLastValue;
81 ClearCounts();
82 return *this;
83}
G4MagneticField & operator=(const G4MagneticField &p)

◆ ReportStatistics()

void G4CachedMagneticField::ReportStatistics ( )

Streams on standard output the values of counters.

Definition at line 54 of file G4CachedMagneticField.cc.

55{
56 G4cout << " Cached field: " << G4endl
57 << " Number of calls: " << fCountCalls << G4endl
58 << " Number of evaluations : " << fCountEvaluations << G4endl;
59}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

◆ SetConstDistance()

void G4CachedMagneticField::SetConstDistance ( G4double dist)
inline

Definition at line 82 of file G4CachedMagneticField.hh.

82{ fDistanceConst = dist;}

Member Data Documentation

◆ fCountCalls

G4int G4CachedMagneticField::fCountCalls = 0
mutableprotected

◆ fCountEvaluations

G4int G4CachedMagneticField::fCountEvaluations = 0
protected

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