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

G4ConstRK4 performs the integration of one step with error calculation in constant magnetic field. The integration method is the same as in ClassicalRK4. The field value is assumed constant for the step. This field evaluation is called only once per step. G4ConstRK4 can be used only for magnetic fields. More...

#include <G4ConstRK4.hh>

Inheritance diagram for G4ConstRK4:

Public Member Functions

 G4ConstRK4 (G4Mag_EqRhs *EquationMotion, G4int numberOfStateVariables=8)
 ~G4ConstRK4 () override
 G4ConstRK4 (const G4ConstRK4 &)=delete
G4ConstRK4operator= (const G4ConstRK4 &)=delete
void Stepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[], G4double yerr[]) override
void DumbStepper (const G4double yIn[], const G4double dydx[], G4double h, G4double yOut[]) override
G4double DistChord () const override
void RightHandSideConst (const G4double y[], G4double dydx[]) const
void GetConstField (const G4double y[], G4double Field[])
G4int IntegratorOrder () const override
G4StepperType StepperType () const override
Public Member Functions inherited from G4MagErrorStepper
 G4MagErrorStepper (G4EquationOfMotion *EqRhs, G4int numberOfVariables, G4int numStateVariables=12)
 ~G4MagErrorStepper () override
 G4MagErrorStepper (const G4MagErrorStepper &)=delete
G4MagErrorStepperoperator= (const G4MagErrorStepper &)=delete
void Stepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[], G4double yerr[]) override
G4double DistChord () const override
Public Member Functions inherited from G4MagIntegratorStepper
 G4MagIntegratorStepper (G4EquationOfMotion *Equation, G4int numIntegrationVariables, G4int numStateVariables=12, G4bool isFSAL=false)
virtual ~G4MagIntegratorStepper ()=default
 G4MagIntegratorStepper (const G4MagIntegratorStepper &)=delete
G4MagIntegratorStepperoperator= (const G4MagIntegratorStepper &)=delete
void NormaliseTangentVector (G4double vec[6])
void NormalisePolarizationVector (G4double vec[12])
void RightHandSide (const G4double y[], G4double dydx[]) const
void RightHandSide (const G4double y[], G4double dydx[], G4double field[]) const
G4int GetNumberOfVariables () const
G4int GetNumberOfStateVariables () const
G4int IntegrationOrder ()
G4EquationOfMotionGetEquationOfMotion ()
const G4EquationOfMotionGetEquationOfMotion () const
void SetEquationOfMotion (G4EquationOfMotion *newEquation)
unsigned long GetfNoRHSCalls ()
void ResetfNORHSCalls ()
G4bool IsFSAL () const
G4bool isQSS () const
void SetIsQSS (G4bool val)

Additional Inherited Members

Protected Member Functions inherited from G4MagIntegratorStepper
void SetIntegrationOrder (G4int order)
void SetFSAL (G4bool flag=true)

Detailed Description

G4ConstRK4 performs the integration of one step with error calculation in constant magnetic field. The integration method is the same as in ClassicalRK4. The field value is assumed constant for the step. This field evaluation is called only once per step. G4ConstRK4 can be used only for magnetic fields.

Definition at line 53 of file G4ConstRK4.hh.

Constructor & Destructor Documentation

◆ G4ConstRK4() [1/2]

G4ConstRK4::G4ConstRK4 ( G4Mag_EqRhs * EquationMotion,
G4int numberOfStateVariables = 8 )

Constructor for G4ConstRK4.

Parameters
[in]EqRhsPointer to the provided equation of motion.
[in]numberOfVariablesThe number of integration variables.

Definition at line 40 of file G4ConstRK4.cc.

41 : G4MagErrorStepper(EqRhs, 6, numStateVariables)
42{
43 // const G4int numberOfVariables= 6;
44 if( numStateVariables < 8 )
45 {
46 std::ostringstream message;
47 message << "The number of State variables at least 8 " << G4endl
48 << "Instead it is - numStateVariables= " << numStateVariables;
49 G4Exception("G4ConstRK4::G4ConstRK4()", "GeomField0002",
50 FatalException, message, "Use another Stepper!");
51 }
52
53 fEq = EqRhs;
54 yMiddle = new G4double[8];
55 dydxMid = new G4double[8];
56 yInitial = new G4double[8];
57 yOneStep = new G4double[8];
58
59 dydxm = new G4double[8];
60 dydxt = new G4double[8];
61 yt = new G4double[8];
62 Field[0]=0.; Field[1]=0.; Field[2]=0.;
63}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
double G4double
Definition G4Types.hh:83
#define G4endl
Definition G4ios.hh:67
G4MagErrorStepper(G4EquationOfMotion *EqRhs, G4int numberOfVariables, G4int numStateVariables=12)

Referenced by G4ConstRK4(), and operator=().

◆ ~G4ConstRK4()

G4ConstRK4::~G4ConstRK4 ( )
override

Destructor.

Definition at line 69 of file G4ConstRK4.cc.

70{
71 delete [] yMiddle;
72 delete [] dydxMid;
73 delete [] yInitial;
74 delete [] yOneStep;
75 delete [] dydxm;
76 delete [] dydxt;
77 delete [] yt;
78}

◆ G4ConstRK4() [2/2]

G4ConstRK4::G4ConstRK4 ( const G4ConstRK4 & )
delete

Copy constructor and assignment operator not allowed.

Member Function Documentation

◆ DistChord()

G4double G4ConstRK4::DistChord ( ) const
overridevirtual

Returns the distance from chord line.

Implements G4MagIntegratorStepper.

Definition at line 211 of file G4ConstRK4.cc.

212{
213 G4double distLine, distChord;
214
215 if (fInitialPoint != fFinalPoint)
216 {
217 distLine= G4LineSection::Distline( fMidPoint, fInitialPoint, fFinalPoint );
218 // This is a class method that gives distance of Mid
219 // from the Chord between the Initial and Final points
220 distChord = distLine;
221 }
222 else
223 {
224 distChord = (fMidPoint-fInitialPoint).mag();
225 }
226 return distChord;
227}
static G4double Distline(const G4ThreeVector &OtherPnt, const G4ThreeVector &LinePntA, const G4ThreeVector &LinePntB)

◆ DumbStepper()

void G4ConstRK4::DumbStepper ( const G4double yIn[],
const G4double dydx[],
G4double h,
G4double yOut[] )
overridevirtual

Given values for the variables y[0,..,n-1] and their derivatives dydx[0,...,n-1] known at x, uses the classical 4th Runge-Kutta method to advance the solution over an interval h and returns the incremented variables as yout[0,...,n-1]. The user supplies the function RightHandSide(x,y,dydx), which returns derivatives dydx at x. The source is routine rk4 from NRC p.712-713.

Parameters
[in]yStarting values array of integration variables.
[in]dydxDerivatives array.
[in]hThe given step size.
[out]youtIntegration output.

Implements G4MagErrorStepper.

Definition at line 90 of file G4ConstRK4.cc.

94{
95 G4double hh = h*0.5 , h6 = h/6.0 ;
96
97 // 1st Step K1=h*dydx
98 yt[5] = yIn[5] + hh*dydx[5] ;
99 yt[4] = yIn[4] + hh*dydx[4] ;
100 yt[3] = yIn[3] + hh*dydx[3] ;
101 yt[2] = yIn[2] + hh*dydx[2] ;
102 yt[1] = yIn[1] + hh*dydx[1] ;
103 yt[0] = yIn[0] + hh*dydx[0] ;
104 RightHandSideConst(yt,dydxt) ;
105
106 // 2nd Step K2=h*dydxt
107 yt[5] = yIn[5] + hh*dydxt[5] ;
108 yt[4] = yIn[4] + hh*dydxt[4] ;
109 yt[3] = yIn[3] + hh*dydxt[3] ;
110 yt[2] = yIn[2] + hh*dydxt[2] ;
111 yt[1] = yIn[1] + hh*dydxt[1] ;
112 yt[0] = yIn[0] + hh*dydxt[0] ;
113 RightHandSideConst(yt,dydxm) ;
114
115 // 3rd Step K3=h*dydxm
116 // now dydxm=(K2+K3)/h
117 yt[5] = yIn[5] + h*dydxm[5] ;
118 dydxm[5] += dydxt[5] ;
119 yt[4] = yIn[4] + h*dydxm[4] ;
120 dydxm[4] += dydxt[4] ;
121 yt[3] = yIn[3] + h*dydxm[3] ;
122 dydxm[3] += dydxt[3] ;
123 yt[2] = yIn[2] + h*dydxm[2] ;
124 dydxm[2] += dydxt[2] ;
125 yt[1] = yIn[1] + h*dydxm[1] ;
126 dydxm[1] += dydxt[1] ;
127 yt[0] = yIn[0] + h*dydxm[0] ;
128 dydxm[0] += dydxt[0] ;
129 RightHandSideConst(yt,dydxt) ;
130
131 // 4th Step K4=h*dydxt
132 yOut[5] = yIn[5]+h6*(dydx[5]+dydxt[5]+2.0*dydxm[5]);
133 yOut[4] = yIn[4]+h6*(dydx[4]+dydxt[4]+2.0*dydxm[4]);
134 yOut[3] = yIn[3]+h6*(dydx[3]+dydxt[3]+2.0*dydxm[3]);
135 yOut[2] = yIn[2]+h6*(dydx[2]+dydxt[2]+2.0*dydxm[2]);
136 yOut[1] = yIn[1]+h6*(dydx[1]+dydxt[1]+2.0*dydxm[1]);
137 yOut[0] = yIn[0]+h6*(dydx[0]+dydxt[0]+2.0*dydxm[0]);
138
139} // end of DumbStepper ....................................................
void RightHandSideConst(const G4double y[], G4double dydx[]) const

Referenced by Stepper().

◆ GetConstField()

void G4ConstRK4::GetConstField ( const G4double y[],
G4double Field[] )
inline

Returns the field values, at position and time 'y'.

Parameters
[in]yThe position vector plus time (x,y,z,t).
[out]FieldThe field value in output.

Definition at line 169 of file G4ConstRK4.hh.

170{
171 G4double PositionAndTime[4];
172
173 PositionAndTime[0] = y[0];
174 PositionAndTime[1] = y[1];
175 PositionAndTime[2] = y[2];
176 // Global Time
177 PositionAndTime[3] = y[7];
178 fEq -> GetFieldValue(PositionAndTime, B);
179}
G4double B(G4double temperature)

Referenced by Stepper().

◆ IntegratorOrder()

G4int G4ConstRK4::IntegratorOrder ( ) const
inlineoverridevirtual

Returns the order, 4, of integration.

Implements G4MagIntegratorStepper.

Definition at line 132 of file G4ConstRK4.hh.

132{ return 4; }

Referenced by Stepper().

◆ operator=()

G4ConstRK4 & G4ConstRK4::operator= ( const G4ConstRK4 & )
delete

◆ RightHandSideConst()

void G4ConstRK4::RightHandSideConst ( const G4double y[],
G4double dydx[] ) const
inline

Returns the derivatives value, at position and time 'y'.

Parameters
[in]yThe position vector plus time (x,y,z,t).
[out]dydxThe derivatives array.

Definition at line 151 of file G4ConstRK4.hh.

153{
154
155 G4double momentum_mag_square = y[3]*y[3] + y[4]*y[4] + y[5]*y[5];
156 G4double inv_momentum_magnitude = 1.0 / std::sqrt( momentum_mag_square );
157
158 G4double cof = fEq->FCof()*inv_momentum_magnitude;
159
160 dydx[0] = y[3]*inv_momentum_magnitude; // (d/ds)x = Vx/V
161 dydx[1] = y[4]*inv_momentum_magnitude; // (d/ds)y = Vy/V
162 dydx[2] = y[5]*inv_momentum_magnitude; // (d/ds)z = Vz/V
163
164 dydx[3] = cof*(y[4]*Field[2] - y[5]*Field[1]) ; // Ax = a*(Vy*Bz - Vz*By)
165 dydx[4] = cof*(y[5]*Field[0] - y[3]*Field[2]) ; // Ay = a*(Vz*Bx - Vx*Bz)
166 dydx[5] = cof*(y[3]*Field[1] - y[4]*Field[0]) ; // Az = a*(Vx*By - Vy*Bx)
167}

Referenced by DumbStepper(), and Stepper().

◆ Stepper()

void G4ConstRK4::Stepper ( const G4double y[],
const G4double dydx[],
G4double h,
G4double yout[],
G4double yerr[] )
overridevirtual

The stepper for the Runge Kutta integration. The stepsize is fixed, with the step size given by 'h'. Integrates ODE starting values y[0 to 6]. Outputs yout[] and its estimated error yerr[].

Parameters
[in]yStarting values array of integration variables.
[in]dydxDerivatives array.
[in]hThe given step size.
[out]youtIntegration output.
[out]yerrThe estimated error.

Implements G4MagIntegratorStepper.

Definition at line 146 of file G4ConstRK4.cc.

151{
152 const G4int nvar = 6; // number of variables integrated
153 const G4int maxvar = GetNumberOfStateVariables();
154
155 // Correction for Richardson extrapolation
156 G4double correction = 1. / ( (1 << IntegratorOrder()) -1 );
157
158 G4int i;
159
160 // Saving yInput because yInput and yOutput can be aliases for same array
161 for (i=0; i<maxvar; ++i) { yInitial[i]= yInput[i]; }
162
163 // Must copy the part of the state *not* integrated to the output
164 for (i=nvar; i<maxvar; ++i) { yOutput[i]= yInput[i]; }
165
166 // yInitial[7]= yInput[7]; // The time is typically needed
167 yMiddle[7] = yInput[7]; // Copy the time from initial value
168 yOneStep[7] = yInput[7]; // As it contributes to final value of yOutput ?
169 // yOutput[7] = yInput[7]; // -> dumb stepper does it too for RK4
170 yError[7] = 0.0;
171
172 G4double halfStep = hstep * 0.5;
173
174 // Do two half steps
175 //
176 GetConstField(yInitial,Field);
177 DumbStepper (yInitial, dydx, halfStep, yMiddle);
178 RightHandSideConst(yMiddle, dydxMid);
179 DumbStepper (yMiddle, dydxMid, halfStep, yOutput);
180
181 // Store midpoint, chord calculation
182 //
183 fMidPoint = G4ThreeVector( yMiddle[0], yMiddle[1], yMiddle[2]);
184
185 // Do a full Step
186 //
187 DumbStepper(yInitial, dydx, hstep, yOneStep);
188 for(i=0; i<nvar; ++i)
189 {
190 yError [i] = yOutput[i] - yOneStep[i] ;
191 yOutput[i] += yError[i]*correction ;
192 // Provides accuracy increased by 1 order via the
193 // Richardson extrapolation
194 }
195
196 fInitialPoint = G4ThreeVector( yInitial[0], yInitial[1], yInitial[2]);
197 fFinalPoint = G4ThreeVector( yOutput[0], yOutput[1], yOutput[2]);
198
199 return;
200}
CLHEP::Hep3Vector G4ThreeVector
int G4int
Definition G4Types.hh:85
G4int IntegratorOrder() const override
void DumbStepper(const G4double yIn[], const G4double dydx[], G4double h, G4double yOut[]) override
Definition G4ConstRK4.cc:90
void GetConstField(const G4double y[], G4double Field[])
G4int GetNumberOfStateVariables() const

◆ StepperType()

G4StepperType G4ConstRK4::StepperType ( ) const
inlineoverridevirtual

Returns the stepper type-ID, "kConstRK4".

Reimplemented from G4MagIntegratorStepper.

Definition at line 137 of file G4ConstRK4.hh.

137{ return kConstRK4; }
@ kConstRK4
G4ConstRK4.

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