00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // $Id: G4NystromRK4.hh 69786 2013-05-15 09:38:51Z gcosmo $ 00027 // 00028 // class G4NystromRK4 00029 // 00030 // Class description: 00031 // 00032 // Integrate the equations of the motion of a particle in a magnetic field 00033 // using 4th Runge-Kutta-Nystrom method with errors estimation 00034 // (ATL-SOFT-PUB-2009-01) 00035 // Current form can be used only for 'pure' magnetic field. 00036 // Notes: 1) field must be time-independent. 00037 // 2) time is not integrated 00038 // 00039 // History: 00040 // - Created: I.Gavrilenko 15.05.2009 (as G4AtlasRK4) 00041 // - Adaptations: J. Apostolakis May-Nov 2009 00042 // ------------------------------------------------------------------- 00043 00044 #ifndef G4NYSTROMRK4_HH 00045 #define G4NYSTROMRK4_HH 00046 00047 #include "globals.hh" 00048 #include "G4MagIntegratorStepper.hh" 00049 #include "G4Mag_EqRhs.hh" 00050 00051 class G4NystromRK4 : public G4MagIntegratorStepper 00052 { 00053 public: 00054 G4NystromRK4(G4Mag_EqRhs *EquationMotion, G4double distanceConstField=0.0); 00055 // Can be used only for Magnetic Fields - and for 6 variables (x,p) 00056 00057 ~G4NystromRK4() ; 00058 00059 void Stepper(const G4double P [], 00060 const G4double dPdS[], 00061 G4double step , 00062 G4double Po [], 00063 G4double Err []); 00064 // Single call for integration result and error 00065 // - Provides Error via analytical method 00066 00067 virtual void ComputeRightHandSide(const double P[],double dPdS[]); 00068 // Must compute RHS - and does caches result 00069 00070 void SetDistanceForConstantField( G4double length ); 00071 G4double GetDistanceForConstantField() const; 00072 00073 G4int IntegratorOrder() const {return 4;} 00074 G4double DistChord() const; 00075 00076 private: 00077 00078 inline void getField (const G4double P[4]); 00079 00081 // Private data 00083 00084 G4Mag_EqRhs* m_fEq; 00085 G4double m_lastField[3]; 00086 G4double m_fldPosition[4]; 00087 G4double m_magdistance ; 00088 G4double m_magdistance2; 00089 G4double m_cof ; 00090 G4double m_mom ; 00091 G4double m_imom ; 00092 G4bool m_cachedMom ; 00093 G4double m_iPoint [3]; 00094 G4double m_mPoint [3]; 00095 G4double m_fPoint [3]; 00096 00097 }; 00098 00100 // Inline methods 00102 inline void G4NystromRK4::SetDistanceForConstantField( G4double length ) 00103 { 00104 m_magdistance= length; 00105 m_magdistance2 = length*length; 00106 } 00107 00108 inline G4double G4NystromRK4::GetDistanceForConstantField() const 00109 { 00110 return m_magdistance; 00111 } 00112 00114 // Get value of magnetic field while checking distance from last stored call 00116 00117 inline void G4NystromRK4::getField (const G4double P[4]) 00118 { 00119 00120 G4double dx = P[0]-m_fldPosition[0]; 00121 G4double dy = P[1]-m_fldPosition[1]; 00122 G4double dz = P[2]-m_fldPosition[2]; 00123 00124 if((dx*dx+dy*dy+dz*dz) > m_magdistance2) 00125 { 00126 m_fldPosition[0] = P[0]; 00127 m_fldPosition[1] = P[1]; 00128 m_fldPosition[2] = P[2]; 00129 m_fldPosition[3] = P[3]; // Generally it is P[7] - changed convention !! 00130 m_fEq->GetFieldValue(m_fldPosition, m_lastField); 00131 } 00132 } 00133 #endif // G4NYSTROMRK4