Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ChebyshevApproximation Class Reference

#include <G4ChebyshevApproximation.hh>

Public Member Functions

 G4ChebyshevApproximation (function pFunction, G4int n, G4double a, G4double b)
 
 G4ChebyshevApproximation (function pFunction, G4int n, G4int m, G4double a, G4double b)
 
 G4ChebyshevApproximation (function pFunction, G4double a, G4double b, G4int n)
 
 ~G4ChebyshevApproximation ()
 
 G4ChebyshevApproximation (const G4ChebyshevApproximation &)=delete
 
G4ChebyshevApproximationoperator= (const G4ChebyshevApproximation &)=delete
 
G4double GetChebyshevCof (G4int number) const
 
G4double ChebyshevEvaluation (G4double x) const
 
void DerivativeChebyshevCof (G4double derCof[]) const
 
void IntegralChebyshevCof (G4double integralCof[]) const
 

Detailed Description

Definition at line 47 of file G4ChebyshevApproximation.hh.

Constructor & Destructor Documentation

◆ G4ChebyshevApproximation() [1/4]

G4ChebyshevApproximation::G4ChebyshevApproximation ( function  pFunction,
G4int  n,
G4double  a,
G4double  b 
)

Definition at line 40 of file G4ChebyshevApproximation.cc.

42 : fFunction(pFunction)
43 , fNumber(n)
44 , fChebyshevCof(new G4double[fNumber])
45 , fMean(0.5 * (b + a))
46 , fDiff(0.5 * (b - a))
47{
48 G4int i = 0, j = 0;
49 G4double rootSum = 0.0, cofj = 0.0;
50 G4double* tempFunction = new G4double[fNumber];
51 G4double weight = 2.0 / fNumber;
52 G4double cof = 0.5 * weight * pi; // pi/n
53
54 for(i = 0; i < fNumber; ++i)
55 {
56 rootSum = std::cos(cof * (i + 0.5));
57 tempFunction[i] = fFunction(rootSum * fDiff + fMean);
58 }
59 for(j = 0; j < fNumber; ++j)
60 {
61 cofj = cof * j;
62 rootSum = 0.0;
63
64 for(i = 0; i < fNumber; ++i)
65 {
66 rootSum += tempFunction[i] * std::cos(cofj * (i + 0.5));
67 }
68 fChebyshevCof[j] = weight * rootSum;
69 }
70 delete[] tempFunction;
71}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
const G4double pi

◆ G4ChebyshevApproximation() [2/4]

G4ChebyshevApproximation::G4ChebyshevApproximation ( function  pFunction,
G4int  n,
G4int  m,
G4double  a,
G4double  b 
)

Definition at line 80 of file G4ChebyshevApproximation.cc.

83 : fFunction(pFunction)
84 , fNumber(nx)
85 , fChebyshevCof(new G4double[fNumber])
86 , fMean(0.5 * (b + a))
87 , fDiff(0.5 * (b - a))
88{
89 if(nx <= mx)
90 {
91 G4Exception("G4ChebyshevApproximation::G4ChebyshevApproximation()",
92 "InvalidCall", FatalException, "Invalid arguments !");
93 }
94 G4int i = 0, j = 0;
95 G4double rootSum = 0.0, cofj = 0.0;
96 G4double* tempFunction = new G4double[fNumber];
97 G4double weight = 2.0 / fNumber;
98 G4double cof = 0.5 * weight * pi; // pi/nx
99
100 for(i = 0; i < fNumber; ++i)
101 {
102 rootSum = std::cos(cof * (i + 0.5));
103 tempFunction[i] = fFunction(rootSum * fDiff + fMean);
104 }
105 for(j = 0; j < fNumber; ++j)
106 {
107 cofj = cof * j;
108 rootSum = 0.0;
109
110 for(i = 0; i < fNumber; ++i)
111 {
112 rootSum += tempFunction[i] * std::cos(cofj * (i + 0.5));
113 }
114 fChebyshevCof[j] = weight * rootSum; // corresponds to pFunction
115 }
116 // Chebyshev coefficients for (mx)-derivative of pFunction
117
118 for(i = 1; i <= mx; ++i)
119 {
120 DerivativeChebyshevCof(tempFunction);
121 fNumber--;
122 for(j = 0; j < fNumber; ++j)
123 {
124 fChebyshevCof[j] = tempFunction[j]; // corresponds to (i)-derivative
125 }
126 }
127 delete[] tempFunction; // delete of dynamically allocated tempFunction
128}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
void DerivativeChebyshevCof(G4double derCof[]) const

◆ G4ChebyshevApproximation() [3/4]

G4ChebyshevApproximation::G4ChebyshevApproximation ( function  pFunction,
G4double  a,
G4double  b,
G4int  n 
)

Definition at line 135 of file G4ChebyshevApproximation.cc.

138 : fFunction(pFunction)
139 , fNumber(n)
140 , fChebyshevCof(new G4double[fNumber])
141 , fMean(0.5 * (b + a))
142 , fDiff(0.5 * (b - a))
143{
144 G4int i = 0, j = 0;
145 G4double rootSum = 0.0, cofj = 0.0;
146 G4double* tempFunction = new G4double[fNumber];
147 G4double weight = 2.0 / fNumber;
148 G4double cof = 0.5 * weight * pi; // pi/n
149
150 for(i = 0; i < fNumber; ++i)
151 {
152 rootSum = std::cos(cof * (i + 0.5));
153 tempFunction[i] = fFunction(rootSum * fDiff + fMean);
154 }
155 for(j = 0; j < fNumber; ++j)
156 {
157 cofj = cof * j;
158 rootSum = 0.0;
159
160 for(i = 0; i < fNumber; ++i)
161 {
162 rootSum += tempFunction[i] * std::cos(cofj * (i + 0.5));
163 }
164 fChebyshevCof[j] = weight * rootSum; // corresponds to pFunction
165 }
166 // Chebyshev coefficients for integral of pFunction
167
168 IntegralChebyshevCof(tempFunction);
169 for(j = 0; j < fNumber; ++j)
170 {
171 fChebyshevCof[j] = tempFunction[j]; // corresponds to integral
172 }
173 delete[] tempFunction; // delete of dynamically allocated tempFunction
174}
void IntegralChebyshevCof(G4double integralCof[]) const

◆ ~G4ChebyshevApproximation()

G4ChebyshevApproximation::~G4ChebyshevApproximation ( )

Definition at line 180 of file G4ChebyshevApproximation.cc.

181{
182 delete[] fChebyshevCof;
183}

◆ G4ChebyshevApproximation() [4/4]

G4ChebyshevApproximation::G4ChebyshevApproximation ( const G4ChebyshevApproximation )
delete

Member Function Documentation

◆ ChebyshevEvaluation()

G4double G4ChebyshevApproximation::ChebyshevEvaluation ( G4double  x) const

Definition at line 205 of file G4ChebyshevApproximation.cc.

206{
207 G4double evaluate = 0.0, evaluate2 = 0.0, temp = 0.0, xReduced = 0.0,
208 xReduced2 = 0.0;
209
210 if((x - fMean + fDiff) * (x - fMean - fDiff) > 0.0)
211 {
212 G4Exception("G4ChebyshevApproximation::ChebyshevEvaluation()",
213 "InvalidCall", FatalException, "Invalid argument !");
214 }
215 xReduced = (x - fMean) / fDiff;
216 xReduced2 = 2.0 * xReduced;
217 for(G4int i = fNumber - 1; i >= 1; --i)
218 {
219 temp = evaluate;
220 evaluate = xReduced2 * evaluate - evaluate2 + fChebyshevCof[i];
221 evaluate2 = temp;
222 }
223 return xReduced * evaluate - evaluate2 + 0.5 * fChebyshevCof[0];
224}

◆ DerivativeChebyshevCof()

void G4ChebyshevApproximation::DerivativeChebyshevCof ( G4double  derCof[]) const

Definition at line 231 of file G4ChebyshevApproximation.cc.

232{
233 G4double cof = 1.0 / fDiff;
234 derCof[fNumber - 1] = 0.0;
235 derCof[fNumber - 2] = 2 * (fNumber - 1) * fChebyshevCof[fNumber - 1];
236 for(G4int i = fNumber - 3; i >= 0; --i)
237 {
238 derCof[i] = derCof[i + 2] + 2 * (i + 1) * fChebyshevCof[i + 1];
239 }
240 for(G4int j = 0; j < fNumber; ++j)
241 {
242 derCof[j] *= cof;
243 }
244}

Referenced by G4ChebyshevApproximation().

◆ GetChebyshevCof()

G4double G4ChebyshevApproximation::GetChebyshevCof ( G4int  number) const

Definition at line 190 of file G4ChebyshevApproximation.cc.

191{
192 if(number < 0 && number >= fNumber)
193 {
194 G4Exception("G4ChebyshevApproximation::GetChebyshevCof()", "InvalidCall",
195 FatalException, "Argument out of range !");
196 }
197 return fChebyshevCof[number];
198}

◆ IntegralChebyshevCof()

void G4ChebyshevApproximation::IntegralChebyshevCof ( G4double  integralCof[]) const

Definition at line 255 of file G4ChebyshevApproximation.cc.

257{
258 G4double cof = 0.5 * fDiff, sum = 0.0, factor = 1.0;
259 for(G4int i = 1; i < fNumber - 1; ++i)
260 {
261 integralCof[i] = cof * (fChebyshevCof[i - 1] - fChebyshevCof[i + 1]) / i;
262 sum += factor * integralCof[i];
263 factor = -factor;
264 }
265 integralCof[fNumber - 1] = cof * fChebyshevCof[fNumber - 2] / (fNumber - 1);
266 sum += factor * integralCof[fNumber - 1];
267 integralCof[0] = 2.0 * sum; // set the constant of integration
268}

Referenced by G4ChebyshevApproximation().

◆ operator=()

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

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