FML
Loading...
Searching...
No Matches
SmoothingFourier.h
Go to the documentation of this file.
1#ifndef SMOOTHINGFOURIER_HEADER
2#define SMOOTHINGFOURIER_HEADER
3
4#ifdef USE_MPI
5#include <mpi.h>
6#endif
7
8#ifdef USE_OMP
9#include <omp.h>
10#endif
11
13#include <FML/Global/Global.h>
14
15namespace FML {
16 namespace GRID {
17
18 //===================================================================================
19 /// @brief Translate a field given in Fourier space: \f$ f(x) \to f(x + {\rm sign}\cdot s) \f$, i.e. multiply
20 /// each mode by \f$ e^{i\,{\rm sign}\, k\cdot s} \f$. This is exact (spectral) interpolation of the
21 /// band-limited field to a shifted set of points: after a c2r the value in cell \f$ i \f$ is
22 /// \f$ f(x_i + s) \f$.
23 ///
24 /// For even Nmesh the Nyquist components are their own mirror images and the band-limited real field there
25 /// is \f$ \propto \cos(k_{\rm Ny} x) \f$. Shifting it gives a factor \f$ \cos(k_{\rm Ny} s) \f$ (not
26 /// \f$ e^{i k_{\rm Ny} s} \f$) so that the result stays a real field. This means a shift by \f$ s \f$ followed
27 /// by \f$ -s \f$ is not the identity for the Nyquist modes unless \f$ s \f$ is a multiple of the cell size.
28 ///
29 /// @tparam N The dimension of the grid
30 /// @param[out] fourier_grid The Fourier grid we shift (in place)
31 /// @param[in] shift The shift vector (in units of the boxsize)
32 /// @param[in] sign +1: f(x) -> f(x+s), -1: f(x) -> f(x-s)
33 ///
34 //===================================================================================
35 template <int N>
36 void shift_grid_fourier(FFTWGrid<N> & fourier_grid, const std::array<double, N> & shift, double sign = +1.0) {
37 const int Nmesh = fourier_grid.get_nmesh();
38 const auto Local_nx = fourier_grid.get_local_nx();
39 assert_mpi(Nmesh > 0, "[shift_grid_fourier] Grid is not allocated\n");
40
41 // The 1D phase factors for integer wavenumbers m = -Nmesh/2, ..., Nmesh/2
42 std::array<std::vector<std::complex<double>>, N> factor;
43 for (int idim = 0; idim < N; idim++) {
44 factor[idim].resize(Nmesh + 1);
45 for (int m = -Nmesh / 2; m <= Nmesh / 2; m++) {
46 const double phase = sign * 2.0 * M_PI * m * shift[idim];
47 const bool nyquist = (Nmesh % 2 == 0) and (std::abs(m) == Nmesh / 2);
48 factor[idim][m + Nmesh / 2] =
49 nyquist ? std::complex<double>(std::cos(phase), 0.0) : std::polar(1.0, phase);
50 }
51 }
52
53#ifdef USE_OMP
54#pragma omp parallel for
55#endif
56 for (int islice = 0; islice < Local_nx; islice++) {
57 for (auto && fourier_index : fourier_grid.get_fourier_range(islice, islice + 1)) {
58 auto kint = fourier_grid.get_fourier_integer_wavevector_from_index(fourier_index);
59 std::complex<double> f = factor[0][kint[0] + Nmesh / 2];
60 for (int idim = 1; idim < N; idim++)
61 f *= factor[idim][kint[idim] + Nmesh / 2];
62 auto value = fourier_grid.get_fourier_from_index(fourier_index);
63 fourier_grid.set_fourier_from_index(fourier_index, value * ComplexType(f));
64 }
65 }
66 }
67
68 //===================================================================================
69 /// @brief Call f(fourier_index, kmag) for every local mode of a grid in fourier space (OpenMP over the
70 /// slices; kmag is the norm of the wavevector in units of 1/boxsize). The function can read and set the
71 /// modes of this and of other grids with the same layout.
72 ///
73 /// @tparam N The dimension of the grid
74 ///
75 //===================================================================================
76 template <int N, class F>
77 void for_each_fourier_mode(const FFTWGrid<N> & fourier_grid, F && f) {
78 const auto Local_nx = fourier_grid.get_local_nx();
79#ifdef USE_OMP
80#pragma omp parallel for
81#endif
82 for (int islice = 0; islice < Local_nx; islice++) {
83 double kmag;
84 std::array<double, N> kvec;
85 for (auto && fourier_index : fourier_grid.get_fourier_range(islice, islice + 1)) {
86 fourier_grid.get_fourier_wavevector_and_norm_by_index(fourier_index, kvec, kmag);
87 f(fourier_index, kmag);
88 }
89 }
90 }
91
92 /// @brief Replace every mode by func(kmag, value) (kmag in units of 1/boxsize)
93 template <int N, class F>
94 void transform_fourier_modes(FFTWGrid<N> & fourier_grid, F && func) {
95 for_each_fourier_mode<N>(fourier_grid, [&](size_t fourier_index, double kmag) {
96 fourier_grid.set_fourier_from_index(fourier_index,
97 func(kmag, fourier_grid.get_fourier_from_index(fourier_index)));
98 });
99 }
100
101 /// @brief Multiply every mode by g(kmag) (kmag in units of 1/boxsize)
102 template <int N, class F>
103 void multiply_fourier_by_function_of_k(FFTWGrid<N> & fourier_grid, F && g) {
104 transform_fourier_modes<N>(fourier_grid,
105 [&](double kmag, ComplexType value) { return value * FloatType(g(kmag)); });
106 }
107
108 /// @brief The linear combination a -> wa a + wb b of two grids in fourier space (same layout)
109 template <int N>
110 void linear_combination_fourier(FFTWGrid<N> & a, const FFTWGrid<N> & b, double wa, double wb) {
111 assert_mpi(a.get_nmesh() == b.get_nmesh(), "[linear_combination_fourier] The grids have different sizes\n");
112 const auto fa = FloatType(wa);
113 const auto fb = FloatType(wb);
114 const auto Local_nx = a.get_local_nx();
115#ifdef USE_OMP
116#pragma omp parallel for
117#endif
118 for (int islice = 0; islice < Local_nx; islice++) {
119 for (auto && fourier_index : a.get_fourier_range(islice, islice + 1)) {
120 a.set_fourier_from_index(fourier_index,
121 a.get_fourier_from_index(fourier_index) * fa +
122 b.get_fourier_from_index(fourier_index) * fb);
123 }
124 }
125 }
126
127 /// @brief Translate a real grid: \f$ f(x) \to f(x + {\rm sign}\cdot s) \f$ using Fourier interpolation (an
128 /// r2c, a phase factor and a c2r). See shift_grid_fourier.
129 template <int N>
130 void shift_grid_real(FFTWGrid<N> & real_grid, const std::array<double, N> & shift, double sign = +1.0) {
131 real_grid.fftw_r2c();
132 shift_grid_fourier<N>(real_grid, shift, sign);
133 real_grid.fftw_c2r();
134 }
135
136 //===================================================================================
137 /// Take a fourier grid and divide each mode by its norm: \f$ f(k) \to f(k) / |f(k)| \f$
138 ///
139 /// @tparam N The dimension of the grid
140 ///
141 /// @param[out] fourier_grid The fourier grid we do the whitening on
142 ///
143 //===================================================================================
144 template <int N>
146 auto Local_nx = fourier_grid.get_local_nx();
147#ifdef USE_OMP
148#pragma omp parallel for
149#endif
150 for (int islice = 0; islice < Local_nx; islice++) {
151 [[maybe_unused]] double kmag2;
152 [[maybe_unused]] std::array<double, N> kvec;
153 for (auto && fourier_index : fourier_grid.get_fourier_range(islice, islice + 1)) {
154 auto value = fourier_grid.get_fourier_from_index(fourier_index);
155 double norm = std::sqrt(std::norm(value));
156 norm = norm == 0.0 ? 0.0 : 1.0 / norm;
157 fourier_grid.set_fourier_from_index(fourier_index, value * norm);
158 }
159 }
160 }
161
162 template <int N>
163 void
165 const std::function<double(double)> & custom_filter_of_kBox_squared) {
166 // Do the smoothing
167 auto Local_nx = fourier_grid.get_local_nx();
168#ifdef USE_OMP
169#pragma omp parallel for
170#endif
171 for (int islice = 0; islice < Local_nx; islice++) {
172 [[maybe_unused]] double kmag2;
173 [[maybe_unused]] std::array<double, N> kvec;
174 for (auto && fourier_index : fourier_grid.get_fourier_range(islice, islice + 1)) {
175 fourier_grid.get_fourier_wavevector_and_norm2_by_index(fourier_index, kvec, kmag2);
176 auto value = fourier_grid.get_fourier_from_index(fourier_index);
177 value *= custom_filter_of_kBox_squared(kmag2);
178 fourier_grid.set_fourier_from_index(fourier_index, value);
179 }
180 }
181 }
182
183 //===================================================================================
184 /// Low-pass filters (tophat, gaussian, sharpk)
185 ///
186 /// @tparam N The dimension of the grid
187 ///
188 /// @param[out] fourier_grid The fourier grid we do the smoothing of
189 /// @param[in] smoothing_scale The smoothing radius of the filter (in units of the boxsize)
190 /// @param[in] smoothing_method The smoothing filter (tophat, gaussian, sharpk)
191 ///
192 //===================================================================================
193 //===================================================================================
194 /// The Bessel function J1(x) for x >= 0 (Abramowitz & Stegun 9.4.4 and 9.4.6, absolute error < 1e-7)
195 //===================================================================================
196 inline double bessel_J1(double x) {
197 if (x <= 3.0) {
198 const double y = (x / 3.0) * (x / 3.0);
199 return x * (0.5 + y * (-0.56249985 +
200 y * (0.21093573 + y * (-0.03954289 +
201 y * (0.00443319 + y * (-0.00031761 + y * 0.00001109))))));
202 }
203 const double y = 3.0 / x;
204 const double f1 =
205 0.79788456 +
206 y * (0.00000156 +
207 y * (0.01659667 + y * (0.00017105 + y * (-0.00249511 + y * (0.00113653 + y * (-0.00020033))))));
208 const double theta1 =
209 x - 2.35619449 +
210 y * (0.12499612 +
211 y * (0.00005650 + y * (-0.00637879 + y * (0.00074348 + y * (0.00079824 + y * (-0.00029166))))));
212 return f1 * std::cos(theta1) / std::sqrt(x);
213 }
214
215 template <int N>
217 double smoothing_scale,
218 std::string smoothing_method) {
219
220 // Sharp cut off kR = 1
221 std::function<double(double)> filter_sharpk = [=](double k2) -> double {
222 double kR2 = k2 * smoothing_scale * smoothing_scale;
223 if (kR2 < 1.0)
224 return 1.0;
225 return 0.0;
226 };
227 // Gaussian exp(-kR^2/2)
228 std::function<double(double)> filter_gaussian = [=](double k2) -> double {
229 double kR2 = k2 * smoothing_scale * smoothing_scale;
230 return std::exp(-0.5 * kR2);
231 };
232 // Top-hat F[ (|x| < R) ]. Implemented only for 2D and 3D
233 // 2D: the Fourier transform of a disk 2 J1(kR) / kR
234 std::function<double(double)> filter_tophat_2D = [=](double k2) -> double {
235 double kR2 = k2 * smoothing_scale * smoothing_scale;
236 double kR = std::sqrt(kR2);
237 if (kR2 < 1e-8)
238 return 1.0;
239 return 2.0 * bessel_J1(kR) / kR;
240 };
241 std::function<double(double)> filter_tophat_3D = [=](double k2) -> double {
242 double kR2 = k2 * smoothing_scale * smoothing_scale;
243 double kR = std::sqrt(kR2);
244 if (kR2 < 1e-8)
245 return 1.0;
246 return 3.0 * (std::sin(kR) - kR * std::cos(kR)) / (kR2 * kR);
247 };
248
249 // Select the filter
250 std::function<double(double)> filter;
251 if (smoothing_method == "sharpk") {
252 filter = filter_sharpk;
253 } else if (smoothing_method == "gaussian") {
254 filter = filter_gaussian;
255 } else if (smoothing_method == "tophat") {
256 assert_mpi(N == 2 or N == 3,
257 "[smoothing_filter_fourier_space] Tophat filter only implemented in 2D and 3D");
258 if (N == 2)
259 filter = filter_tophat_2D;
260 if (N == 3)
261 filter = filter_tophat_3D;
262 } else {
263 throw std::runtime_error("Unknown filter " + smoothing_method + " Options: sharpk, gaussian, tophat");
264 }
265
266 // Do the smoothing
267 auto Local_nx = fourier_grid.get_local_nx();
268#ifdef USE_OMP
269#pragma omp parallel for
270#endif
271 for (int islice = 0; islice < Local_nx; islice++) {
272 [[maybe_unused]] double kmag2;
273 [[maybe_unused]] std::array<double, N> kvec;
274 for (auto && fourier_index : fourier_grid.get_fourier_range(islice, islice + 1)) {
275 fourier_grid.get_fourier_wavevector_and_norm2_by_index(fourier_index, kvec, kmag2);
276 auto value = fourier_grid.get_fourier_from_index(fourier_index);
277 value *= filter(kmag2);
278 fourier_grid.set_fourier_from_index(fourier_index, value);
279 }
280 }
281 }
282
283 //===================================================================================
284 /// @brief From two fourier grids, f and g, compute the convolution
285 /// \f$ f(k) * g(k) = \int d^{\rm N}q f(q) g(k-q) \f$ This is done via multiplication in reals-space. We
286 /// allocate one temporary grid and perform 3 fourier transforms.
287 ///
288 /// @tparam N dimension of the grid
289 ///
290 /// @param[in] fourier_grid_f The fourier grid f
291 /// @param[in] fourier_grid_g The fourier grid g
292 /// @param[out] fourier_grid_result Fourier grid containing the convolution of the two gridsf
293 ///
294 //===================================================================================
295 template <int N>
296 void convolution_fourier_space(const FFTWGrid<N> & fourier_grid_f,
297 const FFTWGrid<N> & fourier_grid_g,
298 FFTWGrid<N> & fourier_grid_result) {
299
300 bool f_and_g_are_the_same_grid = (&fourier_grid_f == &fourier_grid_g);
301
302 // Make copies: tmp contains f and result contains g
303 // unless f = g for which we can don't need the copy
304 // and save doing 1 FFT
305 FFTWGrid<N> tmp;
306 fourier_grid_result = fourier_grid_g;
307 fourier_grid_result.add_memory_label("FFTWGrid::convolution_fourier_space::fourier_grid_result");
308
309 // Fourier transform to real space
310 fourier_grid_result.fftw_c2r();
311 if (not f_and_g_are_the_same_grid) {
312 tmp = fourier_grid_f;
313 tmp.add_memory_label("FFTWGrid::convolution_fourier_space::tmp");
314 tmp.fftw_c2r();
315 }
316
317 // Multiply the two grids in real space
318 auto Local_nx = fourier_grid_result.get_local_nx();
319#ifdef USE_OMP
320#pragma omp parallel for
321#endif
322 for (int islice = 0; islice < Local_nx; islice++) {
323 for (auto && real_index : fourier_grid_result.get_real_range(islice, islice + 1)) {
324 auto g_real = fourier_grid_result.get_real_from_index(real_index);
325 auto f_real = g_real;
326 if (not f_and_g_are_the_same_grid)
327 f_real = tmp.get_real_from_index(real_index);
328 fourier_grid_result.set_real_from_index(real_index, f_real * g_real);
329 }
330 }
331
332 // Transform back to obtain the desired convolution
333 fourier_grid_result.fftw_r2c();
334 }
335
336 //===================================================================================
337 /// @brief From two real grids, f and g, compute the convolution
338 /// \f$ f(x) * g(x) = \int d^{\rm N}y f(y) g(x-y) \f$ This is done via multiplication in fourier-space.
339 /// We allocate one temporary grid and perform 3 fourier transforms. We can merge this with
340 /// convolution_fourier_space and just have one method and get do the real or fourier space convolution
341 /// depending on the status of the grids, but its easy to forget to set the status so we have two methods
342 /// for this.
343 ///
344 /// @tparam N dimension of the grid
345 ///
346 /// @param[in] real_grid_f The real grid f
347 /// @param[in] real_grid_g The real grid g
348 /// @param[out] real_grid_result Real grid containing the convolution of the two grids.
349 ///
350 //===================================================================================
351 template <int N>
352 void convolution_real_space(const FFTWGrid<N> & real_grid_f,
353 const FFTWGrid<N> & real_grid_g,
354 FFTWGrid<N> & real_grid_result) {
355
356 bool f_and_g_are_the_same_grid = (&real_grid_f == &real_grid_g);
357
358 // Make copies: tmp contains f and result contains g
359 // unless f = g for which we can don't need the copy
360 // and save doing 1 FFT
361 FFTWGrid<N> tmp;
362 real_grid_result = real_grid_g;
363 real_grid_result.add_memory_label("FFTWGrid::convolution_real_space::real_grid_result");
364
365 // Fourier transform to fourier space
366 real_grid_result.fftw_r2c();
367 if (not f_and_g_are_the_same_grid) {
368 tmp = real_grid_f;
369 tmp.add_memory_label("FFTWGrid::convolution_real_space::tmp");
370 tmp.fftw_r2c();
371 }
372
373 // Multiply the two grids in fourier space
374 auto Local_nx = real_grid_result.get_local_nx();
375#ifdef USE_OMP
376#pragma omp parallel for
377#endif
378 for (int islice = 0; islice < Local_nx; islice++) {
379 for (auto && fourier_index : real_grid_result.get_fourier_range(islice, islice + 1)) {
380 auto g_fourier = real_grid_result.get_fourier_from_index(fourier_index);
381 auto f_fourier = g_fourier;
382 if (not f_and_g_are_the_same_grid)
383 f_fourier = tmp.get_fourier_from_index(fourier_index);
384 real_grid_result.set_fourier_from_index(fourier_index, f_fourier * g_fourier);
385 }
386 }
387
388 // Transform back to obtain the desired convolution
389 real_grid_result.fftw_c2r();
390 }
391
392 //===================================================================================
393 /// This computes the PDF of whatever quantity is in the grid (e.g. the density if its a density grid)
394 /// The binning is set to be linear. The range is set by the values we find in the grid
395 /// This really belongs in the namespace CORRELATIONFUNCTIONS so should move it there
396 ///
397 /// @tparam N The dimension of the grid
398 ///
399 /// @param[in] real_grid
400 /// @param[in] nbins Number of bins
401 /// @param[out] x Bins for the quantity we are computing the PDF of
402 /// @param[out] pdf The binned PDF normalized such that \f$ \int_{-\infty}^\infty p(x)dx = 1\f$.
403 ///
404 //===================================================================================
405 template <int N>
406 void
407 compute_grid_PDF(const FFTWGrid<N> & real_grid, int nbins, std::vector<double> & x, std::vector<double> & pdf) {
408
409 // Multiply the two grids in real space
410 auto Local_nx = real_grid.get_local_nx();
411
412 // Find minimum and maximum value in the grid
413 double grid_min = std::numeric_limits<double>::max();
414 double grid_max = -grid_min;
415#ifdef USE_OMP
416#pragma omp parallel for reduction(max : grid_max) reduction(min : grid_min)
417#endif
418 for (int islice = 0; islice < Local_nx; islice++) {
419 for (auto && real_index : real_grid.get_real_range(islice, islice + 1)) {
420 auto value = real_grid.get_real_from_index(real_index);
421 grid_min = std::min(grid_min, value);
422 grid_max = std::max(grid_max, value);
423 }
424 }
425 FML::MinOverTasks(&grid_min);
426 FML::MaxOverTasks(&grid_max);
427 assert_mpi(nbins > 0, "[compute_grid_PDF] Need nbins > 0");
428
429 // A constant grid: bins of width 1/nbins around the value
430 if (grid_max == grid_min) {
431 grid_min -= 0.5;
432 grid_max += 0.5;
433 }
434
435 // Set up binning
436 x.resize(nbins);
437 pdf.assign(nbins, 0.0);
438 for (int i = 0; i < nbins; i++) {
439 x[i] = grid_min + (grid_max - grid_min) / double(nbins) * (i + 0.5);
440 }
441
442 // For binning over threads
443 int nthreads = FML::NThreads;
444#ifdef USE_OMP
445 nthreads = std::max(nthreads, omp_get_max_threads());
446#endif
447 std::vector<std::vector<double>> pdfthreads(nthreads, std::vector<double>(nbins, 0.0));
448
449#ifdef USE_OMP
450#pragma omp parallel for
451#endif
452 for (int islice = 0; islice < Local_nx; islice++) {
453 int id = 0;
454#ifdef USE_OMP
455 id = omp_get_thread_num();
456#endif
457 for (auto && real_index : real_grid.get_real_range(islice, islice + 1)) {
458 auto value = real_grid.get_real_from_index(real_index);
459 int ibin = int((value - grid_min) / (grid_max - grid_min) * nbins);
460 // The largest value is in the last bin
461 if (ibin == nbins)
462 ibin = nbins - 1;
463 if (ibin >= 0 and ibin < nbins)
464 pdfthreads[id][ibin] += 1;
465 }
466 }
467
468 // Sum up over threads
469 for (int i = 0; i < nthreads; i++) {
470 for (int j = 0; j < nbins; j++) {
471 pdf[j] += pdfthreads[i][j];
472 }
473 }
474
475 // Sum over tasks
476#ifdef USE_MPI
477 MPI_Allreduce(MPI_IN_PLACE, pdf.data(), nbins, MPI_DOUBLE, MPI_SUM, FML::communicator);
478#endif
479
480 // Normalize so that the PDF integrates to unity
481 const double dx = (grid_max - grid_min) / double(nbins);
482 double integral = 0.0;
483 for (int i = 0; i < nbins; i++) {
484 integral += pdf[i] * dx;
485 }
486 for (int i = 0; i < nbins; i++) {
487 pdf[i] /= integral;
488 }
489 }
490 } // namespace GRID
491} // namespace FML
492#endif
std::vector< double > wb
Definition BBN.cpp:16
std::complex< FloatType > ComplexType
Definition FFTWGlobal.h:37
float FloatType
Definition FFTWGlobal.h:29
double f
Definition Minimizer.cpp:28
const int Nmesh
Definition Main.cpp:48
Class for holding grids and performing real-to-complex and complex-to-real FFTs using FFTW with MPI.
Definition FFTWGrid.h:98
int get_nmesh() const
Number of grid-cells per dimension.
Definition FFTWGrid.h:1230
void fftw_c2r()
Perform complex-to-real fourier transform.
Definition FFTWGrid.h:1132
void set_real_from_index(const IndexIntType ind, const FloatType value)
Set value in grid from (local) index.
Definition FFTWGrid.h:1196
std::array< int, N > get_fourier_integer_wavevector_from_index(const IndexIntType index) const
Definition FFTWGrid.h:1395
void add_memory_label(std::string label)
For memory logging: add a label to the grid.
Definition FFTWGrid.h:404
FloatType get_real_from_index(const IndexIntType index) const
Fetch value in grid by (local) index.
Definition FFTWGrid.h:1461
ptrdiff_t get_local_nx() const
Number of local x-slices in the real grid.
Definition FFTWGrid.h:1255
void set_fourier_from_index(const IndexIntType ind, const ComplexType value)
Set value of cell in fourier grid using (local) index.
Definition FFTWGrid.h:1212
ComplexType get_fourier_from_index(const IndexIntType index) const
Fetch value in fourier grid by (local) index.
Definition FFTWGrid.h:1207
FourierRange get_fourier_range(int islice_begin=0, int islice_end=0) const
Range iterator for going through all active cells in the main fourier grid by index [ e....
Definition FFTWGrid.h:507
void fftw_r2c()
Perform real-to-complex fourier transform.
Definition FFTWGrid.h:1077
void get_fourier_wavevector_and_norm_by_index(const IndexIntType ind, std::array< double, N > &kvec, double &kmag) const
From index in the grid get the k-vector and the magnitude of it.
Definition FFTWGrid.h:1279
void get_fourier_wavevector_and_norm2_by_index(const IndexIntType ind, std::array< double, N > &kvec, double &kmag2) const
From index in the grid get the k-vector and the norm of it (square magnitude)
Definition FFTWGrid.h:1299
RealRange get_real_range(int islice_begin=0, int islice_end=0) const
Range iterator for going through all active cells in the main real real grid by index [ e....
Definition FFTWGrid.h:488
void compute_grid_PDF(const FFTWGrid< N > &real_grid, int nbins, std::vector< double > &x, std::vector< double > &pdf)
This computes the PDF of whatever quantity is in the grid (e.g.
void convolution_real_space(const FFTWGrid< N > &real_grid_f, const FFTWGrid< N > &real_grid_g, FFTWGrid< N > &real_grid_result)
From two real grids, f and g, compute the convolution This is done via multiplication in fourier-spa...
void shift_grid_real(FFTWGrid< N > &real_grid, const std::array< double, N > &shift, double sign=+1.0)
Translate a real grid: using Fourier interpolation (an r2c, a phase factor and a c2r).
void custom_smoothing_filter_fourier_space(FFTWGrid< N > &fourier_grid, const std::function< double(double)> &custom_filter_of_kBox_squared)
void for_each_fourier_mode(const FFTWGrid< N > &fourier_grid, F &&f)
Call f(fourier_index, kmag) for every local mode of a grid in fourier space (OpenMP over the slices; ...
void convolution_fourier_space(const FFTWGrid< N > &fourier_grid_f, const FFTWGrid< N > &fourier_grid_g, FFTWGrid< N > &fourier_grid_result)
From two fourier grids, f and g, compute the convolution This is done via multiplication in reals-sp...
void multiply_fourier_by_function_of_k(FFTWGrid< N > &fourier_grid, F &&g)
Multiply every mode by g(kmag) (kmag in units of 1/boxsize)
void smoothing_filter_fourier_space(FFTWGrid< N > &fourier_grid, double smoothing_scale, std::string smoothing_method)
void shift_grid_fourier(FFTWGrid< N > &fourier_grid, const std::array< double, N > &shift, double sign=+1.0)
Translate a field given in Fourier space: , i.e.
void whitening_fourier_space(FFTWGrid< N > &fourier_grid)
Take a fourier grid and divide each mode by its norm: .
double bessel_J1(double x)
Low-pass filters (tophat, gaussian, sharpk)
void linear_combination_fourier(FFTWGrid< N > &a, const FFTWGrid< N > &b, double wa, double wb)
The linear combination a -> wa a + wb b of two grids in fourier space (same layout)
void transform_fourier_modes(FFTWGrid< N > &fourier_grid, F &&func)
Replace every mode by func(kmag, value) (kmag in units of 1/boxsize)
void MinOverTasks(T *value)
Inplace min over tasks of a single value.
Definition Global.h:209
int NThreads
Total number of threads available.
Definition Global.cpp:41
void MaxOverTasks(T *value)
Inplace max over tasks of a single value.
Definition Global.h:189
return y
Definition Global.h:365
MPI_Comm communicator
The MPI communicator used for all communication in the library (fiducial MPI_COMM_WORLD).
Definition Global.cpp:26
ComplexType value(const std::array< int, N > &wave, int generation)
double norm(Vector a)