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

#include <G4BorisScheme.hh>

Public Member Functions

 G4BorisScheme ()=default
 
 G4BorisScheme (G4EquationOfMotion *equation, G4int nvar=6)
 
 ~G4BorisScheme ()=default
 
void DoStep (G4double restMass, G4double charge, const G4double yIn[], G4double yOut[], G4double hstep) const
 
void StepWithErrorEstimate (const G4double yIn[], G4double restMass, G4double charge, G4double hstep, G4double yOut[], G4double yErr[]) const
 
void StepWithMidAndErrorEstimate (const G4double yIn[], G4double restMass, G4double charge, G4double hstep, G4double yMid[], G4double yOut[], G4double yErr[]) const
 
G4EquationOfMotionGetEquationOfMotion ()
 
G4int GetNumberOfVariables () const
 

Protected Member Functions

void UpdatePosition (const G4double restMass, const G4double charge, const G4double yIn[], G4double yOut[], G4double hstep) const
 
void UpdateVelocity (const G4double restMass, const G4double charge, const G4double yIn[], G4double yOut[], G4double hstep) const
 

Detailed Description

Definition at line 49 of file G4BorisScheme.hh.

Constructor & Destructor Documentation

◆ G4BorisScheme() [1/2]

G4BorisScheme::G4BorisScheme ( )
default

◆ G4BorisScheme() [2/2]

G4BorisScheme::G4BorisScheme ( G4EquationOfMotion equation,
G4int  nvar = 6 
)

Definition at line 42 of file G4BorisScheme.cc.

44 : fEquation(equation), fnvar(nvar)
45{
46 if (nvar <= 0)
47 {
48 G4Exception("G4BorisScheme::G4BorisScheme()",
49 "GeomField0002", FatalException,
50 "Invalid number of variables; must be greater than zero!");
51 }
52}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59

◆ ~G4BorisScheme()

G4BorisScheme::~G4BorisScheme ( )
default

Member Function Documentation

◆ DoStep()

void G4BorisScheme::DoStep ( G4double  restMass,
G4double  charge,
const G4double  yIn[],
G4double  yOut[],
G4double  hstep 
) const

Definition at line 54 of file G4BorisScheme.cc.

56{
59
60 // Used the scheme described in the following paper:https://www.research-collection.ethz.ch/bitstream/handle/20.500.11850/153167/eth-5175-01.pdf?sequence=1
61 UpdatePosition(restMass, charge, yIn, yOut1Temp, hstep/2);
62 UpdateVelocity(restMass, charge, yOut1Temp, yOut2Temp, hstep);
63 UpdatePosition(restMass, charge, yOut2Temp, yOut, hstep/2);
64}
double G4double
Definition: G4Types.hh:83
void UpdateVelocity(const G4double restMass, const G4double charge, const G4double yIn[], G4double yOut[], G4double hstep) const
void UpdatePosition(const G4double restMass, const G4double charge, const G4double yIn[], G4double yOut[], G4double hstep) const

Referenced by StepWithMidAndErrorEstimate().

◆ GetEquationOfMotion()

G4EquationOfMotion * G4BorisScheme::GetEquationOfMotion ( )
inline

◆ GetNumberOfVariables()

G4int G4BorisScheme::GetNumberOfVariables ( ) const
inline

◆ StepWithErrorEstimate()

void G4BorisScheme::StepWithErrorEstimate ( const G4double  yIn[],
G4double  restMass,
G4double  charge,
G4double  hstep,
G4double  yOut[],
G4double  yErr[] 
) const

Definition at line 159 of file G4BorisScheme.cc.

162{
163 // Use two half-steps (comparing to a full step) to obtain output and error estimate
165 StepWithMidAndErrorEstimate(yIn, restMass, charge, hstep, yMid, yOut, yErr);
166}
void StepWithMidAndErrorEstimate(const G4double yIn[], G4double restMass, G4double charge, G4double hstep, G4double yMid[], G4double yOut[], G4double yErr[]) const

Referenced by G4BorisDriver::OneGoodStep().

◆ StepWithMidAndErrorEstimate()

void G4BorisScheme::StepWithMidAndErrorEstimate ( const G4double  yIn[],
G4double  restMass,
G4double  charge,
G4double  hstep,
G4double  yMid[],
G4double  yOut[],
G4double  yErr[] 
) const

Definition at line 170 of file G4BorisScheme.cc.

174{
175 G4double halfStep= 0.5*hstep;
177
178 // In a single step
179 DoStep(restMass, charge, yIn, yOutAlt, hstep );
180
181 // Same, and also return mid-point evaluation
182 DoStep(restMass, charge, yIn, yMid, halfStep );
183 DoStep(restMass, charge, yMid, yOut, halfStep );
184
185 for( G4int i= 0; i<fnvar; i++ )
186 {
187 yErr[i] = yOutAlt[i] - yOut[i];
188 }
189}
int G4int
Definition: G4Types.hh:85
void DoStep(G4double restMass, G4double charge, const G4double yIn[], G4double yOut[], G4double hstep) const

Referenced by G4BorisDriver::QuickAdvance(), and StepWithErrorEstimate().

◆ UpdatePosition()

void G4BorisScheme::UpdatePosition ( const G4double  restMass,
const G4double  charge,
const G4double  yIn[],
G4double  yOut[],
G4double  hstep 
) const
protected

Definition at line 66 of file G4BorisScheme.cc.

68{
69 // Particle information
70 copy(yOut, yIn);
71
72 // Obtaining velocity
73 G4ThreeVector momentum_vec =G4ThreeVector(yIn[3],yIn[4],yIn[5]);
74 G4double momentum_mag = momentum_vec.mag();
75 G4ThreeVector momentum_dir =(1.0/momentum_mag)*momentum_vec;
76
77 G4double velocity_mag = momentum_mag*(c_l)/(std::sqrt(sqr(momentum_mag) +sqr(restMass)));
78 G4ThreeVector velocity = momentum_dir*velocity_mag;
79
80 //Obtaining the time step from the length step
81
82 hstep /= velocity_mag*CLHEP::m;
83
84 // Updating the Position
85 for(G4int i = 0; i <3; i++ )
86 {
87 G4double pos = yIn[i]/CLHEP::m;
88 pos += hstep*velocity[i];
89 yOut[i] = pos*CLHEP::m;
90 }
91}
CLHEP::Hep3Vector G4ThreeVector
double mag() const
T sqr(const T &x)
Definition: templates.hh:128

Referenced by DoStep().

◆ UpdateVelocity()

void G4BorisScheme::UpdateVelocity ( const G4double  restMass,
const G4double  charge,
const G4double  yIn[],
G4double  yOut[],
G4double  hstep 
) const
protected

Definition at line 93 of file G4BorisScheme.cc.

95{
96 //Particle information
97 G4ThreeVector momentum_vec =G4ThreeVector(yIn[3],yIn[4],yIn[5]);
98 G4double momentum_mag = momentum_vec.mag();
99 G4ThreeVector momentum_dir =(1.0/momentum_mag)*momentum_vec;
100
101 G4double gamma = std::sqrt(sqr(momentum_mag) + sqr(restMass))/restMass;
102
103 G4double mass = (restMass/c_squared)/CLHEP::kg;
104
105 //Obtaining velocity
106
107 G4double velocity_mag = momentum_mag*(c_l)/(std::sqrt(sqr(momentum_mag) +sqr(restMass)));
108 G4ThreeVector velocity = momentum_dir*velocity_mag;
109
110 ////Obtaining the time step from the length step
111
112 hstep /= velocity_mag*CLHEP::m;
113
114 // Obtaining the field values
116 G4double fieldValue[6] ={0,0,0,0,0,0};
117 fEquation->EvaluateRhsReturnB(yIn, dydx, fieldValue);
118
119 //Initializing Vectors
122 copy(yOut, yIn);
123 for( G4int i = 0; i < 3; i++)
124 {
125 E[i] = fieldValue[i+3]/CLHEP::volt*CLHEP::meter;// FIXME - Check Units
126 B[i] = fieldValue[i]/CLHEP::tesla;
127 }
128
129 //Boris Algorithm
130 G4double qd = hstep*(charge/(2*mass*gamma));
131 G4ThreeVector h = qd*B;
132 G4ThreeVector u = velocity + qd*E;
133 G4double h_l = h[0]*h[0] + h[1]*h[1] + h[2]*h[2];
134 G4ThreeVector s_1 = (2*h)/(1 + h_l);
135 G4ThreeVector ud = u + (u + u.cross(h)).cross(s_1);
136 G4ThreeVector v_fi = ud +qd*E;
137 G4double v_mag = std::sqrt(v_fi.mag2());
138 G4ThreeVector v_dir = v_fi/v_mag;
139 G4double momen_mag = (restMass*v_mag)/(std::sqrt(c_l*c_l - v_mag*v_mag));
140 G4ThreeVector momen = momen_mag*v_dir;
141
142 // Storing the updated momentum
143 for(int i = 3; i < 6; i++)
144 {
145 yOut[i] = momen[i-3];
146 }
147}
G4double B(G4double temperature)
double mag2() const
Hep3Vector cross(const Hep3Vector &) const
void EvaluateRhsReturnB(const G4double y[], G4double dydx[], G4double Field[]) const

Referenced by DoStep().


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