FML
Typedefs | Functions
Wrapper.cpp File Reference

Go to the source code of this file.

Typedefs

using SphericalCollapseModel = FML::COSMOLOGY::SPHERICALCOLLAPSE::SphericalCollapseModel
 
using HaloModel = FML::COSMOLOGY::HALOMODEL::HaloModel
 
using Func1 = FML::COSMOLOGY::HALOMODEL::Func1
 
using Spline = FML::INTERPOLATION::SPLINE::Spline
 
using DVector = FML::SOLVERS::ODESOLVER::DVector
 

Functions

HaloModel ** get ()
 
void get_deltac (HaloModel **hmp, int nz, double *z, int ndeltac, double *deltac)
 
void get_DeltaVir (HaloModel **hmp, int nz, double *z, int nDeltaVir, double *DeltaVir)
 
void free (HaloModel **hm)
 
void get_pofk (HaloModel **hmp, int nk, double *k, int npofk_lin, double *pofk_lin, int npofk, double *pofk)
 
void get_pofk_1h_2h (HaloModel **hmp, int nk, double *k, int npofk_1h, double *pofk_1h, int npofk_2h, double *pofk_2h)
 
void get_nofM (HaloModel **hmp, int nm, double *M, int ndnofm, double *dnofm, int nnofm, double *nofm)
 
void calc (HaloModel **hmp, double z)
 
void info (HaloModel **hmp)
 
void output (HaloModel **hmp, std::string label)
 
void init (HaloModel **hmp, std::string filename_pofk, double OmegaM, double w0, double wa, double mu0, double mua, bool verbose, bool hmcode, bool sigma8norm, double deltac_multiplier, double DeltaVir_multiplier, double cofM_multiplier)
 
void read_and_spline_mu_file (const std::string filename_mu, Spline &mu_of_x_spline)
 

Typedef Documentation

◆ DVector

Definition at line 8 of file Wrapper.cpp.

◆ Func1

Definition at line 6 of file Wrapper.cpp.

◆ HaloModel

Definition at line 5 of file Wrapper.cpp.

◆ SphericalCollapseModel

Definition at line 4 of file Wrapper.cpp.

◆ Spline

Definition at line 7 of file Wrapper.cpp.

Function Documentation

◆ calc()

void calc ( HaloModel **  hmp,
double  z 
)

Definition at line 74 of file Wrapper.cpp.

74 {
75 HaloModel *hm = *hmp;
76 const double zcollapse = std::exp(-hm->xcollapse)-1.0;
77 if(std::fabs(z-zcollapse) < 1e-8)
78 return;
80}
Class for computing the standard halomodel predictions for plus or just doing spherical collapse.
Definition: Halomodel.h:62
void compute_at_redshift(double zcollapse)
Definition: Halomodel.cpp:752
const double exp
Definition: Global.h:259
float z
Definition: example.py:56

◆ free()

void free ( HaloModel **  hm)

Definition at line 34 of file Wrapper.cpp.

34 {
35 delete *hm;
36}

◆ get()

HaloModel ** get ( )

Definition at line 11 of file Wrapper.cpp.

11 {
12 HaloModel **hm = new HaloModel*();
13 *hm = new HaloModel();
14 return hm;
15}
FML::COSMOLOGY::HALOMODEL::HaloModel HaloModel
Definition: Wrapper.cpp:5

◆ get_deltac()

void get_deltac ( HaloModel **  hmp,
int  nz,
double *  z,
int  ndeltac,
double *  deltac 
)

Definition at line 17 of file Wrapper.cpp.

17 {
18 HaloModel *hm = *hmp;
19 for(int i = 0; i < nz; i++){
20 double x = std::log(1.0/(1+z[i]));
21 deltac[i] = hm->hmcode ? hm->get_deltac_hmcode(x) : hm->deltac_of_x_spline(x);
22 }
23}
double get_deltac_hmcode(double x) const
Definition: Halomodel.cpp:1209
deltac
Definition: example.py:67
x
Definition: test.py:18

◆ get_DeltaVir()

void get_DeltaVir ( HaloModel **  hmp,
int  nz,
double *  z,
int  nDeltaVir,
double *  DeltaVir 
)

Definition at line 25 of file Wrapper.cpp.

25 {
26 HaloModel *hm = *hmp;
27 for(int i = 0; i < nz; i++){
28 double x = std::log(1.0/(1+z[i]));
29 DeltaVir[i] = hm->hmcode ? hm->get_DeltaVir_hmcode(x) : hm->DeltaVir_of_x_spline(x);
30 }
31}
double get_DeltaVir_hmcode(double x) const
Definition: Halomodel.cpp:1219

◆ get_nofM()

void get_nofM ( HaloModel **  hmp,
int  nm,
double *  M,
int  ndnofm,
double *  dnofm,
int  nnofm,
double *  nofm 
)

Definition at line 63 of file Wrapper.cpp.

63 {
64 HaloModel *hm = *hmp;
65 if(nm != nnofm or nm != ndnofm)
66 throw std::runtime_error("Arrays M and nofM must be compatible\n");
67 for(int i = 0; i < nm; i++){
68 dnofm[i] = hm->dndlogM_of_logM_spline(std::log(M[i]));
69 nofm[i] = hm->n_of_logM_spline(std::log(M[i]));
70 }
71}

◆ get_pofk()

void get_pofk ( HaloModel **  hmp,
int  nk,
double *  k,
int  npofk_lin,
double *  pofk_lin,
int  npofk,
double *  pofk 
)

Definition at line 39 of file Wrapper.cpp.

39 {
40 HaloModel *hm = *hmp;
41 if(nk != npofk_lin or nk != npofk)
42 throw std::runtime_error("Arrays k and pofk must be compatible\n");
43 for(int i = 0; i < nk; i++){
44 const double factor = (2.0*M_PI*M_PI)/std::pow(k[i],3);
45 const double scaling = std::pow(hm->growthfactor_of_x_spline(hm->xcollapse) / hm->growthfactor_of_x_spline(hm->xinput_pofk), 2);
46 pofk[i] = std::exp(hm->logDeltaHM_full_of_logk_spline(std::log(k[i])))*factor;
47 pofk_lin[i] = scaling * std::exp(hm->logDelta_of_logk_spline(std::log(k[i])))*factor;
48 }
49}
pofk_lin
Definition: example.py:64

◆ get_pofk_1h_2h()

void get_pofk_1h_2h ( HaloModel **  hmp,
int  nk,
double *  k,
int  npofk_1h,
double *  pofk_1h,
int  npofk_2h,
double *  pofk_2h 
)

Definition at line 51 of file Wrapper.cpp.

51 {
52 HaloModel *hm = *hmp;
53 if(nk != npofk_1h or nk != npofk_2h)
54 throw std::runtime_error("Arrays k and pofk must be compatible\n");
55 for(int i = 0; i < nk; i++){
56 const double factor = (2.0*M_PI*M_PI)/std::pow(k[i],3);
57 pofk_1h[i] = std::exp(hm->logDeltaHM_onehalo_of_logk_spline(std::log(k[i])))*factor;
58 pofk_2h[i] = std::exp(hm->logDeltaHM_twohalo_of_logk_spline(std::log(k[i])))*factor;
59 }
60}
pofk_1h
Definition: example.py:65
pofk_2h
Definition: example.py:65

◆ info()

void info ( HaloModel **  hmp)

Definition at line 83 of file Wrapper.cpp.

83 {
84 HaloModel *hm = *hmp;
85 hm->info();
86}

◆ init()

void init ( HaloModel **  hmp,
std::string  filename_pofk,
double  OmegaM,
double  w0,
double  wa,
double  mu0,
double  mua,
bool  verbose,
bool  hmcode,
bool  sigma8norm,
double  deltac_multiplier,
double  DeltaVir_multiplier,
double  cofM_multiplier 
)

Definition at line 97 of file Wrapper.cpp.

110 {
111
112 HaloModel *hm = *hmp;
113 const double OmegaLambda = 1.0-OmegaM;
114 const double xini_spherical_collapse = std::log(1e-5);
115 const double xpofk = 0.0;
116 const int npts_spherical_collapse = 1000;
117
118 // Cosmology functions E = H(x)/H0, x = log(a)
119 const Func1 Eofx = [OmegaM,OmegaLambda,w0,wa](double x) -> double {
120 const double a = std::exp(x);
121 return std::sqrt(
122 OmegaM * std::exp(-3.0*x) +
123 OmegaLambda * std::exp(3.0 * wa * (a - 1) - 3 * (1 + w0 + wa) * x)
124 );
125 };
126 const Func1 logEprimeofx = [OmegaM,OmegaLambda,w0,wa,Eofx](double x) -> double {
127 const double E = Eofx(x);
128 const double a = std::exp(x);
129 return 1.0 / (2.0 * E * E) * (-3.0 * OmegaM / (a * a * a) +
130 OmegaLambda * std::exp(3.0 * wa * (a - 1) - 3 * (1 + w0 + wa) * x) *
131 (3.0 * wa * a - 3.0 * (1 + w0 + wa)));
132 };
133 const Func1 muofx = [mu0,mua,Eofx](double x) -> double {
134 const double E = Eofx(x);
135 const double a = std::exp(x);
136 return 1.0 + (mu0 + mua*(1.0-a)) / (E*E);
137 };
138 const Func1 muofx_lcdm = []([[maybe_unused]] double x) -> double {
139 return 1.0;
140 };
141 const Func1 wofx = [w0,wa]([[maybe_unused]] double x) -> double {
142 const double a = std::exp(x);
143 return w0 + wa*(1-a);
144 };
145 const Func1 OmegaMofx = [OmegaM,Eofx](double x) -> double {
146 const double E = Eofx(x);
147 return OmegaM*std::exp(-3*x)/(E*E);
148 };
149
150 // Set up the model
152 Eofx,
153 OmegaMofx,
154 logEprimeofx,
155 muofx,
156 wofx);
157
158 SphericalCollapseModel lcdmmodel(
159 Eofx,
160 OmegaMofx,
161 logEprimeofx,
162 muofx_lcdm,
163 wofx);
164
165 // We read in P(k,z=zi) in LCDM and then scale it back
166 // and forward again to get the linear P(k,z=zi) of our mu-sims
167 Spline Dofx_spline, fofx_spline;
168 Spline Dlcdmofx_spline, flcdmofx_spline;
170 FML::COSMOLOGY::SPHERICALCOLLAPSE::compute_growthfactor(lcdmmodel, Dlcdmofx_spline, flcdmofx_spline);
171 const double xlinearpofk = 0.0;
172 const double xscaleback = std::log(1.0/50.0);
173 const double pofk_normalization = (sigma8norm ? 1.0 :
174 std::pow(Dlcdmofx_spline(xscaleback) / Dlcdmofx_spline(xlinearpofk), 2) /
175 std::pow(Dofx_spline(xscaleback) / Dofx_spline(xlinearpofk), 2));
176 Spline logDelta_of_logk_spline;
178 filename_pofk,
179 logDelta_of_logk_spline,
180 pofk_normalization);
181
182 // Set cosmology and Plin
183 hm->spcmodel = model;
184 hm->OmegaM = OmegaM;
185 hm->fnu = 0.0;
186 hm->logDelta_of_logk_spline = logDelta_of_logk_spline;
187 hm->xinput_pofk = xpofk;
188 hm->xini_spherical_collapse = xini_spherical_collapse;
189 hm->npts_spherical_collapse = npts_spherical_collapse;
190 hm->hmcode = hmcode;
191 hm->verbose = verbose;
192
193 // Initialize
194 hm->init();
195 hm->deltac_multiplier = deltac_multiplier;
196 hm->DeltaVir_multiplier = DeltaVir_multiplier;
197 hm->cofM_multiplier = cofM_multiplier;
198}
FML::COSMOLOGY::SPHERICALCOLLAPSE::Func1 Func1
Definition: Main.cpp:6
const double OmegaM
Definition: Main.cpp:65
SphericalCollapseModel spcmodel
Definition: Halomodel.h:65
The class contains all the info about the model needed to run the spherical collapse and halomodel Co...
This is a wrapper class for easy use of GSL splines It is (OpenMP) thread safe as long as splines are...
Definition: Spline.h:80
void read_pofk_file(const std::string filename_pofk, Spline &logDelta_of_logk_spline, double normalization, int col_k, int col_pofk)
Definition: Halomodel.cpp:61
void compute_growthfactor(const SphericalCollapseModel &model, Spline &growthfactor_of_x_spline, Spline &growthrate_of_x_spline, const double xini, const double xend, const int npts)
Computes the growth factor (not normalized) and growth rate for a given model and returns splines wit...
float wa
Definition: example.py:11
bool verbose
Definition: example.py:19
bool sigma8norm
Definition: example.py:17
float mua
Definition: example.py:13
float w0
Definition: example.py:10
bool hmcode
Definition: example.py:18
float mu0
Definition: example.py:12

◆ output()

void output ( HaloModel **  hmp,
std::string  label 
)

Definition at line 89 of file Wrapper.cpp.

89 {
90 HaloModel *hm = *hmp;
91 const double z = std::exp(-hm->xcollapse)-1.0;
92 hm->output_pofk("pofk_" + label + "_z" + std::to_string(z) + ".txt");
93 hm->output_nofM("nofM_" + label + "_z" + std::to_string(z) + ".txt");
94 hm->output_deltac("sph_" + label + "_z" + std::to_string(z) + ".txt");
95}
void output_nofM(std::string filename, double Mmin=1e8, double Mmax=1e16, int npts_M=100) const
Definition: Halomodel.cpp:1080
void output_deltac(std::string filename, double zmin=0.0, double zmax=10.0, int npts_z=100) const
Definition: Halomodel.cpp:1038
void output_pofk(std::string filename, double kmin=1e-5, double kmax=100, int npts_k=1000) const
Definition: Halomodel.cpp:1110

◆ read_and_spline_mu_file()

void read_and_spline_mu_file ( const std::string  filename_mu,
Spline mu_of_x_spline 
)

Definition at line 203 of file Wrapper.cpp.

205 {
206
207 const auto mudata = FML::FILEUTILS::read_regular_ascii(filename_mu, 2, {0,1}, 0);
208
209 DVector xmu, mu;
210 bool negativemu = false;
211 for (auto & line : mudata) {
212 xmu.push_back(std::log(line[0]));
213 mu.push_back(line[1]);
214 if(line[1] < 0.0) negativemu = true;
215 }
216
217 if(negativemu){
218 std::cout << "Error: mu is negative, could be a problem\n";
219 exit(1);
220 }
221
222 mu_of_x_spline = Spline(xmu,mu);
223}
FML::INTERPOLATION::SPLINE::DVector DVector
Definition: Simulation.h:39
FML::INTERPOLATION::SPLINE::Spline Spline
Definition: Wrapper.cpp:7
DVector2D read_regular_ascii(std::string filename, int ncols, std::vector< int > cols_to_keep, int nskip, size_t nestimated_lines)
Read a regular ascii files with nskip header lines and containing ncol collums nestimated_lines is th...
Definition: FileUtils.cpp:14