Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4MagIntegratorDriver.hh
Go to the documentation of this file.
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: G4MagIntegratorDriver.hh 69786 2013-05-15 09:38:51Z gcosmo $
28 //
29 //
30 // class G4MagInt_Driver
31 //
32 // Class description:
33 //
34 // Provides a driver that talks to the Integrator Stepper, and insures that
35 // the error is within acceptable bounds.
36 
37 // History:
38 // - Created. J.Apostolakis.
39 // --------------------------------------------------------------------
40 
41 #ifndef G4MagInt_Driver_Def
42 #define G4MagInt_Driver_Def
43 
44 #include "G4Types.hh"
45 #include "G4FieldTrack.hh"
47 
49 {
50  public: // with description
51 
53  G4double hstep,
54  G4double eps, // Requested y_err/hstep
55  G4double hinitial=0.0); // Suggested 1st interval
56  // Above drivers for integrator (Runge-Kutta) with stepsize control.
57  // Integrates ODE starting values y_current
58  // from current s (s=s0) to s=s0+h with accuracy eps.
59  // On output ystart is replaced by value at end of interval.
60  // The concept is similar to the odeint routine from NRC p.721-722.
61 
62  G4bool QuickAdvance( G4FieldTrack& y_val, // INOUT
63  const G4double dydx[],
64  G4double hstep, // IN
65  G4double& dchord_step,
66  G4double& dyerr ) ;
67  // QuickAdvance just tries one Step - it does not ensure accuracy.
68 
69  G4bool QuickAdvance( G4FieldTrack& y_posvel, // INOUT
70  const G4double dydx[],
71  G4double hstep, // IN
72  G4double& dchord_step,
73  G4double& dyerr_pos_sq,
74  G4double& dyerr_mom_rel_sq ) ;
75  // New QuickAdvance that also just tries one Step
76  // (so also does not ensure accuracy)
77  // but does return the errors in position and
78  // momentum (normalised: Delta_Integration(p^2)/(p^2) )
79 
80  G4MagInt_Driver( G4double hminimum,
81  G4MagIntegratorStepper *pItsStepper,
82  G4int numberOfComponents=6,
83  G4int statisticsVerbosity=1);
85  // Constructor, destructor.
86 
87  inline G4double GetHmin() const;
88  inline G4double Hmin() const; // Obsolete
89  inline G4double GetSafety() const;
90  inline G4double GetPshrnk() const;
91  inline G4double GetPgrow() const;
92  inline G4double GetErrcon() const;
93  inline void GetDerivatives( const G4FieldTrack &y_curr, // const, INput
94  G4double dydx[] ); // OUTput
95  // Accessors.
96 
97  inline void RenewStepperAndAdjust(G4MagIntegratorStepper *pItsStepper);
98  // Sets a new stepper pItsStepper for this driver. Then it calls
99  // ReSetParameters to reset its parameters accordingly.
100 
101  inline void ReSetParameters(G4double new_safety= 0.9 );
102  // i) sets the exponents (pgrow & pshrnk),
103  // using the current Stepper's order,
104  // ii) sets the safety
105  // ii) calculates "errcon" according to the above values.
106 
107  inline void SetSafety(G4double valS);
108  inline void SetPshrnk(G4double valPs);
109  inline void SetPgrow (G4double valPg);
110  inline void SetErrcon(G4double valEc);
111  // When setting safety or pgrow, errcon will be set to a
112  // compatible value.
113 
114  inline G4double ComputeAndSetErrcon();
115 
116  inline void SetChargeMomentumMass( G4double particleCharge,
117  G4double MomentumXc,
118  G4double Mass );
119  // Change them in Equation. particleCharge is in e+ units.
120 
121  inline const G4MagIntegratorStepper* GetStepper() const;
122 
123  void OneGoodStep( G4double ystart[], // Like old RKF45step()
124  const G4double dydx[],
125  G4double& x,
126  G4double htry,
127  G4double eps, // memb variables ?
128  G4double& hdid,
129  G4double& hnext ) ;
130  // This takes one Step that is as large as possible while
131  // satisfying the accuracy criterion of:
132  // yerr < eps * |y_end-y_start|
133 
134  G4double ComputeNewStepSize( G4double errMaxNorm, // normalised error
135  G4double hstepCurrent); // current step size
136  // Taking the last step's normalised error, calculate
137  // a step size for the next step.
138  // Do not limit the next step's size within a factor of the
139  // current one.
140 
142  G4double errMaxNorm, // normalised error
143  G4double hstepCurrent); // current step size
144  // Taking the last step's normalised error, calculate
145  // a step size for the next step.
146  // Limit the next step's size within a range around the current one.
147 
148  inline G4int GetMaxNoSteps() const;
149  inline void SetMaxNoSteps( G4int val);
150  // Modify and Get the Maximum number of Steps that can be
151  // taken for the integration of a single segment -
152  // (ie a single call to AccurateAdvance).
153 
154  public: // without description
155 
156  inline void SetHmin(G4double newval);
157  inline void SetVerboseLevel(G4int newLevel);
158  inline G4double GetVerboseLevel() const;
159 
160  inline G4double GetSmallestFraction() const;
161  void SetSmallestFraction( G4double val );
162 
163  protected: // without description
164  void WarnSmallStepSize( G4double hnext, G4double hstep,
165  G4double h, G4double xDone,
166  G4int noSteps);
167  void WarnTooManyStep( G4double x1start, G4double x2end, G4double xCurrent);
168  void WarnEndPointTooFar (G4double endPointDist,
169  G4double hStepSize ,
170  G4double epsilonRelative,
171  G4int debugFlag);
172  // Issue warnings for undesirable situations
173 
174  void PrintStatus( const G4double* StartArr,
175  G4double xstart,
176  const G4double* CurrentArr,
177  G4double xcurrent,
178  G4double requestStep,
179  G4int subStepNo );
180  void PrintStatus( const G4FieldTrack& StartFT,
181  const G4FieldTrack& CurrentFT,
182  G4double requestStep,
183  G4int subStepNo );
184  void PrintStat_Aux( const G4FieldTrack& aFieldTrack,
185  G4double requestStep,
186  G4double actualStep,
187  G4int subStepNo,
188  G4double subStepSize,
189  G4double dotVelocities );
190  // Verbose output for debugging
191 
192  void PrintStatisticsReport() ;
193  // Report on the number of steps, maximum errors etc.
194 
195 #ifdef QUICK_ADV_TWO
196  G4bool QuickAdvance( G4double yarrin[], // In
197  const G4double dydx[],
198  G4double hstep,
199  G4double yarrout[], // Out
200  G4double& dchord_step, // Out
201  G4double& dyerr ); // in length
202 #endif
203 
204  private:
205 
207  G4MagInt_Driver& operator=(const G4MagInt_Driver&);
208  // Private copy constructor and assignment operator.
209 
210  private:
211 
212  // ---------------------------------------------------------------
213  // INVARIANTS
214 
215  G4double fMinimumStep;
216  // Minimum Step allowed in a Step (in absolute units)
217  G4double fSmallestFraction; // Expected range 1e-12 to 5e-15;
218  // Smallest fraction of (existing) curve length - in relative units
219  // below this fraction the current step will be the last
220 
221  const G4int fNoIntegrationVariables; // Number of Variables in integration
222  const G4int fMinNoVars; // Minimum number for FieldTrack
223  const G4int fNoVars; // Full number of variable
224 
225  G4int fMaxNoSteps;
226  static const G4int fMaxStepBase;
227 
228  G4double safety;
229  G4double pshrnk; // exponent for shrinking
230  G4double pgrow; // exponent for growth
231  G4double errcon;
232  // Parameters used to grow and shrink trial stepsize.
233 
234  static const G4double max_stepping_increase;
235  static const G4double max_stepping_decrease;
236  // Maximum stepsize increase/decrease factors.
237 
238  G4int fStatisticsVerboseLevel;
239 
240  // ---------------------------------------------------------------
241  // DEPENDENT Objects
242  G4MagIntegratorStepper *pIntStepper;
243 
244  // ---------------------------------------------------------------
245  // STATE
246 
247  G4int fNoTotalSteps, fNoBadSteps, fNoSmallSteps, fNoInitialSmallSteps;
248  G4double fDyerr_max, fDyerr_mx2;
249  G4double fDyerrPos_smTot, fDyerrPos_lgTot, fDyerrVel_lgTot;
250  G4double fSumH_sm, fSumH_lg;
251  // Step Statistics
252 
253  G4int fVerboseLevel; // Verbosity level for printing (debug, ..)
254  // Could be varied during tracking - to help identify issues
255 
256 };
257 
258 #include "G4MagIntegratorDriver.icc"
259 
260 #endif /* G4MagInt_Driver_Def */