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

#include <G4CachedMagneticField.hh>

+ Inheritance diagram for G4CachedMagneticField:

Public Member Functions

 G4CachedMagneticField (G4MagneticField *, G4double distanceConst)
 
 ~G4CachedMagneticField () override
 
 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
 
 G4MagneticField (const G4MagneticField &r)
 
G4MagneticFieldoperator= (const G4MagneticField &p)
 
G4bool DoesFieldChangeEnergy () const override
 
- Public Member Functions inherited from G4Field
 G4Field (G4bool gravityOn=false)
 
 G4Field (const G4Field &)
 
virtual ~G4Field ()
 
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

Definition at line 41 of file G4CachedMagneticField.hh.

Constructor & Destructor Documentation

◆ G4CachedMagneticField() [1/2]

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

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()

G4CachedMagneticField::~G4CachedMagneticField ( )
overridedefault

◆ G4CachedMagneticField() [2/2]

G4CachedMagneticField::G4CachedMagneticField ( const G4CachedMagneticField & r)

Definition at line 63 of file G4CachedMagneticField.cc.

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

Member Function Documentation

◆ ClearCounts()

void G4CachedMagneticField::ClearCounts ( )
inline

◆ Clone()

G4Field * G4CachedMagneticField::Clone ( ) const
overridevirtual

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 *, G4double distanceConst)
virtual G4Field * Clone() const
Definition G4Field.cc:49

◆ GetConstDistance()

G4double G4CachedMagneticField::GetConstDistance ( ) const
inline

Definition at line 56 of file G4CachedMagneticField.hh.

56{ return fDistanceConst; }

Referenced by G4NystromRK4::GetDistanceForConstantField().

◆ GetCountCalls()

G4int G4CachedMagneticField::GetCountCalls ( ) const
inline

Definition at line 59 of file G4CachedMagneticField.hh.

59{ return fCountCalls; }

◆ GetCountEvaluations()

G4int G4CachedMagneticField::GetCountEvaluations ( ) const
inline

Definition at line 60 of file G4CachedMagneticField.hh.

60{ return fCountEvaluations; }

◆ GetFieldValue()

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

Implements G4MagneticField.

Definition at line 88 of file G4CachedMagneticField.cc.

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

◆ operator=()

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

Definition at line 75 of file G4CachedMagneticField.cc.

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

◆ ReportStatistics()

void G4CachedMagneticField::ReportStatistics ( )

Definition at line 56 of file G4CachedMagneticField.cc.

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

◆ SetConstDistance()

void G4CachedMagneticField::SetConstDistance ( G4double dist)
inline

Definition at line 57 of file G4CachedMagneticField.hh.

57{ fDistanceConst= dist;}

Referenced by G4NystromRK4::SetDistanceForConstantField().

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: