Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4NystromRK4.cc
이 파일의 문서화 페이지로 가기
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 //
27 // $Id: G4NystromRK4.cc 110753 2018-06-12 15:44:03Z gcosmo $
28 //
29 // History:
30 // - Created: I.Gavrilenko 15.05.2009 (as G4AtlasRK4)
31 // - Adaptations: J.Apostolakis May-Nov 2009
32 // -------------------------------------------------------------------
33 
34 #include <iostream>
35 #include "G4NystromRK4.hh"
36 
38 // Constructor - with optional distance ( has default value)
40 
41 G4NystromRK4::G4NystromRK4(G4Mag_EqRhs* magEqRhs, G4double distanceConstField)
42  : G4MagIntegratorStepper(magEqRhs, 6), // number of variables
43  m_fEq( magEqRhs ),
44  m_magdistance( distanceConstField ),
45  m_cof( 0.0 ),
46  m_mom( 0.0 ),
47  m_imom( 0.0 ),
48  m_cachedMom( false )
49 {
50  m_fldPosition[0] = m_iPoint[0] = m_fPoint[0] = m_mPoint[0] = 9.9999999e+99 ;
51  m_fldPosition[1] = m_iPoint[1] = m_fPoint[1] = m_mPoint[1] = 9.9999999e+99 ;
52  m_fldPosition[2] = m_iPoint[2] = m_fPoint[2] = m_mPoint[2] = 9.9999999e+99 ;
53  m_fldPosition[3] = -9.9999999e+99;
54  m_lastField[0] = m_lastField[1] = m_lastField[2] = 0.0;
55 
56  m_magdistance2 = distanceConstField*distanceConstField;
57 }
58 
60 // Destructor
62 
64 {
65 }
66 
68 // Integration in one step
70 
71 void
73  const G4double dPdS[],
74  G4double Step, G4double Po[], G4double Err[])
75 {
76  const G4double perMillion = 1.0e-6;
77  G4double R[4] = { P[0], P[1] , P[2], P[7] }; // x, y, z, t
78  G4double A[3] = {dPdS[0], dPdS[1], dPdS[2]};
79 
80  m_iPoint[0]=R[0]; m_iPoint[1]=R[1]; m_iPoint[2]=R[2];
81 
82  constexpr G4double one_sixth= 1./6.;
83  const G4double S = Step ;
84  const G4double S5 = .5*Step ;
85  const G4double S4 = .25*Step ;
86  const G4double S6 = Step * one_sixth; // Step / 6.;
87 
88  // Ensure that the location and cached field value are correct
89  getField( R );
90 
91  // Ensure that the momentum is set correctly.
92 
93  // - Quick check momentum magnitude (squared) against previous value
94  G4double newmom2 = (P[3]*P[3]+P[4]*P[4]+P[5]*P[5]);
95  G4double oldmom2 = m_mom * m_mom;
96  if( std::fabs(newmom2 - oldmom2) > perMillion * oldmom2 )
97  {
98  m_mom = std::sqrt(newmom2) ;
99  m_imom = 1./m_mom;
100  m_cof = m_fEq->FCof()*m_imom;
101  }
102 
103 #ifdef G4DEBUG_FIELD
104  CheckCachedMomemtum( P, m_mom );
106 #endif
107 
108  // Point 1
109  //
110  G4double K1[3] = { m_imom*dPdS[3], m_imom*dPdS[4], m_imom*dPdS[5] };
111 
112  // Point2
113  //
114  G4double p[4] = {R[0]+S5*(A[0]+S4*K1[0]),
115  R[1]+S5*(A[1]+S4*K1[1]),
116  R[2]+S5*(A[2]+S4*K1[2]),
117  P[7] };
118  getField(p);
119 
120  G4double A2[3] = {A[0]+S5*K1[0],A[1]+S5*K1[1],A[2]+S5*K1[2]};
121  G4double K2[3] = {(A2[1]*m_lastField[2]-A2[2]*m_lastField[1])*m_cof,
122  (A2[2]*m_lastField[0]-A2[0]*m_lastField[2])*m_cof,
123  (A2[0]*m_lastField[1]-A2[1]*m_lastField[0])*m_cof};
124 
125  m_mPoint[0]=p[0]; m_mPoint[1]=p[1]; m_mPoint[2]=p[2];
126 
127  // Point 3 with the same magnetic field
128  //
129  G4double A3[3] = {A[0]+S5*K2[0],A[1]+S5*K2[1],A[2]+S5*K2[2]};
130  G4double K3[3] = {(A3[1]*m_lastField[2]-A3[2]*m_lastField[1])*m_cof,
131  (A3[2]*m_lastField[0]-A3[0]*m_lastField[2])*m_cof,
132  (A3[0]*m_lastField[1]-A3[1]*m_lastField[0])*m_cof};
133 
134  // Point 4
135  //
136  p[0] = R[0]+S*(A[0]+S5*K3[0]);
137  p[1] = R[1]+S*(A[1]+S5*K3[1]);
138  p[2] = R[2]+S*(A[2]+S5*K3[2]);
139 
140  getField(p);
141 
142  G4double A4[3] = {A[0]+S*K3[0],A[1]+S*K3[1],A[2]+S*K3[2]};
143  G4double K4[3] = {(A4[1]*m_lastField[2]-A4[2]*m_lastField[1])*m_cof,
144  (A4[2]*m_lastField[0]-A4[0]*m_lastField[2])*m_cof,
145  (A4[0]*m_lastField[1]-A4[1]*m_lastField[0])*m_cof};
146 
147  // New position
148  //
149  Po[0] = P[0]+S*(A[0]+S6*(K1[0]+K2[0]+K3[0]));
150  Po[1] = P[1]+S*(A[1]+S6*(K1[1]+K2[1]+K3[1]));
151  Po[2] = P[2]+S*(A[2]+S6*(K1[2]+K2[2]+K3[2]));
152 
153  m_fPoint[0]=Po[0]; m_fPoint[1]=Po[1]; m_fPoint[2]=Po[2];
154 
155  // New direction
156  //
157  Po[3] = A[0]+S6*(K1[0]+K4[0]+2.*(K2[0]+K3[0]));
158  Po[4] = A[1]+S6*(K1[1]+K4[1]+2.*(K2[1]+K3[1]));
159  Po[5] = A[2]+S6*(K1[2]+K4[2]+2.*(K2[2]+K3[2]));
160 
161  // Errors
162  //
163  Err[3] = S*std::fabs(K1[0]-K2[0]-K3[0]+K4[0]);
164  Err[4] = S*std::fabs(K1[1]-K2[1]-K3[1]+K4[1]);
165  Err[5] = S*std::fabs(K1[2]-K2[2]-K3[2]+K4[2]);
166  Err[0] = S*Err[3] ;
167  Err[1] = S*Err[4] ;
168  Err[2] = S*Err[5] ;
169  Err[3]*= m_mom ;
170  Err[4]*= m_mom ;
171  Err[5]*= m_mom ;
172 
173  // Normalize momentum
174  //
175  G4double normF = m_mom/std::sqrt(Po[3]*Po[3]+Po[4]*Po[4]+Po[5]*Po[5]);
176  Po [3]*=normF; Po[4]*=normF; Po[5]*=normF;
177 
178  // Pass Energy, time unchanged -- time is not integrated !!
179  Po[6]=P[6]; Po[7]=P[7];
180 }
181 
182 
184 // Estimate the maximum distance from the curve to the chord
186 
187 G4double
189 {
190  G4double ax = m_fPoint[0]-m_iPoint[0];
191  G4double ay = m_fPoint[1]-m_iPoint[1];
192  G4double az = m_fPoint[2]-m_iPoint[2];
193  G4double dx = m_mPoint[0]-m_iPoint[0];
194  G4double dy = m_mPoint[1]-m_iPoint[1];
195  G4double dz = m_mPoint[2]-m_iPoint[2];
196  G4double d2 = (ax*ax+ay*ay+az*az) ;
197 
198  if(d2!=0.)
199  {
200  G4double ds = (ax*dx+ay*dy+az*dz)/d2;
201  dx -= (ds*ax) ;
202  dy -= (ds*ay) ;
203  dz -= (ds*az) ;
204  }
205  return std::sqrt(dx*dx+dy*dy+dz*dz);
206 }
207 
209 // Derivatives calculation - caching the momentum value
211 
212 void
214 {
215  G4double P4vec[4]= { P[0], P[1], P[2], P[7] }; // Time is P[7]
216  getField(P4vec);
217  m_mom = std::sqrt(P[3]*P[3]+P[4]*P[4]+P[5]*P[5]) ;
218  m_imom = 1./m_mom ;
219  m_cof = m_fEq->FCof()*m_imom ;
220  m_cachedMom = true ; // Caching the value
221  dPdS[0] = P[3]*m_imom ; // dx /ds
222  dPdS[1] = P[4]*m_imom ; // dy /ds
223  dPdS[2] = P[5]*m_imom ; // dz /ds
224  dPdS[3] = m_cof*(P[4]*m_lastField[2]-P[5]*m_lastField[1]) ; // dPx/ds
225  dPdS[4] = m_cof*(P[5]*m_lastField[0]-P[3]*m_lastField[2]) ; // dPy/ds
226  dPdS[5] = m_cof*(P[3]*m_lastField[1]-P[4]*m_lastField[0]) ; // dPz/ds
227 }
228 
230 // Check that the location is (almost) unmoved from 'last' field evaluation
232 
233 G4bool
235  const G4double lastPosition[3] )
236 {
237  G4bool ok= true;
238  G4double dx = Position[0] - lastPosition[0];
239  G4double dy = Position[1] - lastPosition[1];
240  G4double dz = Position[2] - lastPosition[2];
241  G4double distMag2 = dx*dx+dy*dy+dz*dz;
242  if( distMag2 > m_magdistance2)
243  {
244  const G4double allowedDist = std::sqrt( m_magdistance2 );
245  G4double dist= std::sqrt( distMag2 );
246  std::ostringstream message;
247  message << "Moved from correct field position by " << dist
248  << "( larger than allowed = " << allowedDist << " ) ";
249  G4Exception("G4NystromRK4::CheckFieldPosition()",
250  "GeomField1001", JustWarning, message);
251  ok= false;
252  }
253  return ok;
254 }
255 
257 // Check magnitude of momentum against saved value
259 
261  G4double savedMom )
262 {
263  constexpr G4double perThousand = 1.0e-3;
264  G4bool ok= true;
265  G4double new_mom2= (PosMom[3]*PosMom[3]
266  +PosMom[4]*PosMom[4]
267  +PosMom[5]*PosMom[5]);
268  G4double new_mom= std::sqrt(new_mom2);
269  if( std::fabs(new_mom - savedMom ) > perThousand * savedMom )
270  {
271  std::ostringstream message;
272  message << "Momentum magnitude is invalid / has changed !" << G4endl
273  << " new value (p-mag) = " << new_mom << G4endl
274  << " cached value (p-mag) = " << savedMom;
275  if( savedMom > 0.0 )
276  {
277  message << "; ratio (new/old) = " << new_mom / savedMom;
278  }
279  G4Exception("G4NystromRK4::CheckCachedMomemtum()",
280  "GeomField1001", JustWarning, message);
281  ok= false;
282  }
283  return ok;
284 }
G4Mag_EqRhs * m_fEq
Definition: G4NystromRK4.hh:88
G4bool CheckCachedMomemtum(const G4double PosMom[6], G4double savedMom)
G4double m_fPoint[3]
Definition: G4NystromRK4.hh:99
#define G4endl
Definition: G4ios.hh:61
const char * p
Definition: xmltok.h:285
virtual void ComputeRightHandSide(const G4double P[], G4double dPdS[])
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
G4double m_mPoint[3]
Definition: G4NystromRK4.hh:98
G4bool CheckFieldPosition(const G4double Position[3], const G4double lastPosition[3])
static constexpr double perMillion
Definition: G4SIunits.hh:334
G4double m_mom
Definition: G4NystromRK4.hh:94
G4double m_magdistance2
Definition: G4NystromRK4.hh:92
double S(double temp)
G4double m_imom
Definition: G4NystromRK4.hh:95
G4double FCof() const
Definition: G4Mag_EqRhs.hh:84
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4double m_cof
Definition: G4NystromRK4.hh:93
static const G4double d2
Double_t R
double A(double temperature)
G4bool m_cachedMom
Definition: G4NystromRK4.hh:96
G4double DistChord() const
static double P[]
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
void Stepper(const G4double P[], const G4double dPdS[], G4double step, G4double Po[], G4double Err[])
Definition: G4NystromRK4.cc:72
G4NystromRK4(G4Mag_EqRhs *EquationMotion, G4double distanceConstField=0.0)
Definition: G4NystromRK4.cc:41
G4double m_fldPosition[4]
Definition: G4NystromRK4.hh:90
G4double m_lastField[3]
Definition: G4NystromRK4.hh:89
G4double m_iPoint[3]
Definition: G4NystromRK4.hh:97
void getField(const G4double P[4])
Definition: Step.hh:41
static constexpr double perThousand
Definition: G4SIunits.hh:333