FML
Halomodel.h
Go to the documentation of this file.
1#ifndef HALOMODEL_INCLUDE
2#define HALOMODEL_INCLUDE
3
5#include <FML/Spline/Spline.h>
6#include <FML/Math/Math.h>
10#include <cmath>
11#include <tuple>
12#include <iostream>
13#include <fstream>
14
15namespace FML {
16 namespace COSMOLOGY {
17 namespace HALOMODEL {
18
19 extern int _ACCURACY_BOOST;
20
21 class HaloModel;
22
31 using Func1 = std::function<double(double)>;
32 using Func2 = std::function<double(double,double)>;
35
36 // Typedefs for providing functions used by the halomodel
37 using RhoFunction = std::function<double(double,double,HaloModel *hm)>;
38 using cofMFunction = std::function<double(double,HaloModel *hm)>;
39 using HaloMultiplicityFunction = std::function<double(double,HaloModel *hm)>;
40 using HaloBiasFunction = std::function<double(double,HaloModel *hm)>;
41 using WindowFunction = std::function<double(double)>;
42
43 // Fiducial functions (NFW profile, ST mass-function, ...)
49
50 //===========================================================
51 /// @brief Class for computing the standard halomodel predictions
52 /// for \f$P(k,z)\f$ plus \f$n(M,z)\f$ or just doing spherical collapse.
53 /// Contains the HMCode modifications so one can run both the standard halomodel
54 /// and HMCode by setting a flag.
55 /// The mass-consentration relation, PDF and bias and halo density profile
56 /// can easily be modified if wanted by providing a lambda functions defining these
57 /// functions..
58 ///
59 /// The cosmology/gravity model is specified through the spherical-collapse model.
60 /// This currently only handles scale-independent growth.
61 //===========================================================
62 class HaloModel {
63 public:
66 double OmegaM{};
67 double fnu{};
68
69 //===========================================
70 // The linear power-spectrum
71 // and the time x=log(a) it is given at
72 // (fiducial is z=0)
73 //===========================================
75 double xinput_pofk{};
76
77 //===========================================
78 // Values computed at current redshift
79 // after running compute_at_redshift
80 //===========================================
81 double DeltaVir{};
82 double deltac{};
83 double sigma8{};
84 double sigmav{};
85 double sigmav100{};
86 double xcollapse{std::numeric_limits<double>::quiet_NaN()};
87 double rnl_nu{};
88 double neff{};
89
90 //=====================================================
91 // Halo massfunction modelling
92 // The fiducial option is Sheth-Tormen 1999
93 //=====================================================
94 std::string halo_massfunction = "ShethTormen1999";
97
98 // ST parameters
99 double p_ST = 0.3;
100 double a_ST = 0.707;
101 double A_ST = 0.2162;
102
103 //=====================================================
104 // The density profile of halos
105 // The fiducial option is NFW
106 // with the possibillity of using the HMCode modifications
107 // Halo concentration. The fiducial option is Bullock 2001
108 //=====================================================
109 std::string halo_profile = "NFW";
110 std::string cofM_model = "Bullock2001";
113
114 //===========================================
115 // Range for P(k) calculation
116 //===========================================
117 double kmin_pofk = 1e-5;
118 double kmax_pofk = 100.0;
119 int npts_pofk = 1000;
120
121 //===========================================
122 // Modified halomodel parameters
123 //===========================================
124 bool hmcode{true};
125 bool verbose{true};
126 double hmcode_kstar = 0.01; // 0.0 fiducial but 0.01 to avoid messing up lowk
127 double hmcode_alpha = 1.0; // 1.0 fifucial
128 double hmcode_eta = 0.0; // 0.0 fiducial
129 double hmcode_cmin = 4.0; // 4.0 fiducial
130 double hmcode_f = 0.0; // 0.0 fiducial
131 double cofM_0 = 4.75; // For non-Bullock c(M)
132 double cofM_M0 = 1e14; // For non-Bullock c(M)
133 double cofM_beta = 0.13; // For non-Bullock c(M)
134
135 //===========================================
136 // Spherical collapse (accuracy)
137 //===========================================
138 double xini_spherical_collapse = std::log(1e-5);
140
141 //===========================================
142 // For globally setting accuract parameters instead
143 // of relying on fiducial parameters inside methods
144 // to set arrays
145 //===========================================
146 std::shared_ptr<DVector> fiducial_logR_array{nullptr};
147 std::shared_ptr<DVector> fiducial_logk_array{nullptr};
148
149 //===========================================
150 // Parameters for simply rescaling some
151 // of the halomodel parameters from their
152 // fiducial value
153 //===========================================
155 double cofM_multiplier = 1.0;
156 double deltac_multiplier = 1.0;
157
158 //===========================================
159 // Splines we generate as we run
160 //===========================================
180
181 //===========================================
182 // Constructor
183 //===========================================
184 HaloModel(const HaloModel&) = default;
185 HaloModel & operator=(const HaloModel&) = default;
186 HaloModel() = default;
187 HaloModel(
190 double xinput_pofk = 0.0,
191 bool hmcode = false,
192 bool verbose = false,
193 double xini = std::log(1e-5),
194 int npts = 1000);
195 ~HaloModel() = default;
196
197 //===========================================
198 // Smoothing filter for computation of
199 // sigma(R), sigmav(R), sigmav100(R)
200 //===========================================
202
203 //=====================================================
204 // Initialize a run. Runs in the constructor
205 //=====================================================
206 void init();
207
208 //=====================================================
209 // Compute everything at redshift z
210 //=====================================================
211 void compute_at_redshift(double zcollapse);
212
213 //=====================================================
214 // Output P(k) over whole range computed
215 //=====================================================
216 void output_pofk(
217 std::string filename,
218 double kmin = 1e-5,
219 double kmax = 100,
220 int npts_k = 1000) const;
221
222 //=====================================================
223 // Output deltac(z) and DeltaVir(z)
224 //=====================================================
225 void output_deltac(std::string filename,
226 double zmin = 0.0,
227 double zmax = 10.0,
228 int npts_z = 100) const;
229
230 //=====================================================
231 // Output mass-function
232 //=====================================================
233 void output_nofM(
234 std::string filename,
235 double Mmin = 1e8,
236 double Mmax = 1e16,
237 int npts_M = 100) const;
238
239 //=====================================================
240 // Show some info about what we computed
241 //=====================================================
242 void info() const;
243
244 double get_DeltaVir_hmcode(double x) const;
245 double get_deltac_hmcode(double x) const;
246 double get_eta_hmcode(double x) const;
247 double get_kstar_hmcode(double x) const;
248 double get_f_hmcode(double x) const;
249 double get_cmin_hmcode(double x) const;
250 double get_alpha_hmcode() const;
251 };
252
253 // Take in a file with format [k, P(k)] in (h/Mpc, Mpc^3/h^3) units
254 // Read and make a spline of the dimensionless power-spectrum
255 // normalization is used if we by any chance want to scale P(k)
256 void read_pofk_file(
257 const std::string filename_pofk,
258 Spline & logDelta_of_logk_spline,
259 double normalization = 1.0,
260 int col_k = 0,
261 int col_pofk = 1);
262
263 // Assumes k in (h/Mpc), P(k) in (Mpc/h)^3,
264 // R is in Mpc/h. File has format [k, P(k)]
265 void compute_sigma(
266 const std::function<double(double)> logDelta_of_logk,
267 const WindowFunction window_of_kR,
268 Spline & logsigma_of_logR_spline,
269 const DVector *fiducial_logR_array = nullptr,
270 const DVector *fiducial_logk_array = nullptr);
271
272 // M in Msun/h and R given in Mpc/h
273 double RvirofM(
274 double M,
275 double DeltaVir,
276 double OmegaM,
277 double x);
278
279 // R in Mpc/h to mass in Msun/h
280 double RofM(
281 double M,
282 double OmegaM,
283 double x);
284
285 // M in Msun/h and R given in Mpc/h
286 double MofRvir(
287 double Rvir,
288 double DeltaVir,
289 double OmegaM,
290 double x);
291
292 // M in Msun/h and R given in Mpc/h
293 double MofR(
294 double R,
295 double OmegaM,
296 double x);
297
298 // rho_function is 4pi*rho(r,M)r^3/M as function of (r,M)
300 const std::function<double(double, double)> & rho_function,
301 const DVector & k_array,
302 const double M,
303 const double Rvir);
304
305 // rho_function is 4pi*rho(r,M)r^3/M as function of (r,M)
307 const std::function<double(double, double)> & rho_function,
308 Spline2D & y_of_logR_and_logk_spline,
309 const double DeltaVir,
310 const double OmegaM,
311 const double x,
312 const DVector *fiducial_logR_array = nullptr,
313 const DVector *fiducial_logk_array = nullptr);
314
316 const double deltac,
317 const Spline & logsigma_of_logR_spline,
318 Spline & lognu_of_logR_spline,
319 Spline & logR_of_lognu_spline,
320 const DVector *fiducial_logR_array = nullptr);
321
323 const Spline & logR_of_lognu_spline,
324 const Spline & lognu_of_logR_spline,
325 Spline & dndlogM_of_logM_spline,
326 Spline & n_of_logM_spline,
327 const std::function<double(double)> & pdf_of_nu,
328 const double OmegaM,
329 const double x);
330
332 const Spline & logR_of_lognu_spline,
333 const Spline2D & y_of_logR_and_logk_spline,
334 Spline & logDelta_onehalo_of_logk_spline,
335 Spline & logDelta_twohalo_of_logk_spline,
336 Spline & logDelta_full_of_logk_spline,
337 const std::function<double(double)> & logDeltaLin_of_logk,
338 const std::function<double(double)> & pdf_of_nu,
339 const std::function<double(double)> & bias_of_nu,
340 const double eta_hmcode = 0.0,
341 const double kmin = 1e-5,
342 const double kmax = 100.0,
343 const int npts_k = 100);
344
345 // Computes zf in factor = (1+zf(M))/(1+zcollapse) used in Bullock 2001 c(M) = A*factor
347 const Spline & growthfactor_of_x_spline,
348 const Spline & logsigma_of_logR_spline,
349 Spline & formationredshift_of_logM_spline,
350 double deltac,
351 double OmegaM,
352 double xcollapse,
353 double massfraction = 0.01);
354
355 // Compute sigmav
356 double compute_sigmav(
357 const std::function<double(double)> logDelta_of_logk,
358 const WindowFunction window_of_kR,
359 double R = 0.0,
360 const DVector *fiducial_logk_array = nullptr);
361
362 // Return (R,neff) where nu(R)=1 and neff=-3-dsigma^2/dlogR
363 std::pair<double,double> compute_neff(
364 const Spline & logsigma_of_logR_spline,
365 const Spline & lognu_of_logR_spline);
366
367 }
368 }
369}
370
371#endif
const std::string filename
Definition: Main.cpp:63
const double OmegaM
Definition: Main.cpp:65
FML::COSMOLOGY::SPHERICALCOLLAPSE::SphericalCollapse SphericalCollapse
Definition: Main.cpp:5
Class for computing the standard halomodel predictions for plus or just doing spherical collapse.
Definition: Halomodel.h:62
HaloBiasFunction halo_bias_function
Definition: Halomodel.h:96
void output_nofM(std::string filename, double Mmin=1e8, double Mmax=1e16, int npts_M=100) const
Definition: Halomodel.cpp:1080
double get_f_hmcode(double x) const
Definition: Halomodel.cpp:1232
cofMFunction halo_mass_concentration_relation
Definition: Halomodel.h:112
void compute_at_redshift(double zcollapse)
Definition: Halomodel.cpp:752
double get_DeltaVir_hmcode(double x) const
Definition: Halomodel.cpp:1219
std::shared_ptr< DVector > fiducial_logR_array
Definition: Halomodel.h:146
HaloModel & operator=(const HaloModel &)=default
HaloModel(const HaloModel &)=default
double get_cmin_hmcode(double x) const
Definition: Halomodel.cpp:1246
HaloMultiplicityFunction halo_multiplicity_function
Definition: Halomodel.h:95
void output_deltac(std::string filename, double zmin=0.0, double zmax=10.0, int npts_z=100) const
Definition: Halomodel.cpp:1038
double get_deltac_hmcode(double x) const
Definition: Halomodel.cpp:1209
std::shared_ptr< DVector > fiducial_logk_array
Definition: Halomodel.h:147
void output_pofk(std::string filename, double kmin=1e-5, double kmax=100, int npts_k=1000) const
Definition: Halomodel.cpp:1110
SphericalCollapseModel spcmodel
Definition: Halomodel.h:65
double get_kstar_hmcode(double x) const
Definition: Halomodel.cpp:1239
double get_eta_hmcode(double x) const
Definition: Halomodel.cpp:1225
Class for doing general spherical collapse calculations, i.e.
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
This is a wrapper around the GSL library to easily solve ODEs and return the data in whatever format ...
Definition: ODESolver.h:87
Class for performing timings of the code using std::chrono.
Definition: Timings.h:22
std::function< double(double)> WindowFunction
Definition: Halomodel.h:41
double RofM(double M, double OmegaM, double x)
Definition: Halomodel.cpp:216
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)
Definition: Halomodel.cpp:376
std::function< double(double, HaloModel *hm)> HaloMultiplicityFunction
Definition: Halomodel.h:39
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)
Definition: Halomodel.cpp:149
FML::SOLVERS::ODESOLVER::ODESolver ODESolver
Definition: Halomodel.h:28
double compute_sigmav(const Func1 logDelta_of_logk, const WindowFunction window_of_kR, double R, const DVector *fiducial_logk_array)
Definition: Halomodel.cpp:121
FML::SOLVERS::ODESOLVER::DVector DVector
Definition: Halomodel.h:24
FML::SOLVERS::ODESOLVER::ODEFunctionJacobian ODEFunctionJacobian
Definition: Halomodel.h:27
std::function< double(double, HaloModel *hm)> HaloBiasFunction
Definition: Halomodel.h:40
std::pair< double, double > compute_neff(const Spline &logsigma_of_logR_spline, const Spline &lognu_of_logR_spline)
Definition: Halomodel.cpp:101
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)
Definition: Halomodel.cpp:458
cofMFunction get_nfw_halo_mass_concentration_relation()
Definition: Halomodel.cpp:1001
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)
Definition: Halomodel.cpp:580
DVector compute_rho_fourier_single(const Func2 &rho_function, const DVector &k_array, const double M, const double Rvir)
Definition: Halomodel.cpp:257
HaloBiasFunction get_sheth_tormen_halo_bias_function()
Definition: Halomodel.cpp:665
FML::SOLVERS::ODESOLVER::ODEFunction ODEFunction
Definition: Halomodel.h:26
std::function< double(double, double, HaloModel *hm)> RhoFunction
Definition: Halomodel.h:37
double MofRvir(double Rvir, double DeltaVir, double OmegaM, double x)
Definition: Halomodel.cpp:230
WindowFunction get_tophat_window_fourier()
Definition: Halomodel.cpp:677
double RvirofM(double M, double DeltaVir, double OmegaM, double x)
Definition: Halomodel.cpp:205
FML::COSMOLOGY::SPHERICALCOLLAPSE::SphericalCollapseModel SphericalCollapseModel
Definition: Halomodel.h:34
RhoFunction get_nfw_halo_density_profile()
Definition: Halomodel.cpp:1017
std::function< double(double, HaloModel *hm)> cofMFunction
Definition: Halomodel.h:38
HaloMultiplicityFunction get_sheth_tormen_halo_multiplicity_function()
Definition: Halomodel.cpp:657
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)
Definition: Halomodel.cpp:325
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)
Definition: Halomodel.cpp:408
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
FML::SOLVERS::ODESOLVER::DVector2D DVector2D
Definition: Halomodel.h:25
std::function< double(double, double)> Func2
Definition: Halomodel.h:32
double MofR(double R, double OmegaM, double x)
Definition: Halomodel.cpp:241
std::function< double(double)> Func1
Definition: Halomodel.h:31
FML::UTILS::Timings Timings
Definition: FoF.h:33
GSLSpline2D Spline2D
Definition: Spline.h:28
std::function< int(double, const double *, double *)> ODEFunction
Definition: ODESolver.h:33
std::vector< DVector > DVector2D
Definition: ODESolver.h:30
std::vector< double > DVector
Definition: ODESolver.h:29
std::function< int(double, const double *, double *, double *)> ODEFunctionJacobian
Definition: ODESolver.h:34
Definition: CAMBReader.h:10
deltac
Definition: example.py:67
x
Definition: test.py:18