Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_angpow.c
Go to the documentation of this file.
1 #include "ccl.h"
2 #include "ctest.h"
3 #include <stdio.h>
4 #include <math.h>
5 
6 #define NZ 1024
7 #define Z0_GC 1.0
8 #define SZ_GC 0.02
9 #define NL 499
10 
11 #define CLS_PRECISION 3E-3
12 
13 CTEST_DATA(angpow) {
14  double Omega_c;
15  double Omega_b;
16  double h;
17  double A_s;
18  double n_s;
19  double Neff;
20  double* mnu;
22  double Omega_v;
23  double Omega_k;
24  double w_0;
25  double w_a;
26 };
27 
28 
29 
30 
31 // Set up the cosmological parameters to be used
32 CTEST_SETUP(angpow){
33  data->Omega_c = 0.25;
34  data->Omega_b = 0.05;
35  data->h = 0.7;
36  data->A_s = 2.1e-9;
37  data->n_s = 0.96;
38  data->Omega_v = 0.7;
39  data->Neff=3.046;
40  double mnuval = 0.;
41  data->mnu = &mnuval;
42  data->mnu_type = ccl_mnu_sum;
43  data->w_0 = -1;
44  data->w_a = 0;
45  data->Omega_k = 0;
46 }
47 
48 
49 
50 static void test_angpow_precision(struct angpow_data * data)
51 {
52  // Status flag
53  int status =0;
54 
55  // Initialize cosmological parameters
59  ccl_parameters ccl_params = ccl_parameters_create(data->Omega_c, data->Omega_b, data->Omega_k, data->Neff, data->mnu, data->mnu_type,data->w_0, data->w_a, data->h, data->A_s, data->n_s,-1,-1,-1,-1,NULL,NULL, &status);
60  ccl_params.Omega_g=0.;
61  ccl_params.Omega_l=data->Omega_v;
62 
63  // Initialize cosmology object given cosmo params
64  ccl_cosmology *ccl_cosmo=ccl_cosmology_create(ccl_params,ccl_config);
65 
66  // Create tracers for angular power spectra
67  double z_arr_gc[NZ],nz_arr_gc[NZ],bz_arr[NZ];
68  for(int i=0;i<NZ;i++)
69  {
70  z_arr_gc[i]=Z0_GC-5*SZ_GC+10*SZ_GC*(i+0.5)/NZ;
71  nz_arr_gc[i]=exp(-0.5*pow((z_arr_gc[i]-Z0_GC)/SZ_GC,2));
72  bz_arr[i]=1;
73  }
74 
75  // Galaxy clustering tracer
76  bool has_rsd = true;
77  bool has_magnification = false;
78  CCL_ClTracer *ct_gc_A=ccl_cl_tracer_number_counts(ccl_cosmo,has_rsd,has_magnification,NZ,z_arr_gc,nz_arr_gc,NZ,z_arr_gc,bz_arr,-1,NULL,NULL, &status);
79  CCL_ClTracer *ct_gc_B=ccl_cl_tracer_number_counts(ccl_cosmo,has_rsd,has_magnification,NZ,z_arr_gc,nz_arr_gc,NZ,z_arr_gc,bz_arr,-1,NULL,NULL, &status);
80 
81  int *ells=malloc(NL*sizeof(int));
82  double *cells_gg_angpow=malloc(NL*sizeof(double));
83  for(int ii=0;ii<NL;ii++)
84  ells[ii]=ii;
85 
86 
87  // Workspaces
88  double linstep = 40;
89  double logstep = 1.15;
90  double dchi = (ct_gc_A->chimax-ct_gc_A->chimin)/1000.;
91  CCL_ClWorkspace *wap=ccl_cl_workspace_new(NL+1,2*ells[NL-1],logstep,linstep,&status);
92 
93  // Compute C_ell
94  ccl_angular_cls(ccl_cosmo,wap,ct_gc_A,ct_gc_A,NL,ells,cells_gg_angpow,&status);
95  double rel_precision = 0.;
96  FILE *f=fopen("./tests/benchmark/angpow_gg.txt","r");
97  for(int ii=2;ii<NL;ii++) {
98  int l;
99  double ratio,cl_gg_nl,cl_gg_ap=cells_gg_angpow[ii];
100  int stat=fscanf(f,"%d %lE",&l,&cl_gg_nl);
101  ASSERT_TRUE(l==ells[ii]);
102  ASSERT_TRUE(stat==2);
103  ratio = fabs(cl_gg_nl-cl_gg_ap)/cl_gg_nl;
104  rel_precision += ratio;
105  }
106  fclose(f);
107  rel_precision /= NL;
108  ASSERT_TRUE(rel_precision < CLS_PRECISION);
109 
110  //Free up tracers
111  ccl_cl_tracer_free(ct_gc_A);
112  ccl_cl_tracer_free(ct_gc_B);
113  free(ells);
115  free(cells_gg_angpow);
116  ccl_cosmology_free(ccl_cosmo);
117 }
118 
119 CTEST2(angpow,precision) {
120  test_angpow_precision(data);
121 }
double Omega_g
Definition: ccl_core.h:53
#define NZ
#define SZ_GC
ccl_mnu_convention mnu_type
matter_power_spectrum_t matter_power_spectrum_method
Definition: ccl_config.h:112
#define ASSERT_TRUE(real)
Definition: ctest.h:142
#define CTEST_SETUP(sname)
Definition: ctest.h:73
#define CTEST_DATA(sname)
Definition: ctest.h:71
void ccl_cl_tracer_free(CCL_ClTracer *clt)
Definition: ccl_cls.c:592
double Omega_l
Definition: ccl_core.h:63
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
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
#define NL
ccl_mnu_convention
Definition: ccl_core.h:142
void ccl_cosmology_free(ccl_cosmology *cosmo)
Definition: ccl_core.c:829
#define CLS_PRECISION
CCL_ClWorkspace * ccl_cl_workspace_new(int lmax, int l_limber, double l_logstep, int l_linstep, int *status)
Definition: ccl_cls.c:65
static void test_angpow_precision(struct angpow_data *data)
#define Z0_GC
CCL_ClTracer * ccl_cl_tracer_number_counts(ccl_cosmology *cosmo, int has_rsd, int has_magnification, int nz_n, double *z_n, double *n, int nz_b, double *z_b, double *b, int nz_s, double *z_s, double *s, int *status)
Definition: ccl_cls.c:622
const ccl_configuration default_config
Definition: ccl_core.c:21
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
void ccl_cl_workspace_free(CCL_ClWorkspace *w)
Definition: ccl_cls.c:59
double chimax
Definition: ccl_cls.h:34
double chimin
Definition: ccl_cls.h:35
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
#define CTEST2(sname, tname)
Definition: ctest.h:107
double * mnu