G4Solver.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // Hadronic Process: Nuclear De-excitations
00030 // by V. Lara
00031 
00032 #ifndef G4Solver_h
00033 #define G4Solver_h 1
00034 
00035 #include "globals.hh"
00036 
00037 #include <cmath>
00038 
00039 #define DefaultTolerance 5.0e-14
00040 
00041 template <class Function> class G4Solver 
00042 {
00043 public:
00044     enum {DefaultMaxIter = 100};
00045         
00046     // default constructor
00047     G4Solver() : MaxIter(DefaultMaxIter), tolerance(DefaultTolerance),
00048                  a(0.0), b(0.0), root(0.0) {};
00049         
00050     G4Solver(const G4int iterations, const G4double tol) :
00051         MaxIter(iterations), tolerance(tol),
00052         a(0.0), b(0.0), root(0.0) {};
00053 
00054     // copy constructor 
00055     G4Solver(const G4Solver & right);
00056 
00057     // destructor
00058     ~G4Solver() {};
00059         
00060     // operators
00061     G4Solver & operator=(const G4Solver & right);
00062     G4bool operator==(const G4Solver & right) const;
00063     G4bool operator!=(const G4Solver & right) const;
00064                 
00065     G4int GetMaxIterations(void) const {return MaxIter;}
00066     void SetMaxIterations(const G4int iterations) {MaxIter=iterations;}
00067         
00068     G4double GetTolerance(void) const {return tolerance;}
00069     void SetTolerance(const G4double epsilon) {tolerance = epsilon;}
00070         
00071         
00072     G4double GetIntervalLowerLimit(void) const {return a;}
00073     G4double GetIntervalUpperLimit(void) const {return b;}
00074         
00075     void SetIntervalLimits(const G4double Limit1, const G4double Limit2);
00076     
00077     G4double GetRoot(void) const {return root;}
00078     
00079     // Calculates the root by the Bisection method
00080     G4bool Bisection(Function & theFunction);   
00081         
00082     // Calculates the root by the Regula-Falsi method
00083     G4bool RegulaFalsi(Function & theFunction);
00084         
00085         
00086     // Calculates the root by the Brent's method
00087     G4bool Brent(Function & theFunction);
00088 
00089     // Calculates the root by the Inverse Parabolic Interpolation method 
00090     // due to Jack Crenshaw
00091     G4bool Crenshaw(Function & theFunction);
00092         
00093 private:
00094 
00095     // Maximum number of iterations
00096     G4int MaxIter;
00097 
00098     // 
00099     G4double tolerance;
00100 
00101     // interval limits [a,b] which should bracket the root
00102     G4double a;
00103     G4double b;
00104 
00105     // The root
00106     G4double root;
00107 
00108 };
00109 
00110 #include "G4Solver.icc"
00111 
00112 #endif

Generated on Mon May 27 17:49:52 2013 for Geant4 by  doxygen 1.4.7