CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
CAMB.cpp
Go to the documentation of this file.
1 /*******************************************************************
2  * Copyright (C) 2022 by Federico Marulli and Giorgio Lesci *
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 
34 #include "CAMB.h"
35 
36 using namespace std;
37 
38 
39 // ============================================================================
40 
41 
42 std::vector<double> cbl::wrapper::camb::Pk_CAMB (const bool nonlinear, const double redshift, const double kmin, const double kmax, const int npoints, const double ombh2, const double omch2, const double omnuh2, const double massless_nu, const int massive_nu, const double omk, const double H0, const double ns, const double As, const double pivot_scalar, const double w, const double wa, const double tau, const bool accurate_massive_nu, const int neutrino_hierarchy, const int dark_energy_model, const double cs2_lam, const double T_cmb, const double helium_fraction)
43 {
44 
45  if (kmin < 5.e-5)
46  ErrorCBL("the minimum k must be > 5.e-5.", "Pk_CAMB", "CAMB.cpp");
47 
48  void* params = GetCAMBparams();
49  void* data = GetCAMBdata();
50 
51  // Set the cosmological parameters
52  SetCAMBparams(params, ombh2, omch2, omnuh2, massless_nu, massive_nu, neutrino_hierarchy, omk, H0, dark_energy_model, w, wa, tau, cs2_lam, T_cmb, helium_fraction);
53  SetCAMBPk(params, redshift, ns, As, pivot_scalar, accurate_massive_nu, kmax, nonlinear);
54 
55  // Get CAMB's P(k)
56  GetCAMBresults(params, data);
57 
58  std::vector<double> Pk (npoints, 0.);
59  const double h = (H0/100.);
60  const double minkh = kmin/h;
61  const double dlnkh = (log(kmax/h)-log(minkh)) / (npoints-1);
62 
63  GetCAMBPk(data, Pk.data(), minkh, dlnkh, npoints);
64 
65  // De-allocate
66  ReleaseCAMBparams(params);
67  ReleaseCAMBdata(data);
68 
69  return Pk;
70 
71 }
72 
class CAMB that wrap CAMB routines
std::vector< double > Pk_CAMB(const bool nonlinear, const double redshift, const double kmin, const double kmax, const int npoints, const double ombh2, const double omch2, const double omnuh2, const double massless_nu, const int massive_nu, const double omk, const double H0, const double ns, const double As, const double pivot_scalar=0.05, const double w=-1., const double wa=0., const double tau=2.1e-9, const bool accurate_massive_nu=false, const int neutrino_hierarchy=3, const int dark_energy_model=1, const double cs2_lam=1., const double T_cmb=2.7255, const double helium_fraction=0.24)
Get the matter power spectrum from CAMB.
Definition: CAMB.cpp:42
void * ReleaseCAMBdata(void *data)
wrapper of the subroutine ReleaseCAMBdata in CAMB/CAMBinterface.f90, deallocating CAMBdata instance
void * ReleaseCAMBparams(void *params)
wrapper of the subroutine ReleaseCAMBparams in CAMB/CAMBinterface.f90, deallocating CAMBparams instan...
void GetCAMBPk(void *data, double *Pk, const double mink, const double dlnkh, const int npoints)
wrapper of the subroutine GetCAMBPk in CAMB/CAMBinterface.f90, calling the subroutine Transfer_GetMat...
void SetCAMBparams(void *params, const double ombh2, const double omch2, const double omnuh2, const double massless_nu, const int massive_nu, const int neutrino_hierarchy, const double omk, const double H0, const int dark_energy_model, const double w, const double wa, const double tau, const double cs2_lam, const double T_cmb, const double helium_fraction)
wrapper of the subroutine SetCAMBparams in CAMB/CAMBinterface.f90, setting CAMBparams parameters
void GetCAMBresults(void *params, void *data)
wrapper of the subroutine GetCAMBresults in CAMB/CAMBinterface.f90, calling the subroutine CAMB_GetRe...
void * GetCAMBparams()
wrapper of the function GetCAMBparams in CAMB/CAMBinterface.f90, creating an instance of the CAMBpara...
void SetCAMBPk(void *params, const double redshift, const double ns, const double As, const double pivot_scalar, const bool accurate_massive_nu, const double kmax, const bool nonlinear)
wrapper of the subroutine SetCAMBPk in CAMB/CAMBinterface.f90, setting the power spectrum parameters
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