File indexing completed on 2025-01-18 09:58:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifndef G4CONSTRK4_HH
0039 #define G4CONSTRK4_HH
0040
0041 #include "G4MagErrorStepper.hh"
0042 #include "G4EquationOfMotion.hh"
0043 #include "G4Mag_EqRhs.hh"
0044
0045 class G4ConstRK4 : public G4MagErrorStepper
0046 {
0047 public:
0048
0049 G4ConstRK4(G4Mag_EqRhs* EquationMotion, G4int numberOfStateVariables=8);
0050 ~G4ConstRK4() override;
0051
0052 G4ConstRK4(const G4ConstRK4&) = delete;
0053 G4ConstRK4& operator=(const G4ConstRK4&) = delete;
0054
0055
0056 void Stepper( const G4double y[],
0057 const G4double dydx[],
0058 G4double h,
0059 G4double yout[],
0060 G4double yerr[] ) override;
0061 void DumbStepper( const G4double yIn[],
0062 const G4double dydx[],
0063 G4double h,
0064 G4double yOut[] ) override ;
0065 G4double DistChord() const override;
0066
0067 inline void RightHandSideConst(const G4double y[],
0068 G4double dydx[] ) const;
0069
0070 inline void GetConstField(const G4double y[], G4double Field[]);
0071
0072 G4int IntegratorOrder() const override { return 4; }
0073
0074 private:
0075
0076 G4ThreeVector fInitialPoint, fMidPoint, fFinalPoint;
0077
0078 G4double *dydxm, *dydxt, *yt;
0079 G4double *yInitial, *yMiddle, *dydxMid, *yOneStep;
0080 G4Mag_EqRhs* fEq = nullptr;
0081 G4double Field[3];
0082 };
0083
0084
0085
0086 inline void G4ConstRK4::RightHandSideConst(const G4double y[],
0087 G4double dydx[] ) const
0088 {
0089
0090 G4double momentum_mag_square = y[3]*y[3] + y[4]*y[4] + y[5]*y[5];
0091 G4double inv_momentum_magnitude = 1.0 / std::sqrt( momentum_mag_square );
0092
0093 G4double cof = fEq->FCof()*inv_momentum_magnitude;
0094
0095 dydx[0] = y[3]*inv_momentum_magnitude;
0096 dydx[1] = y[4]*inv_momentum_magnitude;
0097 dydx[2] = y[5]*inv_momentum_magnitude;
0098
0099 dydx[3] = cof*(y[4]*Field[2] - y[5]*Field[1]) ;
0100 dydx[4] = cof*(y[5]*Field[0] - y[3]*Field[2]) ;
0101 dydx[5] = cof*(y[3]*Field[1] - y[4]*Field[0]) ;
0102 }
0103
0104 inline void G4ConstRK4::GetConstField(const G4double y[], G4double B[])
0105 {
0106 G4double PositionAndTime[4];
0107
0108 PositionAndTime[0] = y[0];
0109 PositionAndTime[1] = y[1];
0110 PositionAndTime[2] = y[2];
0111
0112 PositionAndTime[3] = y[7];
0113 fEq -> GetFieldValue(PositionAndTime, B);
0114 }
0115
0116 #endif