00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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
00055 G4Solver(const G4Solver & right);
00056
00057
00058 ~G4Solver() {};
00059
00060
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
00080 G4bool Bisection(Function & theFunction);
00081
00082
00083 G4bool RegulaFalsi(Function & theFunction);
00084
00085
00086
00087 G4bool Brent(Function & theFunction);
00088
00089
00090
00091 G4bool Crenshaw(Function & theFunction);
00092
00093 private:
00094
00095
00096 G4int MaxIter;
00097
00098
00099 G4double tolerance;
00100
00101
00102 G4double a;
00103 G4double b;
00104
00105
00106 G4double root;
00107
00108 };
00109
00110 #include "G4Solver.icc"
00111
00112 #endif