FML
Data Structures | Typedefs | Functions | Variables
FML::COSMOLOGY::HALOMODEL Namespace Reference

Data Structures

class  HaloModel
 Class for computing the standard halomodel predictions for \(P(k,z)\) plus \(n(M,z)\) or just doing spherical collapse. More...
 

Typedefs

using Timer = FML::UTILS::Timings
 
using DVector = FML::SOLVERS::ODESOLVER::DVector
 
using DVector2D = FML::SOLVERS::ODESOLVER::DVector2D
 
using ODEFunction = FML::SOLVERS::ODESOLVER::ODEFunction
 
using ODEFunctionJacobian = FML::SOLVERS::ODESOLVER::ODEFunctionJacobian
 
using ODESolver = FML::SOLVERS::ODESOLVER::ODESolver
 
using Spline = FML::INTERPOLATION::SPLINE::Spline
 
using Spline2D = FML::INTERPOLATION::SPLINE::Spline2D
 
using Func1 = std::function< double(double)>
 
using Func2 = std::function< double(double, double)>
 
using SphericalCollapse = FML::COSMOLOGY::SPHERICALCOLLAPSE::SphericalCollapse
 
using SphericalCollapseModel = FML::COSMOLOGY::SPHERICALCOLLAPSE::SphericalCollapseModel
 
using RhoFunction = std::function< double(double, double, HaloModel *hm)>
 
using cofMFunction = std::function< double(double, HaloModel *hm)>
 
using HaloMultiplicityFunction = std::function< double(double, HaloModel *hm)>
 
using HaloBiasFunction = std::function< double(double, HaloModel *hm)>
 
using WindowFunction = std::function< double(double)>
 

Functions

void powerlaw_extend_logY_of_logx_spline (Spline &logY_of_logx_spline, double xmin_new, double xmax_new, int npts_new, std::string label="logY(log(x)) extrapolated")
 
void read_pofk_file (const std::string filename_pofk, Spline &logDelta_of_logk_spline, double normalization, int col_k, int col_pofk)
 
std::pair< double, double > compute_neff (const Spline &logsigma_of_logR_spline, const Spline &lognu_of_logR_spline)
 
double compute_sigmav (const Func1 logDelta_of_logk, const WindowFunction window_of_kR, double R, const DVector *fiducial_logk_array)
 
void compute_sigma (const Func1 logDelta_of_logk, const WindowFunction window_of_kR, Spline &logsigma_of_logR_spline, const DVector *fiducial_logR_array, const DVector *fiducial_logk_array)
 
double RvirofM (double M, double DeltaVir, double OmegaM, double x)
 
double RofM (double M, double OmegaM, double x)
 
double MofRvir (double Rvir, double DeltaVir, double OmegaM, double x)
 
double MofR (double R, double OmegaM, double x)
 
DVector compute_rho_fourier_single (const Func2 &rho_function, const DVector &k_array, const double M, const double Rvir)
 
void compute_rho_fourier (const Func2 &rho_function, Spline2D &y_of_logR_and_logk_spline, const double DeltaVir, const double OmegaM, const double x, const DVector *fiducial_logR_array, const DVector *fiducial_logk_array)
 
void compute_lognu_of_logR (const double deltac, const Spline &logsigma_of_logR_spline, Spline &lognu_of_logR_spline, Spline &logR_of_lognu_spline, const DVector *fiducial_logR_array)
 
void compute_massfunction (const Spline &logR_of_lognu_spline, const Spline &lognu_of_logR_spline, Spline &dndlogM_of_logM_spline, Spline &n_of_logM_spline, const Func1 &pdf_of_nu, const double OmegaM, const double x)
 
void compute_one_and_two_halo_terms (const Spline &logR_of_lognu_spline, const Spline2D &y_of_logR_and_logk_spline, Spline &logDelta_onehalo_of_logk_spline, Spline &logDelta_twohalo_of_logk_spline, Spline &logDelta_full_of_logk_spline, const Func1 &logDeltaLin_of_logk, const Func1 &pdf_of_nu, const Func1 &bias_of_nu, const double eta_hmcode, const double kmin, const double kmax, const int npts_k)
 
void compute_formation_redshift_factor (const Spline &growthfactor_of_x_spline, const Spline &logsigma_of_logR_spline, Spline &formationredshift_of_logM_spline, double deltac, double OmegaM, double xcollapse, double massfraction)
 
HaloMultiplicityFunction get_sheth_tormen_halo_multiplicity_function ()
 
HaloBiasFunction get_sheth_tormen_halo_bias_function ()
 
WindowFunction get_tophat_window_fourier ()
 
cofMFunction get_nfw_halo_mass_concentration_relation ()
 
RhoFunction get_nfw_halo_density_profile ()
 

Variables

int _ACCURACY_BOOST = 1
 

Typedef Documentation

◆ cofMFunction

using FML::COSMOLOGY::HALOMODEL::cofMFunction = typedef std::function<double(double,HaloModel *hm)>

Definition at line 38 of file Halomodel.h.

◆ DVector

Definition at line 24 of file Halomodel.h.

◆ DVector2D

Definition at line 25 of file Halomodel.h.

◆ Func1

using FML::COSMOLOGY::HALOMODEL::Func1 = typedef std::function<double(double)>

Definition at line 31 of file Halomodel.h.

◆ Func2

using FML::COSMOLOGY::HALOMODEL::Func2 = typedef std::function<double(double,double)>

Definition at line 32 of file Halomodel.h.

◆ HaloBiasFunction

using FML::COSMOLOGY::HALOMODEL::HaloBiasFunction = typedef std::function<double(double,HaloModel *hm)>

Definition at line 40 of file Halomodel.h.

◆ HaloMultiplicityFunction

using FML::COSMOLOGY::HALOMODEL::HaloMultiplicityFunction = typedef std::function<double(double,HaloModel *hm)>

Definition at line 39 of file Halomodel.h.

◆ ODEFunction

Definition at line 26 of file Halomodel.h.

◆ ODEFunctionJacobian

Definition at line 27 of file Halomodel.h.

◆ ODESolver

Definition at line 28 of file Halomodel.h.

◆ RhoFunction

using FML::COSMOLOGY::HALOMODEL::RhoFunction = typedef std::function<double(double,double,HaloModel *hm)>

Definition at line 37 of file Halomodel.h.

◆ SphericalCollapse

Definition at line 33 of file Halomodel.h.

◆ SphericalCollapseModel

Definition at line 34 of file Halomodel.h.

◆ Spline

Definition at line 29 of file Halomodel.h.

◆ Spline2D

Definition at line 30 of file Halomodel.h.

◆ Timer

Definition at line 23 of file Halomodel.h.

◆ WindowFunction

using FML::COSMOLOGY::HALOMODEL::WindowFunction = typedef std::function<double(double)>

Definition at line 41 of file Halomodel.h.

Function Documentation

◆ compute_formation_redshift_factor()

void FML::COSMOLOGY::HALOMODEL::compute_formation_redshift_factor ( const Spline &  growthfactor_of_x_spline,
const Spline &  logsigma_of_logR_spline,
Spline &  formationredshift_of_logM_spline,
double  deltac,
double  OmegaM,
double  xcollapse,
double  massfraction 
)

Definition at line 580 of file Halomodel.cpp.

587 {
588
589 // Solve D(zf)/D(z) sigma(massfraction * M, z) == deltac(z) for zf
590 // where z is collapse redshift
591 auto compute_formation_redshift = [&](double M){
592 const double Mform = massfraction * M;
593 const double R = RofM(Mform, OmegaM, xcollapse);
594 auto condition = [&](double x){
595 const double xminspline = growthfactor_of_x_spline.get_xrange().first;
596 double growthratio = growthfactor_of_x_spline(x) / growthfactor_of_x_spline(xcollapse);
597 if(x < xminspline){
598 growthratio = growthfactor_of_x_spline(xminspline) / growthfactor_of_x_spline(xcollapse);
599 growthratio *= std::exp(x-xminspline);
600 }
601 const double sigma = std::exp(logsigma_of_logR_spline(std::log(R)));
602 return growthratio * sigma - deltac;
603 };
604 double xformation = xcollapse;
605 try{
606 xformation = FML::MATH::find_root_bisection(condition, {std::log(1e-10), xcollapse}, 1e-8);
607 } catch(...){
608 }
609 return xformation;
610 };
611
612 //========================================
613 // Make R array
614 //========================================
615 const double Rmin = 1e-8, Rmax = 1e8;
616 const int npts_R = 10000;
617 const auto logR_array = FML::MATH::linspace(std::log(Rmin), std::log(Rmax), npts_R);
618
619 // Compute formation-factor (1+zf(m))/(1+zcollapse) for all radii
620 DVector formationtime_array;
621 DVector logM_array;
622 for(const auto logR : logR_array){
623 const double M = MofR(std::exp(logR), OmegaM, xcollapse);
624 const double xformation = compute_formation_redshift(M);
625 formationtime_array.push_back(std::exp(-xformation)-1.0);
626 logM_array.push_back(std::log(M));
627 }
628 formationredshift_of_logM_spline = Spline(logM_array, formationtime_array, "zf(logM)");
629 }
const double OmegaM
Definition: Main.cpp:65
FML::INTERPOLATION::SPLINE::DVector DVector
Definition: Simulation.h:39
std::pair< double, double > get_xrange() const
Get the range the spline was created on.
Definition: Spline.cpp:277
double RofM(double M, double OmegaM, double x)
Definition: Halomodel.cpp:216
double MofR(double R, double OmegaM, double x)
Definition: Halomodel.cpp:241
FML::INTERPOLATION::SPLINE::Spline Spline
Definition: CAMBReader.h:14
DVector linspace(double xmin, double xmax, int num)
Python linspace. Generate a lineary spaced array.
Definition: Math.cpp:269
double find_root_bisection(const std::function< double(double)> &function, std::pair< double, double > xrange, double epsilon)
Find roots using bisection.
Definition: Math.cpp:51
const double exp
Definition: Global.h:259
deltac
Definition: example.py:67
x
Definition: test.py:18

◆ compute_lognu_of_logR()

void FML::COSMOLOGY::HALOMODEL::compute_lognu_of_logR ( const double  deltac,
const Spline &  logsigma_of_logR_spline,
Spline &  lognu_of_logR_spline,
Spline &  logR_of_lognu_spline,
const DVector *  fiducial_logR_array 
)

Definition at line 376 of file Halomodel.cpp.

381 {
382
383 //================================================
384 // Radius array
385 //================================================
386 const double logRmin = logsigma_of_logR_spline.get_xrange().first;
387 const double logRmax = logsigma_of_logR_spline.get_xrange().second;
388 const int npts_R = 500;
389 auto logR_array = FML::MATH::linspace(logRmin, logRmax, npts_R);
390 if(fiducial_logR_array != nullptr)
391 logR_array = *fiducial_logR_array;
392
393 DVector lognu_array;
394 for(const auto logR : logR_array){
395 const double sigma = std::exp(logsigma_of_logR_spline(logR));
396 const double nu = deltac/sigma;
397 lognu_array.push_back(std::log(nu));
398 }
399
400 lognu_of_logR_spline = Spline(logR_array, lognu_array, "lognu(logR)");
401 logR_of_lognu_spline = Spline(lognu_array, logR_array, "logR(lognu)");
402 }
FML::SOLVERS::ODESOLVER::DVector DVector
Definition: Halomodel.h:24

◆ compute_massfunction()

void FML::COSMOLOGY::HALOMODEL::compute_massfunction ( const Spline &  logR_of_lognu_spline,
const Spline &  lognu_of_logR_spline,
Spline &  dndlogM_of_logM_spline,
Spline &  n_of_logM_spline,
const Func1 &  pdf_of_nu,
const double  OmegaM,
const double  x 
)

Definition at line 408 of file Halomodel.cpp.

415 {
416
417 // Units of (h/Mpc)^3 (same as 1/R^3)
418 auto dndlogM_of_lognu = [&](double lognu){
419 const double nu = std::exp(lognu);
420 const double logR = logR_of_lognu_spline(lognu);
421 const double R = std::exp(logR);
422 const double f = pdf_of_nu(nu);
423 const double dnudlogR = nu * lognu_of_logR_spline.deriv_x(logR);
424 return f * std::abs(dnudlogR) / (4.0 * M_PI * R * R * R);
425 };
426
427 //================================================
428 // M array
429 //================================================
430 const double Mmin = 1e5, Mmax = 1e18;
431 const int npts_M = 500;
432 const auto logM_array = FML::MATH::linspace(std::log(Mmin),std::log(Mmax),npts_M);
433 const double dlogM = logM_array[1]-logM_array[0];
434
435 DVector dndlogM_array(npts_M), n_array(npts_M, 0.0), lognu_array(npts_M,0.0);
436 for(int i = npts_M-1; i >= 0; i--){
437 const double logM = logM_array[i];
438 const double M = std::exp(logM);
439 const double R = RofM(M, OmegaM, x);
440 const double logR = std::log(R);
441 const double lognu = lognu_of_logR_spline(logR);
442 const double dndlogM = dndlogM_of_lognu(lognu);
443 dndlogM_array[i] = dndlogM;
444 n_array[i] = dndlogM * dlogM;
445 if(i < npts_M-1)
446 n_array[i] += n_array[i+1];
447 }
448 dndlogM_of_logM_spline = Spline(logM_array, dndlogM_array, "dndlogM(logM)");
449 n_of_logM_spline = Spline(logM_array, n_array, "n(logM)");
450 }
double deriv_x(double x) const
Get the value of the first derivative of the spline.
Definition: Spline.cpp:275
std::vector< double > DVector
dndlogM
Definition: example.py:66

◆ compute_neff()

std::pair< double, double > FML::COSMOLOGY::HALOMODEL::compute_neff ( const Spline &  logsigma_of_logR_spline,
const Spline &  lognu_of_logR_spline 
)

Definition at line 101 of file Halomodel.cpp.

103 {
104 const double logRmin = std::log(1e-4);
105 const double logRmax = std::log(1e4);
106 const double epsilon = 1e-10;
107
108 const double lognu_goal = std::log(1.0);
109 auto condition = [&](double logR){
110 return lognu_of_logR_spline(logR) - lognu_goal;
111 };
112 const double logR = FML::MATH::find_root_bisection(condition, {logRmin, logRmax}, epsilon);
113 const double neff = -3.0 - 2.0 * logsigma_of_logR_spline.deriv_x(logR);
114 return std::pair(std::exp(logR), neff);
115 }

◆ compute_one_and_two_halo_terms()

void FML::COSMOLOGY::HALOMODEL::compute_one_and_two_halo_terms ( const Spline &  logR_of_lognu_spline,
const Spline2D &  y_of_logR_and_logk_spline,
Spline &  logDelta_onehalo_of_logk_spline,
Spline &  logDelta_twohalo_of_logk_spline,
Spline &  logDelta_full_of_logk_spline,
const Func1 &  logDeltaLin_of_logk,
const Func1 &  pdf_of_nu,
const Func1 &  bias_of_nu,
const double  eta_hmcode,
const double  kmin,
const double  kmax,
const int  npts_k 
)

Definition at line 458 of file Halomodel.cpp.

470 {
471
472 int accuracy_boost = _ACCURACY_BOOST;
473
474 //================================================
475 // nu array
476 //================================================
477 const double numin = 1e-10, numax = 10;
478 const int npts_nu = 200 * accuracy_boost;
479 const auto lognu_array = FML::MATH::linspace(std::log(numin),std::log(numax),npts_nu);
480
481 //================================================
482 // k array
483 //================================================
484 const auto logk_array = FML::MATH::linspace(std::log(kmin), std::log(kmax), npts_k);
485 auto k_array = logk_array;
486 for(auto & k : k_array) k = std::exp(k);
487
488 auto integrand_onehalo = [&logR_of_lognu_spline,&y_of_logR_and_logk_spline,&eta_hmcode,&pdf_of_nu](double lognu, double logk){
489 const double nu = std::exp(lognu);
490 const double logR = logR_of_lognu_spline(lognu);
491 const double y = y_of_logR_and_logk_spline(logR, logk + lognu*eta_hmcode);
492 const double f = pdf_of_nu(nu);
493 const double Moverrhomean = 4.0 * M_PI / 3.0 * std::exp(3.0*logR);
494 return Moverrhomean * f * (y*y) * nu;
495 };
496
497 auto integrand_twohalo = [&eta_hmcode,&logR_of_lognu_spline,&y_of_logR_and_logk_spline,&pdf_of_nu,&bias_of_nu](double lognu, double logk){
498 const double nu = std::exp(lognu);
499 const double logR = logR_of_lognu_spline(lognu);
500 const double y = y_of_logR_and_logk_spline(logR, logk + lognu*eta_hmcode);
501 const double f = pdf_of_nu(nu);
502 const double bias = bias_of_nu(nu);
503 return bias * f * y * nu;
504 };
505
506 // This should integrate to 1
507 auto integrand_norm_onehalo = [&pdf_of_nu](double lognu){
508 const double nu = std::exp(lognu);
509 const double f = pdf_of_nu(nu);
510 return f * nu;
511 };
512
513 // This should integrate to 1
514 auto integrand_norm_twohalo = [&pdf_of_nu,&bias_of_nu](double lognu){
515 const double nu = std::exp(lognu);
516 const double f = pdf_of_nu(nu);
517 const double bias = bias_of_nu(nu);
518 return bias * f * nu;
519 };
520
521 // Compute Int fdnu and Int bf dnu
522 // Both which should be unity
523 double normone = 0.0;
524 double normtwo = 0.0;
525 for(const auto lognu : lognu_array){
526 normone += integrand_norm_onehalo(lognu);
527 normtwo += integrand_norm_twohalo(lognu);
528 }
529 normone *= (lognu_array[1]-lognu_array[0]);
530 normtwo *= (lognu_array[1]-lognu_array[0]);
531 // Sanity check Int f dnu = 1 and Int f b dnu = 1
532 if(std::abs(normone-1.0) > 0.001 or std::abs(normtwo-1.0) > 0.001){
533 // Can happen normally if massfunction is not normalized but in any case Int bf / Int f == 1
534 std::cout << "Warning: Unity check failed for Int f(nu)dnu = " << normone << " Int b(nu)f(nu)dnu = " << normtwo << "\n";
535 std::cout << "Could be that massfunction is not normalized. In that case this should be unity: " << normtwo/normone << "\n";
536 }
537
538 DVector logDelta_onehalo_array;
539 DVector logDelta_twohalo_array;
540 DVector logDelta_full_array;
541 for(const auto logk : logk_array){
542 const double k = std::exp(logk);
543
544 // Integrate up one and two halo integrals
545 double onehalo = 0.0;
546 double twohalo = 0.0;
547 double full = 0.0;
548 for(const auto lognu : lognu_array){
549 onehalo += integrand_onehalo(lognu, logk);
550 twohalo += integrand_twohalo(lognu, logk);
551 }
552 onehalo *= (lognu_array[1]-lognu_array[0]);
553 twohalo *= (lognu_array[1]-lognu_array[0]);
554
555 // Normalize
556 onehalo *= (k*k*k)/(2.0*M_PI*M_PI) / normone;
557 twohalo *= 1.0 / normtwo;
558 twohalo = twohalo * twohalo * std::exp(logDeltaLin_of_logk(logk));
559 full = onehalo + twohalo;
560
561 logDelta_onehalo_array.push_back(std::log(onehalo));
562 logDelta_twohalo_array.push_back(std::log(twohalo));
563 logDelta_full_array.push_back(std::log(full));
564
565 }
566
567 logDelta_onehalo_of_logk_spline = Spline(logk_array, logDelta_onehalo_array, "logDelta1h(logk)");
568 logDelta_twohalo_of_logk_spline = Spline(logk_array, logDelta_twohalo_array, "logDelta2h(logk)");
569 logDelta_full_of_logk_spline = Spline(logk_array, logDelta_full_array, "logDelta(logk)");
570 }
return y
Definition: Global.h:265

◆ compute_rho_fourier()

void FML::COSMOLOGY::HALOMODEL::compute_rho_fourier ( const Func2 &  rho_function,
Spline2D &  y_of_logR_and_logk_spline,
const double  DeltaVir,
const double  OmegaM,
const double  x,
const DVector *  fiducial_logR_array,
const DVector *  fiducial_logk_array 
)

Definition at line 325 of file Halomodel.cpp.

332 {
333
334 int accuracy_boost = _ACCURACY_BOOST;
335
336 //================================================
337 // k array
338 //================================================
339 const double kmin = 1e-8, kmax = 1e8;
340 const int npts_k = 75 * accuracy_boost;
341 auto logk_array = FML::MATH::linspace(std::log(kmin), std::log(kmax), npts_k);
342 if(fiducial_logk_array != nullptr)
343 logk_array = *fiducial_logk_array;
344 auto k_array = logk_array;
345 for(auto & k : k_array) k = std::exp(k);
346
347 //================================================
348 // R array
349 //================================================
350 const double Rmin = 1e-8, Rmax = 1e8;
351 const int npts_R = 75 * accuracy_boost;
352 auto logR_array = FML::MATH::linspace(std::log(Rmin), std::log(Rmax), npts_R);
353 if(fiducial_logR_array != nullptr)
354 logR_array = *fiducial_logR_array;
355 auto R_array = logR_array;
356 for(auto & R : R_array) R = std::exp(R);
357
358 DVector2D yofkandM_array(R_array.size(), DVector(k_array.size()));
359#ifdef USE_OMP
360#pragma omp parallel for schedule(dynamic,1)
361#endif
362 for(size_t i = 0; i < R_array.size(); i++){
363 const double R = R_array[i];
364 const double M = MofR(R, OmegaM, x);
365 const double Rvir = R / std::pow(DeltaVir,1.0/3.0);
366 const auto result = compute_rho_fourier_single(rho_function, k_array, M, Rvir);
367 yofkandM_array[i] = result;
368 }
369 y_of_logR_and_logk_spline = Spline2D(logR_array, logk_array, yofkandM_array, "y(logR,logk)");
370 }
DVector compute_rho_fourier_single(const Func2 &rho_function, const DVector &k_array, const double M, const double Rvir)
Definition: Halomodel.cpp:257
FML::SOLVERS::ODESOLVER::DVector2D DVector2D
Definition: Halomodel.h:25
FML::INTERPOLATION::SPLINE::Spline2D Spline2D
Definition: CAMBReader.h:16

◆ compute_rho_fourier_single()

DVector FML::COSMOLOGY::HALOMODEL::compute_rho_fourier_single ( const Func2 &  rho_function,
const DVector &  k_array,
const double  M,
const double  Rvir 
)

Definition at line 257 of file Halomodel.cpp.

261 {
262
263 int accuracy_boost = _ACCURACY_BOOST;
264
265 //================================================
266 // Determine lower integration limits
267 // by requiring rho(rmin) < 1e-6 rho(Rvir/10)
268 //================================================
269 double rho_start = rho_function(Rvir/10.0,M);
270 int power_min = 1;
271 while(power_min < 5) {
272 ++power_min;
273 double rho = rho_function(Rvir/std::pow(10,power_min),M);
274 if(rho < 1e-4 * rho_start) break;
275 };
276
277 //================================================
278 // Determine upper integration limit
279 //================================================
280 int power_max = 0;
281 while(power_max < 7) {
282 ++power_max;
283 double rho = rho_function(Rvir*std::pow(2,power_max),M);
284 if(rho == 0.0) break;
285 }
286
287 //================================================
288 // Radius integration array
289 //================================================
290 const double rmin = Rvir/std::pow(10,power_min), rmax = Rvir*std::pow(2,power_max);
291 const int npts_r = (power_max+power_min) * 50 * accuracy_boost;
292 const auto logr_array = FML::MATH::linspace(std::log(rmin), std::log(rmax), npts_r);
293 auto r_array = logr_array;
294 for(auto & r : r_array) r = std::exp(r);
295
296 DVector y_array;
297 for(const auto k : k_array){
298
299 auto integrand = [&rho_function](double k, double r, double M){
300 return rho_function(r, M) * std::sin(k*r)/(k*r);
301 };
302
303 // Integrate up to get the dimensionless y = rho(k,M)/M
304 double integral = 0.0;
305 for(const auto r : r_array){
306 integral += integrand(k, r, M);
307 }
308 integral *= (logr_array[1] - logr_array[0]);
309 y_array.push_back(integral);
310 }
311
312 // Ensure normalization in case rho is not properly normalized
313 // y(k,M) -> 1 as k -> 0
314 const double norm = y_array[0];
315 for(auto & y : y_array) y /= norm;
316
317 return y_array;
318 }

◆ compute_sigma()

void FML::COSMOLOGY::HALOMODEL::compute_sigma ( const Func1  logDelta_of_logk,
const WindowFunction  window_of_kR,
Spline &  logsigma_of_logR_spline,
const DVector *  fiducial_logR_array,
const DVector *  fiducial_logk_array 
)

Definition at line 149 of file Halomodel.cpp.

154 {
155
156 //================================================
157 // Radius array
158 // If not provided then we generate it
159 //================================================
160 const double Rmin = 1e-8, Rmax = 1e8;
161 const int npts_R = 500;
162 auto logR_array = FML::MATH::linspace(std::log(Rmin), std::log(Rmax), npts_R);
163 if(fiducial_logR_array != nullptr)
164 logR_array = *fiducial_logR_array;
165 auto R_array = logR_array;
166 for(auto & R : R_array) R = std::exp(R);
167
168 //================================================
169 // k integration array. Linear in logk
170 // If not provided then we generate it
171 //================================================
172 const double kmin = 1e-8, kmax = 1e8;
173 const int npts_k = 500;
174 auto logk_array = FML::MATH::linspace(std::log(kmin), std::log(kmax), npts_k);
175 if(fiducial_logk_array != nullptr)
176 logk_array = *fiducial_logk_array;
177 auto k_array = logk_array;
178 for(auto & k : k_array) k = std::exp(k);
179
180 //================================================
181 // Compute and spline sigma(R)
182 //================================================
183 DVector logsigma_array;
184 for(const auto R : R_array){
185
186 auto integrand = [&logDelta_of_logk,&window_of_kR](double logk, double R){
187 const double k = std::exp(logk);
188 const double W = window_of_kR(k*R);
189 return std::exp(logDelta_of_logk(logk)) * W * W;
190 };
191
192 double integral = 0.0;
193 for(const auto logk : logk_array){
194 integral += integrand(logk, R);
195 }
196 integral *= (logk_array[1]-logk_array[0]);
197 logsigma_array.push_back(0.5*std::log(integral));
198 }
199 logsigma_of_logR_spline = Spline(logR_array, logsigma_array, "sigma(R)");
200 }

◆ compute_sigmav()

double FML::COSMOLOGY::HALOMODEL::compute_sigmav ( const Func1  logDelta_of_logk,
const WindowFunction  window_of_kR,
double  R,
const DVector *  fiducial_logk_array 
)

Definition at line 121 of file Halomodel.cpp.

125 {
126 auto integrand = [&](double logk){
127 const double W = window_of_kR(std::exp(logk)*R);
128 return W*W*std::exp(logDelta_of_logk(logk))*std::exp(-2*logk)/3.0;
129 };
130
131 const double kmin = 1e-8, kmax = 1e4;
132 const int npts_k = 1000;
133 auto logk_array = FML::MATH::linspace(std::log(kmin), std::log(kmax), npts_k);
134 if(fiducial_logk_array != nullptr)
135 logk_array = *fiducial_logk_array;
136 auto k_array = logk_array;
137 for(auto & k : k_array) k = std::exp(k);
138 double integral = 0.0;
139 for(const auto logk : logk_array){
140 integral += integrand(logk);
141 }
142 integral *= (logk_array[1]-logk_array[0]);
143 return std::sqrt(integral);
144 }

◆ get_nfw_halo_density_profile()

RhoFunction FML::COSMOLOGY::HALOMODEL::get_nfw_halo_density_profile ( )

Definition at line 1017 of file Halomodel.cpp.

1017 {
1018 return [&](double r, double M, HaloModel *hm){
1019 const double DeltaVir = hm->DeltaVir;
1020 const double OmegaM = hm->OmegaM;
1021 const double x = hm->xcollapse;
1022 const double c = hm->halo_mass_concentration_relation(M,hm);
1023 const double R = RofM(M, OmegaM, x);
1024 double Rvir = R / std::pow(DeltaVir,1.0/3.0);
1025
1026 // The modification Rvir *= nu^eta is for the halo bloating effect
1027 // Fiducial value is 0.0 which has no effect
1028 // This can be included *either* here or when doing the 1h 2h integrals
1029 // Rvir *= std::pow(std::exp(hm->lognu_of_logR_spline(std::log(R))), hm->hmcode_eta);
1030 // but not both. Currently we do this in the y-integral
1031
1032 const double rs = Rvir / c;
1033 if(r > Rvir) return 0.0;
1034 return std::pow(r/rs, 3) / ( (r/rs) * (1 + r/rs) * (1 + r/rs) ) / (std::log(1 + c) - c/(1 + c));
1035 };
1036 }
Class for computing the standard halomodel predictions for plus or just doing spherical collapse.
Definition: Halomodel.h:62

◆ get_nfw_halo_mass_concentration_relation()

cofMFunction FML::COSMOLOGY::HALOMODEL::get_nfw_halo_mass_concentration_relation ( )

Definition at line 1001 of file Halomodel.cpp.

1001 {
1002 return [&](double M, HaloModel *hm){
1003 if(hm->cofM_model == "Bullock2001"){
1004 const double zf = hm->formationredshift_of_logM_spline(std::log(M));
1005 const double z = std::exp(-hm->xcollapse)-1;
1006 return hm->hmcode_cmin * std::max(1.0, (1.0+zf)/(1+z) );
1007 }
1008 // Simple c = c0/(1+z) * (M/M0)^(-beta) power-law model
1009 return hm->cofM_0 * std::pow(M / hm->cofM_M0, -hm->cofM_beta) * std::exp(hm->xcollapse);
1010 };
1011 }
float z
Definition: example.py:56

◆ get_sheth_tormen_halo_bias_function()

HaloBiasFunction FML::COSMOLOGY::HALOMODEL::get_sheth_tormen_halo_bias_function ( )

Definition at line 665 of file Halomodel.cpp.

665 {
666 return [&](double nu, HaloModel *hm){
667 const double deltac = hm->deltac;
668 const double p_ST = hm->p_ST;
669 const double a_ST = hm->a_ST;
670 return 1.0 + (a_ST*nu*nu-1.0)/deltac + 2.0*p_ST/deltac/(1.0+std::pow(a_ST*nu*nu,p_ST));
671 };
672 }

◆ get_sheth_tormen_halo_multiplicity_function()

HaloMultiplicityFunction FML::COSMOLOGY::HALOMODEL::get_sheth_tormen_halo_multiplicity_function ( )

Definition at line 657 of file Halomodel.cpp.

657 {
658 return [&](double nu, HaloModel *hm){
659 const double A_ST = hm->A_ST;
660 const double p_ST = hm->p_ST;
661 const double a_ST = hm->a_ST;
662 return A_ST * (1.0 + std::pow(a_ST*nu*nu,-p_ST)) * std::exp(-a_ST*nu*nu/2.0);
663 };
664 }

◆ get_tophat_window_fourier()

WindowFunction FML::COSMOLOGY::HALOMODEL::get_tophat_window_fourier ( )

Definition at line 677 of file Halomodel.cpp.

677 {
678 return [](double kR){
679 if(kR < 1e-6) return 1.0 - kR*kR/10.;
680 return 3.0/(kR*kR*kR)*(std::sin(kR)-kR*std::cos(kR));
681 };
682 }

◆ MofR()

double FML::COSMOLOGY::HALOMODEL::MofR ( double  R,
double  OmegaM,
double  x 
)

Definition at line 241 of file Halomodel.cpp.

244 {
245 const double Mpl2overMsunH0overh = 2.493e21;
246 const double H0overh_in_hmpc = 1.0 / 2997.92458;
247 const double rho_mean_in_msunh_over_mpch3 = 3.0 * OmegaM * std::exp(-3.0*x)
248 * std::pow(H0overh_in_hmpc,3) * Mpl2overMsunH0overh;
249 return 4.0 * M_PI / 3.0 * rho_mean_in_msunh_over_mpch3 * std::pow(R, 3);
250 }

◆ MofRvir()

double FML::COSMOLOGY::HALOMODEL::MofRvir ( double  Rvir,
double  DeltaVir,
double  OmegaM,
double  x 
)

Definition at line 230 of file Halomodel.cpp.

234 {
235 return MofR(Rvir, OmegaM, x) * DeltaVir;
236 }

◆ powerlaw_extend_logY_of_logx_spline()

void FML::COSMOLOGY::HALOMODEL::powerlaw_extend_logY_of_logx_spline ( Spline &  logY_of_logx_spline,
double  xmin_new,
double  xmax_new,
int  npts_new,
std::string  label = "logY(log(x)) extrapolated" 
)

Definition at line 22 of file Halomodel.cpp.

27 {
28
29 // Fetch logx-array from spline
30 const auto logx_array = logY_of_logx_spline.get_x_data();
31 const double logxmin = logx_array.front();
32 const double logxmax = logx_array.back();
33
34 // Compute slope near end-points
35 double slope_min = logY_of_logx_spline.deriv_x(logxmin*0.99);
36 double slope_max = logY_of_logx_spline.deriv_x(logxmax*1.01);
37
38 // Extrapolation function
39 auto logY_extrapolated = [&](double logx){
40 if(logx < logxmin){
41 return logY_of_logx_spline(logxmin) + (logx-logxmin) * slope_min;
42 } else if(logx > logxmax){
43 return logY_of_logx_spline(logxmax) + (logx-logxmax) * slope_max;
44 }
45 return logY_of_logx_spline(logx);
46 };
47
48 // Extend spline to one covering a larger region
49 const auto logx_array_new = FML::MATH::linspace(std::log(xmin_new), std::log(xmax_new), npts_new);
50 DVector logY_array_new;
51 for(const auto logx : logx_array_new){
52 logY_array_new.push_back( logY_extrapolated(logx) );
53 }
54 logY_of_logx_spline = Spline(logx_array_new, logY_array_new, label);
55 }
DVector get_x_data()
Get the raw GSL data for x used to create the spline.
Definition: Spline.h:165

◆ read_pofk_file()

void FML::COSMOLOGY::HALOMODEL::read_pofk_file ( const std::string  filename_pofk,
Spline &  logDelta_of_logk_spline,
double  normalization,
int  col_k,
int  col_pofk 
)

Definition at line 61 of file Halomodel.cpp.

66 {
67
68 // Read file
69 auto data = FML::FILEUTILS::loadtxt(filename_pofk);
70
71 // Extract data, transform to Delta, normalize and spline
72 DVector logk_array, logDelta_array;
73 for(size_t i = 0; i < data.size(); i++){
74 double k = data[i][col_k];
75 double pofk = data[i][col_pofk];
76 double Delta_over_pofk = (k*k*k) / (2.0*M_PI*M_PI);
77 logk_array.push_back( std::log(k) );
78 logDelta_array.push_back( std::log( pofk * Delta_over_pofk * normalization ) );
79 }
80
81 // Make spline
82 logDelta_of_logk_spline = Spline(logk_array, logDelta_array, "logDelta(logk)");
83
84 // Extrapolate assuming ~ k^n at each end
85 // and remake spline
86 const double kmin = 1e-12;
87 const double kmax = 1e12;
88 const int npts_spline = 1000;
90 logDelta_of_logk_spline,
91 kmin,
92 kmax,
93 npts_spline,
94 "logDelta(logk) extrapolated");
95 }
void powerlaw_extend_logY_of_logx_spline(Spline &logY_of_logx_spline, double xmin_new, double xmax_new, int npts_new, std::string label="logY(log(x)) extrapolated")
Definition: Halomodel.cpp:22
DVector2D loadtxt(std::string filename, int nreserve_rows, int nreserve_cols)
Similar to pythons loadtxt function Gives warning if file is not regular Skips lines starting with #,...
Definition: FileUtils.cpp:189
data
Definition: test.py:10

◆ RofM()

double FML::COSMOLOGY::HALOMODEL::RofM ( double  M,
double  OmegaM,
double  x 
)

Definition at line 216 of file Halomodel.cpp.

219 {
220 const double Mpl2overMsunH0overh = 2.493e21;
221 const double H0overh_in_hmpc = 1.0 / 2997.92458;
222 const double rho_mean_in_msunh_over_mpch3 = 3.0 * OmegaM * std::exp(-3.0*x)
223 * std::pow(H0overh_in_hmpc,3) * Mpl2overMsunH0overh;
224 return std::pow(M / (4.0 * M_PI / 3.0 * rho_mean_in_msunh_over_mpch3), 1.0/3.0);
225 }

◆ RvirofM()

double FML::COSMOLOGY::HALOMODEL::RvirofM ( double  M,
double  DeltaVir,
double  OmegaM,
double  x 
)

Definition at line 205 of file Halomodel.cpp.

209 {
210 return RofM(M, OmegaM, x) * std::pow(DeltaVir, -1.0/3.0);
211 }

Variable Documentation

◆ _ACCURACY_BOOST

int FML::COSMOLOGY::HALOMODEL::_ACCURACY_BOOST = 1

Definition at line 16 of file Halomodel.cpp.