Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4SimpleIntegration Class Reference

#include <G4SimpleIntegration.hh>

Public Member Functions

 G4SimpleIntegration (function pFunction)
 
 G4SimpleIntegration (function pFunction, G4double pTolerance)
 
 ~G4SimpleIntegration ()
 
G4double Trapezoidal (G4double xInitial, G4double xFinal, G4int iterationNumber)
 
G4double MidPoint (G4double xInitial, G4double xFinal, G4int iterationNumber)
 
G4double Gauss (G4double xInitial, G4double xFinal, G4int iterationNumber)
 
G4double Simpson (G4double xInitial, G4double xFinal, G4int iterationNumber)
 
G4double AdaptGaussIntegration (G4double xInitial, G4double xFinal)
 

Protected Member Functions

G4double Gauss (G4double xInitial, G4double xFinal)
 
void AdaptGauss (G4double xInitial, G4double xFinal, G4double &sum, G4int &depth)
 

Detailed Description

Definition at line 64 of file G4SimpleIntegration.hh.

Constructor & Destructor Documentation

G4SimpleIntegration::G4SimpleIntegration ( function  pFunction)
explicit

Definition at line 36 of file G4SimpleIntegration.cc.

37  : fFunction(pFunction),
38  fTolerance(.0001),
39  fMaxDepth(100)
40 {
41 }
G4SimpleIntegration::G4SimpleIntegration ( function  pFunction,
G4double  pTolerance 
)

Definition at line 43 of file G4SimpleIntegration.cc.

45  : fFunction(pFunction),
46  fTolerance(pTolerance),
47  fMaxDepth(100)
48 {
49 }
G4SimpleIntegration::~G4SimpleIntegration ( )

Definition at line 52 of file G4SimpleIntegration.cc.

53 {
54 }

Member Function Documentation

void G4SimpleIntegration::AdaptGauss ( G4double  xInitial,
G4double  xFinal,
G4double sum,
G4int depth 
)
protected

Definition at line 160 of file G4SimpleIntegration.cc.

164 {
165  if(depth >fMaxDepth)
166  {
167  G4Exception("G4SimpleIntegration::AdaptGauss()", "Error",
168  FatalException, "Function varies too rapidly !") ;
169  }
170  G4double xMean = (xInitial + xFinal)/2.0 ;
171  G4double leftHalf = Gauss(xInitial,xMean) ;
172  G4double rightHalf = Gauss(xMean,xFinal) ;
173  G4double full = Gauss(xInitial,xFinal) ;
174  if(std::fabs(leftHalf+rightHalf-full) < fTolerance)
175  {
176  sum += full ;
177  }
178  else
179  {
180  depth++ ;
181  AdaptGauss(xInitial,xMean,sum,depth) ;
182  AdaptGauss(xMean,xFinal,sum,depth) ;
183  }
184 }
G4double Gauss(G4double xInitial, G4double xFinal, G4int iterationNumber)
void AdaptGauss(G4double xInitial, G4double xFinal, G4double &sum, G4int &depth)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

G4double G4SimpleIntegration::AdaptGaussIntegration ( G4double  xInitial,
G4double  xFinal 
)

Definition at line 134 of file G4SimpleIntegration.cc.

136 {
137  G4int depth = 0 ;
138  G4double sum = 0.0 ;
139  AdaptGauss(xInitial,xFinal,sum,depth) ;
140  return sum ;
141 }
int G4int
Definition: G4Types.hh:78
void AdaptGauss(G4double xInitial, G4double xFinal, G4double &sum, G4int &depth)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4double G4SimpleIntegration::Gauss ( G4double  xInitial,
G4double  xFinal,
G4int  iterationNumber 
)

Definition at line 91 of file G4SimpleIntegration.cc.

94 {
95  G4double x=0.;
96  static const G4double root = 1.0/std::sqrt(3.0) ;
97  G4double Step = (xFinal - xInitial)/(2.0*iterationNumber) ;
98  G4double delta = Step*root ;
99  G4double mean = 0.0 ;
100  for(G4int i=0;i<iterationNumber;i++)
101  {
102  x = (2*i + 1)*Step ;
103  mean += (fFunction(x+delta) + fFunction(x-delta)) ;
104  }
105  return mean*Step ;
106 }
int G4int
Definition: G4Types.hh:78
double G4double
Definition: G4Types.hh:76

Here is the caller graph for this function:

G4double G4SimpleIntegration::Gauss ( G4double  xInitial,
G4double  xFinal 
)
protected

Definition at line 145 of file G4SimpleIntegration.cc.

147 {
148  static const G4double root = 1.0/std::sqrt(3.0) ;
149 
150  G4double xMean = (xInitial + xFinal)/2.0 ;
151  G4double Step = (xFinal - xInitial)/2.0 ;
152  G4double delta = Step*root ;
153  G4double sum = (fFunction(xMean + delta) + fFunction(xMean - delta)) ;
154 
155  return sum*Step ;
156 }
double G4double
Definition: G4Types.hh:76
G4double G4SimpleIntegration::MidPoint ( G4double  xInitial,
G4double  xFinal,
G4int  iterationNumber 
)

Definition at line 75 of file G4SimpleIntegration.cc.

78 {
79  G4double Step = (xFinal - xInitial)/iterationNumber ;
80  G4double x = xInitial + 0.5*Step;
81  G4double mean = fFunction(x) ;
82  for(G4int i=1;i<iterationNumber;i++)
83  {
84  x += Step ;
85  mean += fFunction(x) ;
86  }
87  return mean*Step ;
88 }
int G4int
Definition: G4Types.hh:78
double G4double
Definition: G4Types.hh:76
G4double G4SimpleIntegration::Simpson ( G4double  xInitial,
G4double  xFinal,
G4int  iterationNumber 
)

Definition at line 109 of file G4SimpleIntegration.cc.

112 {
113  G4double Step = (xFinal - xInitial)/iterationNumber ;
114  G4double x = xInitial ;
115  G4double xPlus = xInitial + 0.5*Step ;
116  G4double mean = (fFunction(xInitial) + fFunction(xFinal))*0.5 ;
117  G4double sum = fFunction(xPlus) ;
118  for(G4int i=1;i<iterationNumber;i++)
119  {
120  x += Step ;
121  xPlus += Step ;
122  mean += fFunction(x) ;
123  sum += fFunction(xPlus) ;
124  }
125  mean += 2.0*sum ;
126  return mean*Step/3.0 ;
127 }
int G4int
Definition: G4Types.hh:78
double G4double
Definition: G4Types.hh:76
G4double G4SimpleIntegration::Trapezoidal ( G4double  xInitial,
G4double  xFinal,
G4int  iterationNumber 
)

Definition at line 59 of file G4SimpleIntegration.cc.

62 {
63  G4double Step = (xFinal - xInitial)/iterationNumber ;
64  G4double mean = (fFunction(xInitial) + fFunction(xFinal))*0.5 ;
65  G4double x = xInitial ;
66  for(G4int i=1;i<iterationNumber;i++)
67  {
68  x += Step ;
69  mean += fFunction(x) ;
70  }
71  return mean*Step ;
72 }
int G4int
Definition: G4Types.hh:78
double G4double
Definition: G4Types.hh:76

The documentation for this class was generated from the following files: