@@ -68,6 +68,12 @@ void GravitationalWaves::ComputeSpectrum(
6868 modifier->SelectComponents (comps);
6969
7070 for (int i = 0 ; i < 6 ; ++i) {
71+ #ifdef OLD_FFT
72+ const amrex::BoxArray &ba = ld.boxArray ();
73+ const amrex::DistributionMapping &dm = ld.DistributionMap ();
74+ du_real[i].define (ba, dm, 1 , 0 );
75+ du_imag[i].define (ba, dm, 1 , 0 );
76+ #endif
7177 utils::Fft (ld, comps[i] + idx_offset, du_real[i], du_imag[i],
7278 sim->geom [lev], false , zero_padding);
7379 }
@@ -127,15 +133,31 @@ void GravitationalWaves::ComputeSpectrum(
127133 for (int b = lo.y ; b <= hi.y ; ++b) {
128134 AMREX_PRAGMA_SIMD
129135 for (int a = lo.x ; a <= hi.x ; ++a) {
136+ // To account of negative frequencies
137+ double multpl = (a == 0 || a == dimN / 2 ) ? 1 . : 2 .;
130138 int abc[3 ] = {a, b, c};
131139 double running_sum = 0 ;
132140
141+ int li = a >= dimN / 2 ? a - dimN : a;
142+ int lj = b >= dimN / 2 ? b - dimN : b;
143+ int lk = c >= dimN / 2 ? c - dimN : c;
144+ unsigned int sq = li * li + lj * lj + lk * lk;
145+ unsigned long index;
146+ if (unbinned) {
147+ index = std::lower_bound (ks.begin (), ks.end (), sq) -
148+ ks.begin () + omp_get_thread_num () * kmax;
149+ } else {
150+ index = static_cast <long >(
151+ std::sqrt (static_cast <double >(sq)) + .5 );
152+ }
153+
133154 for (int i = 0 ; i < 3 ; ++i) {
134155 for (int j = 0 ; j < 3 ; ++j) {
135156 for (int l = 0 ; l < 3 ; ++l) {
136157 for (int m = 0 ; m < 3 ; ++m) {
137158 running_sum +=
138159 GetLambda (i, j, l, m, abc, dimN) *
160+ multpl *
139161 (du_real_arr[mat[i][j]]->operator ()(
140162 a, b, c) *
141163 du_real_arr[mat[l][m]]->operator ()(
@@ -148,20 +170,6 @@ void GravitationalWaves::ComputeSpectrum(
148170 }
149171 }
150172 }
151-
152- int li = a >= dimN / 2 ? a - dimN : a;
153- int lj = b >= dimN / 2 ? b - dimN : b;
154- int lk = c >= dimN / 2 ? c - dimN : c;
155- unsigned int sq = li * li + lj * lj + lk * lk;
156- unsigned long index;
157- if (unbinned) {
158- index = std::lower_bound (ks.begin (), ks.end (), sq) -
159- ks.begin () + omp_get_thread_num () * kmax;
160- } else {
161- index = static_cast <long >(
162- std::sqrt (static_cast <double >(sq)) + .5 );
163- }
164-
165173 gw_spectrum[index] += running_sum;
166174 }
167175 }
0 commit comments