Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 09:09:57

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 // G4BogackiShampine45
0027 //
0028 // Class description:
0029 //
0030 // An implementation of the embedded RK method from the following paper 
0031 // by P. Bogacki and L. F. Shampine:
0032 //    "An efficient Runge-Kutta (4,5) pair"
0033 //    Comput. Math. with Appl., vol. 32, no. 6, pp. 15-28, Sep. 1996.
0034 //
0035 // An interpolation method provides the value of an intermediate
0036 // point in a step -- if a step was sucessful.
0037 //
0038 // This version can provide the FSAL property of the method,
0039 // which allows the reuse of the last derivative in the next step,
0040 // but only by using the additional method GetLastDyDx() (an alternative
0041 // interface for simpler use of FSAL is under development).
0042 
0043 // Author: Somnath Banerjee (CERN, Google Summer of Code 2015), 25.05.2015
0044 // Supervision: John Apostolakis (CERN)
0045 // --------------------------------------------------------------------
0046 #ifndef BOGACKI_SHAMPINE_45_HH
0047 #define BOGACKI_SHAMPINE_45_HH
0048 
0049 #include "G4MagIntegratorStepper.hh"
0050 
0051 /**
0052  * @brief G4BogackiShampine45 is an integrator of particle's equation of
0053  * motion based on the Bogacki-Shampine method with FSAL property, allowing
0054  * the reuse of the last derivative in the next step.
0055  * This Stepper provides 'dense output'. After a successful step, it is
0056  * possible to obtain an estimate of the value of the function at an
0057  * intermediate point of the interval. This requires only two additional
0058  * evaluations of the derivative (and thus the field).
0059  */
0060 
0061 class G4BogackiShampine45 : public G4MagIntegratorStepper
0062 {
0063   public:
0064 
0065     /**
0066      * Constructor for G4BogackiShampine45.
0067      *  @param[in] EqRhs Pointer to the provided equation of motion.
0068      *  @param[in] numberOfVariables The number of integration variables.
0069      *  @param[in] primary Flag for initialisation of the auxiliary stepper.
0070      */
0071     G4BogackiShampine45(G4EquationOfMotion* EqRhs,
0072                         G4int numberOfVariables = 6,
0073                         G4bool primary =  true);
0074 
0075     /**
0076      * Destructor.
0077      */
0078     ~G4BogackiShampine45() override;
0079     
0080     /**
0081      * Copy constructor and assignment operator not allowed.
0082      */
0083     G4BogackiShampine45(const G4BogackiShampine45&) = delete;
0084     G4BogackiShampine45& operator=(const G4BogackiShampine45&) = delete;
0085 
0086     /**
0087      * The stepper for the Runge Kutta integration.
0088      * The stepsize is fixed, with the step size given by 'h'.
0089      * Integrates ODE starting values y[0 to 6].
0090      * Outputs yout[] and its estimated error yerr[].
0091      *  @param[in] y Starting values array of integration variables.
0092      *  @param[in] dydx Derivatives array.
0093      *  @param[in] h The given step size.
0094      *  @param[out] yout Integration output.
0095      *  @param[out] yerr The estimated error.
0096      */
0097     void Stepper( const G4double y[],
0098                   const G4double dydx[],
0099                         G4double h,
0100                         G4double yout[],
0101                         G4double yerr[] ) override;
0102 
0103     /**
0104      * Setup all coefficients for interpolation.
0105      */
0106     void SetupInterpolationHigh();  // ( yInput, dydx, Step);
0107     inline void SetupInterpolation() { SetupInterpolationHigh(); }
0108     
0109     /**
0110      * Calculates the output at the tau fraction of step.
0111      *  @param[in] tau The tau fraction of the step.
0112      *  @param[out] yOut Interpolation output.
0113      */
0114     void InterpolateHigh( G4double tau, G4double yOut[] ) const;
0115     inline void Interpolate( G4double tau, 
0116                              G4double yOut[] ) { InterpolateHigh( tau, yOut); }
0117 
0118     /**
0119      * Returns the distance from chord line.
0120      */
0121     G4double DistChord() const override;
0122 
0123     /**
0124      * Returns the order, 4, of integration.
0125      */
0126     inline G4int IntegratorOrder() const override { return 4; }
0127 
0128     /**
0129      * Returns the stepper type-ID, "kBogackiShampine45".
0130      */
0131     inline G4StepperType StepperType() const override { return kBogackiShampine45; }
0132 
0133     /**
0134      * Acccessor for dydx array.
0135      */
0136     void GetLastDydx( G4double dyDxLast[] );
0137 
0138     /**
0139      * Initialises the values of the bi[][] array.
0140      */
0141     void PrepareConstants();
0142    
0143   private:
0144     
0145     G4double *ak2, *ak3, *ak4, *ak5, *ak6, *ak7, *ak8,
0146              *ak9, *ak10, *ak11, *yTemp, *yIn;
0147 
0148     G4double *p[6];
0149 
0150     G4double fLastStepLength = -1.0;
0151 
0152     /** For DistChord() calculations. */
0153     G4double *fLastInitialVector, *fLastFinalVector, *fLastDyDx,
0154              *fMidVector, *fMidError;
0155     
0156     G4BogackiShampine45* fAuxStepper = nullptr;
0157 
0158     /** For chord - until interpolation is proven. */
0159     G4bool fPreparedInterpolation = false;
0160 
0161     /** Class constants. */
0162     static G4bool fPreparedConstants;   
0163     static G4double bi[12][7];
0164 };
0165 
0166 #endif