1#ifndef COMPUTEPOWERSPECTRUM_HEADER
2#define COMPUTEPOWERSPECTRUM_HEADER
38 namespace CORRELATIONFUNCTIONS {
57 template <
int N,
int ORDER,
bool COMPACT>
61 template <
int N,
bool COMPACT = false>
64 template <
int N,
bool COMPACT = false>
67 template <
int N,
bool COMPACT = false>
99 template <
int N,
class T>
105 std::string density_assignment_method,
127 template <
int N,
class T>
166 std::string density_assignment_method);
205 std::vector<double> line_of_sight_direction);
228 template <
int N,
class T>
231 double velocity_to_displacement,
233 std::string density_assignment_method,
259 template <
int N,
class T,
int ORDER,
bool COMPACT>
265 std::string density_assignment_method,
283 template <
int N,
int ORDER,
bool COMPACT>
299 template <
int N,
bool COMPACT>
322 template <
int N,
class T,
bool COMPACT>
328 std::string density_assignment_method,
351 template <
int N,
class T,
bool COMPACT>
357 std::string density_assignment_method,
374 template <
int N,
bool COMPACT>
391 template <
int N,
bool COMPACT>
416 template <
int N,
class T,
bool COMPACT>
422 std::string density_assignment_method,
438 std::vector<double> line_of_sight_direction) {
441 line_of_sight_direction.size() == N,
442 "[compute_power_spectrum_multipoles_fourier] Line of sight direction has wrong number of dimensions\n");
443 assert_mpi(Pell.size() > 0,
"[compute_power_spectrum_multipoles_fourier] Pell must have size > 0\n");
445 "[compute_power_spectrum_multipoles_fourier] grid must have Nmesh > 0\n");
453 for (
int idim = 0; idim < N; idim++)
454 rmag += line_of_sight_direction[idim] * line_of_sight_direction[idim];
455 rmag = std::sqrt(rmag);
456 assert_mpi(rmag > 0.0,
457 "[compute_power_spectrum_multipoles_fourier] Line of sight vector has zero length\n");
460 for (
size_t ell = 0; ell < Pell.size(); ell++)
465#pragma omp parallel for
467 for (
int islice = 0; islice < Local_nx; islice++) {
468 [[maybe_unused]]
double kmag;
469 [[maybe_unused]] std::array<double, N> kvec;
470 for (
auto && fourier_index : fourier_grid.
get_fourier_range(islice, islice + 1)) {
471 if (Local_x_start == 0 and fourier_index == 0)
475 auto last_coord = fourier_index % (
Nmesh / 2 + 1);
481 double power = std::norm(delta);
485 for (
int idim = 0; idim < N; idim++)
486 mu2 += kvec[idim] * line_of_sight_direction[idim];
487 mu2 /= (kmag * rmag);
491 double mutotwoell = 1.0;
492 for (
size_t ell = 0; ell < Pell.size(); ell += 2) {
493 Pell[ell].add_to_bin(kmag,
power * mutotwoell, weight);
500 for (
size_t ell = 0; ell < Pell.size(); ell++)
501 Pell[ell].normalize();
504 auto binomial = [](
int n,
int k) ->
double {
506 for (
int i = 0; i < k; i++) {
507 res *= double(n - i) / double(k - i);
513 auto summand_legendre_polynomial = [&](
int k,
int ell) ->
double {
514 double sign = (k % 2) == 0 ? 1.0 : -1.0;
515 return sign * binomial(ell, k) * binomial(2 * ell - 2 * k, ell) / std::pow(2.0, ell);
519 std::vector<std::vector<double>> temp;
520 for (
int ell = 0; ell < int(Pell.size()); ell++) {
521 std::vector<double> sum(Pell[0].pofk.size(), 0.0);
522 for (
int k = 0; k <= ell / 2; k++) {
523 std::vector<double> & mu_power = Pell[ell - 2 * k].pofk;
524 for (
size_t i = 0; i < sum.size(); i++)
525 sum[i] += mu_power[i] * summand_legendre_polynomial(k, ell) * double(2 * ell + 1);
531 for (
size_t ell = 0; ell < Pell.size(); ell++) {
532 Pell[ell].pofk = temp[ell];
544 const int Local_nx =
grid.get_local_nx();
545 const int Local_x_start =
grid.get_local_x_start();
546 const int nover2 =
Nmesh / 2;
547 const int nover2plus1 =
Nmesh / 2 + 1;
548 const double twopi = 2.0 * M_PI;
550#pragma omp parallel for
552 for (
int islice = 0; islice < Local_nx; islice++) {
553 std::array<double, 3> kvec;
554 const int ix = islice + Local_x_start;
555 kvec[0] = twopi * double(ix <= nover2 ? ix : ix -
Nmesh);
556 for (
int iy = 0; iy <
Nmesh; iy++) {
557 kvec[1] = twopi * double(iy <= nover2 ? iy : iy -
Nmesh);
558 size_t fourier_index = (size_t(islice) *
Nmesh + iy) * nover2plus1;
559 for (
int iz = 0; iz < nover2plus1; iz++, fourier_index++) {
560 if (Local_x_start == 0 and fourier_index == 0)
562 kvec[2] = twopi * double(iz <= nover2 ? iz : iz -
Nmesh);
563 const double kmag = std::sqrt(kvec[0] * kvec[0] + kvec[1] * kvec[1] + kvec[2] * kvec[2]);
565 f(fourier_index, kvec, kmag, weight);
574 std::string density_assignment_method) {
576 assert_mpi(fourier_grid.
get_nmesh() > 0,
"[bin_up_deconvolved_power_spectrum] grid must have Nmesh > 0\n");
577 assert_mpi(pofk.n > 0 && pofk.kmax > pofk.kmin && pofk.kmin >= 0.0,
578 "[bin_up_deconvolved_power_spectrum] Binning has inconsistent parameters\n");
589 if constexpr (N == 3) {
594 [&](
size_t fourier_index,
const std::array<double, N> & kvec,
double kmag,
double weight) {
596 auto delta_norm = std::norm(delta);
597 auto window = window_function(kvec);
598 delta_norm /= (window * window);
599 pofk.add_to_bin(kmag, delta_norm, weight);
605#pragma omp parallel for
607 for (
int islice = 0; islice < Local_nx; islice++) {
608 [[maybe_unused]]
double kmag;
609 [[maybe_unused]] std::array<double, N> kvec;
610 for (
auto && fourier_index : fourier_grid.
get_fourier_range(islice, islice + 1)) {
611 if (Local_x_start == 0 and fourier_index == 0)
617 auto last_coord = fourier_index % (
Nmesh / 2 + 1);
623 auto delta_norm = std::norm(delta);
624 auto window = window_function(kvec);
625 delta_norm /= (window * window);
628 pofk.add_to_bin(kmag, delta_norm, weight);
640 assert_mpi(fourier_grid.
get_nmesh() > 0,
"[bin_up_power_spectrum] grid must have Nmesh > 0\n");
641 assert_mpi(pofk.n > 0 && pofk.kmax > pofk.kmin && pofk.kmin >= 0.0,
642 "[bin_up_power_spectrum] Binning has inconsistent parameters\n");
652 if constexpr (N == 3) {
656 [&](
size_t fourier_index,
const std::array<double, N> &,
double kmag,
double weight) {
658 auto delta_norm = std::norm(delta);
659 pofk.add_to_bin(kmag, delta_norm, weight);
665#pragma omp parallel for
667 for (
int islice = 0; islice < Local_nx; islice++) {
668 [[maybe_unused]]
double kmag;
669 [[maybe_unused]] std::array<double, N> kvec;
670 for (
auto && fourier_index : fourier_grid.
get_fourier_range(islice, islice + 1)) {
671 if (Local_x_start == 0 and fourier_index == 0)
677 auto last_coord = fourier_index % (
Nmesh / 2 + 1);
681 auto delta_norm = std::norm(delta);
685 pofk.add_to_bin(kmag, delta_norm, weight);
699 assert_mpi(fourier_grid_1.
get_nmesh() > 0,
"[bin_up_cross_power_spectrum] grid must have Nmesh > 0\n");
701 "[bin_up_cross_power_spectrum] Grids must have the same gridsize\n");
702 assert_mpi(pofk.n > 0 && pofk.kmax > pofk.kmin && pofk.kmin >= 0.0,
703 "[bin_up_cross_power_spectrum] Binning has inconsistent parameters\n");
718#pragma omp parallel for
720 for (
int islice = 0; islice < Local_nx; islice++) {
721 [[maybe_unused]]
double kmag;
722 [[maybe_unused]] std::array<double, N> kvec;
723 for (
auto && fourier_index : fourier_grid_1.
get_fourier_range(islice, islice + 1)) {
724 if (Local_x_start == 0 and fourier_index == 0)
730 auto last_coord = fourier_index % (
Nmesh / 2 + 1);
735 auto delta12_real = delta_1.real() * delta_2.real() + delta_1.imag() * delta_2.imag();
736 auto delta12_imag = -delta_1.real() * delta_2.imag() + delta_1.imag() * delta_2.real();
740 pofk.add_to_bin(kmag, delta12_real, weight);
741 pofk_imag.
add_to_bin(kmag, delta12_imag, weight);
751 const bool show_warning =
false;
753 for (
int i = 0; i < pofk.n; i++) {
754 if (std::abs(pofk.pofk[i]) < 1e3 * std::abs(pofk_imag.
pofk[i]) and
755 std::abs(pofk_imag.
pofk[i]) > 1e-15) {
757 <<
"Warning: the imaginary part of the cross spectrum is > 0.1%% times the real part [ k: "
758 << pofk.kbin[i] <<
" Real(d1d2): " << pofk.pofk[i] <<
" Imag(d1d2): " << pofk_imag.
pofk[i]
775 const double n = double(NumPartTotal);
776 constexpr bool has_deltaf_weight = FML::PARTICLE::has_get_deltaf_weight<T>();
777 constexpr bool has_mass = FML::PARTICLE::has_get_mass<T>() and not has_deltaf_weight;
778 if constexpr (has_mass or has_deltaf_weight) {
779 double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0;
780 for (
size_t i = 0; i < NumPart; i++) {
782 if constexpr (has_deltaf_weight)
783 m = FML::PARTICLE::GetDeltafWeight(
const_cast<T &
>(part[i]));
794 const double norm = has_deltaf_weight ? n : sum1;
797 return {1.0 / n, 1.0 / (n * n)};
801 template <
int N,
class T>
808 FML::PARTICLE::has_get_pos<T>(),
809 "[compute_power_spectrum_direct_summation] Particle class needs to have positions to use this method");
813 long long int tmp1 = NumPart;
815 long long int tmp2 = NumPart;
821 assert_mpi(tmp1 == tmp2 and std::abs(x -
y) < 1e-10,
822 "[direct_summation_power_spectrum] All tasks must have the same particles for this method "
826 assert_mpi(Ngrid > 0,
"[direct_summation_power_spectrum] Ngrid > 0 required\n");
828 std::cout <<
"[direct_summation_power_spectrum] Warning: this method assumes all tasks have the same "
831 const std::complex<FML::GRID::FloatType>
I(0, 1);
832 const FML::GRID::FloatType
norm = 1.0 / FML::GRID::FloatType(NumPart);
835 density_k.
add_memory_label(
"FFTWGrid::compute_power_spectrum_direct_summation::density_k");
840 FML::GRID::FloatType real = 0.0;
841 FML::GRID::FloatType imag = 0.0;
843#pragma omp parallel for reduction(+ : real, imag)
845 for (
size_t i = 0; i < NumPart; i++) {
847 FML::GRID::FloatType kx = 0.0;
848 for (
int idim = 0; idim < N; idim++) {
849 kx += kvec[idim] * x[idim];
851 auto val = std::exp(-kx *
I);
856 std::complex<FML::GRID::FloatType> sum = {real, imag};
857 if (
ThisTask == 0 and fourier_index == 0)
866 if (pofk.subtract_shotnoise)
867 for (
int i = 0; i < pofk.n; i++)
868 pofk.pofk[i] -= 1.0 /
double(NumPart);
877 template <
int N,
class T>
880 double velocity_to_displacement,
882 std::string density_assignment_method,
886 static_assert(FML::PARTICLE::has_get_pos<T>(),
887 "[compute_power_spectrum_multipoles] Particle class needs to have positions to use "
890 FML::PARTICLE::has_get_vel<T>(),
891 "[compute_power_spectrum_multipoles] Particle class needs to have velocity to use this method");
896 const int nleft = nleftright.first;
897 const int nright = nleftright.second + (interlacing ? 1 : 0);
900 for (
size_t ell = 0; ell < Pell.size(); ell++)
904 std::vector<std::vector<PowerSpectrumBinning<N>>> Pell_all(N);
905 for (
int idim = 0; idim < N; idim++) {
906 Pell_all[idim] = Pell;
911 density_k.
add_memory_label(
"FFTWGrid::compute_power_spectrum_multipoles::density_k");
915 for (
int idim = 0; idim < N; idim++) {
918 std::vector<PowerSpectrumBinning<N>> Pell_current = Pell_all[idim];
919 for (
size_t ell = 0; ell < Pell_current.size(); ell++)
920 Pell_current[ell].reset();
923 std::vector<double> line_of_sight_direction(N, 0.0);
924 line_of_sight_direction[idim] = 1.0;
938 density_assignment_method);
948 density_assignment_method);
957 Pell_all[idim] = Pell_current;
965 for (
size_t ell = 0; ell < Pell.size(); ell++) {
966 for (
int idim = 0; idim < N; idim++) {
967 Pell[ell] += Pell_all[idim][ell];
970 for (
size_t ell = 0; ell < Pell.size(); ell++) {
971 for (
int i = 0; i < Pell[ell].n; i++) {
972 Pell[ell].pofk[i] /= double(N);
973 Pell[ell].count[i] /= double(N);
974 Pell[ell].kbin[i] /= double(N);
981 if (Pell[0].subtract_shotnoise) {
982 const double shotnoise =
984 for (
int i = 0; i < Pell[0].n; i++) {
985 Pell[0].pofk[i] -= shotnoise;
994 template <
int N,
class T>
1000 std::string density_assignment_method,
1005 const int nleft = nleftright.first;
1006 const int nright = nleftright.second + (interlacing ? 1 : 0);
1019 density_assignment_method);
1034 if (pofk.subtract_shotnoise) {
1036 for (
int i = 0; i < pofk.n; i++) {
1037 pofk.pofk[i] -= shotnoise;
1137 template <
int N,
class T,
bool COMPACT>
1141 size_t NumPartTotal,
1143 std::string density_assignment_method,
1152 density_assignment_method,
1156 template <
int N,
class T,
bool COMPACT>
1160 size_t NumPartTotal,
1162 std::string density_assignment_method,
1171 density_assignment_method,
1175 template <
int N,
class T,
bool COMPACT>
1179 size_t NumPartTotal,
1181 std::string density_assignment_method,
1188 density_assignment_method,
1193 template <
int N,
class T,
int ORDER,
bool COMPACT>
1197 size_t NumPartTotal,
1199 std::string density_assignment_method,
1204 const int nleft = nleftright.first;
1205 const int nright = nleftright.second + 1;
1217 density_assignment_method);
1232 if constexpr (ORDER == 2) {
1236 for (
int i = 0; i < polyofk.
n; i++) {
1237 polyofk.
pofk[i] -= shotnoise;
1238 std::array<int, 2> ik{i, i};
1243 }
else if constexpr (ORDER == 3) {
1248 for (
int i = 0; i < polyofk.
n; i++) {
1249 polyofk.
pofk[i] -= S2;
1253 for (
size_t i = 0; i < polyofk.
P123.size(); i++) {
1254 if (polyofk.
N123[i] <= 0.0)
1257 polyofk.
P123[i] -= S2 * (polyofk.
pofk[ik[0]] + polyofk.
pofk[ik[1]] + polyofk.
pofk[ik[2]]) + S3;
1264 template <
int ORDER>
1265 int polyspectrum_work_mesh(
int nmesh,
const std::vector<double> & khigh,
bool dealias) {
1266 if (!dealias || ORDER == 2 || ORDER * *std::max_element(khigh.begin(), khigh.end()) < 2 * M_PI * nmesh)
1270 const long long multiple = std::lcm(2LL,
static_cast<long long>(
FML::NTasks));
1271 const long long minimum = (ORDER *
static_cast<long long>(nmesh) + 1) / 2;
1272 const long long padded = ((minimum + multiple - 1) / multiple) * multiple;
1273 assert_mpi(padded <= INT_MAX,
"[polyspectrum] Padded mesh exceeds int range");
1276 template <
int N,
int ORDER>
1278 const std::array<double, N> &
wave,
1283 if (!(k2 > 0 && k2 >= low2 && k2 < high2))
1285 if (dealias && ORDER > 2 &&
grid.get_nmesh() % 2 == 0)
1287 if (std::abs(k) >= M_PI *
grid.get_nmesh())
1309 template <
int N,
int ORDER,
bool COMPACT>
1311 assert_mpi(
Nmesh > 0 && bins.
n > 0 && bins.
klow.size() ==
size_t(bins.
n) &&
1312 bins.
khigh.size() ==
size_t(bins.
n),
1313 "[compute_polyspectrum_bincount] Mesh and shell binning must be initialized");
1315 assert_mpi(bins.
valid_storage(),
"[compute_polyspectrum_bincount] Invalid result storage");
1319 double requested_kmax = 0;
1320 for (
const auto & cfg : configs)
1321 for (
auto bin : cfg)
1322 requested_kmax = std::max(requested_kmax, bins.
khigh[bin]);
1323 const int mesh = detail::polyspectrum_work_mesh<ORDER>(
Nmesh, {requested_kmax}, bins.
dealias);
1324 auto build = [&](
int bin) {
1328 std::array<double, N>
wave;
1333 detail::polyspectrum_uses_mode<N, ORDER>(field,
1348 plan.
apply(field, padded);
1350 field = std::move(padded);
1355 detail::ShellCache<N, ORDER> cache(bins.
n,
1362 std::fill(bins.
N123.begin(), bins.
N123.end(), 0.0);
1363 const double measure = std::pow(2 * M_PI, N);
1364 const double norm = std::pow(1.0 /
mesh / (2 * M_PI), N);
1365 detail::integrate_configurations<N, ORDER>(
1370 [&](
auto cfg,
double sum) {
1371 double value = sum * norm;
1372 if (value * measure < 0.5)
1374 detail::store_permutations<N, ORDER>(bins, bins.N123, cfg, value);
1377 detail::finish_memory_report(bins);
1380 template <
int N,
bool COMPACT>
1385 template <
int N,
bool COMPACT>
1390 template <
int N,
bool COMPACT>
1395 template <
int N,
int ORDER,
bool COMPACT>
1397 static_assert(ORDER > 1);
1399 assert_mpi(
Nmesh > 0 && bins.
n > 0 && bins.
klow.size() ==
size_t(bins.
n) &&
1400 bins.
khigh.size() ==
size_t(bins.
n) && bins.
pofk.size() ==
size_t(bins.
n) &&
1401 bins.
kmean.size() ==
size_t(bins.
n),
1402 "[compute_polyspectrum] Invalid grid or binning");
1404 assert_mpi(bins.
valid_storage(),
"[compute_polyspectrum] Invalid result storage");
1410 double requested_kmax = 0;
1411 for (
const auto & cfg : configs)
1412 for (
auto bin : cfg)
1413 requested_kmax = std::max(requested_kmax, bins.
khigh[bin]);
1414 const int mesh = detail::polyspectrum_work_mesh<ORDER>(
Nmesh, {requested_kmax}, bins.
dealias);
1417 const size_t metadata_count = 3 * size_t(bins.
n);
1418 assert_mpi(metadata_count <=
size_t(INT_MAX),
"[polyspectrum] Too many shell statistics for MPI");
1419 std::vector<double> metadata(metadata_count, 0.0);
1421 std::array<double, N>
wave;
1424 for (
int bin = 0; bin < bins.
n; bin++) {
1425 if (!detail::polyspectrum_uses_mode<N, ORDER>(input,
1433 metadata[3 * bin] += weight * std::sqrt(k2);
1435 metadata[3 * bin + 2] += weight;
1442 for (
int bin = 0; bin < bins.
n; bin++) {
1443 const double count = metadata[3 * bin + 2];
1444 bins.
kmean[bin] = count ? metadata[3 * bin] / count : bins.
kbin[bin];
1445 bins.
pofk[bin] = count ? metadata[3 * bin + 1] / count : 0.0;
1447 auto build = [&](
int bin) {
1451 std::array<double, N>
wave;
1454 const bool use = detail::polyspectrum_uses_mode<N, ORDER>(input,
1468 plan.
apply(field, padded);
1470 field = std::move(padded);
1475 detail::ShellCache<N, ORDER>
1477 std::fill(bins.
P123.begin(), bins.
P123.end(), 0.0);
1478 const double norm = std::pow(1.0 /
mesh / (2 * M_PI), N);
1479 detail::integrate_configurations<N, ORDER>(
1484 [&](
auto cfg,
double sum) {
1485 const double count = bins.N123[bins.get_index_from_coord(cfg)];
1486 detail::store_permutations<N, ORDER>(bins, bins.P123, cfg, count > 0 ? sum * norm / count : 0.0);
1488 detail::finish_memory_report(bins);
std::array< int, 3 > wave(const Grid &grid, ptrdiff_t index)
Dense results by default; COMPACT stores one slot per canonical tuple.
std::vector< double > pofk
The power-spectrum.
std::array< int, ORDER > get_coord_from_index(size_t index)
The coord (k1,k2,...) corresponding to a given index in the P123 and N123 array These methods determi...
size_t get_index_from_coord(const std::array< int, ORDER > &ik)
std::vector< double > khigh
khigh is higher bin edge
double get_bincount(const std::array< int, ORDER > &ik)
Returns the volume factor N123.
std::vector< Configuration > configurations()
bool valid_storage() const
PolyspectrumOptions options
std::vector< double > P123
The polyspectrum.
std::vector< double > kmean
kmean is the mean of wavenumbers added to the bin
std::vector< double > kbin
kbin is center of bin
std::vector< double > N123
The volume (number of generalized triangles) of each bin.
PolyspectrumStatistics statistics
bool has_bincount(int nmesh)
void prepare_storage()
Allocate compact results only when needed. No dense tensor is constructed.
std::vector< double > klow
klow is lower bin edge
bool dealias
True integer-wavevector closure.
void mark_bincount_computed(int nmesh)
bool subtract_shotnoise
Subtract shotnoise? Algorithms (compute_polyspectrum) using this class checks this value.
Class for holding the results after binning up a power-spectrum.
void reset()
Reset everything. Call before starting to bim.
void add_to_bin(double kvalue, double power, double weight=1.0)
Add a new point to a bin.
void normalize()
Normalize (i.e. find mean in each bin) Do summation over MPI tasks.
std::vector< double > pofk
The power-spectrum in the bin.
Class for holding grids and performing real-to-complex and complex-to-real FFTs using FFTW with MPI.
int get_nmesh() const
Number of grid-cells per dimension.
void fftw_c2r()
Perform complex-to-real fourier transform.
void add_memory_label(std::string label)
For memory logging: add a label to the grid.
ptrdiff_t get_local_x_start() const
The x-slice the first local slice has in the global grid.
ptrdiff_t get_local_nx() const
Number of local x-slices in the real grid.
void set_fourier_from_index(const IndexIntType ind, const ComplexType value)
Set value of cell in fourier grid using (local) index.
ComplexType get_fourier_from_index(const IndexIntType index) const
Fetch value in fourier grid by (local) index.
std::array< double, N > get_fourier_wavevector_from_index(const IndexIntType index) const
Get the wave-vector of a grid-cell in Fourier space (for physical [k] multiply by 1/Boxsize)
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....
void fftw_r2c()
Perform real-to-complex fourier transform.
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.
void set_grid_status_real(bool grid_is_a_real_grid)
Set the status of the grid: is it currently a real grid or a fourier grid?
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)
size_t allocated_storage_bytes() const
Actual retained payload capacity, including halos/padding; excludes object/allocator overhead.
Reusable geometry for normalized, non-transposed FFTWGrid slab layouts.
void apply(const Grid &input, Grid &output, size_t max_message_bytes=64 *1024 *1024)
Collective; reuse with different fields having the same meshes and local slab geometry.
size_t workspace_storage_bytes() const
Geometry plus the larger of construction scratch or retained payload buffers.
The Fourier window of the density assignment, , from a table of the 1D factors (the wavevector compo...
A container class for holding particles that are distributed across many CPUs and to easily deal with...
size_t get_npart_total() const
Total number of active particles across all tasks.
T * get_particles_ptr()
Get a pointer to the first particle.
size_t get_npart() const
Number of active particles on the local task.
void compute_polyspectrum_bincount(int Nmesh, PolyspectrumBinning< N, ORDER, COMPACT > &bins)
This method is used by compute_polyspectrum.
void compute_monospectrum(const FFTWGrid< N > &fourier_grid, MonospectrumBinning< N, COMPACT > &pofk)
Computes the monospectrum from a fourier grid.
void compute_power_spectrum_multipoles_fourier(const FFTWGrid< N > &fourier_grid, std::vector< PowerSpectrumBinning< N > > &Pell, std::vector< double > line_of_sight_direction)
Compute power-spectrum multipoles from a Fourier grid where we have a fixed line_of_sight_direction (...
void bin_up_deconvolved_power_spectrum(const FFTWGrid< N > &fourier_grid, PowerSpectrumBinning< N > &pofk, std::string density_assignment_method)
Compute the power-spectrum of a fourier grid.
void compute_power_spectrum(int Ngrid, T *part, size_t NumPart, size_t NumPartTotal, PowerSpectrumBinning< N > &pofk, std::string density_assignment_method, bool interlacing)
Assign particles to grid using density_assignment_method = NGP,CIC,TSC,PCS,... Fourier transform,...
void compute_trispectrum(const FFTWGrid< N > &fourier_grid, TrispectrumBinning< N, COMPACT > &tofk)
Computes the trispectrum from a fourier grid.
void bin_up_power_spectrum(const FFTWGrid< N > &fourier_grid, PowerSpectrumBinning< N > &pofk)
Compute the power-spectrum of a fourier grid.
void compute_power_spectrum_multipoles(int Ngrid, FML::PARTICLE::MPIParticles< T > &part, double velocity_to_displacement, std::vector< PowerSpectrumBinning< N > > &Pell, std::string density_assignment_method, bool interlacing)
A simple power-spectrum estimator for multipoles in simulations.
void compute_power_spectrum_direct_summation(int Ngrid, const T *part, size_t NumPart, PowerSpectrumBinning< N > &pofk)
Brute force (but aliasing free) computation of the power spectrum.
void compute_bispectrum(int Ngrid, T *part, size_t NumPart, size_t NumPartTotal, BispectrumBinning< N, COMPACT > &bofk, std::string density_assignment_method, bool interlacing)
Computes the bispectrum from particles.
void bin_up_fourier_modes_3d(const FFTWGrid< 3 > &grid, F &&f)
Loop over the local Fourier modes of a 3D grid (except k = 0) in the order of the Fourier index,...
void compute_polyspectrum(int Ngrid, T *part, size_t NumPart, size_t NumPartTotal, PolyspectrumBinning< N, ORDER, COMPACT > &polyofk, std::string density_assignment_method, bool interlacing)
Computes the polyspectrum from particles.
std::pair< double, double > particle_shotnoise(const T *part, size_t NumPart, size_t NumPartTotal)
The shot noise of the density field of a set of particles as assigned by particles_to_grid: returns ...
void bin_up_cross_power_spectrum(const FFTWGrid< N > &fourier_grid_1, const FFTWGrid< N > &fourier_grid_2, PowerSpectrumBinning< N > &pofk)
Compute the cross power-spectrum of two fourier grids.
void particles_to_redshiftspace(FML::PARTICLE::MPIParticles< T > &part, std::vector< double > line_of_sight_direction, double velocity_to_displacement)
This takes a set of particles and displace them from realspace to redshiftspace Using a fixed line of...
int fourier_mode_multiplicity(int last_coord, int nmesh)
Number of full-complex modes represented by a stored r2c coefficient.
This namespace deals with interpolation and density assignment.
std::pair< int, int > get_extra_slices_needed_for_density_assignment(std::string density_assignment_method)
Compute how many extra slices we need in the FFTWGrid for a given density assignment / interpolation ...
void particles_to_fourier_grid_interlacing(const T *part, size_t NumPart, size_t NumPartTot, FFTWGrid< N > &density_grid_fourier, std::string density_assignment_method)
Internal method.
void deconvolve_window_function_fourier(FFTWGrid< N > &fourier_grid, std::string density_assignment_method)
Deconvolves the density assignment kernel in Fourier space.
void particles_to_grid(const T *part, size_t NumPart, size_t NumPartTot, FFTWGrid< N > &density, std::string density_assignment_method)
Assign particles to a grid to compute the over density field delta.
get_vel constexpr double * GetPos(...)
set_mass constexpr double GetMass(Args &... args)
void MinOverTasks(T *value)
Inplace min over tasks of a single value.
void MaxOverTasks(T *value)
Inplace max over tasks of a single value.
constexpr long long int power(int base, int exponent)
Simple integer a^b power-function by squaring (b >= 0; returns 0 for b < 0 instead of recursing forev...
int ThisTask
The MPI task number.
void SumArrayOverTasks(T *value, size_t n)
Inplace sum over tasks of a contiguous array of values.
void SumOverTasks(T *value)
Inplace sum over tasks of a single value.
int NTasks
Total number of MPI tasks.
size_t configuration_bytes
size_t metadata_work_bytes
size_t padding_source_bytes
size_t reduction_batch_size
Canonical configurations per collective; zero requests one batch (up to INT_MAX).
size_t geometry_shell_builds
size_t geometry_reduction_batches
size_t field_reduction_batches
size_t field_shell_builds
PolyspectrumMemory memory
size_t metadata_reduction_batches
Binning measure(double fnl, unsigned int seed)