Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_distances_class_allz.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 chi
7 #define DISTANCES_TOLERANCE 1.0e-6
8 
9 // We test the models CCL1-5 and CCL7-11 from the paper.
10 #define N_MODEL 10
11 // The test are done at 10 logarithmically spaced redshifts between 1e-2 and 1000.
12 #define N_Z 10
13 
14 CTEST_DATA(distances_class) {
15  double Omega_c;
16  double Omega_b;
17  double h;
18  double A_s;
19  double n_s;
20  double Neff[N_MODEL];
21  double mnu[N_MODEL][3];
23  double Omega_k[N_MODEL];
24  double w_0[N_MODEL];
25  double w_a[N_MODEL];
26 
27  double z_chi[N_Z];
28  double z_dm[N_Z];
29 
30  double chi_benchmark[N_Z][N_MODEL];
31  double dm_benchmark[N_Z][N_MODEL];
32 };
33 
34 // Read the fixed format file containing all the radial comoving
35 // distance benchmarks
36 static void read_benchmark_file(const char* filename, double z[N_Z], double benchmark[N_Z][N_MODEL])
37 {
38  //Distances are in Mpc
39  FILE * f = fopen(filename, "r");
40  ASSERT_NOT_NULL(f);
41 
42  // Ignore header line
43  fscanf(f, "%*[^\n]\n", NULL);
44 
45  double val;
46  // Read the file
47  for(int i_z=0; i_z<N_Z; i_z++) {
48  for(int i_model=0; i_model<N_MODEL+1; i_model++) {
49  int count = fscanf(f, "%le", &val);
50  // Check that all the value was read successfully
51  ASSERT_EQUAL(1, count);
52  if(i_model == 0) {
53  // The first column holds the redshift values
54  z[i_z] = val;
55  }
56  else {
57  benchmark[i_z][i_model-1] = val;
58  }
59  }
60  }
61  fclose(f);
62 }
63 
64 // Set up the cosmological parameters to be used in each of the
65 // models
66 CTEST_SETUP(distances_class) {
67  // Values that are the same for all 5 models
68  data->Omega_c = 0.25;
69  data->Omega_b = 0.05;
70  data->h = 0.7;
71  data->A_s = 2.1e-9;
72  data->n_s = 0.96;
73  data->mnu_type = ccl_mnu_list;
74 
75  // Values that are different for the different models
76  double Omega_k[N_MODEL] = { 0.0, 0.0, 0.0, 0.05, -0.05,
77  0.0, 0.0, 0.0, 0.05, -0.05 };
78  double w_0[N_MODEL] = { -1.0, -0.9, -0.9, -0.9, -0.9,
79  -1.0, -0.9, -0.9, -0.9, -0.9 };
80  double w_a[N_MODEL] = { 0.0, 0.0, 0.1, 0.1, 0.1,
81  0.0, 0.0, 0.1, 0.1, 0.1 };
82 
83  double mnu[N_MODEL][3] = { {0.0, 0.0, 0.0},
84  {0.0, 0.0, 0.0},
85  {0.0, 0.0, 0.0},
86  {0.0, 0.0, 0.0},
87  {0.0, 0.0, 0.0},
88  {0.04, 0.0, 0.0},
89  {0.05, 0.01, 0.0},
90  {0.03, 0.02, 0.04},
91  {0.05, 0.0, 0.0},
92  {0.03, 0.02, 0.0} };
93 
94  double Neff[N_MODEL] = {3.046, 3.046, 3.046, 3.046, 3.046,
95  3.013, 3.026, 3.040, 3.013, 3.026};
96 
97 
98  // Fill in the values from these constant arrays.
99  for(int i=0; i<N_MODEL; i++) {
100  data->Omega_k[i] = Omega_k[i];
101  data->w_0[i] = w_0[i];
102  data->w_a[i] = w_a[i];
103  data->Neff[i] = Neff[i];
104  for(int j=0; j<3; j++) {
105  data->mnu[i][j] = mnu[i][j];
106  }
107  }
108 
109  // The file of benchmark data.
110  read_benchmark_file("./tests/benchmark/chi_class_allz.txt", data->z_chi, data->chi_benchmark);
111  read_benchmark_file("./tests/benchmark/dm_class_allz.txt", data->z_dm, data->dm_benchmark);
112 }
113 
114 static void compare_distances(int model, struct distances_class_data * data)
115 {
116  int status=0;
117  // Make the parameter set from the input data
118  // Values of some parameters depend on the model index
119 
120  // The arrays of massive neutrions are different lengths, so we need to have an if-statement here to deal with that.
121 
123 
124  params = ccl_parameters_create(data->Omega_c, data->Omega_b, data->Omega_k[model],
125  data->Neff[model], data->mnu[model], data->mnu_type,
126  data->w_0[model], data->w_a[model],
127  data->h, data->A_s, data->n_s,
128  -1,-1,-1,-1,NULL,NULL, &status);
129  ASSERT_EQUAL(0, status);
130 
131  // Make a cosmology object from the parameters with the default configuration
133  ASSERT_NOT_NULL(cosmo);
134 
135  // Compare to benchmark data
136  for(int i=0; i<N_Z; i++) {
137  // Check comoving radial distance
138  double a = 1/(1.+data->z_chi[i]);
139  double chi_ccl = ccl_comoving_radial_distance(cosmo, a, &status);
140  if(status) printf("%s\n",cosmo->status_message);
141 
142  double absolute_tolerance = DISTANCES_TOLERANCE*data->chi_benchmark[i][model];
143  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
144  ASSERT_DBL_NEAR_TOL(data->chi_benchmark[i][model], chi_ccl, absolute_tolerance);
145 
146  // Check distance modulus
147  a = 1/(1.+data->z_dm[i]);
148  double dm_ccl = ccl_distance_modulus(cosmo, a, &status);
149  if(status) printf("%s\n",cosmo->status_message);
150 
151  absolute_tolerance = DISTANCES_TOLERANCE*data->dm_benchmark[i][model];
152  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
153  ASSERT_DBL_NEAR_TOL(data->dm_benchmark[i][model], dm_ccl, absolute_tolerance);
154  }
155 
156  ccl_cosmology_free(cosmo);
157 }
158 
159 CTEST2(distances_class, model_1) {
160  int model = 0;
161  compare_distances(model, data);
162 }
163 
164 CTEST2(distances_class, model_2) {
165  int model = 1;
166  compare_distances(model, data);
167 }
168 
169 CTEST2(distances_class, model_3) {
170  int model = 2;
171  compare_distances(model, data);
172 }
173 
174 CTEST2(distances_class, model_4) {
175  int model = 3;
176  compare_distances(model, data);
177 }
178 
179 CTEST2(distances_class, model_5) {
180  int model = 4;
181  compare_distances(model, data);
182 }
183 
184 CTEST2(distances_class, model_7) {
185  int model = 5;
186  compare_distances(model, data);
187 }
188 
189 CTEST2(distances_class, model_8) {
190  int model = 6;
191  compare_distances(model, data);
192 }
193 
194 CTEST2(distances_class, model_9) {
195  int model = 7;
196  compare_distances(model, data);
197 }
198 
199 CTEST2(distances_class, model_10) {
200  int model = 8;
201  compare_distances(model, data);
202 }
203 
204 CTEST2(distances_class, model_11) {
205  int model = 9;
206  compare_distances(model, data);
207 }
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2747
#define CTEST_SETUP(sname)
Definition: ctest.h:73
#define CTEST_DATA(sname)
Definition: ctest.h:71
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
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
#define DISTANCES_TOLERANCE
static double z[8]
const ccl_configuration default_config
Definition: ccl_core.c:21
static void compare_distances(int model, struct distances_class_data *data)
#define ASSERT_EQUAL(exp, real)
Definition: ctest.h:121
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
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)
#define CTEST2(sname, tname)
Definition: ctest.h:107
static void read_benchmark_file(const char *filename, double z[10], double benchmark[10][10])
char status_message[500]
Definition: ccl_core.h:136