Import Geant4 11.4.0 source tree
This commit is contained in:
@@ -30,9 +30,8 @@
|
||||
// Provides a driver that talks to the Integrator Stepper, and insures that
|
||||
// the error is within acceptable bounds.
|
||||
|
||||
// V.Grichine, 07.10.1996 - Created
|
||||
// W.Wander, 28.01.1998 - Added ability for low order integrators
|
||||
// J.Apostolakis, 08.11.2001 - Respect minimum step in AccurateAdvance
|
||||
// Author: Vladimir Grichine (CERN), 07.10.1996 - Created
|
||||
// W.Wander (MIT), 28.01.1998 - Added ability for low order integrators
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4MAGINT_DRIVER_HH
|
||||
#define G4MAGINT_DRIVER_HH
|
||||
@@ -41,61 +40,123 @@
|
||||
#include "G4MagIntegratorStepper.hh"
|
||||
#include "G4ChordFinderDelegate.hh"
|
||||
|
||||
/**
|
||||
* @brief G4MagInt_Driver provides a driver that talks to the Integrator
|
||||
* Stepper and insures that the error is within acceptable bounds.
|
||||
*/
|
||||
|
||||
class G4MagInt_Driver : public G4VIntegrationDriver,
|
||||
public G4ChordFinderDelegate<G4MagInt_Driver>
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor for G4MagInt_Driver.
|
||||
* @param[in] hminimum The minumum allowed step.
|
||||
* @param[in] pItsStepper Pointer to the integrator stepper.
|
||||
* @param[in] numberOfComponents The number of integration variables.
|
||||
* @param[in] statisticsVerbosity Flag for verbosity.
|
||||
*/
|
||||
G4MagInt_Driver(G4double hminimum,
|
||||
G4MagIntegratorStepper* pItsStepper,
|
||||
G4int numberOfComponents = 6,
|
||||
G4int statisticsVerbosity = 0);
|
||||
~G4MagInt_Driver() override;
|
||||
// Constructor, destructor.
|
||||
|
||||
/**
|
||||
* Destructor. Provides statistics if verbosity level is greater than 1.
|
||||
*/
|
||||
~G4MagInt_Driver() override;
|
||||
|
||||
/**
|
||||
* Copy constructor and assignment operator not allowed.
|
||||
*/
|
||||
G4MagInt_Driver(const G4MagInt_Driver&) = delete;
|
||||
G4MagInt_Driver& operator=(const G4MagInt_Driver&) = delete;
|
||||
|
||||
/**
|
||||
* Computes the step to take, based on chord limits.
|
||||
* @param[in,out] track The current track in field.
|
||||
* @param[in] stepMax Proposed maximum step length.
|
||||
* @param[in] epsStep Requested accuracy, y_err/hstep.
|
||||
* @param[in] chordDistance Maximum sagitta distance.
|
||||
* @returns The length of step taken.
|
||||
*/
|
||||
inline G4double AdvanceChordLimited(G4FieldTrack& track,
|
||||
G4double stepMax,
|
||||
G4double epsStep,
|
||||
G4double chordDistance) override;
|
||||
|
||||
/**
|
||||
* Dispatch interface method for initialisation/reset of driver.
|
||||
*/
|
||||
inline void OnStartTracking() override;
|
||||
|
||||
/**
|
||||
* Dispatch interface method for computing step. Does nothing here.
|
||||
*/
|
||||
inline void OnComputeStep(const G4FieldTrack* = nullptr) override {}
|
||||
|
||||
/**
|
||||
* The driver implements re-integration, so returns true.
|
||||
*/
|
||||
G4bool DoesReIntegrate() const override { return true; }
|
||||
|
||||
/**
|
||||
* Advances integration accurately by relative accuracy better than 'eps'.
|
||||
* @param[in,out] y_current The current track in field.
|
||||
* @param[in] hstep Proposed step length.
|
||||
* @param[in] eps Requested accuracy, y_err/hstep.
|
||||
* @param[in] hinitial Initial minimum integration step.
|
||||
* @returns true if integration succeeds.
|
||||
*/
|
||||
G4bool AccurateAdvance(G4FieldTrack& y_current,
|
||||
G4double hstep,
|
||||
G4double eps, // Requested y_err/hstep
|
||||
G4double hinitial = 0.0) override;
|
||||
// Above drivers for integrator (Runge-Kutta) with stepsize control.
|
||||
// Integrates ODE starting values y_current
|
||||
// from current s (s=s0) to s=s0+h with accuracy eps.
|
||||
// On output ystart is replaced by value at end of interval.
|
||||
// The concept is similar to the odeint routine from NRC p.721-722.
|
||||
|
||||
G4bool QuickAdvance( G4FieldTrack& y_val, // INOUT
|
||||
/**
|
||||
* Attempts one integration step, and returns estimated error 'dyerr'.
|
||||
* It does not ensure accuracy.
|
||||
* @param[in,out] y_val The current track in field.
|
||||
* @param[in] dydx dydx array.
|
||||
* @param[in] hstep Proposed step length.
|
||||
* @param[out] dchord_step Estimated sagitta distance.
|
||||
* @param[out] dyerr Estimated error.
|
||||
* @returns true if integration succeeds.
|
||||
*/
|
||||
G4bool QuickAdvance(G4FieldTrack& y_val, // In/Out
|
||||
const G4double dydx[],
|
||||
G4double hstep,
|
||||
G4double& dchord_step,
|
||||
G4double& dyerr) override;
|
||||
// QuickAdvance just tries one Step - it does not ensure accuracy.
|
||||
G4double hstep,
|
||||
G4double& dchord_step,
|
||||
G4double& dyerr) override;
|
||||
|
||||
void StreamInfo( std::ostream& os ) const override;
|
||||
// Write out the parameters / state of the driver
|
||||
/**
|
||||
* Writes out to stream the parameters/state of the driver.
|
||||
*/
|
||||
void StreamInfo( std::ostream& os ) const override;
|
||||
|
||||
G4bool QuickAdvance( G4FieldTrack& y_posvel, // INOUT
|
||||
/**
|
||||
* Attempts one integration step, and returns estimated error 'dyerr'.
|
||||
* It does not ensure accuracy.
|
||||
* @param[in,out] y_posvel The current track in field.
|
||||
* @param[in] dydx dydx array.
|
||||
* @param[in] hstep Proposed step length.
|
||||
* @param[out] dchord_step Estimated sagitta distance.
|
||||
* @param[out] dyerr_pos_sq Estimated error in position.
|
||||
* @param[out] dyerr_mom_rel_sq Estimated error in momentum
|
||||
* (normalised: Delta_Integration(p^2)/(p^2)).
|
||||
* @returns true if integration succeeds.
|
||||
*/
|
||||
G4bool QuickAdvance(G4FieldTrack& y_posvel, // In/Out
|
||||
const G4double dydx[],
|
||||
G4double hstep, // IN
|
||||
G4double& dchord_step,
|
||||
G4double& dyerr_pos_sq,
|
||||
G4double& dyerr_mom_rel_sq );
|
||||
// New QuickAdvance that also just tries one Step
|
||||
// (so also does not ensure accuracy)
|
||||
// but does return the errors in position and
|
||||
// momentum (normalised: Delta_Integration(p^2)/(p^2) )
|
||||
G4double hstep, // In
|
||||
G4double& dchord_step,
|
||||
G4double& dyerr_pos_sq,
|
||||
G4double& dyerr_mom_rel_sq );
|
||||
|
||||
/**
|
||||
* Accessors.
|
||||
*/
|
||||
inline G4double GetHmin() const;
|
||||
inline G4double Hmin() const; // Obsolete
|
||||
inline G4double GetSafety() const;
|
||||
@@ -104,95 +165,125 @@ class G4MagInt_Driver : public G4VIntegrationDriver,
|
||||
inline G4double GetErrcon() const;
|
||||
void GetDerivatives(const G4FieldTrack& y_curr, // INput
|
||||
G4double dydx[]) const override; // OUTput
|
||||
|
||||
void GetDerivatives(const G4FieldTrack& track,
|
||||
G4double dydx[],
|
||||
G4double field[]) const override;
|
||||
// Accessors
|
||||
|
||||
/**
|
||||
* Getter and setter for the equation of motion.
|
||||
*/
|
||||
G4EquationOfMotion* GetEquationOfMotion() override;
|
||||
void SetEquationOfMotion(G4EquationOfMotion* equation) override;
|
||||
|
||||
/**
|
||||
* Sets a new stepper 'pItsStepper' for this driver. Then it calls
|
||||
* ResetParameters() to update its parameters accordingly.
|
||||
*/
|
||||
void RenewStepperAndAdjust(G4MagIntegratorStepper* pItsStepper) override;
|
||||
// Sets a new stepper pItsStepper for this driver. Then it calls
|
||||
// ReSetParameters to reset its parameters accordingly.
|
||||
|
||||
/**
|
||||
* Resets the qarameters according to the new provided safety value.
|
||||
* i) sets the exponents (pgrow & pshrnk), using the current order;
|
||||
* ii) sets the safety and calculates "errcon" according to the above values.
|
||||
*/
|
||||
inline void ReSetParameters(G4double new_safety = 0.9);
|
||||
// i) sets the exponents (pgrow & pshrnk),
|
||||
// using the current Stepper's order,
|
||||
// ii) sets the safety
|
||||
// ii) calculates "errcon" according to the above values.
|
||||
|
||||
/**
|
||||
* Modifiers. When setting safety or pgrow, errcon will be set
|
||||
* to a compatible value.
|
||||
*/
|
||||
inline void SetSafety(G4double valS);
|
||||
inline void SetPshrnk(G4double valPs);
|
||||
inline void SetPgrow (G4double valPg);
|
||||
inline void SetErrcon(G4double valEc);
|
||||
// When setting safety or pgrow, errcon will be set to a compatible value.
|
||||
|
||||
inline G4double ComputeAndSetErrcon();
|
||||
|
||||
/**
|
||||
* Accessors for the integrator stepper.
|
||||
*/
|
||||
const G4MagIntegratorStepper* GetStepper() const override;
|
||||
G4MagIntegratorStepper* GetStepper() override;
|
||||
G4MagIntegratorStepper* GetStepper() override;
|
||||
|
||||
void OneGoodStep( G4double ystart[], // Like old RKF45step()
|
||||
const G4double dydx[],
|
||||
G4double& x,
|
||||
G4double htry,
|
||||
G4double eps, // memb variables ?
|
||||
G4double& hdid,
|
||||
G4double& hnext ) ;
|
||||
// This takes one Step that is as large as possible while
|
||||
// satisfying the accuracy criterion of:
|
||||
// yerr < eps * |y_end-y_start|
|
||||
/**
|
||||
* Takes one Step that is as large as possible while satisfying the
|
||||
* accuracy criterion of: yerr < eps * |y_end-y_start|.
|
||||
* @param[in,out] ystart The current track state, y.
|
||||
* @param[in] dydx The derivatives array.
|
||||
* @param[in,out] x Step start, x.
|
||||
* @param[in] htry Step to attempt.
|
||||
* @param[in] eps The relative accuracy.
|
||||
* @param[out] hdid Step achieved.
|
||||
* @param[out] hnext Proposed next step.
|
||||
* @returns true if integration succeeds.
|
||||
*/
|
||||
void OneGoodStep(G4double ystart[], // Like old RKF45step()
|
||||
const G4double dydx[],
|
||||
G4double& x,
|
||||
G4double htry,
|
||||
G4double eps,
|
||||
G4double& hdid,
|
||||
G4double& hnext ) ;
|
||||
|
||||
/**
|
||||
* Takes the last step's normalised error and calculates a step size
|
||||
* for the next step. Does it limit the next step's size within a factor
|
||||
* of the current?
|
||||
* -- DOES NOT limit for very bad steps
|
||||
* -- DOES limit for very good (x5).
|
||||
*/
|
||||
G4double ComputeNewStepSize(G4double errMaxNorm, // normalised
|
||||
G4double hstepCurrent) override;
|
||||
// Taking the last step's normalised error, calculate
|
||||
// a step size for the next step.
|
||||
// Does it limit the next step's size within a factor of the current?
|
||||
// -- DOES NOT limit for very bad steps
|
||||
// -- DOES limit for very good (x5)
|
||||
|
||||
G4double
|
||||
ComputeNewStepSize_WithoutReductionLimit(G4double errMaxNorm,
|
||||
G4double hstepCurrent);
|
||||
// Taking the last step's normalised error, calculate
|
||||
// a step size for the next step.
|
||||
// Do not limit the next step's size within a factor of the
|
||||
// current one when *reducing* the size, i.e. for badly failing steps.
|
||||
/**
|
||||
* Taking the last step's normalised error, calculates a step size for
|
||||
* the next step. Does not limit the next step's size within a factor of
|
||||
* the current one when *reducing* the size, i.e. for badly failing steps.
|
||||
*/
|
||||
G4double ComputeNewStepSize_WithoutReductionLimit(G4double errMaxNorm,
|
||||
G4double hstepCurrent);
|
||||
|
||||
/**
|
||||
* Taking the last step's normalised error, calculates a step size for
|
||||
* the next step. Limits the next step's size within a range around the
|
||||
* current one.
|
||||
*/
|
||||
G4double ComputeNewStepSize_WithinLimits(G4double errMaxNorm, // normalised
|
||||
G4double hstepCurrent);
|
||||
// Taking the last step's normalised error, calculate
|
||||
// a step size for the next step.
|
||||
// Limit the next step's size within a range around the current one.
|
||||
|
||||
/**
|
||||
* Modifier and accessor for the maximum number of steps that can be taken
|
||||
* for the integration of a single segment, i.e. a single call to
|
||||
* AccurateAdvance().
|
||||
*/
|
||||
inline G4int GetMaxNoSteps() const;
|
||||
inline void SetMaxNoSteps(G4int val);
|
||||
// Modify and Get the Maximum number of Steps that can be
|
||||
// taken for the integration of a single segment -
|
||||
// (i.e. a single call to AccurateAdvance).
|
||||
|
||||
/**
|
||||
* More modifiers and accessors.
|
||||
*/
|
||||
inline void SetHmin(G4double newval);
|
||||
void SetVerboseLevel(G4int newLevel) override;
|
||||
G4int GetVerboseLevel() const override;
|
||||
|
||||
inline G4double GetSmallestFraction() const;
|
||||
void SetSmallestFraction( G4double val );
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Loggers, issuing warnings for undesirable situations.
|
||||
*/
|
||||
void WarnSmallStepSize(G4double hnext, G4double hstep,
|
||||
G4double h, G4double xDone,
|
||||
G4int noSteps);
|
||||
|
||||
void WarnTooManyStep(G4double x1start, G4double x2end, G4double xCurrent);
|
||||
void WarnEndPointTooFar(G4double endPointDist,
|
||||
G4double hStepSize ,
|
||||
G4double epsilonRelative,
|
||||
G4int debugFlag);
|
||||
// Issue warnings for undesirable situations
|
||||
|
||||
/**
|
||||
* Loggers for verbosity printouts.
|
||||
*/
|
||||
void PrintStatus(const G4double* StartArr,
|
||||
G4double xstart,
|
||||
const G4double* CurrentArr,
|
||||
@@ -209,10 +300,10 @@ class G4MagInt_Driver : public G4VIntegrationDriver,
|
||||
G4int subStepNo,
|
||||
G4double subStepSize,
|
||||
G4double dotVelocities);
|
||||
// Verbose output for debugging
|
||||
|
||||
/**
|
||||
* Reports on the number of steps, maximum errors etc.
|
||||
*/
|
||||
void PrintStatisticsReport();
|
||||
// Report on the number of steps, maximum errors etc.
|
||||
|
||||
#ifdef QUICK_ADV_TWO
|
||||
G4bool QuickAdvance( G4double yarrin[], // In
|
||||
@@ -228,25 +319,31 @@ class G4MagInt_Driver : public G4VIntegrationDriver,
|
||||
// ---------------------------------------------------------------
|
||||
// INVARIANTS
|
||||
|
||||
/** Minimum Step allowed in a Step (in absolute units). */
|
||||
G4double fMinimumStep = 0.0;
|
||||
// Minimum Step allowed in a Step (in absolute units)
|
||||
|
||||
/** Smallest fraction of (existing) curve length, in relative units.
|
||||
Below this fraction the current step will be the last. */
|
||||
G4double fSmallestFraction = 1.0e-12; // Expected range 1e-12 to 5e-15
|
||||
// Smallest fraction of (existing) curve length - in relative units
|
||||
// below this fraction the current step will be the last
|
||||
|
||||
const G4int fNoIntegrationVariables = 0; // Variables in integration
|
||||
const G4int fMinNoVars = 12; // Minimum number for FieldTrack
|
||||
const G4int fNoVars = 0; // Full number of variable
|
||||
/** Variables in integration. */
|
||||
const G4int fNoIntegrationVariables = 0;
|
||||
|
||||
/** Minimum number for FieldTrack. */
|
||||
const G4int fMinNoVars = 12;
|
||||
|
||||
/** Full number of variable. */
|
||||
const G4int fNoVars = 0;
|
||||
|
||||
/** Default maximum number of steps is Base divided by the order of Stepper. */
|
||||
G4int fMaxNoSteps;
|
||||
G4int fMaxStepBase = 250; // was 5000
|
||||
// Default maximum number of steps is Base divided by the order of Stepper
|
||||
|
||||
/** Parameters used to grow and shrink trial stepsize. */
|
||||
G4double safety;
|
||||
G4double pshrnk; // exponent for shrinking
|
||||
G4double pgrow; // exponent for growth
|
||||
G4double errcon;
|
||||
// Parameters used to grow and shrink trial stepsize.
|
||||
|
||||
G4int fStatisticsVerboseLevel = 0;
|
||||
|
||||
@@ -258,15 +355,15 @@ class G4MagInt_Driver : public G4VIntegrationDriver,
|
||||
// ---------------------------------------------------------------
|
||||
// STATE
|
||||
|
||||
/** Step Statistics. */
|
||||
unsigned long fNoTotalSteps=0, fNoBadSteps=0;
|
||||
unsigned long fNoSmallSteps=0, fNoInitialSmallSteps=0, fNoCalls=0;
|
||||
G4double fDyerr_max=0.0, fDyerr_mx2=0.0;
|
||||
G4double fDyerrPos_smTot=0.0, fDyerrPos_lgTot=0.0, fDyerrVel_lgTot=0.0;
|
||||
G4double fSumH_sm=0.0, fSumH_lg=0.0;
|
||||
// Step Statistics
|
||||
|
||||
/** Could be varied during tracking - to help identify issues. */
|
||||
G4int fVerboseLevel = 0; // Verbosity level for printing (debug, ..)
|
||||
// Could be varied during tracking - to help identify issues
|
||||
|
||||
using ChordFinderDelegate = G4ChordFinderDelegate<G4MagInt_Driver>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user