Geant4 10.7.0
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)
 
virtual ~G4CachedMagneticField ()
 
 G4CachedMagneticField (const G4CachedMagneticField &r)
 
G4CachedMagneticFieldoperator= (const G4CachedMagneticField &p)
 
virtual void GetFieldValue (const G4double Point[4], G4double *Bfield) const
 
G4double GetConstDistance () const
 
void SetConstDistance (G4double dist)
 
G4int GetCountCalls () const
 
G4int GetCountEvaluations () const
 
void ClearCounts ()
 
void ReportStatistics ()
 
virtual G4FieldClone () const
 
- Public Member Functions inherited from G4MagneticField
 G4MagneticField ()
 
virtual ~G4MagneticField ()
 
 G4MagneticField (const G4MagneticField &r)
 
G4MagneticFieldoperator= (const G4MagneticField &p)
 
G4bool DoesFieldChangeEnergy () const
 
virtual void GetFieldValue (const G4double Point[4], G4double *Bfield) const =0
 
- Public Member Functions inherited from G4Field
 G4Field (G4bool gravityOn=false)
 
 G4Field (const G4Field &)
 
virtual ~G4Field ()
 
G4Fieldoperator= (const G4Field &p)
 
virtual void GetFieldValue (const G4double Point[4], G4double *fieldArr) const =0
 
virtual G4bool DoesFieldChangeEnergy () const =0
 
G4bool IsGravityActive () const
 
void SetGravityActive (G4bool OnOffFlag)
 
virtual G4FieldClone () const
 

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 : G4MagneticField(), 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

◆ ~G4CachedMagneticField()

G4CachedMagneticField::~G4CachedMagneticField ( )
virtual

Definition at line 53 of file G4CachedMagneticField.cc.

54{
55}

◆ G4CachedMagneticField() [2/2]

G4CachedMagneticField::G4CachedMagneticField ( const G4CachedMagneticField r)

Definition at line 65 of file G4CachedMagneticField.cc.

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

Member Function Documentation

◆ ClearCounts()

void G4CachedMagneticField::ClearCounts ( )
inline

◆ Clone()

G4Field * G4CachedMagneticField::Clone ( ) const
virtual

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 G4MagneticField* aF = static_cast<G4MagneticField*>(fpMagneticField->Clone());
46 G4CachedMagneticField* cloned = new G4CachedMagneticField(aF, fDistanceConst);
47
48 cloned->fLastLocation = fLastLocation;
49 cloned->fLastValue = fLastValue;
50 return cloned;
51}
virtual G4Field * Clone() const
Definition: G4Field.cc:54

◆ 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
virtual

Implements G4MagneticField.

Definition at line 90 of file G4CachedMagneticField.cc.

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

◆ operator=()

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

Definition at line 77 of file G4CachedMagneticField.cc.

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

◆ ReportStatistics()

void G4CachedMagneticField::ReportStatistics ( )

Definition at line 58 of file G4CachedMagneticField.cc.

59{
60 G4cout << " Cached field: " << G4endl
61 << " Number of calls: " << fCountCalls << G4endl
62 << " Number of evaluations : " << fCountEvaluations << G4endl;
63}
#define G4endl
Definition: G4ios.hh:57
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: