File indexing completed on 2025-01-18 09:59:14
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
0039
0040
0041
0042
0043
0044
0045
0046
0047 #ifndef TSIMPLEHEUM_HH
0048 #define TSIMPLEHEUM_HH
0049
0050 #include <cassert>
0051 #include "G4TMagErrorStepper.hh"
0052 #include "G4ThreeVector.hh"
0053
0054 template <class T_Equation, unsigned int N>
0055 class G4TSimpleHeum
0056 : public G4TMagErrorStepper<G4TSimpleHeum<T_Equation, N>, T_Equation, N>
0057 {
0058 public:
0059 constexpr static unsigned int gIntegratorOrder = 3;
0060 static constexpr double IntegratorCorrection= 1.0 /
0061 ((1<<gIntegratorOrder) - 1);
0062
0063 G4TSimpleHeum(T_Equation* EqRhs, unsigned int numberOfVariables = 6);
0064
0065 ~G4TSimpleHeum() { ; }
0066
0067
0068 inline void RightHandSide(G4double y[],
0069 G4double dydx[])
0070 {
0071 fEquation_Rhs->T_Equation::RightHandSide(y, dydx);
0072 }
0073
0074 inline void DumbStepper(const G4double yIn[],
0075 const G4double dydx[],
0076 G4double h, G4double yOut[]);
0077
0078 public:
0079 G4int IntegratorOrder() const { return gIntegratorOrder; }
0080
0081 private:
0082 G4int fNumberOfVariables;
0083
0084 G4double dydxTemp[N];
0085 G4double dydxTemp2[N];
0086 G4double yTemp[N];
0087 G4double yTemp2[N];
0088
0089
0090 T_Equation* fEquation_Rhs;
0091 };
0092
0093 template <class T_Equation, unsigned int N >
0094 G4TSimpleHeum<T_Equation,N>::G4TSimpleHeum(T_Equation* EqRhs,
0095 unsigned int numberOfVariables )
0096 : G4TMagErrorStepper<G4TSimpleHeum<T_Equation, N>, T_Equation, N>(
0097 EqRhs, numberOfVariables)
0098 , fNumberOfVariables(numberOfVariables)
0099 , fEquation_Rhs(EqRhs)
0100 {
0101 assert(fNumberOfVariables == N);
0102 if( dynamic_cast<G4EquationOfMotion*>(EqRhs) == nullptr )
0103 {
0104 G4Exception("G4TSimpleHeum: constructor", "GeomField0001",
0105 FatalException, "Equation is not an G4EquationOfMotion.");
0106 }
0107 }
0108
0109 template <class T_Equation, unsigned int N >
0110 inline void
0111 G4TSimpleHeum<T_Equation,N>::DumbStepper(const G4double yIn[],
0112 const G4double dydx[],
0113 G4double h, G4double yOut[])
0114 {
0115 for(unsigned int i = 0; i < N; ++i)
0116 {
0117 yTemp[i] = yIn[i] + (1.0 / 3.0) * h * dydx[i];
0118 }
0119
0120 this->RightHandSide(yTemp, dydxTemp);
0121
0122 for(unsigned int i = 0; i < N; ++i)
0123 {
0124 yTemp2[i] = yIn[i] + (2.0 / 3.0) * h * dydxTemp[i];
0125 }
0126
0127 this->RightHandSide(yTemp2, dydxTemp2);
0128
0129 for(unsigned int i = 0; i < N; ++i)
0130 {
0131 yOut[i] = yIn[i] + h * (0.25 * dydx[i] + 0.75 * dydxTemp2[i]);
0132 }
0133
0134 if(fNumberOfVariables == 12)
0135 {
0136 this->NormalisePolarizationVector(yOut);
0137 }
0138 }
0139
0140 #endif