HILA
Loading...
Searching...
No Matches
test_FFT.cpp
1#include "test.h"
2#include "plumbing/fft.h"
3//#include "plumbing/FFT.h"
4
5constexpr double Pi = 3.14159265358979;
6
7int main(int argc, char **argv) {
8
9 // using T = Matrix<2,2,Complex<double>>;
10 using T = Complex<double>;
11
12 test_setup(argc, argv);
13
14 Field<T> f, f2, p, p2;
15 double sum = 0;
16
17 for (int iter = 0; iter < 3; iter++) {
18
19 // Start with unit field
20 f = 1;
21
22 // After one FFT the field is 0 except at coord 0
23 p2 = 0;
24
25 p2[{0,0,0,0}] = lattice.volume();
26
27 hila::out0 << "Start fft\n";
28
29 FFT_field(f, p);
30
31 sum = 0;
32 onsites(ALL) { sum += (p[X] - p2[X]).squarenorm(); }
33 hila::out0 << "Sum " << sum << '\n';
34 if (fabs(sum) < 1e-10) {
35 hila::out0 << "First FFT passed" << std::endl;
36 } else {
37 hila::out0 << "First FFT FAILED; limit 1e-10" << std::endl;
38 }
39
40 // After two applications the field should be back to a constant * volume
41 f2[ALL] = lattice.volume();
42
43 FFT_field(p, f, fft_direction::back);
44
45 sum = 0;
46 double tnorm = 0;
47 onsites(ALL) {
48 sum += (f[X] - f2[X]).squarenorm();
49 tnorm += f[X].squarenorm();
50 }
51 hila::out0 << "Norm " << sum / tnorm << '\n';
52 if (fabs(sum / tnorm) < 1e-10) {
53 hila::out0 << "2nd FFT passed\n";
54 } else {
55 hila::out0 << "Second FFT FAILED, limit 1e-10" << std::endl;
56 }
57
58
59 onsites(ALL) {
60 double d = X.coordinate(e_x)*2.0*Pi/lattice.size(e_x);
61 f[X] = Complex<double>(cos(d),sin(d));
62 }
63
64 FFT_field(f, p);
65
66 p2 = 0;
67 p2[{1,0,0,0}] = lattice.volume();
68
69
70 sum = 0;
71 onsites(ALL) { sum += (p[X] - p2[X]).squarenorm(); }
72 hila::out0 << "Wave sum " << sum << '\n';
73 if (fabs(sum) > 1e-10) {
74 hila::out0 << "Wave FFT FAILED" << std::endl;
75 }
76 }
77
78
79 // write_fields("test_config_filename", p, f);
80 // read_fields("test_config_filename", p, f2);
81
82 // sum=0;
83 // onsites(ALL) {
84 // sum += (f2[X]-f[X]).squarenorm();
85 //}
86
87 // assert(sum==0 && "Write and read field");
88
90}
hila::arithmetic_type< T > squarenorm(const Array< n, m, T > &rhs)
Return square norm of Array.
Definition array.h:1018
Array< n, m, T > cos(Array< n, m, T > a)
Cosine.
Definition array.h:1089
Array< n, m, T > sin(Array< n, m, T > a)
Sine.
Definition array.h:1079
Complex definition.
Definition cmplx.h:56
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:61
double squarenorm() const
Squarenorm.
Definition field.h:1064
constexpr Parity ALL
bit pattern: 011
void FFT_field(const Field< T > &input, Field< T > &result, const CoordinateVector &directions, fft_direction fftdir=fft_direction::forward)
Definition fft.h:376
std::ostream out0
This writes output only from main process (node 0)
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...