Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:03

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4RKIntegrationDriver
0027 //
0028 // Class description:
0029 //
0030 // Driver class which controls the integration error of a 
0031 // Runge-Kutta stepper 
0032 
0033 // Created: D.Sorokin, 2017
0034 // --------------------------------------------------------------------
0035 #ifndef G4RKINTEGRATIONDRIVER_HH
0036 #define G4RKINTEGRATIONDRIVER_HH
0037 
0038 #include "G4VIntegrationDriver.hh"
0039 
0040 template <class T>
0041 class G4RKIntegrationDriver : public G4VIntegrationDriver
0042 {
0043   public:
0044 
0045     G4RKIntegrationDriver(T* stepper);
0046 
0047     G4RKIntegrationDriver(const G4RKIntegrationDriver&) = delete;
0048     G4RKIntegrationDriver& operator=(const G4RKIntegrationDriver&) = delete;
0049 
0050     void GetDerivatives(const G4FieldTrack& track,
0051                               G4double dydx[]) const override;
0052 
0053     void GetDerivatives(const G4FieldTrack& track,
0054                               G4double dydx[],
0055                               G4double field[]) const override;
0056 
0057     G4double ComputeNewStepSize(G4double errMaxNorm, // normalised error
0058                                 G4double hstepCurrent) final;
0059       // Taking the last step's normalised error, calculate
0060       // a step size for the next step.
0061       // - Limits the next step's size within a factor of the current one.
0062 
0063     G4EquationOfMotion* GetEquationOfMotion() override;
0064     void SetEquationOfMotion(G4EquationOfMotion* equation) override;
0065 
0066     const T* GetStepper() const override;
0067     T* GetStepper() override;
0068 
0069     void  StreamInfo( std::ostream& os ) const override;
0070    
0071     // Accessors.
0072     G4double GetSafety() const;
0073     G4double GetPshrnk() const;
0074     G4double GetPgrow() const;
0075 
0076     void RenewStepperAndAdjust(G4MagIntegratorStepper* stepper) override;
0077 
0078     void ReSetParameters(G4double safety = 0.9);
0079     void SetSafety(G4double valS);
0080       //  i) sets the exponents (pgrow & pshrnk),
0081       //     using the current Stepper's order,
0082       // ii) sets the safety
0083 
0084      G4int GetMaxNoSteps() const;
0085      void SetMaxNoSteps(G4int val);
0086        // Modify and Get the Maximum number of Steps that can be
0087        // taken for the integration of a single segment -
0088        // (ie a single call to AccurateAdvance).
0089 
0090      G4double GetSmallestFraction() const;
0091      void SetSmallestFraction(G4double val);
0092 
0093   protected:
0094 
0095     G4double ShrinkStepSize(G4double h, G4double error) const;
0096     G4double GrowStepSize(G4double h, G4double error) const;
0097 
0098     G4double ShrinkStepSize2(G4double h, G4double error2) const;
0099     G4double GrowStepSize2(G4double h, G4double error2) const;
0100 
0101     void UpdateErrorConstraints();
0102 
0103   private:
0104 
0105     inline void RenewStepperAndAdjustImpl(T* stepper);
0106 
0107     G4int fMaxNoSteps;
0108 
0109     G4int fMaxStepBase;
0110       // The (default) maximum number of steps is Base
0111       // divided by the order of Stepper
0112 
0113     // Parameters used to grow and shrink trial stepsize.
0114     //
0115     G4double safety;
0116     G4double pshrnk;   //  exponent for shrinking
0117     G4double pgrow;    //  exponent for growth
0118 
0119     // muximum error values for shrinking / growing (optimisation).
0120     //
0121     G4double errorConstraintShrink;
0122     G4double errorConstraintGrow;
0123 
0124     T* pIntStepper = nullptr;
0125 };
0126 
0127 #include "G4RKIntegrationDriver.icc"
0128 
0129 #endif