Back to home page

EIC code displayed by LXR

 
 

    


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

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 //
0027 //
0028 // Hadronic Process: Nuclear De-excitations
0029 // by V. Lara
0030 
0031 #ifndef G4Solver_h
0032 #define G4Solver_h 1
0033 
0034 #include "globals.hh"
0035 
0036 #include <cmath>
0037 
0038 #define DefaultTolerance 5.0e-14
0039 
0040 template <class Function> class G4Solver 
0041 {
0042 public:
0043     enum {DefaultMaxIter = 100};
0044     
0045     // default constructor
0046     G4Solver() : MaxIter(DefaultMaxIter), tolerance(DefaultTolerance),
0047          a(0.0), b(0.0), root(0.0) {};
0048     
0049     G4Solver(const G4int iterations, const G4double tol) :
0050     MaxIter(iterations), tolerance(tol),
0051     a(0.0), b(0.0), root(0.0) {};
0052 
0053     // copy constructor 
0054     G4Solver(const G4Solver & right);
0055 
0056     // destructor
0057     ~G4Solver() {};
0058     
0059     // operators
0060     G4Solver & operator=(const G4Solver & right);
0061     G4bool operator==(const G4Solver & right) const;
0062     G4bool operator!=(const G4Solver & right) const;
0063         
0064     G4int GetMaxIterations(void) const {return MaxIter;}
0065     void SetMaxIterations(const G4int iterations) {MaxIter=iterations;}
0066     
0067     G4double GetTolerance(void) const {return tolerance;}
0068     void SetTolerance(const G4double epsilon) {tolerance = epsilon;}
0069     
0070     
0071     G4double GetIntervalLowerLimit(void) const {return a;}
0072     G4double GetIntervalUpperLimit(void) const {return b;}
0073     
0074     void SetIntervalLimits(const G4double Limit1, const G4double Limit2);
0075     
0076     G4double GetRoot(void) const {return root;}
0077     
0078     // Calculates the root by the Bisection method
0079     G4bool Bisection(Function & theFunction);   
0080     
0081     // Calculates the root by the Regula-Falsi method
0082     G4bool RegulaFalsi(Function & theFunction);
0083     
0084     
0085     // Calculates the root by the Brent's method
0086     G4bool Brent(Function & theFunction);
0087 
0088     // Calculates the root by the Inverse Parabolic Interpolation method 
0089     // due to Jack Crenshaw
0090     G4bool Crenshaw(Function & theFunction);
0091     
0092 private:
0093 
0094     // Maximum number of iterations
0095     G4int MaxIter;
0096 
0097     // 
0098     G4double tolerance;
0099 
0100     // interval limits [a,b] which should bracket the root
0101     G4double a;
0102     G4double b;
0103 
0104     // The root
0105     G4double root;
0106 
0107 };
0108 
0109 #include "G4Solver.icc"
0110 
0111 #endif