#include <G4DataInterpolation.hh>
|
| G4DataInterpolation (G4double pX[], G4double pY[], G4int number) |
|
| G4DataInterpolation (G4double pX[], G4double pY[], G4int number, G4double pFirstDerStart, G4double pFirstDerFinish) |
|
| ~G4DataInterpolation () |
|
G4double | PolynomInterpolation (G4double pX, G4double &deltaY) const |
|
void | PolIntCoefficient (G4double cof[]) const |
|
G4double | RationalPolInterpolation (G4double pX, G4double &deltaY) const |
|
G4double | CubicSplineInterpolation (G4double pX) const |
|
G4double | FastCubicSpline (G4double pX, G4int index) const |
|
G4int | LocateArgument (G4double pX) const |
|
void | CorrelatedSearch (G4double pX, G4int &index) const |
|
Definition at line 116 of file G4DataInterpolation.hh.
Definition at line 58 of file G4DataInterpolation.cc.
65 fSecondDerivative(
new G4double[number]),
70 const G4double maxDerivative = 0.99e30 ;
73 for(i=0;i<fNumber;i++)
75 fArgument[i] = pX[i] ;
76 fFunction[i] = pY[i] ;
78 if(pFirstDerStart > maxDerivative)
80 fSecondDerivative[0] = 0.0 ;
85 fSecondDerivative[0] = -0.5 ;
86 u[0] = (3.0/(fArgument[1]-fArgument[0]))
87 * ((fFunction[1]-fFunction[0])/(fArgument[1]-fArgument[0])
94 for(i=1;i<fNumber-1;i++)
96 sig = (fArgument[i]-fArgument[i-1])/(fArgument[i+1]-fArgument[i-1]) ;
97 p = sig*fSecondDerivative[i-1] + 2.0 ;
98 fSecondDerivative[i] = (sig - 1.0)/
p ;
99 u[i] = (fFunction[i+1]-fFunction[i])/(fArgument[i+1]-fArgument[i]) -
100 (fFunction[i]-fFunction[i-1])/(fArgument[i]-fArgument[i-1]) ;
101 u[i] =(6.0*u[i]/(fArgument[i+1]-fArgument[i-1]) - sig*u[i-1])/
p ;
103 if(pFirstDerFinish > maxDerivative)
111 un = (3.0/(fArgument[fNumber-1]-fArgument[fNumber-2]))
112 * (pFirstDerFinish - (fFunction[fNumber-1]-fFunction[fNumber-2])
113 / (fArgument[fNumber-1]-fArgument[fNumber-2])) ;
115 fSecondDerivative[fNumber-1] = (un - qn*u[fNumber-2])/
116 (qn*fSecondDerivative[fNumber-2] + 1.0) ;
121 for(
G4int k=fNumber-2;k>=0;k--)
123 fSecondDerivative[k] = fSecondDerivative[k]*fSecondDerivative[k+1] + u[k];
G4DataInterpolation::~G4DataInterpolation |
( |
| ) |
|
Definition at line 133 of file G4DataInterpolation.cc.
135 delete [] fArgument ;
136 delete [] fFunction ;
137 if(fSecondDerivative) {
delete [] fSecondDerivative; }
Definition at line 414 of file G4DataInterpolation.cc.
417 G4int kHigh=0, k=0, Increment=0 ;
419 G4bool ascend = (fArgument[fNumber-1] >= fArgument[0]) ;
420 if(index < 0 || index > fNumber-1)
428 if((pX >= fArgument[index]) == ascend)
430 if(index == fNumber -1)
436 while((pX >= fArgument[kHigh]) == ascend)
439 Increment += Increment ;
440 kHigh = index + Increment ;
441 if(kHigh > (fNumber - 1))
456 while((pX < fArgument[index]) == ascend)
460 if(Increment >= kHigh)
467 index = kHigh - Increment ;
474 while((kHigh - index) != 1)
476 k = (kHigh + index) >> 1 ;
477 if((pX >= fArgument[k]) == ascend)
486 if (!(pX != fArgument[fNumber-1]))
488 index = fNumber - 2 ;
490 if (!(pX != fArgument[0]))
Definition at line 311 of file G4DataInterpolation.cc.
313 G4int kLow=0, kHigh=fNumber-1, k=0 ;
318 while((kHigh - kLow) > 1)
320 k = (kHigh + kLow) >> 1 ;
321 if(fArgument[k] > pX)
330 G4double deltaHL = fArgument[kHigh] - fArgument[kLow] ;
331 if (!(deltaHL != 0.0))
333 G4Exception(
"G4DataInterpolation::CubicSplineInterpolation()",
336 G4double a = (fArgument[kHigh] - pX)/deltaHL ;
337 G4double b = (pX - fArgument[kLow])/deltaHL ;
341 return a*fFunction[kLow] + b*fFunction[kHigh] +
342 ((a*a*a - a)*fSecondDerivative[kLow] +
343 (b*b*b - b)*fSecondDerivative[kHigh])*deltaHL*deltaHL/6.0 ;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition at line 353 of file G4DataInterpolation.cc.
356 G4double delta = fArgument[index+1] - fArgument[index] ;
359 G4Exception(
"G4DataInterpolation::FastCubicSpline()",
362 G4double a = (fArgument[index+1] - pX)/delta ;
363 G4double b = (pX - fArgument[index])/delta ;
367 return a*fFunction[index] + b*fFunction[index+1] +
368 ((a*a*a - a)*fSecondDerivative[index] +
369 (b*b*b - b)*fSecondDerivative[index+1])*delta*delta/6.0 ;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition at line 378 of file G4DataInterpolation.cc.
380 G4int kLow=-1, kHigh=fNumber, k=0 ;
381 G4bool ascend=(fArgument[fNumber-1] >= fArgument[0]) ;
382 while((kHigh - kLow) > 1)
384 k = (kHigh + kLow) >> 1 ;
385 if( (pX >= fArgument[k]) == ascend)
394 if (!(pX != fArgument[0]))
398 else if (!(pX != fArgument[fNumber-1]))
void G4DataInterpolation::PolIntCoefficient |
( |
G4double |
cof[] | ) |
const |
Definition at line 202 of file G4DataInterpolation.cc.
209 for(i=0;i<fNumber;i++)
211 tempArgument[i] = cof[i] = 0.0 ;
213 tempArgument[fNumber-1] = -fArgument[0] ;
215 for(i=1;i<fNumber;i++)
217 for(j=fNumber-1-i;j<fNumber-1;j++)
219 tempArgument[j] -= fArgument[i]*tempArgument[j+1] ;
221 tempArgument[fNumber-1] -= fArgument[i] ;
223 for(i=0;i<fNumber;i++)
226 for(j=fNumber-1;j>=1;j--)
228 factor = j*tempArgument[j] + factor*fArgument[i] ;
230 reducedY = fFunction[i]/factor ;
232 for(j=fNumber-1;j>=0;j--)
234 cof[j] += mult*reducedY ;
235 mult = tempArgument[j] + mult*fArgument[i] ;
238 delete[] tempArgument ;
Definition at line 148 of file G4DataInterpolation.cc.
151 G4int i=0, j=1, k=0 ;
152 G4double mult=0.0, difi=0.0, deltaLow=0.0, deltaUp=0.0,
cd=0.0, y=0.0 ;
155 G4double diff = std::fabs(pX-fArgument[0]) ;
156 for(i=0;i<fNumber;i++)
158 difi = std::fabs(pX-fArgument[i]) ;
164 c[i] = fFunction[i] ;
165 d[i] = fFunction[i] ;
168 for(j=1;j<fNumber;j++)
170 for(i=0;i<fNumber-j;i++)
172 deltaLow = fArgument[i] - pX ;
173 deltaUp = fArgument[i+j] - pX ;
175 mult = deltaLow - deltaUp ;
178 G4Exception(
"G4DataInterpolation::PolynomInterpolation()",
182 d[i] = deltaUp*mult ;
183 c[i] = deltaLow*mult ;
185 y += (deltaY = (2*k < (fNumber - j -1) ? c[k+1] : d[k--] )) ;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition at line 249 of file G4DataInterpolation.cc.
252 G4int i=0, j=1, k=0 ;
253 const G4double tolerance = 1.6e-24 ;
254 G4double mult=0.0, difi=0.0,
cd=0.0, y=0.0, cof=0.0 ;
257 G4double diff = std::fabs(pX-fArgument[0]) ;
258 for(i=0;i<fNumber;i++)
260 difi = std::fabs(pX-fArgument[i]) ;
274 c[i] = fFunction[i] ;
275 d[i] = fFunction[i] + tolerance ;
278 for(j=1;j<fNumber;j++)
280 for(i=0;i<fNumber-j;i++)
283 difi = fArgument[i+j] - pX ;
284 cof = (fArgument[i] - pX)*d[i]/difi ;
285 mult = cof - c[i+1] ;
288 G4Exception(
"G4DataInterpolation::RationalPolInterpolation()",
295 y += (deltaY = (2*k < (fNumber - j - 1) ? c[k+1] : d[k--] )) ;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
The documentation for this class was generated from the following files: