Skip to content

Commit 4482b3d

Browse files
committed
Properly include negative frequencies due to convention change in AMReX
1 parent 327b819 commit 4482b3d

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

source/gravitational_waves.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

source/output_types/spectrum.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ void Spectrum::Compute(const int id, const hid_t file_id, Sledgehamr *sim) {
7373
for (int j = jl; j <= jh; ++j) {
7474
AMREX_PRAGMA_SIMD
7575
for (int k = kl; k <= kh; ++k) {
76+
// To account for negative frequencies
77+
double multpl = (i == 0 || i == dimN / 2) ? 1. : 2.;
7678
int li = i >= dimN / 2 ? i - dimN : i;
7779
int lj = j >= dimN / 2 ? j - dimN : j;
7880
int lk = k >= dimN / 2 ? k - dimN : k;
7981
unsigned int sq = li * li + lj * lj + lk * lk;
8082
unsigned long index =
8183
std::lower_bound(ks.begin(), ks.end(), sq) -
8284
ks.begin() + omp_get_thread_num() * kmax;
83-
spectrum[index] += pre * field_fft_arr(i, j, k, 0) *
85+
spectrum[index] += multpl * pre *
86+
field_fft_arr(i, j, k, 0) *
8487
field_fft_arr(i, j, k, 0);
8588
}
8689
}

0 commit comments

Comments
 (0)