Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_growth_lowz.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 // The tolerance in D(z)
7 #define GROWTH_TOLERANCE 6e-6
8 #define MGROWTH_TOLERANCE 5.0e-5
9 
10 CTEST_DATA(growth_lowz) {
11  double Omega_c;
12  double Omega_b;
13  double h;
14  double A_s;
15  double n_s;
16  double Neff;
17  double* mnu;
18  double Omega_v[5];
19  double Omega_k[5];
20  double w_0[5];
21  double w_a[5];
23 
24  double z[6];
25  double gf[5][6];
26 };
27 
28 // Read the fixed format file containing all the growth factor
29 // benchmarks
30 static void read_growth_test_file(double z[6], double gf[5][6])
31 {
32  //Growth is normalized to ~a at early times
33  FILE * f = fopen("./tests/benchmark/growth_model1-5.txt", "r");
34  ASSERT_NOT_NULL(f);
35 
36  // Ignore header line
37  char str[1024];
38  char* rtn;
39  rtn = fgets(str, 1024, f);
40 
41  // File is fixed format - five rows and six columns
42  for (int i=0; i<6; i++) {
43  int count = fscanf(f, "%le %le %le %le %le %le\n", &z[i],
44  &gf[0][i], &gf[1][i], &gf[2][i], &gf[3][i], &gf[4][i]);
45  // Check that all the stuff in the benchmark is there
46  ASSERT_EQUAL(6, count);
47  }
48  fclose(f);
49 }
50 
51 // Set up the cosmological parameters to be used in each of the
52 // models
53 CTEST_SETUP(growth_lowz) {
54  // Values that are the same for all 5 models
55  data->Omega_c = 0.25;
56  data->Omega_b = 0.05;
57  data->h = 0.7;
58  data->A_s = 2.1e-9;
59  data->n_s = 0.96;
60  data->Neff=0;
61  double mnuval = 0.;
62  data->mnu= &mnuval;
63  data-> mnu_type = ccl_mnu_sum;
64 
65 
66  // Values that are different for the different models
67  double Omega_v[5] = { 0.7, 0.7, 0.7, 0.65, 0.75 };
68  double w_0[5] = { -1.0, -0.9, -0.9, -0.9, -0.9 };
69  double w_a[5] = { 0.0, 0.0, 0.1, 0.1, 0.1 };
70 
71  // Fill in the values from these constant arrays.
72  for (int i=0; i<5; i++) {
73  data->Omega_v[i] = Omega_v[i];
74  data->w_0[i] = w_0[i];
75  data->w_a[i] = w_a[i];
76  data->Omega_k[i] = 1.0 - data->Omega_c - data->Omega_b - data->Omega_v[i];
77  }
78 
79  // The file of benchmark data.
80  read_growth_test_file(data->z, data->gf);
81 }
82 
83 static void compare_growth(int model, struct growth_lowz_data * data)
84 {
85  int status=0;
86  // Make the parameter set from the input data
87  // Values of some parameters depend on the model index
88  ccl_parameters params = ccl_parameters_create(data->Omega_c, data->Omega_b, data->Omega_k[model], data->Neff, data->mnu, data->mnu_type, data->w_0[model], data->w_a[model], data->h, data->A_s, data->n_s,-1,-1,-1,-1,NULL,NULL, &status);
89  params.Omega_g=0;//enforce no radiation
90  params.Omega_l = 1.-params.Omega_m-params.Omega_k; //recompute Omega_l without radiation
91  // Make a cosmology object from the parameters with the default configuration
93  ASSERT_NOT_NULL(cosmo);
94 
95  // Compare to benchmark data
96  for (int j=0; j<6; j++) {
97  double a = 1/(1.+data->z[j]);
98  double gf_ij=ccl_growth_factor_unnorm(cosmo,a, &status);
99  if (status) printf("%s\n",cosmo->status_message);
100  double absolute_tolerance = GROWTH_TOLERANCE*data->gf[model][j];
101  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
102  ASSERT_DBL_NEAR_TOL(data->gf[model][j], gf_ij, absolute_tolerance);
103  }
104 
105  ccl_cosmology_free(cosmo);
106 }
107 
108 //This test code compares the modified growth function computed by CCL
109 //against the exact result for a particular modification of the growth rate.
110 static void check_mgrowth(void)
111 {
112  int ii,nz_mg=128;
113  double *z_mg,*df_mg;
114  ccl_parameters params1,params2;
115  ccl_cosmology *cosmo1,*cosmo2;
116  int status=0;
117  z_mg=malloc(nz_mg*sizeof(double));
118  df_mg=malloc(nz_mg*sizeof(double));
119  for(ii=0;ii<nz_mg;ii++) {
120  z_mg[ii]=4*(ii+0.0)/(nz_mg-1.);
121  df_mg[ii]=0.1/(1+z_mg[ii]);
122  }
123  double mnuval = 0;
124 
125 
126  params1=ccl_parameters_create(0.25,0.05,0,0,&mnuval, 1, -1,0,0.7,2.1E-9,0.96,-1,-1,-1,-1,NULL,NULL, &status);
127  params2=ccl_parameters_create(0.25,0.05,0,0,&mnuval, 1, -1,0,0.7,2.1E-9,0.96,-1,-1,-1,nz_mg,z_mg,df_mg, &status);
128  params1.Omega_g=0; //enforce no radiation
129  params1.Omega_l = 1.-params1.Omega_m-params1.Omega_k; //reomcpute Omega_l without radiation
130  params2.Omega_g=0; //enforce no radiation
131  params2.Omega_l = 1.-params2.Omega_m-params2.Omega_k; //reomcpute Omega_l without radiation
132  cosmo1=ccl_cosmology_create(params1,default_config);
133  cosmo2=ccl_cosmology_create(params2,default_config);
134 
135  //We have included a growth modification \delta f = K*a (with K==0.1 arbitrarily)
136  //This case has an analytic solution, given by D(a) = D_0(a)*exp(K*(a-1))
137  //Here we check the growth computed by the library with the analytic solution.
138  for(ii=0;ii<nz_mg;ii++) {
139  double a=1./(1+z_mg[ii]);
140  double d1=ccl_growth_factor(cosmo1,a,&status);
141  double d2=ccl_growth_factor(cosmo2,a,&status);
142  double f1=ccl_growth_rate(cosmo1,a,&status);
143  double f2=ccl_growth_rate(cosmo2,a,&status);
144  double f2r=f1+0.1*a;
145  double d2r=d1*exp(0.1*(a-1));
148  }
149 
150  free(z_mg);
151  free(df_mg);
152  ccl_cosmology_free(cosmo1);
153  ccl_cosmology_free(cosmo2);
154 }
155 
156 CTEST2(growth_lowz, model_1) {
157  int model = 0;
158  compare_growth(model, data);
159 }
160 
161 CTEST2(growth_lowz, model_2) {
162  int model = 1;
163  compare_growth(model, data);
164 }
165 
166 CTEST2(growth_lowz, model_3) {
167  int model = 2;
168  compare_growth(model, data);
169 }
170 
171 CTEST2(growth_lowz, model_4) {
172  int model = 3;
173  compare_growth(model, data);
174 }
175 
176 CTEST2(growth_lowz, model_5) {
177  int model = 4;
178  compare_growth(model, data);
179 }
180 
181 CTEST2(growth_lowz, mgrowth) {
182  check_mgrowth();
183 }
double Omega_g
Definition: ccl_core.h:53
static void compare_growth(int model, struct growth_lowz_data *data)
ccl_mnu_convention mnu_type
double ccl_growth_factor(ccl_cosmology *cosmo, double a, int *status)
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2747
double ccl_growth_factor_unnorm(ccl_cosmology *cosmo, double a, int *status)
#define CTEST_SETUP(sname)
Definition: ctest.h:73
#define CTEST_DATA(sname)
Definition: ctest.h:71
double ccl_growth_rate(ccl_cosmology *cosmo, double a, int *status)
double Omega_l
Definition: ccl_core.h:63
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
ccl_mnu_convention
Definition: ccl_core.h:142
void ccl_cosmology_free(ccl_cosmology *cosmo)
Definition: ccl_core.c:829
dictionary params
Definition: halomod_bm.py:27
static void check_mgrowth(void)
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
static void read_growth_test_file(double z[6], double gf[5][6])
static double z[8]
const ccl_configuration default_config
Definition: ccl_core.c:21
#define ASSERT_EQUAL(exp, real)
Definition: ctest.h:121
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
double Omega_k
Definition: ccl_core.h:22
double Omega_m
Definition: ccl_core.h:21
#define MGROWTH_TOLERANCE
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
#define GROWTH_TOLERANCE
char status_message[500]
Definition: ccl_core.h:136