Geant4 11.2.2
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 ()=default
 
 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 ( )
default

◆ 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 132 of file G4SimpleIntegration.cc.

134{
135 if(depth > fMaxDepth)
136 {
137 G4Exception("G4SimpleIntegration::AdaptGauss()", "Error", FatalException,
138 "Function varies too rapidly !");
139 }
140 G4double xMean = (xInitial + xFinal) / 2.0;
141 G4double leftHalf = Gauss(xInitial, xMean);
142 G4double rightHalf = Gauss(xMean, xFinal);
143 G4double full = Gauss(xInitial, xFinal);
144 if(std::fabs(leftHalf + rightHalf - full) < fTolerance)
145 {
146 sum += full;
147 }
148 else
149 {
150 ++depth;
151 AdaptGauss(xInitial, xMean, sum, depth);
152 AdaptGauss(xMean, xFinal, sum, depth);
153 }
154}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
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 111 of file G4SimpleIntegration.cc.

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

◆ Gauss() [1/2]

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

Definition at line 120 of file G4SimpleIntegration.cc.

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

◆ Gauss() [2/2]

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

Definition at line 74 of file G4SimpleIntegration.cc.

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

Referenced by AdaptGauss().

◆ MidPoint()

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

Definition at line 60 of file G4SimpleIntegration.cc.

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

◆ operator=()

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

◆ Simpson()

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

Definition at line 90 of file G4SimpleIntegration.cc.

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

◆ Trapezoidal()

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

Definition at line 46 of file G4SimpleIntegration.cc.

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

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