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10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/magneticfield/include/G4TMagErrorStepper.hh (Version 11.3.0) and /geometry/magneticfield/include/G4TMagErrorStepper.hh (Version 10.7.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4TMagErrorStepper                              26 // G4TMagErrorStepper
 27 //                                                 27 //
 28 // Class description:                              28 // Class description:
 29 //                                                 29 //
 30 // Templated version of G4MagErrorStepper          30 // Templated version of G4MagErrorStepper
 31 //                                                 31 //
 32 //                                                 32 //
 33 // Created: Josh Xie  (supported by Google Sum     33 // Created: Josh Xie  (supported by Google Summer of Code 2014 )
 34 // Supervisors:  Sandro Wenzel, John Apostolak     34 // Supervisors:  Sandro Wenzel, John Apostolakis (CERN)
 35 // Adapted from G4G4TMagErrorStepper class         35 // Adapted from G4G4TMagErrorStepper class
 36 // -------------------------------------------     36 // --------------------------------------------------------------------
 37 #ifndef G4TMAG_ERROR_STEPPER_HH                    37 #ifndef G4TMAG_ERROR_STEPPER_HH
 38 #define G4TMAG_ERROR_STEPPER_HH                    38 #define G4TMAG_ERROR_STEPPER_HH
 39                                                    39 
 40 #include "G4Types.hh"                              40 #include "G4Types.hh"
 41 #include "G4MagIntegratorStepper.hh"               41 #include "G4MagIntegratorStepper.hh"
 42 #include "G4ThreeVector.hh"                        42 #include "G4ThreeVector.hh"
 43 #include "G4LineSection.hh"                        43 #include "G4LineSection.hh"
 44                                                    44 
 45 template <class T_Stepper, class T_Equation, u     45 template <class T_Stepper, class T_Equation, unsigned int N>
 46 class G4TMagErrorStepper : public G4MagIntegra     46 class G4TMagErrorStepper : public G4MagIntegratorStepper
 47 {                                                  47 {
 48  public:  // with description                      48  public:  // with description
 49   G4TMagErrorStepper(T_Equation* EqRhs, G4int      49   G4TMagErrorStepper(T_Equation* EqRhs, G4int numberOfVariables,
 50                      G4int numStateVariables =     50                      G4int numStateVariables = 12)
 51     : G4MagIntegratorStepper(EqRhs, numberOfVa     51     : G4MagIntegratorStepper(EqRhs, numberOfVariables, numStateVariables)
 52     , fEquation_Rhs(EqRhs)                         52     , fEquation_Rhs(EqRhs)
 53   {                                                53   {
 54     // G4int nvar = std::max(this->GetNumberOf     54     // G4int nvar = std::max(this->GetNumberOfVariables(), 8);
 55   }                                                55   }
 56                                                    56 
 57   virtual ~G4TMagErrorStepper() { ; }              57   virtual ~G4TMagErrorStepper() { ; }
 58                                                    58 
 59   inline void RightHandSide(G4double y[], G4do     59   inline void RightHandSide(G4double y[], G4double dydx[])
 60   {                                                60   {
 61     fEquation_Rhs->T_Equation::RightHandSide(y     61     fEquation_Rhs->T_Equation::RightHandSide(y, dydx);
 62   }                                                62   }
 63                                                    63 
 64   inline void Stepper(const G4double yInput[],     64   inline void Stepper(const G4double yInput[], const G4double dydx[],
 65                       G4double hstep, G4double     65                       G4double hstep, G4double yOutput[], G4double yError[]) override final;
 66                                                    66  
 67   inline G4double DistChord() const override f     67   inline G4double DistChord() const override final;
 68                                                    68 
 69  private:                                          69  private:
 70   G4TMagErrorStepper(const G4TMagErrorStepper&     70   G4TMagErrorStepper(const G4TMagErrorStepper&);
 71   G4TMagErrorStepper& operator=(const G4TMagEr     71   G4TMagErrorStepper& operator=(const G4TMagErrorStepper&);
 72   // Private copy constructor and assignment o     72   // Private copy constructor and assignment operator.
 73                                                    73 
 74  private:                                          74  private:
 75   // STATE                                         75   // STATE
 76   G4ThreeVector fInitialPoint, fMidPoint, fFin     76   G4ThreeVector fInitialPoint, fMidPoint, fFinalPoint;
 77   // Data stored in order to find the chord        77   // Data stored in order to find the chord
 78                                                    78 
 79   // Dependent Objects, owned --- part of the      79   // Dependent Objects, owned --- part of the STATE
 80   G4double yInitial[N < 8 ? 8 : N];                80   G4double yInitial[N < 8 ? 8 : N];
 81   G4double yMiddle[N < 8 ? 8 : N];                 81   G4double yMiddle[N < 8 ? 8 : N];
 82   G4double dydxMid[N < 8 ? 8 : N];                 82   G4double dydxMid[N < 8 ? 8 : N];
 83   G4double yOneStep[N < 8 ? 8 : N];                83   G4double yOneStep[N < 8 ? 8 : N];
 84   // The following arrays are used only for te     84   // The following arrays are used only for temporary storage
 85   // they are allocated at the class level onl     85   // they are allocated at the class level only for efficiency -
 86   // so that calls to new and delete are not m     86   // so that calls to new and delete are not made in Stepper().
 87                                                    87 
 88   T_Equation* fEquation_Rhs;                       88   T_Equation* fEquation_Rhs;
 89 };                                                 89 };
 90                                                    90 
 91 // ------------   Implementation -------------     91 // ------------   Implementation -----------------------
 92                                                    92 
 93 template <class T_Stepper, class T_Equation, u     93 template <class T_Stepper, class T_Equation, unsigned int N >
 94 void G4TMagErrorStepper<T_Stepper,T_Equation,N     94 void G4TMagErrorStepper<T_Stepper,T_Equation,N>::
 95 Stepper(const G4double yInput[],                   95 Stepper(const G4double yInput[],
 96         const G4double dydx[],                     96         const G4double dydx[],
 97               G4double hstep,                      97               G4double hstep,
 98               G4double yOutput[],                  98               G4double yOutput[],
 99               G4double yError[])                   99               G4double yError[])
100 // The stepper for the Runge Kutta integration    100 // The stepper for the Runge Kutta integration. The stepsize
101 // is fixed, with the Step size given by hstep    101 // is fixed, with the Step size given by hstep.
102 // Integrates ODE starting values y[0 to N].      102 // Integrates ODE starting values y[0 to N].
103 // Outputs yout[] and its estimated error yerr    103 // Outputs yout[] and its estimated error yerr[].
104 {                                                 104 {
105   const unsigned int maxvar = GetNumberOfState    105   const unsigned int maxvar = GetNumberOfStateVariables();
106                                                   106   
107   //  Saving yInput because yInput and yOutput    107   //  Saving yInput because yInput and yOutput can be aliases for same array
108   for(unsigned int i = 0; i < N; ++i)             108   for(unsigned int i = 0; i < N; ++i)
109      yInitial[i] = yInput[i];                     109      yInitial[i] = yInput[i];
110   yInitial[7] =                                   110   yInitial[7] =
111      yInput[7];  // Copy the time in case ...     111      yInput[7];  // Copy the time in case ... even if not really needed
112   yMiddle[7]  = yInput[7];  // Copy the time f    112   yMiddle[7]  = yInput[7];  // Copy the time from initial value
113   yOneStep[7] = yInput[7];  // As it contribut    113   yOneStep[7] = yInput[7];  // As it contributes to final value of yOutput ?
114   // yOutput[7] = yInput[7];  // -> dumb stepp    114   // yOutput[7] = yInput[7];  // -> dumb stepper does it too for RK4
115   for(unsigned int i = N; i < maxvar; ++i)        115   for(unsigned int i = N; i < maxvar; ++i)
116      yOutput[i] = yInput[i];                      116      yOutput[i] = yInput[i];
117                                                   117 
118   G4double halfStep = hstep * 0.5;                118   G4double halfStep = hstep * 0.5;
119                                                   119   
120   // Do two half steps                            120   // Do two half steps
121                                                   121   
122   static_cast<T_Stepper*>(this)->DumbStepper(y    122   static_cast<T_Stepper*>(this)->DumbStepper(yInitial, dydx, halfStep,
123                                                   123                                                yMiddle);
124   this->RightHandSide(yMiddle, dydxMid);          124   this->RightHandSide(yMiddle, dydxMid);
125   static_cast<T_Stepper*>(this)->DumbStepper(y    125   static_cast<T_Stepper*>(this)->DumbStepper(yMiddle, dydxMid, halfStep,
126                                              y    126                                              yOutput);
127                                                   127   
128   // Store midpoint, chord calculation            128   // Store midpoint, chord calculation
129                                                   129   
130   fMidPoint = G4ThreeVector(yMiddle[0], yMiddl    130   fMidPoint = G4ThreeVector(yMiddle[0], yMiddle[1], yMiddle[2]);
131                                                   131   
132   // Do a full Step                               132   // Do a full Step
133   static_cast<T_Stepper*>(this)->DumbStepper(y    133   static_cast<T_Stepper*>(this)->DumbStepper(yInitial, dydx, hstep, yOneStep);
134   for(unsigned int i = 0; i < N; ++i)             134   for(unsigned int i = 0; i < N; ++i)
135   {                                               135   {
136     yError[i] = yOutput[i] - yOneStep[i];         136     yError[i] = yOutput[i] - yOneStep[i];
137     yOutput[i] +=                                 137     yOutput[i] +=
138        yError[i] *                                138        yError[i] *
139        T_Stepper::IntegratorCorrection;  // Pr    139        T_Stepper::IntegratorCorrection;  // Provides accuracy increased
140     // by 1 order via the                         140     // by 1 order via the
141     // Richardson Extrapolation                   141     // Richardson Extrapolation
142   }                                               142   }
143                                                   143 
144   fInitialPoint = G4ThreeVector(yInitial[0], y    144   fInitialPoint = G4ThreeVector(yInitial[0], yInitial[1], yInitial[2]);
145   fFinalPoint   = G4ThreeVector(yOutput[0], yO    145   fFinalPoint   = G4ThreeVector(yOutput[0], yOutput[1], yOutput[2]);
146                                                   146   
147   return;                                         147   return;
148 }                                                 148 }
149                                                   149 
150                                                   150 
151 template <class T_Stepper, class T_Equation, u    151 template <class T_Stepper, class T_Equation, unsigned int N >
152 inline G4double                                   152 inline G4double
153 G4TMagErrorStepper<T_Stepper,T_Equation,N>::Di    153 G4TMagErrorStepper<T_Stepper,T_Equation,N>::DistChord() const
154 {                                                 154 {
155   // Estimate the maximum distance from the cu    155   // Estimate the maximum distance from the curve to the chord
156   //                                              156   //
157   //  We estimate this using the distance of t    157   //  We estimate this using the distance of the midpoint to
158   //  chord (the line between                     158   //  chord (the line between
159   //                                              159   //
160   //  Method below is good only for angle devi    160   //  Method below is good only for angle deviations < 2 pi,
161   //   This restriction should not a problem f    161   //   This restriction should not a problem for the Runge cutta methods,
162   //   which generally cannot integrate accura    162   //   which generally cannot integrate accurately for large angle deviations.
163   G4double distLine, distChord;                   163   G4double distLine, distChord;
164                                                   164 
165   if(fInitialPoint != fFinalPoint)                165   if(fInitialPoint != fFinalPoint)
166   {                                               166   {
167     distLine = G4LineSection::Distline(fMidPoi    167     distLine = G4LineSection::Distline(fMidPoint, fInitialPoint, fFinalPoint);
168     // This is a class method that gives dista    168     // This is a class method that gives distance of Mid
169     //  from the Chord between the Initial and    169     //  from the Chord between the Initial and Final points.
170                                                   170     
171     distChord = distLine;                         171     distChord = distLine;
172   }                                               172   }
173   else                                            173   else
174   {                                               174   {
175      distChord = (fMidPoint - fInitialPoint).m    175      distChord = (fMidPoint - fInitialPoint).mag();
176   }                                               176   }
177                                                   177   
178   return distChord;                               178   return distChord;
179 }                                                 179 }
180                                                   180 
181 #endif /* G4TMagErrorStepper_HH */                181 #endif /* G4TMagErrorStepper_HH */
182                                                   182