Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 09:11:13

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 // Author: Dmitry Sorokin (CERN, Google Summer of Code 2017), 20.10.2017
0034 // --------------------------------------------------------------------
0035 #ifndef G4RKINTEGRATIONDRIVER_HH
0036 #define G4RKINTEGRATIONDRIVER_HH
0037 
0038 #include "G4VIntegrationDriver.hh"
0039 
0040 /**
0041  * @brief G4RKIntegrationDriver is a templated driver class which controls the
0042  * integration error of a Runge-Kutta stepper.
0043  */
0044 
0045 template <class T>
0046 class G4RKIntegrationDriver : public G4VIntegrationDriver
0047 {
0048   public:
0049 
0050     /**
0051      * Constructor for G4RKIntegrationDriver.
0052      *  @param[in] stepper Pointer to the stepper algorithm.
0053      */
0054     G4RKIntegrationDriver(T* stepper);
0055 
0056     /**
0057      * Copy constructor and assignment operator not allowed.
0058      */
0059     G4RKIntegrationDriver(const G4RKIntegrationDriver&) = delete;
0060     G4RKIntegrationDriver& operator=(const G4RKIntegrationDriver&) = delete;
0061 
0062     /**
0063      * Accessors for derivatives.
0064      */
0065     void GetDerivatives(const G4FieldTrack& track,
0066                               G4double dydx[]) const override;
0067     void GetDerivatives(const G4FieldTrack& track,
0068                               G4double dydx[],
0069                               G4double field[]) const override;
0070 
0071     /**
0072      * Taking the last step's normalised error, it calculates a step size for
0073      * the next step; it limits the next step's size within a factor of the
0074      * current one.
0075      */
0076     G4double ComputeNewStepSize(G4double errMaxNorm, // normalised error
0077                                 G4double hstepCurrent) final;
0078 
0079     /**
0080      * Getter and setter for the equation of motion.
0081      */
0082     G4EquationOfMotion* GetEquationOfMotion() override;
0083     void SetEquationOfMotion(G4EquationOfMotion* equation) override;
0084 
0085     /**
0086      * Accessors for the stepper.
0087      */
0088     const T* GetStepper() const override;
0089     T* GetStepper() override;
0090 
0091     /**
0092      * Writes out to stream the parameters/state of the driver.
0093      */
0094     void  StreamInfo( std::ostream& os ) const override;
0095    
0096     /**
0097      * Accessors.
0098      */
0099     G4double GetSafety() const;
0100     G4double GetPshrnk() const;
0101     G4double GetPgrow() const;
0102 
0103     void RenewStepperAndAdjust(G4MagIntegratorStepper* stepper) override;
0104 
0105     void ReSetParameters(G4double safety = 0.9);
0106     void SetSafety(G4double valS);
0107       //  i) sets the exponents (pgrow & pshrnk),
0108       //     using the current Stepper's order,
0109       // ii) sets the safety
0110 
0111      G4int GetMaxNoSteps() const;
0112      void SetMaxNoSteps(G4int val);
0113        // Modify and Get the Maximum number of Steps that can be
0114        // taken for the integration of a single segment -
0115        // (ie a single call to AccurateAdvance).
0116 
0117      G4double GetSmallestFraction() const;
0118      void SetSmallestFraction(G4double val);
0119 
0120   protected:
0121 
0122     /**
0123      * Utility methods to control step size.
0124      */
0125     G4double ShrinkStepSize(G4double h, G4double error) const;
0126     G4double GrowStepSize(G4double h, G4double error) const;
0127     G4double ShrinkStepSize2(G4double h, G4double error2) const;
0128     G4double GrowStepSize2(G4double h, G4double error2) const;
0129     void UpdateErrorConstraints();
0130 
0131   private:
0132 
0133     /**
0134      * Sets the stepper according to the provided one.
0135      */
0136     inline void RenewStepperAndAdjustImpl(T* stepper);
0137 
0138   private:
0139 
0140     G4int fMaxNoSteps;
0141 
0142     /** The (default) max number of steps is Base divided by the order of Stepper. */
0143     G4int fMaxStepBase;
0144 
0145     /** Parameters used to grow and shrink trial stepsize. */
0146     G4double safety;
0147     G4double pshrnk;   //  exponent for shrinking
0148     G4double pgrow;    //  exponent for growth
0149 
0150     /** Maximum error values for shrinking / growing (optimisation). */
0151     G4double errorConstraintShrink;
0152     G4double errorConstraintGrow;
0153 
0154     T* pIntStepper = nullptr;
0155 };
0156 
0157 #include "G4RKIntegrationDriver.icc"
0158 
0159 #endif