Geant4 9.6.0
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 ()
 
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 128 of file G4ChebyshevApproximation.hh.

Constructor & Destructor Documentation

◆ G4ChebyshevApproximation() [1/3]

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

Definition at line 39 of file G4ChebyshevApproximation.cc.

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

◆ G4ChebyshevApproximation() [2/3]

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

Definition at line 79 of file G4ChebyshevApproximation.cc.

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

◆ G4ChebyshevApproximation() [3/3]

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

Definition at line 133 of file G4ChebyshevApproximation.cc.

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

◆ ~G4ChebyshevApproximation()

G4ChebyshevApproximation::~G4ChebyshevApproximation ( )

Definition at line 179 of file G4ChebyshevApproximation.cc.

180{
181 delete[] fChebyshevCof ;
182}

Member Function Documentation

◆ ChebyshevEvaluation()

G4double G4ChebyshevApproximation::ChebyshevEvaluation ( G4double  x) const

Definition at line 207 of file G4ChebyshevApproximation.cc.

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

◆ DerivativeChebyshevCof()

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

Definition at line 234 of file G4ChebyshevApproximation.cc.

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

Referenced by G4ChebyshevApproximation().

◆ GetChebyshevCof()

G4double G4ChebyshevApproximation::GetChebyshevCof ( G4int  number) const

Definition at line 191 of file G4ChebyshevApproximation.cc.

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

◆ IntegralChebyshevCof()

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

Definition at line 259 of file G4ChebyshevApproximation.cc.

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

Referenced by G4ChebyshevApproximation().


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