Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:14

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4TSimpleHeum
0027 //
0028 // Class description:
0029 //
0030 // Templated version of G4SimpleHeum
0031 //
0032 // Created: Josh Xie  (supported by Google Summer of Code 2014 )
0033 // Supervisors:  Sandro Wenzel, John Apostolakis (CERN)
0034 // --------------------------------------------------------------------
0035 // Adapted from G4G4TSimpleHeum class
0036 // Original desription:
0037 //
0038 // Simple Heum stepper for magnetic field:
0039 //        x_1 = x_0  +
0040 //              h * 1/4 * dx(t0,x0)  +
0041 //                  3/4 * dx(t0+2/3*h, x0+2/3*h*(dx(t0+h/3,x0+h/3*dx(t0,x0)))) 
0042 //
0043 // Third order solver.
0044 // Created: W.Wander <wwc@mit.edu>, 12/09/1997
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:  // with description
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   // Constructor and destructor.
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[]); // override final
0077 
0078  public:  // without description
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   // scratch space
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 /* TSIMPLEHEUM_HH */