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

#include <G4ConstRK4.hh>

+ Inheritance diagram for G4ConstRK4:

Public Member Functions

 G4ConstRK4 (G4Mag_EqRhs *EquationMotion, G4int numberOfStateVariables=8)
 
 ~G4ConstRK4 ()
 
 G4ConstRK4 (const G4ConstRK4 &)=delete
 
G4ConstRK4operator= (const G4ConstRK4 &)=delete
 
void Stepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[], G4double yerr[])
 
void DumbStepper (const G4double yIn[], const G4double dydx[], G4double h, G4double yOut[])
 
G4double DistChord () const
 
void RightHandSideConst (const G4double y[], G4double dydx[]) const
 
void GetConstField (const G4double y[], G4double Field[])
 
G4int IntegratorOrder () const
 
- Public Member Functions inherited from G4MagErrorStepper
 G4MagErrorStepper (G4EquationOfMotion *EqRhs, G4int numberOfVariables, G4int numStateVariables=12)
 
virtual ~G4MagErrorStepper ()
 
 G4MagErrorStepper (const G4MagErrorStepper &)=delete
 
G4MagErrorStepperoperator= (const G4MagErrorStepper &)=delete
 
void Stepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[], G4double yerr[])
 
virtual void DumbStepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[])=0
 
G4double DistChord () const
 
- 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
 
virtual void Stepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[], G4double yerr[])=0
 
virtual G4double DistChord () const =0
 
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
 
virtual G4int IntegratorOrder () const =0
 
G4int IntegrationOrder ()
 
G4EquationOfMotionGetEquationOfMotion ()
 
const G4EquationOfMotionGetEquationOfMotion () const
 
void SetEquationOfMotion (G4EquationOfMotion *newEquation)
 
unsigned long GetfNoRHSCalls ()
 
void ResetfNORHSCalls ()
 
G4bool IsFSAL () const
 

Additional Inherited Members

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

Detailed Description

Definition at line 45 of file G4ConstRK4.hh.

Constructor & Destructor Documentation

◆ G4ConstRK4() [1/2]

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

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)
Definition: G4Exception.cc:35
double G4double
Definition: G4Types.hh:83
#define G4endl
Definition: G4ios.hh:57

◆ ~G4ConstRK4()

G4ConstRK4::~G4ConstRK4 ( )

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

Member Function Documentation

◆ DistChord()

G4double G4ConstRK4::DistChord ( ) const
virtual

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[] 
)
virtual

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
Definition: G4ConstRK4.hh:88

Referenced by Stepper().

◆ GetConstField()

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

Definition at line 106 of file G4ConstRK4.hh.

107{
108 G4double PositionAndTime[4];
109
110 PositionAndTime[0] = y[0];
111 PositionAndTime[1] = y[1];
112 PositionAndTime[2] = y[2];
113 // Global Time
114 PositionAndTime[3] = y[7];
115 fEq -> GetFieldValue(PositionAndTime, B);
116}

Referenced by Stepper().

◆ IntegratorOrder()

G4int G4ConstRK4::IntegratorOrder ( ) const
inlinevirtual

Implements G4MagIntegratorStepper.

Definition at line 74 of file G4ConstRK4.hh.

74{ return 4; }

Referenced by Stepper().

◆ operator=()

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

◆ RightHandSideConst()

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

Definition at line 88 of file G4ConstRK4.hh.

90{
91
92 G4double momentum_mag_square = y[3]*y[3] + y[4]*y[4] + y[5]*y[5];
93 G4double inv_momentum_magnitude = 1.0 / std::sqrt( momentum_mag_square );
94
95 G4double cof = fEq->FCof()*inv_momentum_magnitude;
96
97 dydx[0] = y[3]*inv_momentum_magnitude; // (d/ds)x = Vx/V
98 dydx[1] = y[4]*inv_momentum_magnitude; // (d/ds)y = Vy/V
99 dydx[2] = y[5]*inv_momentum_magnitude; // (d/ds)z = Vz/V
100
101 dydx[3] = cof*(y[4]*Field[2] - y[5]*Field[1]) ; // Ax = a*(Vy*Bz - Vz*By)
102 dydx[4] = cof*(y[5]*Field[0] - y[3]*Field[2]) ; // Ay = a*(Vz*Bx - Vx*Bz)
103 dydx[5] = cof*(y[3]*Field[1] - y[4]*Field[0]) ; // Az = a*(Vx*By - Vy*Bx)
104}
G4double FCof() const
Definition: G4Mag_EqRhs.hh:62

Referenced by DumbStepper(), and Stepper().

◆ Stepper()

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

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
void DumbStepper(const G4double yIn[], const G4double dydx[], G4double h, G4double yOut[])
Definition: G4ConstRK4.cc:90
G4int IntegratorOrder() const
Definition: G4ConstRK4.hh:74
void GetConstField(const G4double y[], G4double Field[])
Definition: G4ConstRK4.hh:106
G4int GetNumberOfStateVariables() const

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