-
Notifications
You must be signed in to change notification settings - Fork 1
/
time_interp.cpp
182 lines (136 loc) · 4.71 KB
/
time_interp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "General.hpp"
#include "MLFMM_Env.hpp"
#include "Direct.hpp"
double printResults( const vector<complex>& mlfmm,
const vector<complex>& exact )
{
double TotRelError = 0;
double TotErrorSq = 0;
double TotNormSq = 0;
double MaxRelErr = 0;
int N = exact.size();
for( int k = 0; k < N; ++k ) {
//cerr << mlfmm[k] << "\t\t" << exact[k] << "\t\t" << mlfmm[k]-exact[k] << endl;
// Individual Relative
TotRelError += abs(mlfmm[k] - exact[k]) / abs(exact[k]);
// Total Relative
TotErrorSq += norm(mlfmm[k] - exact[k]);
TotNormSq += norm(exact[k]);
// Max Absolute
MaxRelErr = max(abs(mlfmm[k] - exact[k]) / abs(exact[k]), MaxRelErr);
}
// Relative Error
double RelError = sqrt(TotErrorSq/TotNormSq);
cout << "Tot Rel Error: " << RelError << endl;
// Average Relative Error
double AveRelError = TotRelError/N;
cout << "Ave Rel Error: " << AveRelError << endl;
// Max Relative Error
cout << "Max Rel Error: " << MaxRelErr << endl;
return AveRelError;
}
struct HelmKernel
{
double kappa;
inline complex operator()( double r ) { return exp( CI * kappa * r ) / r; }
};
template <typename Interp>
double test_interp(NFunction& f1, NFunction& f2) {
Interp interp(f1.quad, f2.quad);
StopWatch timer;
timer.start();
interp.apply(f1, f2);
interp.apply(f1, f2);
interp.apply(f1, f2);
interp.apply(f1, f2);
interp.apply(f1, f2);
interp.apply(f1, f2);
interp.apply(f1, f2);
interp.apply(f1, f2);
interp.apply(f1, f2);
interp.apply(f1, f2);
double time = timer.stop() / 10;
return time;
}
// Timing comparison of interpolation and anterpolation stage
int main( int argc, char* argv[] )
{
(void) argc; (void) argv;
double boxSize = 1;
double eps = 1e-6;
// Set MLFMM_ALPHA = 0.8
HelmKernel K;
fstream myFile("time_interp.dat", ios::out);
myFile << "kappa\tell\tPolyInterp\tFFTInterp\tFFTInterp2\tFFTInterp3" << endl;
for( double kappa = 0.95; kappa < 10000; kappa *= 1.20 ) {
K.kappa = kappa;
// Uniform Quadrature Fourier version
Quadrature_Uniform* quad_L = new Quadrature_Uniform(K, boxSize, eps);
Quadrature_Uniform* quad_H = new Quadrature_Uniform(K, 2*boxSize, eps);
std::cout << "Quadratures Created. Kappa = " << kappa << "\n";
int ell = quad_H->getTruncation();
// Create a NFunction
NFunction F_U_L = Translation_Function( quad_L, Vec3(boxSize,0,0) );
NFunction F_U_H = NFunction(quad_H);
double timeOrig = test_interp<FFTInterp_Poles>(F_U_L, F_U_H);
std::cout << "Done FFTInterp_Poles\n";
NFunction F_U_H_FFT2 = NFunction(quad_H);
double time_fft2 = test_interp<FFTInterp_FFT2>(F_U_L, F_U_H_FFT2);
std::cout << "Done FFTInterp_FFT2\n";
NFunction F_U_H_Fast = NFunction(quad_H);
double time_fast = test_interp<FFTInterp_FFT2_Fast>(F_U_L, F_U_H_Fast);
std::cout << "Done FFTInterp_FFT2_Fast\n";
NFunction F_U_H_Fast2 = NFunction(quad_H);
double time_fast2 = test_interp<FFTInterp_FFT2_Fast2>(F_U_L, F_U_H_Fast2);
std::cout << "Done FFTInterp_FFT2_Fast2\n";
double error = 0;
double error2 = 0;
double error3 = 0;
for( int k = 0; k < quad_H->size(); ++k ) {
error = max(abs(F_U_H.C[k] - F_U_H_FFT2.C[k]), error);
error2 = max(abs(F_U_H.C[k] - F_U_H_Fast.C[k]), error2);
error3 = max(abs(F_U_H.C[k] - F_U_H_Fast2.C[k]), error3);
}
cerr << "Error:\t" << error << "\t" << error2 << "\t" << error3 << endl;
delete quad_L;
delete quad_H;
/*
// Spherical Harmonics version
Quadrature_S2* quadS2_L = new Quadrature_S2(K, boxSize, eps);
Quadrature_S2* quadS2_H = new Quadrature_S2(K, 2*boxSize, eps);
// Create a NFunction
NFunction F_S2_L = Translation_Function(quadS2_L, Vec3(0.5*boxSize,0,0));
S2Interp s2interp(quadS2_L, quadS2_H);
NFunction F_S2_H = NFunction(quadS2_H);
timer.start();
s2interp.apply(F_S2_L, F_S2_H);
s2interp.apply(F_S2_L, F_S2_H);
s2interp.apply(F_S2_L, F_S2_H);
s2interp.apply(F_S2_L, F_S2_H);
s2interp.apply(F_S2_L, F_S2_H);
s2interp.apply(F_S2_L, F_S2_H);
s2interp.apply(F_S2_L, F_S2_H);
s2interp.apply(F_S2_L, F_S2_H);
s2interp.apply(F_S2_L, F_S2_H);
s2interp.apply(F_S2_L, F_S2_H);
double timeS2 = timer.stop() / 10;
delete quadS2_L;
delete quadS2_H;
*/
cout << kappa << "\t" << ell << "\t"
//<< timeS2 << "\t"
<< timeOrig << "\t"
<< time_fft2 << "\t"
<< time_fast << "\t"
<< time_fast2 << "\t"
<< endl;
myFile << kappa << "\t" << ell << "\t"
//<< timeS2 << "\t"
<< timeOrig << "\t"
<< time_fft2 << "\t"
<< time_fast << "\t"
<< time_fast2 << "\t"
<< endl;
}
return 0;
}