The hybrid bias (Lagrangian bias basis) spectra P_ab(k) of the operators 1, delta_L, delta_L^2, s^2 and nabla^2 delta_L advected with the CDM+baryon particles (written to file).
delta_L is the linear field of the initial conditions scaled to the output redshift with the 1LPT growth factor D(k,z) / D(k,zini) of the gravity model
395 {
405 const double a = 1.0 / (1.0 + redshift);
407
409 options.noperators = settings.noperators;
410 options.density_assignment_method = settings.density_assignment_method;
411 options.interlacing = settings.interlacing;
412 options.subtract_shotnoise = settings.subtract_shotnoise;
414 options.smoothing_method = settings.smoothing_filter;
415
417
419 std::cout << "\n";
420 std::cout << "#=====================================================\n";
421 std::cout << "# Computing hybrid bias spectra\n";
422 std::cout << "# hybridbias_nmesh : " << settings.nmesh << "\n";
423 std::cout << "# hybridbias_noperators : " << settings.noperators << "\n";
424 std::cout << "# hybridbias_density_assignment_method : " << settings.density_assignment_method << "\n";
425 std::cout << "# hybridbias_interlacing : " << settings.interlacing << "\n";
426 std::cout << "# hybridbias_subtract_shotnoise : " << settings.subtract_shotnoise << "\n";
427 std::cout << "# hybridbias_smoothing_scale (Mpc/h) : " << settings.smoothing_scale << "\n";
428 std::cout << "# hybridbias_kcut_over_nyquist : " << settings.kcut_over_nyquist << "\n";
429 std::cout << "# hybridbias_zeldovich : " << settings.zeldovich << "\n";
430 std::cout << "# hybridbias_oneloop : " << settings.oneloop << "\n";
431 std::cout << "#=====================================================\n";
432 }
433
434
435 auto growth_factor_of_kBox = [&](double kBox) {
436 if (kBox <= 0.0)
437 return 1.0;
440 };
441
444 part.get_npart(),
445 part.get_npart_total(),
448 settings.nmesh,
450 spectra,
451 growth_factor_of_kBox);
453
454
455 std::vector<double> pofk_linear(spectra.
pofk[0].n, 0.0);
456 for (
int i = 0;
i < spectra.
pofk[0].n;
i++) {
457 const double k = spectra.
pofk[0].kbin[
i];
458 if (power_initial_spline) {
459 const double D =
grav->get_D_1LPT(a, k /
grav->H0_hmpc);
460 const double Dini =
grav->get_D_1LPT(
aini, k /
grav->H0_hmpc);
461 pofk_linear[
i] = power_initial_spline(k) * std::pow(D / Dini, 2);
462 } else if (transferdata) {
463 pofk_linear[
i] = transferdata->get_cdm_baryon_power_spectrum(k, a);
464 }
465 }
466
467 std::ostringstream
header;
468 header <<
"# Hybrid bias spectra at z = " << redshift <<
" (boxsize " <<
boxsize <<
" Mpc/h, Npart_1D " <<
Npart_1D
469 << ", nmesh " << settings.nmesh << ", " << settings.density_assignment_method
470 << (settings.interlacing ? " with interlacing" : "") << ", shot noise subtracted: " << std::boolalpha
471 << settings.subtract_shotnoise << ")\n";
472 header <<
"# The tracer power spectrum is P_tt = sum_ab b_a b_b P_ab with b = (1, b1, b2, bs, bnabla) for the "
473 "operators (1, delta_L, delta_L^2 - <delta_L^2>, s^2 - <s^2>, nabla^2 delta_L)\n";
476 {{"Pcb_linear(k)", pofk_linear}});
477
478
479
480
481
482 if (not settings.zeldovich and not settings.oneloop)
483 return;
484 if (not power_initial_spline) {
486 std::cout
487 << "Warning: no linear P(k) so we cannot compute the LPT predictions of the hybrid bias spectra\n";
488 return;
489 }
490 const auto krange = power_initial_spline.get_xrange();
491 auto pofk_linear_of_k = [&](
double k) {
492 if (k < krange.first or k > krange.second)
493 return 0.0;
494 const double D =
grav->get_D_1LPT(a, k /
grav->H0_hmpc);
495 const double Dini =
grav->get_D_1LPT(
aini, k /
grav->H0_hmpc);
496 return power_initial_spline(k) * std::pow(D / Dini, 2);
497 };
499 const double smoothing_scale = settings.smoothing_scale;
500 const std::string filter = settings.smoothing_filter;
501 auto W_operators = [&](
double k) {
502 if (k >= kcut)
503 return 0.0;
504 if (smoothing_scale <= 0.0)
505 return 1.0;
506 const double kR =
k * smoothing_scale;
507 if (filter == "gaussian")
508 return std::exp(-0.5 * kR * kR);
509 if (filter == "sharpk")
510 return kR < 1.0 ? 1.0 : 0.0;
511
512 return kR < 1
e-4 ? 1.0 : 3.0 * (std::sin(kR) - kR * std::cos(kR)) / (kR * kR * kR);
513 };
514
516 auto W_displacement = [&](
double k) {
return k < kcut_displacement ? 1.0 : 0.0; };
517
518
519
520
521 const auto & kbin = spectra.
pofk[0].kbin;
523 const auto modes = modes_in_bins<NDIM>(spectra.
pofk[0], 2.0 * M_PI * 16);
524 double kmode_min = std::numeric_limits<double>::max(), kmode_max = 0.0;
525 for (
int i = 0;
i <
nbins;
i++)
526 for (
auto & m :
modes[
i]) {
527 kmode_min = std::min(kmode_min,
m.first /
boxsize);
528 kmode_max = std::max(kmode_max,
m.first /
boxsize);
529 }
530
531 const int ntable = kmode_max > 0.0 ? 40 : 0;
532 std::vector<double> kall;
533 for (int j = 0; j < ntable; j++)
534 kall.push_back(std::exp(std::log(kmode_min * 0.999) +
535 std::log(kmode_max * 1.001 / (kmode_min * 0.999)) * j / double(ntable - 1)));
536 std::vector<int> jbin(nbins, -1);
537 for (
int i = 0;
i <
nbins;
i++)
538 if (modes[i].empty() and kbin[i] > 0.0) {
539 jbin[
i] =
int(kall.size());
540 kall.push_back(kbin[i]);
541 }
542
543 std::vector<double> klocal;
544 std::vector<int> jlocal;
545 for (
int j = 0; j <
int(kall.size()); j++)
547 klocal.push_back(kall[j]);
548 jlocal.push_back(j);
549 }
550
551
552 auto write_prediction = [&](const std::vector<std::vector<double>> & prediction,
553 const std::string &
label,
555 double kcut_displacement_used) {
556 auto theory = spectra;
557 for (
size_t p = 0;
p < theory.pofk.size();
p++) {
558 std::vector<double> all(kall.size(), 0.0);
559 for (size_t j = 0; j < jlocal.size(); j++)
560 all[jlocal[j]] = prediction[p][j];
562 std::vector<double> logk_table(ntable), p_table(ntable);
563 for (int j = 0; j < ntable; j++) {
564 logk_table[j] = std::log(kall[j]);
565 p_table[j] = all[j];
566 }
568 if (ntable > 0)
570 for (
int i = 0;
i <
nbins;
i++) {
572 if (not modes[i].empty()) {
573 double wsum = 0.0;
574 for (
auto & m :
modes[
i]) {
577 }
579 } else if (jbin[i] >= 0) {
581 }
582 theory.pofk[
p].pofk[
i] =
value;
583 }
584 theory.shotnoise[
p] = 0.0;
585 }
586 std::ostringstream
header;
587 header <<
"# " <<
description <<
" of the hybrid bias spectra at z = " << redshift
588 << " (linear P_cb(k,z), operators cut at k = " << kcut << " h/Mpc"
589 << (smoothing_scale > 0.0 ?
590 " and smoothed with R = " + std::to_string(smoothing_scale) + " Mpc/h " + filter :
591 std::string(""))
592 << ", displacement cut at k = " << kcut_displacement_used << " h/Mpc). Same columns as hybridbias_z"
594 << ".txt (the shot noise is not included; for k < 16 k_fundamental the prediction is averaged over "
595 "the modes in each bin)\n";
596 theory.write(snapshot_folder +
"/hybridbias_" + label +
"_z" +
redshift_to_string(redshift) +
".txt",
598 {{"Pcb_linear(k)", pofk_linear}});
599 };
600
604 if (settings.zeldovich) {
605 zoptions.
kmax_integration = std::min(std::max(kcut, kcut_displacement), krange.second);
607 write_prediction(zeldovich, "zeldovich", "Zel'dovich prediction", kcut_displacement);
608 }
609 if (settings.oneloop) {
610
611 if (
FML::ThisTask == 0 and kcut_displacement > kcut * 1.0001)
612 std::cout << "Note: the one-loop prediction uses the operator cut k = " << kcut
613 << " h/Mpc also for the displacement field (the IC have modes up to " << kcut_displacement
614 << " h/Mpc)\n";
616 if (settings.oneloop_kernels == "model") {
617
625 }
else if (
grav->get_name() !=
"GR") {
626 const double H0_hmpc =
grav->H0_hmpc;
628 [grav, H0_hmpc](
double k,
double aa) {
return grav->GeffOverG(aa, k / H0_hmpc); });
629 }
632 std::cout <<
"One-loop prediction with the LPT kernels of " <<
description <<
"\n";
633
634
635 static std::shared_ptr<MGLoopTables> mg_tables;
636 static std::vector<double> mg_tables_redshifts;
637 if (not mg_tables) {
639 std::vector<double> aouts;
640 std::vector<std::function<double(double)>> pofks;
641 for (double z : mg_tables_redshifts) {
642 const double aa = 1.0 / (1.0 +
z);
643 aouts.push_back(aa);
644 pofks.push_back([&, aa](double k) {
645 if (k < krange.first or k > krange.second)
646 return 0.0;
647 const double D =
grav->get_D_1LPT(aa, k /
grav->H0_hmpc);
648 const double Dini =
grav->get_D_1LPT(
aini, k /
grav->H0_hmpc);
649 return power_initial_spline(k) * std::pow(D / Dini, 2);
650 });
651 }
652 mg_tables = std::make_shared<MGLoopTables>(
mg_loop_tables(model, aouts, pofks, W_operators, zoptions));
653 }
654 int io = -1;
655 for (
size_t i = 0;
i < mg_tables_redshifts.size();
i++)
656 if (std::abs(mg_tables_redshifts[i] - redshift) < 1e-6 * (1.0 + redshift))
658 std::vector<std::vector<double>> oneloop;
659 if (io >= 0)
661 io,
662 pofk_linear_of_k,
663 W_operators,
664 klocal,
665 zoptions);
666 else
668 {1.0 / (1.0 + redshift)},
669 {pofk_linear_of_k},
670 W_operators,
671 klocal,
672 zoptions)[0];
673 write_prediction(oneloop,
674 "oneloop",
675 "One-loop LPT (CLEFT, no counterterms; the LPT kernels of " +
description +
") prediction",
676 kcut);
677 } else {
679 write_prediction(oneloop, "oneloop", "One-loop LPT (CLEFT, no counterterms; EdS kernels) prediction", kcut);
680 }
681 }
682}
This is a wrapper class for easy use of GSL splines It is (OpenMP) thread safe as long as splines are...
const FFTWGrid< NDIM > & get_hybridbias_linear_field() const
The linear density field delta_cb(zini,k) of the initial conditions (only if hybridbias)
std::shared_ptr< Cosmology > get_cosmology() const
const Spline & get_power_initial_spline() const
std::shared_ptr< GravityModel< NDIM > > get_gravity_model() const
std::shared_ptr< LinearTransferData > get_transferdata() const
Hybrid bias (Lagrangian bias basis) spectra, Modi, Chen & White 2020 (1910.07097),...
MGModel mgmodel_dgp(double OmegaM, double H0rc, bool screening=true)
MGModel mgmodel_gr(double OmegaM)
Convenience constructors.
MGLoopTables mg_loop_tables(const MGModel &model, const std::vector< double > &aout, const std::vector< std::function< double(double)> > &pofk, const std::function< double(double)> &W, const ZeldovichOptions &options, const MGOneLoopSettings &settings={})
The loop functions of oneloop_hybrid_bias_spectra_mg for several output times at once (the expensive ...
MGModel mgmodel_fofr(double OmegaM, double fofr0, double nfofr=1.0, bool screening=true)
std::vector< std::vector< double > > oneloop_hybrid_bias_spectra_mg_from_tables(const MGLoopTables &tab, int io, const std::function< double(double)> &pofk, const std::function< double(double)> &W, const std::vector< double > &kvalues, const ZeldovichOptions &options, std::vector< std::string > *names=nullptr, std::vector< std::array< int, 2 > > *pairs=nullptr)
The one-loop prediction for output number io of the tables (pofk the linear P(k) at that output,...
MGModel mgmodel_mu(double OmegaM, std::function< double(double, double)> mu_of_k_hmpc_a)
std::vector< std::vector< double > > oneloop_hybrid_bias_spectra(const std::function< double(double)> &pofk, const std::function< double(double)> &W, const std::vector< double > &kvalues, const ZeldovichOptions &options, std::vector< std::string > *names=nullptr, std::vector< std::array< int, 2 > > *pairs=nullptr)
The one-loop (CLEFT) prediction for the hybrid bias spectra.
std::vector< std::vector< double > > zeldovich_hybrid_bias_spectra(const std::function< double(double)> &pofk, const std::function< double(double)> &W_operators, const std::function< double(double)> &W_displacement, const std::vector< double > &kvalues, const ZeldovichOptions &options, std::vector< std::string > *names=nullptr, std::vector< std::array< int, 2 > > *pairs=nullptr)
The Zel'dovich prediction for the hybrid bias spectra.
std::vector< std::vector< std::vector< double > > > oneloop_hybrid_bias_spectra_mg(const MGModel &model, const std::vector< double > &aout, const std::vector< std::function< double(double)> > &pofk, const std::function< double(double)> &W, const std::vector< double > &kvalues, const ZeldovichOptions &options, const MGOneLoopSettings &settings={}, std::vector< std::string > *names=nullptr, std::vector< std::array< int, 2 > > *pairs=nullptr)
The one-loop LPT prediction of the hybrid bias spectra in modified gravity with the full scale-depend...
void compute_hybrid_bias_spectra(const T *p, size_t NumPart, size_t NumPartTot, const FFTWGrid< N > &delta_linear_fourier, int Nlattice, int Nmesh, const HybridBiasOptions &options, HybridBiasSpectra< N > &spectra, std::function< double(double)> growth_factor_of_kBox=nullptr, detail::LatticeCoordinateFunction< N, T > lattice_coordinate=nullptr, std::vector< FFTWGrid< N > > *advected_out=nullptr)
Compute the hybrid bias spectra from particles and the linear density field.
void SumArrayOverTasks(T *value, size_t n)
Inplace sum over tasks of a contiguous array of values.
int NTasks
Total number of MPI tasks.
The result: the cross spectra of the advected operators for all pairs a <= b.
void write(const std::string &filename, const std::string &header="", const std::vector< std::pair< std::string, std::vector< double > > > &extra_columns={}) const
Write all the spectra to file (only task 0): k, the number of modes, P_ab for all pairs and then the ...
void scale(double boxsize)
To physical units: k -> k / B, P -> B^N P, and 1/B^2 for every nabla^2 delta in the pair.
std::vector< PowerSpectrumBinning< N > > pofk
One-loop LPT (CLEFT) prediction of the hybrid bias spectra in modified gravity with the full scale- a...
The Zel'dovich (resummed 1LPT) prediction for the hybrid bias basis spectra P_ab(k) of the operators ...
int noperators
How many of the operators (1, delta, delta2, s2, nabla2delta) to use.
double kmin_integration
The range of the k-integrals over P(k) (kmax: where W_op and W_disp are zero, e.g....
std::vector< double > redshifts
ParticleSettings particle
HybridBiasSettings hybridbias
ComplexType value(const std::array< int, N > &wave, int generation)