CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Velocities.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2010 by Federico Marulli *
3  * federico.marulli3@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ********************************************************************/
20 
35 #include "Cosmology.h"
36 
37 using namespace std;
38 
39 using namespace cbl;
40 
41 
42 // =====================================================================================
43 
44 
45 double cbl::cosmology::Cosmology::square_bulk_flow (const double rr, const double k_int_min, const string method_Pk, const double redshift, const bool store_output, const string output_root, const double k_min, const double k_max, const double prec, const string file_par)
46 {
47  double bulk = -1.;
48  Pk_0(method_Pk, redshift, store_output, output_root, k_min, k_max, prec, file_par);
49 
50  function<double(double)> ff;
51 
52  if (method_Pk=="EisensteinHu") {
53  if (m_sigma8<0) ErrorCBL("sigma8 must be >0 using EisensteinHu!", "square_bulk_flow", "Velocities.cpp");
54  cbl::classfunc::func_V2 func (m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, method_Pk, rr, redshift, store_output);
55 
56  ff = bind(&cbl::classfunc::func_V2::operator(), func, std::placeholders::_1);
57  }
58 
59  if (method_Pk=="CAMB" || method_Pk=="CLASS") {
60  vector<double> lgkk, lgPk;
61  bool do_nonlinear = 0;
62 
63  Table_PkCodes(method_Pk, do_nonlinear, lgkk, lgPk, redshift, store_output, output_root, k_max, file_par);
64 
65  cbl::classfunc::func_V2_Table func (m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, lgkk, lgPk, rr, redshift);
66 
67  ff = bind(&cbl::classfunc::func_V2_Table::operator(), func, std::placeholders::_1);
68 
69  }
70 
71  double Int1 = wrapper::gsl::GSL_integrate_qag(ff, k_int_min, 1., 1.e-3);
72  double Int2 = wrapper::gsl::GSL_integrate_qag(ff, 1., 1.e30, 1.e-3);
73 
74  bulk = m_Pk0_EH*(Int1+Int2);
75  return pow(HH(redshift)/(1.+redshift),2)/(2.*par::pi*par::pi)*bulk;
76 }
77 
78 
79 // =====================================================================================
80 
81 
82 double cbl::cosmology::Cosmology::square_bulk_flow_Table (const double rr, const double k_int_min, const vector<double> lgkk, const vector<double> lgPk, const double redshift) const
83 {
84  cbl::classfunc::func_V2_Table func (m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, lgkk, lgPk, rr, redshift);
85 
86  function<double(double)> ff = bind(&cbl::classfunc::func_V2_Table::operator(), func, std::placeholders::_1);
87 
88  double Int1 = wrapper::gsl::GSL_integrate_qag(ff, k_int_min, 1., 1.e-3);
89  double Int2 = wrapper::gsl::GSL_integrate_qag(ff, 1., 1.e30, 1.e-3);
90 
91  return pow(HH(redshift)/(1.+redshift),2)/(2.*par::pi*par::pi)*(Int1+Int2);
92 }
93 
94 
95 // =====================================================================================
96 
97 
98 double cbl::cosmology::Cosmology::square_velocity_dispersion (const double rr, const double k_int_min, const string method_Pk, const double redshift, const bool store_output, const string output_root, const double k_min, const double k_max, const double prec, const string file_par)
99 {
100  (void)k_int_min;
101 
102  double sigma2 = -1.;
103  Pk_0(method_Pk, redshift, store_output, output_root, k_min, k_max, prec, file_par);
104  function<double(double)> ff;
105 
106  if (method_Pk=="EisensteinHu") {
107  if (m_sigma8<0) ErrorCBL("sigma8 must be >0 using EisensteinHu!", "square_velocity_dispersion", "Velocities.cpp");
108  cbl::classfunc::func_sigma2 func (m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, method_Pk, rr, redshift, store_output);
109 
110  ff = bind(&cbl::classfunc::func_sigma2::operator(), func, std::placeholders::_1);
111 
112  }
113 
114  if (method_Pk=="CAMB" || method_Pk=="CLASS") {
115  vector<double> lgkk, lgPk;
116  bool do_nonlinear = 0;
117 
118  Table_PkCodes(method_Pk, do_nonlinear, lgkk, lgPk, redshift, store_output, output_root, k_max, file_par);
119 
120  cbl::classfunc::func_sigma2_Table func (m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, lgkk, lgPk, rr, redshift);
121 
122  ff = bind(&cbl::classfunc::func_sigma2_Table::operator(), func, std::placeholders::_1);
123  }
124 
125  return pow(HH(redshift)/(1.+redshift),2)/(2.*par::pi*par::pi)*sigma2;
126 }
127 
128 
129 // =====================================================================================
130 
131 
132 double cbl::cosmology::Cosmology::CMN (const double rr, const double k_int_min, const string method_Pk, const double redshift, const bool store_output, const string output_root, const double k_max, const string file_par) const
133 {
134  double CMN = -1000.;
135 
136  function<double(double)> ff1;
137  function<double(double)> ff2;
138 
139  if (method_Pk=="EisensteinHu") {
140 
141  cbl::classfunc::func_V2 func1 (m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, method_Pk, rr, redshift, store_output);
142  cbl::classfunc::func_sigma2 func2 (m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, method_Pk, rr, redshift, store_output);
143 
144  ff1 = bind(&cbl::classfunc::func_V2::operator(), func1, std::placeholders::_1);
145  ff2 = bind(&cbl::classfunc::func_sigma2::operator(), func2, std::placeholders::_1);
146  }
147 
148  if (method_Pk=="CAMB" || method_Pk=="CLASS") {
149 
150  vector<double> lgkk, lgPk;
151  bool do_nonlinear = 0;
152 
153  Table_PkCodes(method_Pk, do_nonlinear, lgkk, lgPk, redshift, store_output, output_root, k_max, file_par);
154 
155  cbl::classfunc::func_V2_Table func1 (m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, lgkk, lgPk, rr, redshift);
156  cbl::classfunc::func_sigma2_Table func2 (m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, lgkk, lgPk, rr, redshift);
157 
158  ff1 = bind(&cbl::classfunc::func_V2_Table::operator(), func1, std::placeholders::_1);
159  ff2 = bind(&cbl::classfunc::func_sigma2_Table::operator(), func2, std::placeholders::_1);
160 
161  }
162 
163  double i1 = wrapper::gsl::GSL_integrate_qag(ff1, k_int_min, 1.,1.e-3);
164  double i2 = wrapper::gsl::GSL_integrate_qag(ff1, 1., 1.e30,1.e-3);
165  double Int1 = i1+i2;
166 
167  i1 = wrapper::gsl::GSL_integrate_qag(ff2, k_int_min, 1.,1.e-3);
168  i2 = wrapper::gsl::GSL_integrate_qag(ff2, 1., 1.e30,1.e-3);
169  double Int2 = i1+i2;
170 
171  CMN = Int1/Int2;
172  return sqrt(CMN);
173 }
The class Cosmology.
double square_velocity_dispersion(const double rr, const double k_int_min, const std::string method_Pk, const double redshift, const bool store_output=true, const std::string output_root="test", const double k_min=0.001, const double k_max=100., const double prec=1.e-2, const std::string file_par=par::defaultString)
the mean square velocity dispersion
Definition: Velocities.cpp:98
double square_bulk_flow_Table(const double rr, const double k_int_min, const std::vector< double > lgkk, const std::vector< double > lgPk, const double redshift) const
the mean square bulk flow
Definition: Velocities.cpp:82
double square_bulk_flow(const double rr, const double k_int_min, const std::string method_Pk, const double redshift, const bool store_output=true, const std::string output_root="test", const double k_min=0.001, const double k_max=100., const double prec=1.e-2, const std::string file_par=par::defaultString)
the mean square bulk flow
Definition: Velocities.cpp:45
double CMN(const double rr, const double k_int_min, const std::string method_Pk, const double redshift, const bool store_output=true, const std::string output_root="test", const double k_max=100., const std::string file_par=par::defaultString) const
the Cosmic Mach Number
Definition: Velocities.cpp:132
static const double pi
: the ratio of a circle's circumference to its diameter
Definition: Constants.h:199
double GSL_integrate_qag(gsl_function Func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000, const int rule=6)
integral, computed using the GSL qag method
Definition: GSLwrapper.cpp:180
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
Definition: Kernel.h:780