Warning, file /include/Geant4/G4TClassicalRK4.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 #ifndef G4TCLASSICALRK4_HH
0037 #define G4TCLASSICALRK4_HH
0038
0039 #include "G4ThreeVector.hh"
0040 #include "G4MagIntegratorStepper.hh"
0041 #include "G4TMagErrorStepper.hh"
0042
0043
0044
0045
0046
0047
0048 template <class T_Equation, unsigned int N>
0049 class G4TClassicalRK4 : public G4TMagErrorStepper<G4TClassicalRK4<T_Equation, N>, T_Equation, N>
0050 {
0051 public:
0052
0053 static constexpr G4double IntegratorCorrection = 1. / ((1 << 4) - 1);
0054
0055 G4TClassicalRK4(T_Equation* EqRhs, G4int numberOfVariables = 8);
0056
0057 ~G4TClassicalRK4() override = default;
0058
0059 G4TClassicalRK4(const G4TClassicalRK4&) = delete;
0060 G4TClassicalRK4& operator=(const G4TClassicalRK4&) = delete;
0061
0062 void RightHandSideInl(G4double y[], G4double dydx[])
0063 {
0064 fEquation_Rhs->T_Equation::RightHandSide(y, dydx);
0065 }
0066
0067
0068
0069
0070 inline void DumbStepper(const G4double yIn[],
0071 const G4double dydx[],
0072 G4double h,
0073 G4double yOut[]);
0074
0075 G4int IntegratorOrder() const { return 4; }
0076
0077 private:
0078
0079 G4double dydxm[N < 8 ? 8 : N];
0080 G4double dydxt[N < 8 ? 8 : N];
0081 G4double yt[N < 8 ? 8 : N];
0082
0083
0084 T_Equation* fEquation_Rhs;
0085 };
0086
0087 template <class T_Equation, unsigned int N >
0088 G4TClassicalRK4<T_Equation,N>::
0089 G4TClassicalRK4(T_Equation* EqRhs, G4int numberOfVariables)
0090 : G4TMagErrorStepper<G4TClassicalRK4<T_Equation, N>, T_Equation, N>(
0091 EqRhs, numberOfVariables > 8 ? numberOfVariables : 8 )
0092 , fEquation_Rhs(EqRhs)
0093 {
0094
0095 if( dynamic_cast<G4EquationOfMotion*>(EqRhs) == nullptr )
0096 {
0097 G4Exception("G4TClassicalRK4: constructor", "GeomField0001",
0098 FatalException, "Equation is not an G4EquationOfMotion.");
0099 }
0100 }
0101
0102 template <class T_Equation, unsigned int N >
0103 void
0104 G4TClassicalRK4<T_Equation,N>::DumbStepper(const G4double yIn[],
0105 const G4double dydx[],
0106 G4double h,
0107 G4double yOut[])
0108
0109
0110
0111
0112
0113
0114
0115 {
0116 G4double hh = h * 0.5, h6 = h / 6.0;
0117
0118
0119
0120
0121 yt[7] = yIn[7];
0122 yOut[7] = yIn[7];
0123
0124 for(unsigned int i = 0; i < N; ++i)
0125 {
0126 yt[i] = yIn[i] + hh * dydx[i];
0127 }
0128 this->RightHandSideInl(yt, dydxt);
0129
0130 for(unsigned int i = 0; i < N; ++i)
0131 {
0132 yt[i] = yIn[i] + hh * dydxt[i];
0133 }
0134 this->RightHandSideInl(yt, dydxm);
0135
0136 for(unsigned int i = 0; i < N; ++i)
0137 {
0138 yt[i] = yIn[i] + h * dydxm[i];
0139 dydxm[i] += dydxt[i];
0140 }
0141 this->RightHandSideInl(yt, dydxt);
0142
0143 for(unsigned int i = 0; i < N; ++i)
0144 {
0145 yOut[i] = yIn[i] + h6 * (dydx[i] + dydxt[i] +
0146 2.0 * dydxm[i]);
0147 }
0148 if(N == 12)
0149 {
0150 this->NormalisePolarizationVector(yOut);
0151 }
0152 }
0153
0154 #endif