source: trunk/source/geometry/magneticfield/include/G4NystromRK4.hh @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 5.0 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26// $Id: G4NystromRK4.hh,v 1.3 2009/11/12 15:01:36 japost Exp $
27// GEANT4 tag $Name: geant4-09-04-beta-01 $
28//
29// class G4NystromRK4
30//
31// Class description:
32//
33// Integrate the equations of the motion of a particle in a magnetic field
34// using 4th Runge-Kutta-Nystrom method with errors estimation
35// (ATL-SOFT-PUB-2009-01)
36// Current form can be used only for 'pure' magnetic field.
37// Notes: 1) field must be time-independent.
38//        2) time is not integrated
39//
40// History:
41// - Created: I.Gavrilenko   15.05.2009   (as G4AtlasRK4)
42// - Adaptations:  J. Apostolakis  May-Nov 2009
43// -------------------------------------------------------------------
44
45#ifndef G4NYSTROMRK4_HH
46#define G4NYSTROMRK4_HH
47
48#include "globals.hh"
49#include "G4MagIntegratorStepper.hh"
50#include "G4Mag_EqRhs.hh"
51
52class G4NystromRK4 : public G4MagIntegratorStepper
53{
54  public: 
55    G4NystromRK4(G4Mag_EqRhs *EquationMotion, G4double distanceConstField=0.0); 
56      // Can be used only for Magnetic Fields - and for 6 variables (x,p)
57
58    ~G4NystromRK4() ;
59
60    void Stepper(const G4double P   [],
61                 const G4double dPdS[],
62                       G4double step  ,
63                       G4double Po  [],
64                       G4double Err []);
65      // Single call for integration result and error
66      // - Provides Error via analytical method
67
68    virtual void ComputeRightHandSide(const double P[],double dPdS[]);   
69      // Must compute RHS - and does caches result
70
71    void      SetDistanceForConstantField( G4double length ); 
72    G4double  GetDistanceForConstantField() const; 
73   
74    G4int     IntegratorOrder() const {return 4;}
75    G4double  DistChord() const; 
76 
77  private:
78
79    inline void getField   (const G4double P[4]);
80
81    ////////////////////////////////////////////////////////////////
82    // Private data
83    ////////////////////////////////////////////////////////////////
84
85    G4Mag_EqRhs*           m_fEq;         
86    G4double      m_lastField[3];
87    G4double      m_fldPosition[4];
88    G4double      m_magdistance ;
89    G4double      m_magdistance2;
90    G4double      m_cof         ;
91    G4double      m_mom         ;
92    G4double      m_imom        ;
93    G4bool        m_cachedMom   ;
94    G4double      m_iPoint   [3];
95    G4double      m_mPoint   [3];
96    G4double      m_fPoint   [3];
97   
98};
99
100/////////////////////////////////////////////////////////////////////////////////
101// Inline methods
102/////////////////////////////////////////////////////////////////////////////////
103inline void  G4NystromRK4::SetDistanceForConstantField( G4double length )
104{
105  m_magdistance=   length;
106  m_magdistance2 = length*length;
107}
108
109inline G4double  G4NystromRK4::GetDistanceForConstantField() const
110{
111  return m_magdistance; 
112}
113
114/////////////////////////////////////////////////////////////////////////////////
115// Get value of magnetic field while checking distance from last stored call
116/////////////////////////////////////////////////////////////////////////////////
117
118inline void G4NystromRK4::getField (const G4double P[4])
119{
120 
121  G4double dx = P[0]-m_fldPosition[0];
122  G4double dy = P[1]-m_fldPosition[1];
123  G4double dz = P[2]-m_fldPosition[2];
124
125  if((dx*dx+dy*dy+dz*dz) > m_magdistance2) {
126
127    m_fldPosition[0] = P[0];
128    m_fldPosition[1] = P[1];
129    m_fldPosition[2] = P[2];
130    m_fldPosition[3] = P[3];   //  Generally it is P[7] - changed convention !!
131    m_fEq->GetFieldValue(m_fldPosition, m_lastField);
132  }
133}
134#endif  // G4NYSTROMRK4
Note: See TracBrowser for help on using the repository browser.