1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // $Id: testDataInterpolation.cc,v 1.6 2006/06/29 19:00:31 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
29 | // |
---|
30 | #include "G4ios.hh" |
---|
31 | #include "globals.hh" |
---|
32 | #include "G4DataInterpolation.hh" |
---|
33 | |
---|
34 | G4double TestFunction(G4double x) |
---|
35 | { |
---|
36 | return 10.0*std::exp(-0.1*x)*std::cos(x) ; |
---|
37 | //return 10.0*std::exp(-5*(x-pi)*(x-pi)) ; |
---|
38 | } |
---|
39 | |
---|
40 | int main() |
---|
41 | { |
---|
42 | G4int i, j ; |
---|
43 | const G4int n = 15 ; |
---|
44 | G4double pY[n], pX[n], cof[n] ; |
---|
45 | G4double x, polcof, pol, yTest, deltaY, deltaX = twopi/n ; |
---|
46 | for(i=0;i<n;i++) |
---|
47 | { |
---|
48 | pX[i] = deltaX*i ; |
---|
49 | pY[i] = TestFunction(deltaX*i) ; |
---|
50 | } |
---|
51 | |
---|
52 | G4DataInterpolation myPolInt(pX,pY,n) ; |
---|
53 | myPolInt.PolIntCoefficient(cof) ; |
---|
54 | |
---|
55 | // Test PolCof against Polynom |
---|
56 | |
---|
57 | G4cout<<"Test function"<<"\t"<<"Delta Pol"<<"\t"<<"delta " |
---|
58 | <<"\t"<<"Delta PolCof"<<"\t"<<"Delta Pol-PolCof"<<G4endl<<G4endl ; |
---|
59 | for(i=1;i<n-1;i++) |
---|
60 | { |
---|
61 | x = deltaX/2 + deltaX*i ; |
---|
62 | |
---|
63 | polcof = cof[n-1] ; |
---|
64 | for(j=n-2;j>=0;j--) |
---|
65 | { |
---|
66 | polcof = polcof*x +cof[j] ; |
---|
67 | } |
---|
68 | pol = myPolInt.PolynomInterpolation(x,deltaY) ; |
---|
69 | G4cout<<TestFunction(x)<<"\t" |
---|
70 | <<TestFunction(x) - pol<<"\t" |
---|
71 | <<deltaY<<"\t" |
---|
72 | <<TestFunction(x) - polcof<<"\t" |
---|
73 | <<pol - polcof<<G4endl ; |
---|
74 | } |
---|
75 | G4cout<<G4endl ; |
---|
76 | /* ************************* |
---|
77 | |
---|
78 | // Test RationalPol against Polynomial |
---|
79 | |
---|
80 | G4cout<<"Test function"<<"\t"<<"Delta Pol"<<"\t"<<"delta " |
---|
81 | <<"\t"<<"Delta RatPol"<<"\t"<<"delta"<<G4endl<<G4endl ; |
---|
82 | for(i=1;i<n-1;i++) |
---|
83 | { |
---|
84 | x = deltaX/2 + deltaX*i ; |
---|
85 | //yTest = myPolInt.RationalPolInterpolation(x,deltaY) ; |
---|
86 | G4cout<<TestFunction(x)<<"\t" |
---|
87 | <<TestFunction(x) - myPolInt.PolynomInterpolation(x,deltaY)<<"\t" |
---|
88 | <<deltaY<<"\t" |
---|
89 | <<TestFunction(x) - myPolInt.RationalPolInterpolation(x,deltaY)<<"\t" |
---|
90 | <<deltaY<<G4endl ; |
---|
91 | } |
---|
92 | // Test CubicSpline against Polynomial |
---|
93 | // Evaluation of start and finish first derivatives |
---|
94 | G4double deriStart = (pY[1]-pY[0])/deltaX ; |
---|
95 | G4double deriFinish = (pY[n-1]-pY[n-2])/deltaX ; |
---|
96 | |
---|
97 | G4DataInterpolation myPolIntCub(pX,pY,n,deriStart,deriFinish) ; // f''[i] is OK |
---|
98 | |
---|
99 | G4cout<<"Test function"<<"\t"<<"Delta Pol"<<"\t"<<"delta " |
---|
100 | <<"\t"<<"Delta CubicSpline"<<"\t"<<"Delta FastCubicSpline"<<G4endl<<G4endl ; |
---|
101 | for(i=1;i<n-1;i++) |
---|
102 | { |
---|
103 | x = deltaX/2 + deltaX*i ; |
---|
104 | //yTest = myPolInt.RationalPolInterpolation(x,deltaY) ; |
---|
105 | G4cout<<TestFunction(x)<<"\t" |
---|
106 | <<TestFunction(x) - myPolIntCub.PolynomInterpolation(x,deltaY)<<"\t" |
---|
107 | <<deltaY<<"\t" |
---|
108 | <<TestFunction(x) - myPolIntCub.CubicSplineInterpolation(x)<<"\t" |
---|
109 | <<TestFunction(x) - myPolIntCub.FastCubicSpline(x,i)<<G4endl ; |
---|
110 | } |
---|
111 | G4cout<<G4endl ; |
---|
112 | G4cout<<"j"<<"\t"<<"x[j]"<<"\t"<<"pX"<<"Locate j"<<"\t"<<"Correlated j"<<G4endl ; |
---|
113 | G4int index ; |
---|
114 | for(i=1;i<n-1;i++) |
---|
115 | { |
---|
116 | x = deltaX/2 + deltaX*i ; |
---|
117 | index = i ; |
---|
118 | myPolInt.CorrelatedSearch(x,index) ; |
---|
119 | G4cout<<i<<"\t"<<pX[i]<<"\t"<<x<<"\t" |
---|
120 | <<myPolInt.LocateArgument(x)<<"\t"<<index<<G4endl ; |
---|
121 | } |
---|
122 | */ /////////////////////////// |
---|
123 | // myPolIntCub.~G4DataInterpolation() ; |
---|
124 | return 0; |
---|
125 | } |
---|