Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 09:10:50

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 // G4CashKarpRKF45
0027 //
0028 // Class description:
0029 //
0030 // The Cash-Karp Runge-Kutta-Fehlberg 4/5 method is an embedded fourth
0031 // order method (giving fifth-order accuracy) for the solution of an ODE.
0032 // Two different fourth order estimates are calculated; their difference
0033 // gives an error estimate. [ref. Numerical Recipes in C, 2nd Edition]
0034 // It is used to integrate the equations of the motion of a particle 
0035 // in a magnetic field.
0036 
0037 // Authors: J.Apostolakis, V.Grichine (CERN), 30.01.1997
0038 // -------------------------------------------------------------------
0039 #ifndef G4CASHKARP_RKF45_HH
0040 #define G4CASHKARP_RKF45_HH
0041 
0042 #include "G4MagIntegratorStepper.hh"
0043 
0044 /**
0045  * @brief G4CashKarpRKF45 implements the Cash-Karp Runge-Kutta-Fehlberg
0046  * 4/5 method, an embedded fourth order method (giving fifth-order accuracy)
0047  * for the solution of an ODE. Two different fourth order estimates are
0048  * calculated; their difference gives an error estimate. 
0049  * It is used to integrate the equations of the motion of a particle 
0050  * in a magnetic field.
0051  */
0052 
0053 class G4CashKarpRKF45 : public G4MagIntegratorStepper
0054 {
0055   public:
0056 
0057     /**
0058      * Constructor for G4CashKarpRKF45.
0059      *  @param[in] EqRhs Pointer to the provided equation of motion.
0060      *  @param[in] numberOfVariables The number of integration variables.
0061      *  @param[in] primary Flag for initialisation of the auxiliary stepper.
0062      */
0063     G4CashKarpRKF45( G4EquationOfMotion* EqRhs,
0064                      G4int numberOfVariables = 6,
0065                      G4bool primary = true );
0066 
0067     /**
0068      * Destructor.
0069      */
0070     ~G4CashKarpRKF45() override;
0071 
0072     /**
0073      * Copy constructor and assignment operator not allowed.
0074      */
0075     G4CashKarpRKF45(const G4CashKarpRKF45&) = delete;
0076     G4CashKarpRKF45& operator=(const G4CashKarpRKF45&) = delete;
0077  
0078     /**
0079      * The stepper for the Runge Kutta integration.
0080      * The stepsize is fixed, with the step size given by 'h'.
0081      * Integrates ODE starting values y[0 to 6].
0082      * Outputs yout[] and its estimated error yerr[].
0083      *  @param[in] y Starting values array of integration variables.
0084      *  @param[in] dydx Derivatives array.
0085      *  @param[in] h The given step size.
0086      *  @param[out] yout Integration output.
0087      *  @param[out] yerr The estimated error.
0088      */
0089     void Stepper( const G4double y[],
0090                   const G4double dydx[],
0091                         G4double h,
0092                         G4double yout[],
0093                         G4double yerr[] ) override;
0094 
0095     /**
0096      * Returns the distance from chord line.
0097      */
0098     G4double DistChord() const override; 
0099 
0100     /**
0101      * Returns the order, 4, of integration.
0102      */
0103     inline G4int IntegratorOrder() const override { return 4; }
0104 
0105     /**
0106      * Returns the stepper type-ID, "kCashKarpRKF45".
0107      */
0108     inline G4StepperType StepperType() const override { return kCashKarpRKF45; }
0109 
0110   private:
0111 
0112     /** Scratch space. */
0113     G4double *ak2, *ak3, *ak4, *ak5, *ak6, *yTemp, *yIn;
0114 
0115     G4double fLastStepLength = 0.0;
0116 
0117     /** For DistChord calculations. */
0118     G4double *fLastInitialVector, *fLastFinalVector,
0119              *fLastDyDx, *fMidVector, *fMidError;
0120 
0121     G4CashKarpRKF45* fAuxStepper = nullptr;
0122 };
0123 
0124 #endif