Geant4 10.7.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 ()
 
 G4SimpleIntegration (const G4SimpleIntegration &)=delete
 
G4SimpleIntegrationoperator= (const G4SimpleIntegration &)=delete
 
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 45 of file G4SimpleIntegration.hh.

Constructor & Destructor Documentation

◆ G4SimpleIntegration() [1/3]

G4SimpleIntegration::G4SimpleIntegration ( function  pFunction)
explicit

Definition at line 34 of file G4SimpleIntegration.cc.

35 : fFunction(pFunction)
36{}

◆ G4SimpleIntegration() [2/3]

G4SimpleIntegration::G4SimpleIntegration ( function  pFunction,
G4double  pTolerance 
)

Definition at line 38 of file G4SimpleIntegration.cc.

40 : fFunction(pFunction)
41 , fTolerance(pTolerance)
42{}

◆ ~G4SimpleIntegration()

G4SimpleIntegration::~G4SimpleIntegration ( )

Definition at line 44 of file G4SimpleIntegration.cc.

44{}

◆ G4SimpleIntegration() [3/3]

G4SimpleIntegration::G4SimpleIntegration ( const G4SimpleIntegration )
delete

Member Function Documentation

◆ AdaptGauss()

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

Definition at line 134 of file G4SimpleIntegration.cc.

136{
137 if(depth > fMaxDepth)
138 {
139 G4Exception("G4SimpleIntegration::AdaptGauss()", "Error", FatalException,
140 "Function varies too rapidly !");
141 }
142 G4double xMean = (xInitial + xFinal) / 2.0;
143 G4double leftHalf = Gauss(xInitial, xMean);
144 G4double rightHalf = Gauss(xMean, xFinal);
145 G4double full = Gauss(xInitial, xFinal);
146 if(std::fabs(leftHalf + rightHalf - full) < fTolerance)
147 {
148 sum += full;
149 }
150 else
151 {
152 ++depth;
153 AdaptGauss(xInitial, xMean, sum, depth);
154 AdaptGauss(xMean, xFinal, sum, depth);
155 }
156}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
double G4double
Definition: G4Types.hh:83
G4double Gauss(G4double xInitial, G4double xFinal, G4int iterationNumber)
void AdaptGauss(G4double xInitial, G4double xFinal, G4double &sum, G4int &depth)

Referenced by AdaptGauss(), and AdaptGaussIntegration().

◆ AdaptGaussIntegration()

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

Definition at line 113 of file G4SimpleIntegration.cc.

115{
116 G4int depth = 0;
117 G4double sum = 0.0;
118 AdaptGauss(xInitial, xFinal, sum, depth);
119 return sum;
120}
int G4int
Definition: G4Types.hh:85

◆ Gauss() [1/2]

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

Definition at line 122 of file G4SimpleIntegration.cc.

123{
124 static const G4double root = 1.0 / std::sqrt(3.0);
125
126 G4double xMean = (xInitial + xFinal) / 2.0;
127 G4double Step = (xFinal - xInitial) / 2.0;
128 G4double delta = Step * root;
129 G4double sum = (fFunction(xMean + delta) + fFunction(xMean - delta));
130
131 return sum * Step;
132}

◆ Gauss() [2/2]

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

Definition at line 76 of file G4SimpleIntegration.cc.

78{
79 G4double x = 0.;
80 static const G4double root = 1.0 / std::sqrt(3.0);
81 G4double Step = (xFinal - xInitial) / (2.0 * iterationNumber);
82 G4double delta = Step * root;
83 G4double mean = 0.0;
84 for(G4int i = 0; i < iterationNumber; ++i)
85 {
86 x = (2 * i + 1) * Step;
87 mean += (fFunction(x + delta) + fFunction(x - delta));
88 }
89 return mean * Step;
90}

Referenced by AdaptGauss().

◆ MidPoint()

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

Definition at line 62 of file G4SimpleIntegration.cc.

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

◆ operator=()

G4SimpleIntegration & G4SimpleIntegration::operator= ( const G4SimpleIntegration )
delete

◆ Simpson()

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

Definition at line 92 of file G4SimpleIntegration.cc.

94{
95 G4double Step = (xFinal - xInitial) / iterationNumber;
96 G4double x = xInitial;
97 G4double xPlus = xInitial + 0.5 * Step;
98 G4double mean = (fFunction(xInitial) + fFunction(xFinal)) * 0.5;
99 G4double sum = fFunction(xPlus);
100 for(G4int i = 1; i < iterationNumber; ++i)
101 {
102 x += Step;
103 xPlus += Step;
104 mean += fFunction(x);
105 sum += fFunction(xPlus);
106 }
107 mean += 2.0 * sum;
108 return mean * Step / 3.0;
109}

◆ Trapezoidal()

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

Definition at line 48 of file G4SimpleIntegration.cc.

50{
51 G4double Step = (xFinal - xInitial) / iterationNumber;
52 G4double mean = (fFunction(xInitial) + fFunction(xFinal)) * 0.5;
53 G4double x = xInitial;
54 for(G4int i = 1; i < iterationNumber; ++i)
55 {
56 x += Step;
57 mean += fFunction(x);
58 }
59 return mean * Step;
60}

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