Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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() [1/2]

G4SimpleIntegration::G4SimpleIntegration ( function  pFunction)
explicit

Definition at line 39 of file G4SimpleIntegration.cc.

40 : fFunction(pFunction),
41 fTolerance(.0001)
42{
43}

◆ G4SimpleIntegration() [2/2]

G4SimpleIntegration::G4SimpleIntegration ( function  pFunction,
G4double  pTolerance 
)

Definition at line 45 of file G4SimpleIntegration.cc.

47 : fFunction(pFunction),
48 fTolerance(pTolerance)
49{
50}

◆ ~G4SimpleIntegration()

G4SimpleIntegration::~G4SimpleIntegration ( )

Definition at line 53 of file G4SimpleIntegration.cc.

54{
55}

Member Function Documentation

◆ AdaptGauss()

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

Definition at line 161 of file G4SimpleIntegration.cc.

165{
166 if(depth >fMaxDepth)
167 {
168 G4Exception("G4SimpleIntegration::AdaptGauss()", "Error",
169 FatalException, "Function varies too rapidly !") ;
170 }
171 G4double xMean = (xInitial + xFinal)/2.0 ;
172 G4double leftHalf = Gauss(xInitial,xMean) ;
173 G4double rightHalf = Gauss(xMean,xFinal) ;
174 G4double full = Gauss(xInitial,xFinal) ;
175 if(std::fabs(leftHalf+rightHalf-full) < fTolerance)
176 {
177 sum += full ;
178 }
179 else
180 {
181 depth++ ;
182 AdaptGauss(xInitial,xMean,sum,depth) ;
183 AdaptGauss(xMean,xFinal,sum,depth) ;
184 }
185}
@ FatalException
double G4double
Definition: G4Types.hh:64
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

Referenced by AdaptGauss(), and AdaptGaussIntegration().

◆ AdaptGaussIntegration()

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

Definition at line 135 of file G4SimpleIntegration.cc.

137{
138 G4int depth = 0 ;
139 G4double sum = 0.0 ;
140 AdaptGauss(xInitial,xFinal,sum,depth) ;
141 return sum ;
142}
int G4int
Definition: G4Types.hh:66

◆ Gauss() [1/2]

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

Definition at line 146 of file G4SimpleIntegration.cc.

148{
149 static G4double root = 1.0/std::sqrt(3.0) ;
150
151 G4double xMean = (xInitial + xFinal)/2.0 ;
152 G4double Step = (xFinal - xInitial)/2.0 ;
153 G4double delta = Step*root ;
154 G4double sum = (fFunction(xMean + delta) + fFunction(xMean - delta)) ;
155
156 return sum*Step ;
157}

◆ Gauss() [2/2]

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

Definition at line 92 of file G4SimpleIntegration.cc.

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

Referenced by AdaptGauss().

◆ MidPoint()

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

Definition at line 76 of file G4SimpleIntegration.cc.

79{
80 G4double Step = (xFinal - xInitial)/iterationNumber ;
81 G4double x = xInitial + 0.5*Step;
82 G4double mean = fFunction(x) ;
83 for(G4int i=1;i<iterationNumber;i++)
84 {
85 x += Step ;
86 mean += fFunction(x) ;
87 }
88 return mean*Step ;
89}

◆ Simpson()

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

Definition at line 110 of file G4SimpleIntegration.cc.

113{
114 G4double Step = (xFinal - xInitial)/iterationNumber ;
115 G4double x = xInitial ;
116 G4double xPlus = xInitial + 0.5*Step ;
117 G4double mean = (fFunction(xInitial) + fFunction(xFinal))*0.5 ;
118 G4double sum = fFunction(xPlus) ;
119 for(G4int i=1;i<iterationNumber;i++)
120 {
121 x += Step ;
122 xPlus += Step ;
123 mean += fFunction(x) ;
124 sum += fFunction(xPlus) ;
125 }
126 mean += 2.0*sum ;
127 return mean*Step/3.0 ;
128}

◆ Trapezoidal()

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

Definition at line 60 of file G4SimpleIntegration.cc.

63{
64 G4double Step = (xFinal - xInitial)/iterationNumber ;
65 G4double mean = (fFunction(xInitial) + fFunction(xFinal))*0.5 ;
66 G4double x = xInitial ;
67 for(G4int i=1;i<iterationNumber;i++)
68 {
69 x += Step ;
70 mean += fFunction(x) ;
71 }
72 return mean*Step ;
73}

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