Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:04

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 // G4ConstRK4
0027 //
0028 // class description:
0029 //
0030 // G4ConstRK4 performs the integration of one step with error calculation
0031 // in constant magnetic field. The integration method is the same as in
0032 // ClassicalRK4. The field value is assumed constant for the step.
0033 // This field evaluation is called only once per step.
0034 // G4ConstRK4 can be used only for magnetic fields.
0035 
0036 // Created: J.Apostolakis, T.Nikitina - 18.09.2008
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        // Copy constructor and assignment operator not allowed
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      // Data stored in order to find the chord
0078      G4double *dydxm, *dydxt, *yt; // scratch space - not state 
0079      G4double *yInitial, *yMiddle, *dydxMid, *yOneStep;
0080      G4Mag_EqRhs* fEq = nullptr;
0081      G4double Field[3];
0082 };
0083 
0084 // Inline methods
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;       //  (d/ds)x = Vx/V
0096   dydx[1] = y[4]*inv_momentum_magnitude;       //  (d/ds)y = Vy/V
0097   dydx[2] = y[5]*inv_momentum_magnitude;       //  (d/ds)z = Vz/V
0098  
0099   dydx[3] = cof*(y[4]*Field[2] - y[5]*Field[1]) ;   // Ax = a*(Vy*Bz - Vz*By)
0100   dydx[4] = cof*(y[5]*Field[0] - y[3]*Field[2]) ;   // Ay = a*(Vz*Bx - Vx*Bz)
0101   dydx[5] = cof*(y[3]*Field[1] - y[4]*Field[0]) ;   // Az = a*(Vx*By - Vy*Bx)
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   // Global Time
0112   PositionAndTime[3] = y[7];
0113   fEq -> GetFieldValue(PositionAndTime, B);
0114 }
0115 
0116 #endif