G4MagIntegratorDriver.hh

Go to the documentation of this file.
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 //
00027 // $Id: G4MagIntegratorDriver.hh 69786 2013-05-15 09:38:51Z gcosmo $
00028 //
00029 //
00030 // class G4MagInt_Driver
00031 //
00032 // Class description:
00033 //
00034 // Provides a driver that talks to the Integrator Stepper, and insures that 
00035 // the error is within acceptable bounds.
00036 
00037 // History:
00038 // - Created. J.Apostolakis.
00039 // --------------------------------------------------------------------
00040 
00041 #ifndef G4MagInt_Driver_Def
00042 #define G4MagInt_Driver_Def
00043 
00044 #include "G4Types.hh"
00045 #include "G4FieldTrack.hh"
00046 #include "G4MagIntegratorStepper.hh"
00047 
00048 class G4MagInt_Driver
00049 {
00050    public:  // with description
00051 
00052      G4bool  AccurateAdvance(G4FieldTrack&  y_current,
00053                              G4double hstep,
00054                              G4double eps,            // Requested y_err/hstep
00055                              G4double hinitial=0.0);  // Suggested 1st interval
00056        // Above drivers for integrator (Runge-Kutta) with stepsize control. 
00057        // Integrates ODE starting values y_current
00058        // from current s (s=s0) to s=s0+h with accuracy eps. 
00059        // On output ystart is replaced by value at end of interval. 
00060        // The concept is similar to the odeint routine from NRC p.721-722.
00061 
00062      G4bool  QuickAdvance(      G4FieldTrack& y_val,      // INOUT
00063                           const G4double     dydx[],  
00064                                 G4double     hstep,       // IN 
00065                                 G4double&    dchord_step,
00066                                 G4double&    dyerr )  ;
00067         // QuickAdvance just tries one Step - it does not ensure accuracy.
00068 
00069      G4bool  QuickAdvance(      G4FieldTrack& y_posvel,        // INOUT
00070                           const G4double      dydx[],  
00071                                 G4double      hstep,           // IN
00072                                 G4double&     dchord_step,
00073                                 G4double&     dyerr_pos_sq,
00074                                 G4double&     dyerr_mom_rel_sq ) ;
00075        // New QuickAdvance that also just tries one Step
00076        //    (so also does not ensure accuracy)
00077        //    but does return the errors in  position and
00078        //        momentum (normalised: Delta_Integration(p^2)/(p^2) )
00079 
00080      G4MagInt_Driver( G4double                hminimum, 
00081                       G4MagIntegratorStepper *pItsStepper,
00082                       G4int                   numberOfComponents=6,
00083                       G4int                   statisticsVerbosity=1);
00084      ~G4MagInt_Driver();
00085         // Constructor, destructor.
00086 
00087      inline G4double GetHmin() const;
00088      inline G4double Hmin() const;     // Obsolete
00089      inline G4double GetSafety() const;
00090      inline G4double GetPshrnk() const;
00091      inline G4double GetPgrow() const;
00092      inline G4double GetErrcon() const;
00093      inline void GetDerivatives( const G4FieldTrack &y_curr,     // const, INput
00094                                        G4double    dydx[]   );  //       OUTput
00095         // Accessors.
00096 
00097      inline void RenewStepperAndAdjust(G4MagIntegratorStepper *pItsStepper);
00098         // Sets a new stepper pItsStepper for this driver. Then it calls
00099         // ReSetParameters to reset its parameters accordingly.
00100 
00101      inline void ReSetParameters(G4double new_safety= 0.9 );
00102         //  i) sets the exponents (pgrow & pshrnk), 
00103         //     using the current Stepper's order, 
00104         // ii) sets the safety
00105         // ii) calculates "errcon" according to the above values.
00106 
00107      inline void SetSafety(G4double valS);
00108      inline void SetPshrnk(G4double valPs);
00109      inline void SetPgrow (G4double valPg);
00110      inline void SetErrcon(G4double valEc);
00111         // When setting safety or pgrow, errcon will be set to a 
00112         // compatible value.
00113 
00114      inline G4double ComputeAndSetErrcon();
00115 
00116      inline void SetChargeMomentumMass( G4double particleCharge,
00117                                         G4double MomentumXc,
00118                                         G4double Mass );
00119         // Change them in Equation. particleCharge is in e+ units.
00120 
00121      inline const G4MagIntegratorStepper* GetStepper() const;
00122 
00123      void  OneGoodStep(       G4double  ystart[], // Like old RKF45step()
00124                         const G4double  dydx[],
00125                               G4double& x,
00126                               G4double htry,
00127                               G4double  eps,      //  memb variables ?
00128                               G4double& hdid,
00129                               G4double& hnext ) ;
00130         // This takes one Step that is as large as possible while 
00131         // satisfying the accuracy criterion of:
00132         // yerr < eps * |y_end-y_start|
00133 
00134      G4double ComputeNewStepSize( G4double  errMaxNorm,    // normalised error
00135                                   G4double  hstepCurrent); // current step size
00136         // Taking the last step's normalised error, calculate
00137         // a step size for the next step.
00138         // Do not limit the next step's size within a factor of the
00139         // current one.
00140 
00141      G4double ComputeNewStepSize_WithinLimits(
00142                           G4double  errMaxNorm,    // normalised error
00143                           G4double  hstepCurrent); // current step size
00144         // Taking the last step's normalised error, calculate
00145         // a step size for the next step.
00146         // Limit the next step's size within a range around the current one.
00147 
00148      inline G4int    GetMaxNoSteps() const;
00149      inline void     SetMaxNoSteps( G4int val); 
00150         //  Modify and Get the Maximum number of Steps that can be
00151         //   taken for the integration of a single segment -
00152         //   (ie a single call to AccurateAdvance).
00153 
00154    public:  // without description
00155 
00156      inline void SetHmin(G4double newval);
00157      inline void SetVerboseLevel(G4int newLevel); 
00158      inline G4double GetVerboseLevel() const;
00159 
00160      inline G4double GetSmallestFraction() const; 
00161      void     SetSmallestFraction( G4double val ); 
00162 
00163    protected:  // without description
00164      void WarnSmallStepSize( G4double hnext, G4double hstep, 
00165                              G4double h,     G4double xDone,
00166                              G4int noSteps);
00167      void WarnTooManyStep( G4double x1start, G4double x2end, G4double xCurrent);
00168      void WarnEndPointTooFar (G4double  endPointDist, 
00169                               G4double  hStepSize , 
00170                               G4double  epsilonRelative,
00171                               G4int     debugFlag);
00172         //  Issue warnings for undesirable situations
00173 
00174      void PrintStatus(  const G4double*      StartArr,
00175                               G4double       xstart,
00176                         const G4double*      CurrentArr, 
00177                               G4double       xcurrent, 
00178                               G4double       requestStep, 
00179                               G4int          subStepNo );
00180      void PrintStatus(  const G4FieldTrack&  StartFT,
00181                         const G4FieldTrack&  CurrentFT, 
00182                               G4double       requestStep, 
00183                               G4int          subStepNo );
00184      void PrintStat_Aux( const G4FieldTrack& aFieldTrack,
00185                                G4double      requestStep, 
00186                                G4double      actualStep,
00187                                G4int         subStepNo,
00188                                G4double      subStepSize,
00189                                G4double      dotVelocities );       
00190        //  Verbose output for debugging
00191 
00192      void PrintStatisticsReport() ;
00193        //  Report on the number of steps, maximum errors etc.
00194 
00195 #ifdef QUICK_ADV_TWO
00196      G4bool QuickAdvance(      G4double     yarrin[],     // In
00197                          const G4double     dydx[],  
00198                                G4double     hstep,        
00199                                G4double     yarrout[],    // Out
00200                                G4double&    dchord_step,  // Out
00201                                G4double&    dyerr );      // in length
00202 #endif
00203 
00204    private:
00205 
00206      G4MagInt_Driver(const G4MagInt_Driver&);
00207      G4MagInt_Driver& operator=(const G4MagInt_Driver&);
00208         // Private copy constructor and assignment operator.
00209 
00210    private:
00211 
00212      // ---------------------------------------------------------------
00213      //  INVARIANTS 
00214 
00215      G4double  fMinimumStep;
00216         // Minimum Step allowed in a Step (in absolute units)
00217      G4double  fSmallestFraction;      //   Expected range 1e-12 to 5e-15;  
00218         // Smallest fraction of (existing) curve length - in relative units
00219         //  below this fraction the current step will be the last 
00220 
00221      const G4int  fNoIntegrationVariables;  // Number of Variables in integration
00222      const G4int  fMinNoVars;               // Minimum number for FieldTrack
00223      const G4int  fNoVars;                  // Full number of variable
00224 
00225      G4int   fMaxNoSteps;
00226      static const G4int  fMaxStepBase;  
00227 
00228      G4double safety;
00229      G4double pshrnk;   //  exponent for shrinking
00230      G4double pgrow;    //  exponent for growth
00231      G4double errcon;
00232         // Parameters used to grow and shrink trial stepsize.
00233 
00234      static const G4double max_stepping_increase;
00235      static const G4double max_stepping_decrease;
00236         // Maximum stepsize increase/decrease factors.
00237 
00238      G4int    fStatisticsVerboseLevel;
00239 
00240      // ---------------------------------------------------------------
00241      // DEPENDENT Objects
00242      G4MagIntegratorStepper *pIntStepper;
00243 
00244      // ---------------------------------------------------------------
00245      //  STATE
00246 
00247      G4int  fNoTotalSteps, fNoBadSteps, fNoSmallSteps, fNoInitialSmallSteps; 
00248      G4double fDyerr_max, fDyerr_mx2;
00249      G4double fDyerrPos_smTot, fDyerrPos_lgTot, fDyerrVel_lgTot; 
00250      G4double fSumH_sm, fSumH_lg; 
00251         // Step Statistics 
00252 
00253      G4int  fVerboseLevel;   // Verbosity level for printing (debug, ..)
00254         // Could be varied during tracking - to help identify issues
00255 
00256 };
00257 
00258 #include "G4MagIntegratorDriver.icc"
00259 
00260 #endif /* G4MagInt_Driver_Def */

Generated on Mon May 27 17:48:50 2013 for Geant4 by  doxygen 1.4.7