9#include <gsl/gsl_integration.h>
10#include <gsl/gsl_deriv.h>
19#define Grav 4.7788e-20
23#define lightspeed 2.99792458e5
28#define ERROR_MESSAGE() std::cerr << "ERROR: file: " << __FILE__ << " line: " << __LINE__ << std::endl;
31#define CRITD 2.49783e18
32#define CRITD2 2.7752543e11
37enum class CosmoParamSet {WMAP5yr,Millennium,Planck1yr,Planck15,Planck18,BigMultiDark,Uchuu,none};
39std::string to_string(
const CosmoParamSet &p);
40std::ostream &operator<<(std::ostream &os,
const CosmoParamSet &p);
55 COSMOLOGY(CosmoParamSet cosmo_p = CosmoParamSet::WMAP5yr);
57 COSMOLOGY(
double omegam,
double omegal,
double h,
double w = -1,
double wa = 0
58 ,
bool justdistances=
false
66 CosmoParamSet ParamSet(){
return cosmo_set;}
67 void ParamSet(std::string &s);
70 std::string
print(
short physical= 0)
const;
79 double coorDist(
double zo,
double z)
const;
84 double radDist(
double zo,
double z)
const;
86 double angDist(
double zo,
double z)
const;
88 double lumDist(
double zo,
double z)
const;
98 double DRradius(
double zo,
double z,
double pfrac);
106 double Omegam(
double z)
const;
109 double drdz(
double x)
const;
111 double drdz_dark(
double x)
const;
112 inline double dark_factor(
double x)
const;
118 double DeltaVir(
double z,
int caseunit=0)
const;
119 double Deltao(
double m)
const;
120 double time(
double z)
const;
121 double nonlinMass(
double z)
const;
129 double Dgrowth(
double z)
const;
139 double psdfdm(
double z,
double m,
int caseunit=0);
140 double halo_bias (
double m,
double z,
int t=0);
141 double stdfdm(
double z,
double m,
int caseunit=0);
142 double powerlawdfdm(
double z,
double m,
double alpha,
int caseunit=0);
151 ,
double k_max = 100,
double k_min = 1.0e-3);
153 struct CorrFunctorType{
154 CorrFunctorType(
COSMOLOGY *cosmo,
double radius,
double redshift)
155 : cosmology(cosmo),z(redshift),r(radius)
157 norm = 0.5/PI/PI/(1+z)/(1+z);
166 double operator () (
double k) {
169 double jo = sin(rk)/rk;
170 if(rk < 1.0e-3) jo = 1.0;
172 return norm*jo*k*k*cosmology->
powerCDMz(k,z);
178 double haloNumberInBufferedCone (
double mass ,
double z1,
double z2,
double fov,
double buffer ,
int type ,
double alpha=0.0);
179 double haloMassInBufferedCone (
double mass ,
double z1,
double z2,
double fov,
double buffer ,
int type ,
double alpha=0.0);
193 power_normalize(sig8); calc_interp_dist(); cosmo_set = CosmoParamSet::none;}
194 double gethubble()
const {
return h;}
200 double getindex()
const {
return n;}
204 double getOmega_matter()
const {
return Omo;}
208 double getOmega_lambda()
const {
return Oml;}
213 double getOmega_baryon()
const {
return Omb;}
218 double getOmega_neutrino()
const {
return Omnu;}
222 double getNneutrino()
const {
return Nnu;}
225 void setW(
double w){
ww = w; calc_interp_dist(); cosmo_set = CosmoParamSet::none;}
226 double getW()
const {
return ww;}
227 void setW1(
double w){
ww1 = w; calc_interp_dist(); cosmo_set = CosmoParamSet::none;}
228 double getW1()
const {
return ww1;}
232 double getdndlnk()
const {
return dndlnk;}
236 double getgamma()
const {
return gamma;}
239 void setDEtype(
short tt){darkenergy = tt; cosmo_set = CosmoParamSet::none;}
240 short getDEtype()
const {
return darkenergy;}
242 void setSigma8(
double my_sig8){
power_normalize(my_sig8); cosmo_set = CosmoParamSet::none;}
243 double getSigma8()
const {
return sig8;}
246 void dzdangDist(
double D,
double z[],
double dzdD[]);
254 double SigmaCrit(
double zlens,
double zsource)
const;
259 CosmoParamSet cosmo_set;
263 drdz_struct(
COSMOLOGY const &cosmo):cos(cosmo){};
264 double operator()(
double x)
const {
return cos.drdz(x);}
267 struct drdzdark_struct{
268 drdzdark_struct(
COSMOLOGY const &cosmo):cos(cosmo){};
269 double operator()(
double x)
const {
return cos.drdz_dark(x);}
273 adrdz_struct(
COSMOLOGY const &cosmo):cos(cosmo){};
274 double operator()(
double x)
const {
return cos.drdz(x)/x;}
277 struct adrdzdark_struct{
278 adrdzdark_struct(
COSMOLOGY const &cosmo):cos(cosmo){};
279 double operator()(
double x)
const {
return cos.drdz_dark(x)/x;}
284 normL_struct(
COSMOLOGY &cosmo):cos(cosmo){};
285 double operator()(
double x)
const {
return cos.normL(x);}
289 double ddrdzdOmo(
double x)
const;
290 double ddrdzdw(
double x)
const;
291 double ddrdzdw1(
double x)
const;
293 struct ddrdzdOmo_struct{
294 ddrdzdOmo_struct(
COSMOLOGY const &cosmo):cos(cosmo){};
295 double operator()(
double x)
const {
return cos.ddrdzdOmo(x);}
298 struct ddrdzdw_struct{
299 ddrdzdw_struct(
COSMOLOGY const &cosmo):cos(cosmo){};
300 double operator()(
double x)
const {
return cos.ddrdzdw(x);}
303 struct ddrdzdw1_struct{
304 ddrdzdw1_struct(
COSMOLOGY const &cosmo):cos(cosmo){};
305 double operator()(
double x)
const {
return cos.ddrdzdw1(x);}
309 bool init_structure_functions;
350 double powerEH(
double k,
double z);
353 double npow(
double k);
354 double normL(
double lgk);
355 double gradius(
double R,
double rd)
const;
358 std:: vector<double> vDeltaCz,vlz,vt;
359 double DpropDz(
double z);
361 double timeEarly(
double a)
const;
362 double dNdz(
double z);
364 typedef double (
COSMOLOGY::*pt2MemFunc)(double)
const;
365 typedef double (
COSMOLOGY::*pt2MemFuncNonConst)(double);
367 double nintegrateDcos(pt2MemFunc func,
double a,
double b,
double tols)
const;
368 double trapzdDcoslocal(pt2MemFunc func,
double a,
double b,
int n,
double *s2)
const;
369 void polintD(
double xa[],
double ya[],
int n,
double x,
double *y,
double *dy)
const;
370 double nintegrateDcos(pt2MemFuncNonConst func,
double a,
double b,
double tols);
371 double trapzdDcoslocal(pt2MemFuncNonConst func,
double a,
double b,
int n,
double *s2);
372 double dfridrDcos(pt2MemFunc func,
double x,
double h,
double *err);
373 double f4(
double u)
const;
376 std::vector<float> xf, wf;
380 short TFmdm_set_cosm_change_z(
double redshift);
381 short TFmdm_set_cosm();
382 double TFmdm_onek_mpc(
double kk);
383 double TFmdm_onek_hmpc(
double kk);
394 double num_degen_hdm;
400 double omega_lambda_z;
401 double omega_matter_z;
406 double sound_horizon_fit;
414 void TFset_parameters(
double omega0hh,
double f_baryon,
double Tcmb);
415 double TFfit_onek(
double k,
double *tf_baryon,
double *tf_cdm);
419 double sound_horizon;
435 std::size_t n_interp;
436 void calc_interp_dist();
437 double interp(
const std::vector<double>& table,
double z)
const;
438 double invert(
const std::vector<double>& table,
double f_z)
const;
439 std::vector<double> redshift_interp;
440 std::vector<double> coorDist_interp;
441 std::vector<double> radDist_interp;
457 double NFW_V200(
double M200,
double R200);
458 double NFW_Vmax(
double cons,
double M200,
double R200);
459 double NFW_Vr(
double x,
double cons,
double M200,
double R200);
460 double NFW_M(
double x,
double cons,
double M200);
463 double NFW_rho(
double cons,
double x);
465 void match_nfw(
float Vmax,
float R_half,
float mass,
float *cons,
float *Rsize);
466 float Rsize(
float cons,
float Vmax,
float mass);
467 float g_func(
float x);
470 float Vmax,R_half,mass;
473 float zbrentD(MemFunc func,
float a,
float b,
float tols);
474 float nfwfunc(
float cons);
475 float funcforconcentration(
float cons);
480double drdz_wrapper(
double x,
void *params);
481double drdz_dark_wrapper(
double x,
void *params);
482double Deltao_wrapper(
double m,
void *params);
490void ders(
double z,
double Da[],
double dDdz[]);
491void dir(
double r,
double a[],
double dadr[]);
492double arctanh(
double x);
493double fmini(
double a,
double b);
494double fmaxi(
double a,
double b);
495double **dmatrixcos(
long nrl,
long nrh,
long ncl,
long nch);
496void free_dmatrixcos(
double **m,
long nrl,
long nrh,
long ncl,
long nch);
501void TFset_parameters(
double omega0hh,
double f_baryon,
double Tcmb);
502double TFfit_onek(
double k,
double *tf_baryon,
double *tf_cdm);
The cosmology and all the functions required to calculated quantities based on the cosmology.
Definition cosmo.h:52
double DeltaVir(double z, int caseunit=0) const
Virial overdensity.
Definition cosmo.cpp:1092
void setOmega_neutrino(double Omega_neutrino)
Omega neutrino, renormalizes P(k) to keep sig8 fixed.
Definition cosmo.h:216
double stdfdm(double z, double m, int caseunit=0)
Sheth-Tormen mass function.
Definition cosmo.cpp:803
void setInterpolation(double z_interp, std::size_t n_interp)
set interpolation range and number of points
Definition cosmo.cpp:1465
double haloNumberDensityOnSky(double m, double z1, double z2, int t, double alpha=0.0)
Number of halos with mass larger than m (in solar masses) between redshifts z1 and z2 per square degr...
Definition cosmo.cpp:953
double powerloc(double k, double z)
The linear power spectrum without growth factor growth factor should be normalized to 1 at z=0.
Definition powerCDM.cpp:144
double radDist(double zo, double z) const
Non-comoving radial distance in units Mpc also known as the lookback time. This is coorDist only inte...
Definition cosmo.cpp:687
double npow(double k)
Logorithmic slope of the power spectrum.
Definition powerCDM.cpp:124
double d_coorDist_dOmo(double zo, double z) const
derivative of coordinate distance with respect to Omo in flat cosmology. Useful for Fisher matrix cal...
Definition cosmo.cpp:672
void setNneutrino(double Nneutrino)
Number of neutrino species, renormalizes P(k) to keep sig8 fixed.
Definition cosmo.h:221
double rcurve() const
Curvature radius in Mpc.
Definition cosmo.cpp:461
double Nnu
Number of neutrino species.
Definition cosmo.h:324
std::string print(short physical=0) const
Print cosmological parameters.
Definition cosmo.cpp:390
void setOmega_matter(double Omega_matter, bool FLAT=false)
Omega matter, renormalizes P(k) to keep sig8 fixed.
Definition cosmo.h:203
void PrintCosmology(short physical=0) const
Print cosmological parameters.
Definition cosmo.cpp:359
void SetConcordenceCosmology(CosmoParamSet cosmo_p)
Sets cosmology to WMAP 2009 model. This is done automatically in the constructor.
Definition cosmo.cpp:198
double powerlawdfdm(double z, double m, double alpha, int caseunit=0)
Power-law mass function.
Definition cosmo.cpp:846
double gradius(double R, double rd) const
Incorporates curvature for angular size distance.
Definition cosmo.cpp:755
double powerEH(double k, double z)
The power spectrum from Eisinstein & Hu with neutrinos but no BAO.
Definition powerCDM.cpp:218
double invComovingDist(double d) const
The inverse of the angular size distance in units Mpc, works within interpolation range.
Definition cosmo.cpp:733
double psdfdm(double z, double m, int caseunit=0)
Press-Schechter halo mass function - default i.e. fraction of mass or if caseunit==1 the .
Definition cosmo.cpp:770
double power_normalize(double sigma8)
Set the linear normalization for the power spectrum.
Definition powerCDM.cpp:155
double scalefactor(double rad) const
The scale factor, a = 1/(1+z), as a function of radius in Mpc.
Definition powerCDM.cpp:84
double delta_c() const
the critical over density
Definition cosmo.cpp:1242
double Omnu
Omega neutrino.
Definition cosmo.h:322
double getHubble() const
Hubble parameter in 1/Mpc units.
Definition cosmo.h:196
double SigmaCrit(double zlens, double zsource) const
The lensing critical density in Msun / Mpc^2.
Definition cosmo.cpp:1540
double invCoorDist(double d) const
The inverse of the coordinate distance in units Mpc, returning redshift. It works within interpolatio...
Definition cosmo.cpp:726
double DRradius(double zo, double z, double pfrac)
Comoving Dyer-Roeder angular size distance for lambda=0.
Definition cosmo.cpp:485
void setW(double w)
Dark energy equation of state parameter p/rho = w + w_1 (1+z)
Definition cosmo.h:225
void setgamma(double gamm)
Alternative to w for dark energy/ alt. grav. structure evolution.
Definition cosmo.h:235
double rho_crit_comoving(double z) const
comoving critical density in M_sun/Mpc^3
Definition cosmo.cpp:607
double gamma
Alternative to w for dark energy/ alt. grav. structure evolution.
Definition cosmo.h:333
double d_coorDist_dw1(double zo, double z) const
derivative of coordinate distance with respect to w1. Useful for Fisher matrix calculations
Definition cosmo.cpp:680
double lumDist(double zo, double z) const
The bolometric luminosity distance in units Mpc.
Definition cosmo.cpp:719
double dndlnk
Running of primordial spectral index, P(k)_primordial \propto pow(k/h,n+dndlnk*log(k))
Definition cosmo.h:330
double Omegam(double z) const
Matter density parameter at redshift z.
Definition cosmo.cpp:478
void setOmega_lambda(double Omega_lambda, bool FLAT=false)
Omega lambda, renormalizes P(k) to keep sig8 fixed.
Definition cosmo.h:207
double dsigdM(double m)
Derivative of in CDM model.
Definition cosmo.cpp:1073
double halo_bias(double m, double z, int t=0)
Halo bias, uses formalism by Mo-White.
Definition cosmo.cpp:1271
void setindex(double nn)
Primordial spectral index, renormalizes P(k) to keep sig8 fixed.
Definition cosmo.h:199
double ww
Dark energy equation of state parameter p/rho = ww + ww_1 (1+z)
Definition cosmo.h:326
double Dgrowth(double z) const
Linear growth factor normalized to 1 at z=0.
Definition cosmo.cpp:588
double Oml
Omega lambda.
Definition cosmo.h:318
double coorDist(double zo, double z) const
The coordinate distance in units Mpc. This is the radial distance found by integrating 1/H(z)....
Definition cosmo.cpp:657
double time(double z) const
Return the time from the Big Bang in Gyr at a given redshift z.
Definition cosmo.cpp:1182
double TopHatVariance(double m) const
Mass variance . This uses a fitting formula for the CDM model which might not be perfectly accurate....
Definition cosmo.cpp:1062
double angDist(double zo, double z) const
The angular size distance in units Mpc.
Definition cosmo.cpp:704
double h
Hubble paremters in units of 100 km/s/Mpc.
Definition cosmo.h:312
void setdndlnk(double w)
Running of primordial spectral index, P(k)_primordial \propto pow(k/h,n+dndlnk*log(k)),...
Definition cosmo.h:231
double invRadDist(double d) const
The inverse of the coordinate distance in units Mpc, works within interpolation range.
Definition cosmo.cpp:747
double Omo
Omega matter, dark matter + baryons.
Definition cosmo.h:316
double haloNumberInBufferedCone(double mass, double z1, double z2, double fov, double buffer, int type, double alpha=0.0)
The number of halos in a buffered cone between redshift z1 and z2.
Definition cosmo.cpp:994
double haloMassInBufferedCone(double mass, double z1, double z2, double fov, double buffer, int type, double alpha=0.0)
Total mass contained in halos in a buffered cone between redshift z1 and z2.
Definition cosmo.cpp:1025
double TopHatVarianceR(double R, double z)
Variance within a spherical top-hat filter of size R (Mpc), , at redshift z.
Definition powerCDM.cpp:188
double DRradius2(double zo, double z)
Comoving Dyer-Roeder angular size distance for lambda=0 and pfrac = 1 (all matter in particles)
Definition cosmo.cpp:525
double power_linear(double k, double z)
Linear power spectrum P(k,z)/a^2.
Definition powerCDM.cpp:133
void sethubble(double ht)
accesser functions:
Definition cosmo.h:192
void setOmega_baryon(double Omega_baryon)
Omega baryon, renormalizes P(k) to keep sig8 fixed.
Definition cosmo.h:211
double getZfromDeltaC(double dc)
Return the redshift given .
Definition cosmo.cpp:1124
double powerEHv2(double k)
This is the power spectrum from Eisinstein & Hu with BAO but no neutrinos
Definition powerCDM.cpp:235
double Omb
Omega baryon.
Definition cosmo.h:320
double d_coorDist_dw(double zo, double z) const
derivative of coordinate distance with respect to w. Useful for Fisher matrix calculations
Definition cosmo.cpp:676
double CorrelationFunction(double radius, double redshift, double k_max=100, double k_min=1.0e-3)
Dark matter correlation function.
Definition powerCDM.cpp:246
double totalMassDensityinHalos(int t, double alpha, double m_min, double z, double z1, double z2)
The halo total surface mass density in haloes with mass larger than m_min (solar masses) in the redsh...
Definition cosmo.cpp:915
double n
Primordial spectral index.
Definition cosmo.h:314
double getTimefromDeltaC(double dc)
Return the time from the Big Bang in Gyr given .
Definition cosmo.cpp:1151
double ww1
Dark energy equation of state parameter p/rho = ww + ww_1 (1+z)
Definition cosmo.h:328
double powerCDMz(double k, double z)
powerCDM.c calculates the nonlinear P(k,z)/a(r)^2
Definition powerCDM.cpp:10
double TopHatVarianceM(double M, double z)
Variance within a spherical top-hat filter at mass scale M at redshift z.
Definition powerCDM.cpp:207
double haloNumberDensity(double m, double z, double a, int t, double alpha=0.0)
The cumulative comoving number density of haloes with mass larger than m (in solar masses) at redshif...
Definition cosmo.cpp:874
Class for calculating properties of NFW halo profile.
Definition cosmo.h:451
double NFW_M(double x, double cons, double M200)
Mass within a radius x in Msun.
Definition nfw.cpp:53
void match_nfw(float Vmax, float R_half, float mass, float *cons, float *Rsize)
Returns the concentration and radius of an NFW halo with the mass, half mass radius and Vmax provided...
Definition nfw.cpp:110
double NFW_rho(double cons, double x)
The density of an NFW profile in units of the critical density.
Definition nfw.cpp:101
double NFW_Vr(double x, double cons, double M200, double R200)
Circular velocity in km/s.
Definition nfw.cpp:42
double NFW_Concentration(double Vmax, double M200, double R200)
Concentration of NFW given Vmax in km/s.
Definition nfw.cpp:69
double NFW_Vmax(double cons, double M200, double R200)
Maximum circular velocity in km/s.
Definition nfw.cpp:32
double NFW_V200(double M200, double R200)
Circular velocity at R200 in km/s.
Definition nfw.cpp:25
double NFW_deltac(double cons)
central over-density of nfw halo
Definition nfw.cpp:63