Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_sample_run.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ccl.h>
#include <ccl_redshifts.h>
Include dependency graph for ccl_sample_run.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  user_func_params
 
struct  user_dN_params
 

Macros

#define OC   0.25
 
#define OB   0.05
 
#define OK   0.00
 
#define ON   0.00
 
#define HH   0.70
 
#define W0   -1.0
 
#define WA   0.00
 
#define NS   0.96
 
#define NORMPS   0.80
 
#define ZD   0.5
 
#define NZ   128
 
#define Z0_GC   0.50
 
#define SZ_GC   0.05
 
#define Z0_SH   0.65
 
#define SZ_SH   0.05
 
#define NL   513
 
#define PS   0.1
 
#define NEFF   3.046
 

Functions

double sigmaz_sources (double z)
 
double user_pz_probability (double z_ph, double z_s, void *user_par, int *status)
 
double user_dNdz (double z, void *user_par, int *status)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

#define HH   0.70

Definition at line 12 of file ccl_sample_run.c.

Referenced by main().

#define NEFF   3.046

Definition at line 25 of file ccl_sample_run.c.

Referenced by main().

#define NL   513

Definition at line 23 of file ccl_sample_run.c.

Referenced by main().

#define NORMPS   0.80

Definition at line 16 of file ccl_sample_run.c.

Referenced by main().

#define NS   0.96

Definition at line 15 of file ccl_sample_run.c.

Referenced by main().

#define NZ   128

Definition at line 18 of file ccl_sample_run.c.

Referenced by main().

#define OB   0.05

Definition at line 9 of file ccl_sample_run.c.

Referenced by main().

#define OC   0.25

Definition at line 8 of file ccl_sample_run.c.

Referenced by main().

#define OK   0.00

Definition at line 10 of file ccl_sample_run.c.

Referenced by main().

#define ON   0.00

Definition at line 11 of file ccl_sample_run.c.

#define PS   0.1

Definition at line 24 of file ccl_sample_run.c.

#define SZ_GC   0.05

Definition at line 20 of file ccl_sample_run.c.

Referenced by main().

#define SZ_SH   0.05

Definition at line 22 of file ccl_sample_run.c.

Referenced by main().

#define W0   -1.0

Definition at line 13 of file ccl_sample_run.c.

Referenced by main().

#define WA   0.00

Definition at line 14 of file ccl_sample_run.c.

Referenced by main().

#define Z0_GC   0.50

Definition at line 19 of file ccl_sample_run.c.

Referenced by main().

#define Z0_SH   0.65

Definition at line 21 of file ccl_sample_run.c.

Referenced by main().

#define ZD   0.5

Definition at line 17 of file ccl_sample_run.c.

Referenced by main().

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 65 of file ccl_sample_run.c.

References user_dN_params::alpha, beta, user_dN_params::beta, ccl_angular_cls(), ccl_boltzmann_class, ccl_cl_tracer_cmblens(), ccl_cl_tracer_free(), ccl_cl_tracer_lensing_simple(), ccl_cl_tracer_number_counts_simple(), ccl_comoving_radial_distance(), ccl_cosmology_create(), ccl_cosmology_free(), ccl_create_dNdz_info(), ccl_create_gaussian_photoz_info(), ccl_create_photoz_info(), ccl_create_Smail_dNdz_info(), ccl_distance_modulus(), ccl_dNdz_tomog(), ccl_free_dNdz_info(), ccl_free_photoz_info(), ccl_get_tracer_fas(), ccl_growth_factor(), ccl_growth_rate(), ccl_halo_bias(), ccl_luminosity_distance(), ccl_massfunc(), ccl_mnu_sum, ccl_omega_x(), ccl_parameters_create(), ccl_rho_x(), ccl_scale_factor_of_chi(), ccl_sigma8(), ccl_species_crit_label, ccl_species_g_label, ccl_species_l_label, ccl_species_m_label, CCL_ClTracer::chimax, CCL_ClTracer::chimin, cl_cmbl_bm::cosmo, default_config, HH, cl_cmbl_bm::l, MNU, NEFF, NL, NORMPS, NS, NZ, OB, OC, OK, halomod_bm::params, pow(), RHO_CRITICAL, user_func_params::sigma_z, sigmaz_sources(), sqrt(), SZ_GC, SZ_SH, ccl_configuration::transfer_function_method, user_dNdz(), user_pz_probability(), w, W0, WA, z, user_dN_params::z0, Z0_GC, Z0_SH, and ZD.

66 {
67  //status flag
68  int status =0;
69 
70  // Set neutrino masses
71  double* MNU;
72  double mnuval = 0.;
73  MNU = &mnuval;
75 
76  //whether comoving or physical
77  int isco=0;
78 
79  // Initialize cosmological parameters
82  ccl_parameters params = ccl_parameters_create(OC, OB, OK, NEFF, MNU, MNUTYPE, W0, WA, HH, NORMPS, NS,-1,-1,-1,-1,NULL,NULL, &status);
83  //printf("in sample run w0=%1.12f, wa=%1.12f\n", W0, WA);
84 
85  // Initialize cosmology object given cosmo params
87 
88  // Compute radial distances (see include/ccl_background.h for more routines)
89  printf("Comoving distance to z = %.3lf is chi = %.3lf Mpc\n",
90  ZD,ccl_comoving_radial_distance(cosmo,1./(1+ZD), &status));
91  printf("Luminosity distance to z = %.3lf is chi = %.3lf Mpc\n",
92  ZD,ccl_luminosity_distance(cosmo,1./(1+ZD), &status));
93  printf("Distance modulus to z = %.3lf is mu = %.3lf Mpc\n",
94  ZD,ccl_distance_modulus(cosmo,1./(1+ZD), &status));
95 
96 
97  //Consistency check
98  printf("Scale factor is a=%.3lf \n",1./(1+ZD));
99  printf("Consistency: Scale factor at chi=%.3lf Mpc is a=%.3lf\n",
100  ccl_comoving_radial_distance(cosmo,1./(1+ZD), &status),
101  ccl_scale_factor_of_chi(cosmo,ccl_comoving_radial_distance(cosmo,1./(1+ZD), &status), &status));
102 
103  // Compute growth factor and growth rate (see include/ccl_background.h for more routines)
104  printf("Growth factor and growth rate at z = %.3lf are D = %.3lf and f = %.3lf\n",
105  ZD, ccl_growth_factor(cosmo,1./(1+ZD), &status),ccl_growth_rate(cosmo,1./(1+ZD), &status));
106 
107  // Compute Omega_m, Omega_L, Omega_r, rho_crit, rho_m at different times
108  printf("z\tOmega_m\tOmega_L\tOmega_r\trho_crit\trho_m\tRHO_CRITICAL\n");
109  double Om, OL, Or, rhoc, rhom;
110  for (int z=10000;z!=0;z/=3){
111  Om = ccl_omega_x(cosmo, 1./(z+1), ccl_species_m_label, &status);
112  OL = ccl_omega_x(cosmo, 1./(z+1), ccl_species_l_label, &status);
113  Or = ccl_omega_x(cosmo, 1./(z+1), ccl_species_g_label, &status);
114  rhoc = ccl_rho_x(cosmo, 1./(z+1), ccl_species_crit_label, isco, &status);
115  rhom = ccl_rho_x(cosmo, 1./(z+1), ccl_species_m_label, isco, &status);
116  printf("%i\t%.3f\t%.3f\t%.3f\t%.3e\t%.3e\t%.3e\n", z, Om, OL, Or, rhoc, rhom, RHO_CRITICAL);
117  }
118  Om = ccl_omega_x(cosmo, 1., ccl_species_m_label, &status);
119  OL = ccl_omega_x(cosmo, 1., ccl_species_l_label, &status);
120  Or = ccl_omega_x(cosmo, 1., ccl_species_g_label, &status);
121  rhoc = ccl_rho_x(cosmo, 1., ccl_species_crit_label, isco, &status);
122  rhom = ccl_rho_x(cosmo, 1., ccl_species_m_label, isco, &status);
123  printf("%i\t%.3f\t%.3f\t%.3f\t%.3e\t%.3e\t%.3e\n", 0, Om, OL, Or, rhoc, rhom, RHO_CRITICAL);
124 
125  // Compute sigma8
126  printf("Initializing power spectrum...\n");
127  printf("sigma8 = %.3lf\n\n", ccl_sigma8(cosmo, &status));
128 
129  //Create tracers for angular power spectra
130  double z_arr_gc[NZ],z_arr_sh[NZ],nz_arr_gc[NZ],nz_arr_sh[NZ],bz_arr[NZ];
131  for(int i=0;i<NZ;i++) {
132  z_arr_gc[i]=Z0_GC-5*SZ_GC+10*SZ_GC*(i+0.5)/NZ;
133  nz_arr_gc[i]=exp(-0.5*pow((z_arr_gc[i]-Z0_GC)/SZ_GC,2));
134  bz_arr[i]=1+z_arr_gc[i];
135  z_arr_sh[i]=Z0_SH-5*SZ_SH+10*SZ_SH*(i+0.5)/NZ;
136  nz_arr_sh[i]=exp(-0.5*pow((z_arr_sh[i]-Z0_SH)/SZ_SH,2));
137  }
138  double *a_arr_resample=(double *)malloc(2*NZ*sizeof(double));
139  double *nz_resampled=(double *)malloc(2*NZ*sizeof(double));
140  for(int i=0;i<2*NZ;i++) {
141  double z=(i+0.5)/NZ;
142  a_arr_resample[i]=1./(1+z);
143  }
144 
145  //CMB lensing tracer
146  CCL_ClTracer *ct_cl=ccl_cl_tracer_cmblens(cosmo,1100.,&status);
147 
148  //Galaxy clustering tracer
149  CCL_ClTracer *ct_gc=ccl_cl_tracer_number_counts_simple(cosmo,NZ,z_arr_gc,nz_arr_gc,NZ,z_arr_gc,bz_arr, &status);
150 
151  //Cosmic shear tracer
152  CCL_ClTracer *ct_wl=ccl_cl_tracer_lensing_simple(cosmo,NZ,z_arr_sh,nz_arr_sh, &status);
153  printf("ell C_ell(c,c) C_ell(c,g) C_ell(c,s) C_ell(g,g) C_ell(g,s) C_ell(s,s) | r(g,s)\n");
154 
155  //This function allows you to retrieve some of the tracer's internal functions of redshift
156  ccl_get_tracer_fas(cosmo,ct_gc,2*NZ,a_arr_resample,nz_resampled,CCL_CLT_NZ,&status);
157 
158  int ells[NL];
159  double cells_cc_limber[NL];
160  double cells_cg_limber[NL];
161  double cells_cl_limber[NL];
162  double cells_ll_limber[NL];
163  double cells_gl_limber[NL];
164  double cells_gg_limber[NL];
165  for(int ii=0;ii<NL;ii++)
166  ells[ii]=ii;
167 
168  double linstep = 40;
169  double logstep = 1.15;
170  double dchi = (ct_gc->chimax-ct_gc->chimin)/1000.; // must be below 3 to converge toward limber computation at high ell
171  double dlk = 0.003;
172  double zmin = 0.05;
173  CCL_ClWorkspace *w=ccl_cl_workspace_default(NL+1,-1,CCL_NONLIMBER_METHOD_NATIVE,logstep,linstep,dchi,dlk,zmin,&status);
174  ccl_angular_cls(cosmo,w,ct_cl,ct_cl,NL,ells,cells_cc_limber,&status);
175  ccl_angular_cls(cosmo,w,ct_cl,ct_gc,NL,ells,cells_cg_limber,&status);
176  ccl_angular_cls(cosmo,w,ct_cl,ct_wl,NL,ells,cells_cl_limber,&status);
177  ccl_angular_cls(cosmo,w,ct_gc,ct_gc,NL,ells,cells_gg_limber,&status);
178  ccl_angular_cls(cosmo,w,ct_gc,ct_wl,NL,ells,cells_gl_limber,&status);
179  ccl_angular_cls(cosmo,w,ct_wl,ct_wl,NL,ells,cells_ll_limber,&status);
180 
181 
182  for(int l=2;l<=NL;l*=2)
183  printf("%d %.3lE %.3lE %.3lE %.3lE %.3lE %.3lE | %.3lE\n",l,cells_cc_limber[l],cells_cg_limber[l],cells_cl_limber[l],cells_gg_limber[l],cells_gl_limber[l],cells_ll_limber[l],cells_gl_limber[l]/sqrt(cells_gg_limber[l]*cells_ll_limber[l]));
184  printf("\n");
185 
186  //Free up tracers
187  ccl_cl_tracer_free(ct_cl);
188  ccl_cl_tracer_free(ct_gc);
189  ccl_cl_tracer_free(ct_wl);
190 
191  // Free arrays
192  free(a_arr_resample);
193  free(nz_resampled);
194 
195  //Halo mass function
196  printf("M\tdN/dlog10M(z = 0, 0.5, 1))\n");
197  for(int logM=9;logM<=15;logM+=1) {
198  printf("%.1e\t",pow(10,logM));
199  for(double z=0; z<=1; z+=0.5) {
200  printf("%e\t", ccl_massfunc(cosmo, pow(10,logM),1.0/(1.0+z), 200., &status));
201  }
202  printf("\n");
203  }
204  printf("\n");
205 
206  //Halo bias
207  printf("Halo bias: z, M, b1(M,z)\n");
208  for(int logM=9;logM<=15;logM+=1) {
209  for(double z=0; z<=1; z+=0.5) {
210  printf("%.1e %.1e %.2e\n",1.0/(1.0+z),pow(10,logM),ccl_halo_bias(cosmo,pow(10,logM),1.0/(1.0+z), 200., &status));
211  }
212  }
213  printf("\n");
214 
215  // If you don't have an external N(z) you are loading, CCL also has functionality
216  // to produce this for you from an analytic form.
217 
218  // The user declares and sets an instance of parameters to their photo_z and dNdz function:
219  struct user_func_params my_params_example;
220  my_params_example.sigma_z = sigmaz_sources;
221  struct user_dN_params my_dN_params_example;
222  my_dN_params_example.alpha = 1.24;
223  my_dN_params_example.beta = 1.01;
224  my_dN_params_example.z0 = 0.51;
225 
226  // Declare a variable of the type of to hold the struct to be created.
227  pz_info * pz_info_example;
228 
229  // Create the struct to hold the user information about photo_z's.
230  pz_info_example = ccl_create_photoz_info(&my_params_example, &user_pz_probability);
231 
232  // Alternatively, we could have used the built-in Gaussian photo-z pdf,
233  // which assumes sigma_z = sigma_z0 * (1 + z) (not used in what follows).
234  double sigma_z0 = 0.05;
235  pz_info *pz_info_gaussian;
236  pz_info_gaussian = ccl_create_gaussian_photoz_info(sigma_z0);
237 
238  // Declare a variable of the type of dN_info to hold the struct to be created
239  dNdz_info * dN_info_example;
240 
241  // Create a simple analytic true redshift distribution:
242  dN_info_example = ccl_create_dNdz_info(&my_dN_params_example, &user_dNdz);
243 
244  // Alternatively, we could have used the built-in Smail-type dNdz
245  // (not used in what follows
246  dNdz_info *dN_info_gaussian;
247  double alpha = 1.24;
248  double beta = 1.01;
249  double z0 = 0.51;
250  dN_info_gaussian = ccl_create_Smail_dNdz_info(alpha, beta, z0);
251 
252  double z_test;
253  double dNdz_tomo;
254  int z;
255  FILE * output;
256 
257  //Try splitting dNdz (lensing) into 5 redshift bins
258  double tmp1,tmp2,tmp3,tmp4,tmp5;
259  printf("Trying splitting dNdz (lensing) into 5 redshift bins. "
260  "Output written into file tests/example_tomographic_bins.out\n");
261  output = fopen("./tests/example_tomographic_bins.out", "w");
262 
263  if(!output) {
264  fprintf(stderr, "Could not write to 'tests' subdirectory"
265  " - please run this program from the main CCL directory\n");
266  exit(1);
267  }
268  status = 0;
269  for (z=0; z<100; z=z+1) {
270  z_test = 0.035*z;
271  ccl_dNdz_tomog(z_test, 0.,6., pz_info_example, dN_info_example, &dNdz_tomo,&status);
272  ccl_dNdz_tomog(z_test, 0.,0.6, pz_info_example,dN_info_example, &tmp1,&status);
273  ccl_dNdz_tomog(z_test, 0.6,1.2, pz_info_example,dN_info_example, &tmp2,&status);
274  ccl_dNdz_tomog(z_test, 1.2,1.8, pz_info_example,dN_info_example, &tmp3,&status);
275  ccl_dNdz_tomog(z_test, 1.8,2.4, pz_info_example,dN_info_example, &tmp4,&status);
276  ccl_dNdz_tomog(z_test, 2.4,3.0, pz_info_example,dN_info_example, &tmp5,&status);
277  fprintf(output, "%f %f %f %f %f %f %f\n", z_test,tmp1,tmp2,tmp3,tmp4,tmp5,dNdz_tomo);
278  }
279 
280  fclose(output);
281 
282  //Free up photo-z info
283  ccl_free_photoz_info(pz_info_example);
284  ccl_free_photoz_info(pz_info_gaussian);
285 
286  // Free the dNdz information
287  ccl_free_dNdz_info(dN_info_example);
288  ccl_free_dNdz_info(dN_info_gaussian);
289 
290  //Always clean up!!
291  ccl_cosmology_free(cosmo);
292 
293  return 0;
294 }
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
#define OK
#define OB
Definition: ccl_sample_run.c:9
double user_dNdz(double z, void *user_par, int *status)
double ccl_omega_x(ccl_cosmology *cosmo, double a, ccl_species_x_label label, int *status)
#define Z0_SH
double ccl_growth_factor(ccl_cosmology *cosmo, double a, int *status)
double ccl_massfunc(ccl_cosmology *cosmo, double smooth_mass, double a, double odelta, int *status)
Definition: ccl_massfunc.c:562
#define NORMPS
double ccl_luminosity_distance(ccl_cosmology *cosmo, double a, int *status)
double ccl_growth_rate(ccl_cosmology *cosmo, double a, int *status)
void ccl_cl_tracer_free(CCL_ClTracer *clt)
Definition: ccl_cls.c:592
#define WA
#define NEFF
dNdz_info * ccl_create_dNdz_info(void *params, double(*dNdz_func)(double, void *, int *))
Definition: ccl_redshifts.c:94
int ccl_get_tracer_fas(ccl_cosmology *cosmo, CCL_ClTracer *clt, int na, double *a, double *fa, int func_code, int *status)
Definition: ccl_cls.c:1091
transfer_function_t transfer_function_method
Definition: ccl_config.h:111
void ccl_angular_cls(ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt1, CCL_ClTracer *clt2, int nl_out, int *l, double *cl, int *status)
Definition: ccl_cls.c:943
#define HH
dNdz_info * ccl_create_Smail_dNdz_info(double alpha, double beta, double z0)
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
Definition: grid.h:231
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
static double beta[2][28][8]
Definition: ccl_emu17.c:32
#define W0
pz_info * ccl_create_gaussian_photoz_info(double sigma_z0)
Definition: ccl_redshifts.c:67
ccl_mnu_convention
Definition: ccl_core.h:142
CCL_ClTracer * ccl_cl_tracer_number_counts_simple(ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int nz_b, double *z_b, double *b, int *status)
Definition: ccl_cls.c:633
void ccl_cosmology_free(ccl_cosmology *cosmo)
Definition: ccl_core.c:829
#define ZD
dictionary params
Definition: halomod_bm.py:27
double user_pz_probability(double z_ph, double z_s, void *user_par, int *status)
double ccl_rho_x(ccl_cosmology *cosmo, double a, ccl_species_x_label label, int is_comoving, int *status)
static double z[8]
double ccl_halo_bias(ccl_cosmology *cosmo, double smooth_mass, double a, double odelta, int *status)
Definition: ccl_massfunc.c:582
double sigmaz_sources(double z)
double(* sigma_z)(double)
double ccl_sigma8(ccl_cosmology *cosmo, int *status)
Definition: ccl_power.c:1777
const ccl_configuration default_config
Definition: ccl_core.c:21
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
CCL_ClTracer * ccl_cl_tracer_cmblens(ccl_cosmology *cosmo, double z_source, int *status)
Definition: ccl_cls.c:614
pz_info * ccl_create_photoz_info(void *params, double(*pz_func)(double, double, void *, int *))
Definition: ccl_redshifts.c:21
#define SZ_SH
#define NZ
#define NS
void ccl_free_photoz_info(pz_info *my_photoz_info)
Definition: ccl_redshifts.c:84
double chimax
Definition: ccl_cls.h:34
double chimin
Definition: ccl_cls.h:35
#define RHO_CRITICAL
Definition: ccl_constants.h:61
#define OC
Definition: ccl_sample_run.c:8
#define SZ_GC
void ccl_dNdz_tomog(double z, double bin_zmin, double bin_zmax, pz_info *photo_info, dNdz_info *dN_info, double *tomoout, int *status)
double ccl_distance_modulus(ccl_cosmology *cosmo, double a, int *status)
ccl_parameters ccl_parameters_create(double Omega_c, double Omega_b, double Omega_k, double Neff, double *mnu, ccl_mnu_convention mnu_type, double w0, double wa, double h, double norm_pk, double n_s, double bcm_log10Mc, double bcm_etab, double bcm_ks, int nz_mgrowth, double *zarr_mgrowth, double *dfarr_mgrowth, int *status)
Definition: ccl_core.c:294
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
static double w[2][28][111]
Definition: ccl_emu17.c:33
#define MNU
#define Z0_GC
#define NL
void ccl_free_dNdz_info(dNdz_info *dN_info)
CCL_ClTracer * ccl_cl_tracer_lensing_simple(ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int *status)
Definition: ccl_cls.c:653
double sigmaz_sources ( double  z)

Definition at line 36 of file ccl_sample_run.c.

References z.

Referenced by main().

37 {
38  return 0.05*(1.0+z);
39 }
static double z[8]
double user_dNdz ( double  z,
void *  user_par,
int *  status 
)

Definition at line 57 of file ccl_sample_run.c.

References user_dN_params::alpha, user_dN_params::beta, p, pow(), and user_dN_params::z0.

Referenced by main().

58 {
59  struct user_dN_params * p = (struct user_dN_params *) user_par;
60 
61  return pow(z, p->alpha) * exp(- pow(z/(p->z0), p->beta) );
62 
63 }
static double z[8]
static int p
Definition: ccl_emu17.c:25
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
double user_pz_probability ( double  z_ph,
double  z_s,
void *  user_par,
int *  status 
)

Definition at line 42 of file ccl_sample_run.c.

References beta, M_PI, pow(), and user_func_params::sigma_z.

Referenced by main().

43 {
44  double sigma_z = ((struct user_func_params *) user_par)->sigma_z(z_s);
45  return exp(- (z_ph-z_s)*(z_ph-z_s) / (2.*sigma_z*sigma_z)) / (pow(2.*M_PI,0.5)*sigma_z);
46 }
#define M_PI
Definition: ccl_constants.h:22
double(* sigma_z)(double)
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39