cosmology.c File Reference

Documented cosmology module. More...

#include "header.h"
Include dependency graph for cosmology.c:

Functions

int Cosmology_init (struct Cosmology *Cx, double pk_kmax, double pk_zmax, int nlines, int *line_type, size_t npoints_interp, double M_min, long mode_mf)
 Allocate memory and initialize the cosmology structure, which includes the CLASS cosmology structure and line strucrure. More...
 
int Cosmology_free (struct Cosmology *Cx)
 Free the memory allocated to cosmology structure. More...
 
int CL_Cosmology_initilize (struct Cosmology *Cx, double pk_kmax, double pk_zmax)
 Allocate memory and initialize the CLASS cosmology structure. More...
 
int CL_Cosmology_free (struct Cosmology *Cx)
 Free the memory allocated to CLASS cosmology structure. More...
 
struct PS_xtrPS_xtrapol_init (struct Cosmology *Cx)
 Call CLASS and build a 2d interpolator for Plin(k,z), which will be used when building an extrapolator for P(k,z) beyond a given kmax computed by CLASS. More...
 
int PS_xtrapol_free (struct PS_xtr *PS_xtrapol)
 frees the interpolation elements for P_m spline More...
 
double PS (struct Cosmology *Cx, double k, double z)
 Evaluate the extrapolation for matter power spectrum beyond what is calculated by CLASS, same expansion as that used in CORE cosmology librrary (see arXiv:1812.05995) If requested k-value was beyond what is calculated by CLASS, this function extrapolates. More...
 
double PS_class (struct Cosmology *Cx, double k, double z, long mode)
 Call CLASS-V3.1 functions to compute the cdm+b pk (in Mpc**3) for a given k (in 1/Mpc) and z In LIM_FISHER code, we always include massive neutrinos. More...
 
double Pk_dlnPk_HV (struct Cosmology *Cx, double k, double z, int mode)
 Read in the linear power spectrum, used to set the initial conditions of Hidden-Valley sims. More...
 
double transfer (struct Cosmology *Cx, double k, double z, int mode)
 call CLASS-V3.1 to compute transfer function for different species depending on the switch "mode" mode can be set to cdm, baryons or total matter transfer function. More...
 
double growth_D (struct Cosmology *Cx, double k, double z)
 Compute the growth factor D(k,z) for a general case where it can be scale-dependant The scale-dep growth is calculated by taking the ratio of the transfer function at redshift z and zero. More...
 
double growth_f (struct Cosmology *Cx, double k, double z)
 Compute the growth factor D(k,z) by taking the ratio of the transfer function at redshift z and zero. More...
 
double scale_indep_growth_D (struct Cosmology *Cx, double z)
 Compute the growth factor D(k,z) which is scale-indep valid when neutrinos are massless The scale-dep growth is calculated by taking the ratio of the transfer function at redshift z and zero. More...
 
double scale_indep_growth_f (struct Cosmology *Cx, double z)
 Compute the scale-independent growth rate f(z) which is scale-indep valid when neutrinos are massless. More...
 
double Hubble (struct Cosmology *Cx, double z)
 Compute the the hubble rate (exactly the quantity defined by CLASS as index_bg_H in the background module). More...
 
double angular_distance (struct Cosmology *Cx, double z)
 Compute the angular diameter distance (exactly the quantity defined by CLASS as ba.index_bg_ang_distance in the background module). More...
 
double comoving_radial_distance (struct Cosmology *Cx, double z)
 Compute the comoving radial distance
More...
 
double sig_sq_integrand (double x, void *par)
 The integrand function passed to qags integrator to compute the variance of the smoothed matter density. More...
 
double sig_sq (struct Cosmology *Cx, double z, double R)
 Compute variance of smoothed matter density fluctuations. More...
 
double der_lnsig_sq (struct Cosmology *Cx, double z, double R)
 Compute the logarithmic derivative of the variance of smoothed matter density fluctuations w.r.t. More...
 
double sigma0_sq_integrand (double x, void *par)
 The integrand function passed to qags integrator to compute the variance of the unsmoothed matter density. More...
 
double sigma0_sq (struct Cosmology *Cx, double z, double kmax)
 Compute variance of unsmoothed matter density fluctuations. More...
 
double rhoc (struct Cosmology *Cx, double z)
 Compute the critical density in unit of M_sun/Mpc^3. More...
 
double R_scale (struct Cosmology *Cx, double h_mass)
 Compute the Lagrangian radius of halos in unit of Mpc , fixing z=0. More...
 
double R_scale_wrong (struct Cosmology *Cx, double z, double h_mass)
 Compute the Lagrangian radius of halos in unit of Mpc at z. More...
 
double R_vir (struct Cosmology *Cx, double M)
 Compute the comoving virial radius of halos in unit of Mpc, which is defined as the radius at which the average density within this radius is Delta X rho_c. More...
 
double concentration_cdm (double M, double z)
 Compute the cold dark matter concentration-mass relation. More...
 
double nfw_profile (struct Cosmology *Cx, double k, double M, double z)
 Compute the NFW halo profile in Fourier space, given by Eq. More...
 
double window_rth (double k, double R)
 Fourier transform of top-hat window in real space. More...
 
double window_kth (double k, double R)
 Top-hat window in Fourier space. More...
 
double window_g (double k, double R)
 Gaussian window. More...
 
double derR_window_rth (double k, double R)
 Derivative w.r.t. More...
 
double derR_logwindow_g (double k, double R)
 Derivative w.r.t smoothing scale of Gaussian window. More...
 

Detailed Description

Documented cosmology module.

Azadeh Moradinezhad Dizgah, November 4th 2021

The first routine of this module initalizes the Cosmology structure, which is the main building block of this entire code. This structure includes two sub-structures: the CLASS cosmology structure and line structure. Once the CLASS cosmology is initialized, various useful functions can be directly called from CLASS, example to compute matter power spectrum and transfer function, angular and comoving radii, growth factor and growth rate, variance of matter fluctuations and its derivative. Lastly, the module also includes various window functions and their derivatives.

In summary, the following functions can be called from other modules:

  1. Cosmology_init() allocates memory to and initializes cosmology structure
  2. Cosmology_free() frees the memory allocated to cosmology structure
  3. CL_Cosmology_initilize() initializes the class cosmology structure
  4. CL_Cosmology_free() frees the class cosmology structure
  5. PS_xtrapol_init() initizalizes the interpolator for Pm(k,z)
  6. PS_xtrapol_free() frees the interpolator for Pm(k,z)
  7. PS() computes matter power spectrum calling class and extrapolating if k>kmax computed by class
  8. PS_class() calls class to calculate
  9. Pk_dlnPk_HV() reads in the mesaured Pm on HV simulation and interpolates
  10. transfer() computes matter transfer function calling class function
  11. growth_D() computes the scale-dep growth factor
  12. growth_f() computes the scale-dep growth rate dlnD(k,a)/dlna
  13. scale_indep_growth_D() computes the scale-indep growth factor using directly CLASS functions
  14. scale_indep_growth_f() computes the scale-indep growth rate dlnD(k,a)/dlna using directly CLASS functions
  15. Hubble() computes hubbble parameter using directly CLASS functions
  16. angular_distance() computes angular diamtere distance using directly CLASS functions
  17. comoving_radial_distance() computes radial distance using directly CLASS functions
  18. sig_sq() computes variance of smoothed matter fluctuations
  19. der_lnsig_sq() computes natural log derivative of the variance of smoothed matter fluctuations w.r.t. smoothing scale
  20. sigma0_sq() computes variance of unsmoothed matter fluctuations
  21. rhoc() computes the critical density of the universe
  22. R_scale() computes the size of a spherical halo corresponding to a given mass at z=0
  23. R_scale_wrong() computes the size of a spherical halo corresponding to a given mass at a given redshift
  24. R_vir() computes the virial radius
  25. concentration_cdm() computes the halo concentration
  26. nfw profile() computes the nfw profile
  27. window_rth() computes top-hat filter in real space
  28. window_g() computes Gaussian window
  29. window_kth() computes top-hat filter in Fourier space
  30. derR_window_rth() computes derivative of top-hat filter in real space w.r.t. smoothing scale
  31. derR_logwindow_g() computes derivative of top-hat filter in Fourier space w.r.t. smoothing scale

Function Documentation

◆ angular_distance()

double angular_distance ( struct Cosmology Cx,
double  z 
)

Compute the angular diameter distance (exactly the quantity defined by CLASS as ba.index_bg_ang_distance in the background module).

luminosity distance d_L = (1+z) d_M angular diameter distance d_A = d_M/(1+z) where d_M is the transverse comoving distance, which is equal to comoving distance for flat cosmology and has a dependance on curvature for non-flat cosmologies, as described in lines 849 - 851

Parameters
CxInput: pointer to Cosmology structure
zInput: redshift to compute the spectrum
Returns
D_A

junk

Here is the caller graph for this function:

◆ CL_Cosmology_free()

int CL_Cosmology_free ( struct Cosmology Cx)

Free the memory allocated to CLASS cosmology structure.

Parameters
CxInput: pointer to Cosmology structure
Returns
the error status
Here is the caller graph for this function:

◆ CL_Cosmology_initilize()

int CL_Cosmology_initilize ( struct Cosmology Cx,
double  pk_kmax,
double  pk_zmax 
)

Allocate memory and initialize the CLASS cosmology structure.

Parameters
CxInput: pointer to Cosmology structure
pk_kmaxInput: kmax for computation of matter power spectrum by CLASS
pk_zmaxInput: zmax for computation of matter power spectrum by CLASS
Returns
the error status

pivot scale in unit of 1/Mpc

Here is the caller graph for this function:

◆ comoving_radial_distance()

double comoving_radial_distance ( struct Cosmology Cx,
double  z 
)

Compute the comoving radial distance

Parameters
CxInput: pointer to Cosmology structure
zInput: redshift to compute the spectrum
Returns
the double value D_c

junk

Here is the caller graph for this function:

◆ concentration_cdm()

double concentration_cdm ( double  M,
double  z 
)

Compute the cold dark matter concentration-mass relation.

Parameters
MInput: halo mass in unit of solar mass
zInput: redshift of interest
Returns
the cdm concentration
Here is the caller graph for this function:

◆ Cosmology_free()

int Cosmology_free ( struct Cosmology Cx)

Free the memory allocated to cosmology structure.

Parameters
CxInput: pointer to Cosmology structure
Returns
the error status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cosmology_init()

int Cosmology_init ( struct Cosmology Cx,
double  pk_kmax,
double  pk_zmax,
int  nlines,
int *  line_type,
size_t  npoints_interp,
double  M_min,
long  mode_mf 
)

Allocate memory and initialize the cosmology structure, which includes the CLASS cosmology structure and line strucrure.

Parameters
CxInput: pointer to Cosmology structure
pk_kmaxInput: kmax for computation of matter power spectrum by CLASS
pk_zmaxInput: zmax for computation of matter power spectrum by CLASS
nlinesInput: number of lines whose properties we want to compute
line_typeInpute: name of the line to compute. It can be set to CII, CO10, CO21, CO32, CO43, CO54, CO65
npoints_interpInput: number of points in redshift for interpolation of line properties
M_minInput: minimum halo mass for mass integrals
mode_mfInpute: theoretical model of halo mass function to use. It can be set to sheth-Tormen (ST), Tinker (TR) or Press-Schecter (PSC)
Returns
an integer if succeeded
Here is the call graph for this function:
Here is the caller graph for this function:

◆ der_lnsig_sq()

double der_lnsig_sq ( struct Cosmology Cx,
double  z,
double  R 
)

Compute the logarithmic derivative of the variance of smoothed matter density fluctuations w.r.t.

smoothing scale

Parameters
CxInput: pointer to Cosmology structure
zInput: redshift to compute the spectrum
RInput: smoothing scale in unit of Mpc
Returns
the log-derivative of variance
Here is the call graph for this function:

◆ derR_logwindow_g()

double derR_logwindow_g ( double  k,
double  R 
)

Derivative w.r.t smoothing scale of Gaussian window.

Parameters
kInput: wavenumber in unit of 1/Mpc
RInput: smoothing scale in unit of Mpc
Returns
the derivative of the window function

◆ derR_window_rth()

double derR_window_rth ( double  k,
double  R 
)

Derivative w.r.t.

smoothing scale of the Fourier transform of top-hat window in real space

Parameters
kInput: wavenumber in unit of 1/Mpc
RInput: smoothing scale in unit of Mpc
Returns
the derivative of the window function

◆ growth_D()

double growth_D ( struct Cosmology Cx,
double  k,
double  z 
)

Compute the growth factor D(k,z) for a general case where it can be scale-dependant The scale-dep growth is calculated by taking the ratio of the transfer function at redshift z and zero.

cdm, baryon and total matter.

Parameters
CxInput: pointer to Cosmology structure
kInput: wavenumbber in unit of 1/Mpc
zInput: redshift to compute the spectrum
Returns
the growth factor, can be k-dep (ex. with nonzero neutrino mass)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ growth_f()

double growth_f ( struct Cosmology Cx,
double  k,
double  z 
)

Compute the growth factor D(k,z) by taking the ratio of the transfer function at redshift z and zero.

For a general case growth rate can be scale-dependant

Parameters
CxInput: pointer to Cosmology structure
kInput: wavenumbber in unit of 1/Mpc
zInput: redshift to compute the spectrum
Returns
the growth factor
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Hubble()

double Hubble ( struct Cosmology Cx,
double  z 
)

Compute the the hubble rate (exactly the quantity defined by CLASS as index_bg_H in the background module).

Parameters
CxInput: pointer to Cosmology structure
zInput: redshift to compute the spectrum
Returns
the hubble parameter

junk

Here is the caller graph for this function:

◆ nfw_profile()

double nfw_profile ( struct Cosmology Cx,
double  k,
double  M,
double  z 
)

Compute the NFW halo profile in Fourier space, given by Eq.

3.7 of 2004.09515 The profile is normalized to unity at k->0, (see fig 3 of 1003.4740)

Parameters
CxInput: pointer to Cosmology structure
kInput: wavenumber in unit of 1/Mpc
MInput: halo mass in unit of solar mass
zInput: redshift of interest
Returns
the nfw profile

rho_s is computed by enforcing int dr r^2 u(r) = 1

Here is the call graph for this function:

◆ Pk_dlnPk_HV()

double Pk_dlnPk_HV ( struct Cosmology Cx,
double  k,
double  z,
int  mode 
)

Read in the linear power spectrum, used to set the initial conditions of Hidden-Valley sims.

Input k is in unit of 1/Mpc. First convert it to h/Mpc, and also convert the final matter power spectrum in unit of (Mpc/h)^3

Parameters
CxInput: pointer to Cosmology structure
kInput: wavenumbber in unit of 1/Mpc
zInput: redshift to compute the spectrum
modeInput: switch to decide whether to evaluate the interpolator of the power spectrum or free the interpolator
Returns
the HV linear matter power spectrum
Here is the call graph for this function:

◆ PS()

double PS ( struct Cosmology Cx,
double  k,
double  z 
)

Evaluate the extrapolation for matter power spectrum beyond what is calculated by CLASS, same expansion as that used in CORE cosmology librrary (see arXiv:1812.05995) If requested k-value was beyond what is calculated by CLASS, this function extrapolates.

Parameters
CxInput: pointer to Cosmology structure
kInput: wavenumbber in unit of 1/Mpc
zInput: redshift to compute the spectrum
Returns
the double value of matter power spectrum
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PS_class()

double PS_class ( struct Cosmology Cx,
double  k,
double  z,
long  mode 
)

Call CLASS-V3.1 functions to compute the cdm+b pk (in Mpc**3) for a given k (in 1/Mpc) and z In LIM_FISHER code, we always include massive neutrinos.

In this case, to compute the galaxy power spectrum, we should use cdm+b pk. Therefore hete when calling PS_class, we always get cdm+b pk, i.e. set &Cx -> ccs.fo.index_pk_cb. If you wanted to set neutrinos to be massless, you should replace this index by &Cx -> ccs.fo.index_pk_m The older routine of CLASS-v2.7, spectra_pk_at_k_and_z(), is replaced by fourier_pk_at_k_and_z(),

Input k is in unit of 1/Mpc. First convert it to h/Mpc, and also convert the final matter power spectrum in unit of (Mpc/h)^3

Parameters
CxInput: pointer to Cosmology structure
kInput: wavenumbber in unit of 1/Mpc
zInput: redshift to compute the spectrum
modeInput: switch to decide whether to compute linear (LPOWER) or nonlinear (NLPOWER) spectrum
Returns
the double value of matter power spectrum
Here is the caller graph for this function:

◆ PS_xtrapol_free()

int PS_xtrapol_free ( struct PS_xtr PS_xtrapol)

frees the interpolation elements for P_m spline

Parameters
PS_xtrapolInput: pointer to the structure containing the interpolation pointers
Returns
an integer indicating sucess
Here is the caller graph for this function:

◆ PS_xtrapol_init()

struct PS_xtr * PS_xtrapol_init ( struct Cosmology Cx)

Call CLASS and build a 2d interpolator for Plin(k,z), which will be used when building an extrapolator for P(k,z) beyond a given kmax computed by CLASS.

Parameters
CxInput: pointer to Cosmology structure
Returns
a structure containing the interpolation pointers
Here is the call graph for this function:
Here is the caller graph for this function:

◆ R_scale()

double R_scale ( struct Cosmology Cx,
double  h_mass 
)

Compute the Lagrangian radius of halos in unit of Mpc , fixing z=0.

Parameters
CxInput: pointer to Cosmology structure
h_massInput: halo mass in unit of solar mass
Returns
R_s
Here is the call graph for this function:
Here is the caller graph for this function:

◆ R_scale_wrong()

double R_scale_wrong ( struct Cosmology Cx,
double  z,
double  h_mass 
)

Compute the Lagrangian radius of halos in unit of Mpc at z.

Parameters
CxInput: pointer to Cosmology structure
zInput: redshift
h_massInput: halo mass in unit of solar mass
Returns
R_s
Here is the call graph for this function:

◆ R_vir()

double R_vir ( struct Cosmology Cx,
double  M 
)

Compute the comoving virial radius of halos in unit of Mpc, which is defined as the radius at which the average density within this radius is Delta X rho_c.

Parameters
CxInput: pointer to Cosmology structure
MInput: halo mass in unit of solar mass
Returns
R_vir
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rhoc()

double rhoc ( struct Cosmology Cx,
double  z 
)

Compute the critical density in unit of M_sun/Mpc^3.

Parameters
CxInput: pointer to Cosmology structure
zInput: redshift to compute the spectrum
Returns
the double value of rho_c

E (a) = H(a)^2/H0^2

G is in unit of m^3 kg^-1 s^-2, conversion factor from m to Mpc

To convert to solar mass

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scale_indep_growth_D()

double scale_indep_growth_D ( struct Cosmology Cx,
double  z 
)

Compute the growth factor D(k,z) which is scale-indep valid when neutrinos are massless The scale-dep growth is calculated by taking the ratio of the transfer function at redshift z and zero.

The scale-indep growth is computed by CLASS directly

Parameters
CxInput: pointer to Cosmology structure
zInput: redshift to compute the spectrum
Returns
the growth factor, can be k-dep (ex. with nonzero neutrino mass)

junk

◆ scale_indep_growth_f()

double scale_indep_growth_f ( struct Cosmology Cx,
double  z 
)

Compute the scale-independent growth rate f(z) which is scale-indep valid when neutrinos are massless.

Parameters
CxInput: pointer to Cosmology structure
zInput: redshift to compute the spectrum
Returns
the growth factor

junk

◆ sig_sq()

double sig_sq ( struct Cosmology Cx,
double  z,
double  R 
)

Compute variance of smoothed matter density fluctuations.

The function sigma0_integrand() defines the integrand and sigma0_sq() computes the k-integral

Parameters
CxInput: pointer to Cosmology structure
zInput: redshift to compute the spectrum
RInput: smoothing scale
Returns
the unsmoothed variance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sig_sq_integrand()

double sig_sq_integrand ( double  x,
void *  par 
)

The integrand function passed to qags integrator to compute the variance of the smoothed matter density.

Parameters
xInput: integration variable
parInput: integration parmaeters
Returns
value of the integrand
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigma0_sq()

double sigma0_sq ( struct Cosmology Cx,
double  z,
double  kmax 
)

Compute variance of unsmoothed matter density fluctuations.

The function sigma0_integrand() defines the integrand and sigma0_sq() computes the k-integral

Parameters
CxInput: pointer to Cosmology structure
kmaxInput: maximum wavenumber in unit of 1/Mpc
zInput: redshift to compute the spectrum
Returns
the unsmoothed variance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigma0_sq_integrand()

double sigma0_sq_integrand ( double  x,
void *  par 
)

The integrand function passed to qags integrator to compute the variance of the unsmoothed matter density.

Parameters
xInput: integration variable
parInput: integration parmaeters
Returns
value of the integrand
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transfer()

double transfer ( struct Cosmology Cx,
double  k,
double  z,
int  mode 
)

call CLASS-V3.1 to compute transfer function for different species depending on the switch "mode" mode can be set to cdm, baryons or total matter transfer function.

The older routine of CLASS-v2.7, spectra_tk_at_k_and_z(), is replaced by perturbations_sources_at_k_and_z(), which evaluates the matter transfer functions at a given value of k and z

Parameters
CxInput: pointer to Cosmology structure
kInput: wavenumbber in unit of 1/Mpc
zInput: redshift to compute the spectrum
modeInput: switch to decide which species to consider, can be set to cdm, baryons or total matter transfer function.
Returns
the transfer function of a given species
Here is the caller graph for this function:

◆ window_g()

double window_g ( double  k,
double  R 
)

Gaussian window.

Parameters
kInput: wavenumber in unit of 1/Mpc
RInput: smoothing scale in unit of Mpc
Returns
the window function

◆ window_kth()

double window_kth ( double  k,
double  R 
)

Top-hat window in Fourier space.

Parameters
kInput: wavenumber in unit of 1/Mpc
RInput: smoothing scale in unit of Mpc
Returns
the window function

◆ window_rth()

double window_rth ( double  k,
double  R 
)

Fourier transform of top-hat window in real space.

Parameters
kInput: wavenumber in unit of 1/Mpc
RInput: smoothing scale in unit of Mpc
Returns
the window function
Here is the caller graph for this function: