Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_distances_cosmomad_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 chi for all the
7 #define DISTANCES_TOLERANCE 5.0e-7
8 #define DM_TOLERANCE 1.0E-3
9 
10 CTEST_DATA(distances_cosmomad_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;
19  double Omega_v[5];
20  double Omega_k[5];
21  double w_0[5];
22  double w_a[5];
23 
24  double z[6];
25  double chi[5][6];
26  double dm[5][6];
27 };
28 
29 // Read the fixed format file containing all the radial comoving
30 // distance benchmarks
31 static void read_chi_test_file(double z[6], double chi[5][6])
32 {
33  //Distances are in Mpc/h
34  FILE * f = fopen("./tests/benchmark/chi_model1-5.txt", "r");
35  ASSERT_NOT_NULL(f);
36 
37  // Ignore header line
38  char str[1024];
39  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  &chi[0][i], &chi[1][i], &chi[2][i], &chi[3][i], &chi[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 static void read_dm_test_file(double z[6], double dm[5][6])
52 {
53  //Distances are in Mpc/h
54  FILE * f = fopen("./tests/benchmark/dm_model1-5.txt", "r");
55  ASSERT_NOT_NULL(f);
56 
57  // Ignore header line
58  char str[1024];
59  fgets(str, 1024, f);
60 
61  // File is fixed format - five rows and six columns
62  for (int i=0; i<6; i++) {
63  int count = fscanf(f, "%le %le %le %le %le %le\n", &z[i],
64  &dm[0][i], &dm[1][i], &dm[2][i], &dm[3][i], &dm[4][i]);
65  // Check that all the stuff in the benchmark is there
66  ASSERT_EQUAL(6, count);
67  }
68  fclose(f);
69 }
70 
71 // Set up the cosmological parameters to be used in each of the
72 // models
73 CTEST_SETUP(distances_cosmomad_lowz) {
74  // Values that are the same for all 5 models
75  data->Omega_c = 0.25;
76  data->Omega_b = 0.05;
77  data->h = 0.7;
78  data->A_s = 2.1e-9;
79  data->n_s = 0.96;
80  data->Neff=0;
81  double mnuval = 0.;
82  data->mnu= &mnuval;
83  data->mnu_type = ccl_mnu_sum;
84 
85 
86  // Values that are different for the different models
87  double Omega_v[5] = { 0.7, 0.7, 0.7, 0.65, 0.75 };
88  double w_0[5] = { -1.0, -0.9, -0.9, -0.9, -0.9 };
89  double w_a[5] = { 0.0, 0.0, 0.1, 0.1, 0.1 };
90 
91  // Fill in the values from these constant arrays.
92  for (int i=0; i<5; i++) {
93  data->Omega_v[i] = Omega_v[i];
94  data->w_0[i] = w_0[i];
95  data->w_a[i] = w_a[i];
96  data->Omega_k[i] = 1.0 - data->Omega_c - data->Omega_b - data->Omega_v[i];
97  }
98 
99  // The file of benchmark data.
100  read_dm_test_file(data->z, data->dm);
101  read_chi_test_file(data->z, data->chi);
102 }
103 
104 static void compare_distances(int model, struct distances_cosmomad_lowz_data * data)
105 {
106  int status=0;
107  // Make the parameter set from the input data
108  // Values of some parameters depend on the model index
109  ccl_parameters params = ccl_parameters_create(data->Omega_c, data->Omega_b, data->Omega_k[model],
110  data->Neff, data->mnu, data->mnu_type,
111  data->w_0[model], data->w_a[model],
112  data->h, data->A_s, data->n_s,-1,-1,-1,-1,NULL,NULL, &status);
113 
114  params.Omega_g=0; //enforce no radiation
115  params.Omega_l = 1.-params.Omega_m-params.Omega_k; //reomcpute Omega_l without radiation
116 
117  // Make a cosmology object from the parameters with the default configuration
119  ASSERT_NOT_NULL(cosmo);
120 
121  // Compare to benchmark data
122  for (int j=0; j<6; j++) {
123  double a = 1/(1.+data->z[j]);
124  double chi_ij=ccl_comoving_radial_distance(cosmo,a, &status)*data->h;
125  if (status) printf("%s\n",cosmo->status_message);
126  double absolute_tolerance = DISTANCES_TOLERANCE*data->chi[model][j];
127  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
128  ASSERT_DBL_NEAR_TOL(data->chi[model][j], chi_ij, absolute_tolerance);
129 
130  if(a!=1) { //skip this test for a=1 since it will raise an error
131  double dm_ij=ccl_distance_modulus(cosmo,a, &status);
132  if (status) printf("%s\n",cosmo->status_message);
133  //NOTE tolerances are different!
134  absolute_tolerance = DM_TOLERANCE*data->dm[model][j];
135  if (fabs(absolute_tolerance)<1e-4) absolute_tolerance = 1e-4;
136  ASSERT_DBL_NEAR_TOL(data->dm[model][j], dm_ij, absolute_tolerance);
137  }
138  }
139 
140  ccl_cosmology_free(cosmo);
141 }
142 
143 CTEST2(distances_cosmomad_lowz, model_1) {
144  int model = 0;
145  compare_distances(model, data);
146 }
147 
148 CTEST2(distances_cosmomad_lowz, model_2) {
149  int model = 1;
150  compare_distances(model, data);
151 }
152 
153 CTEST2(distances_cosmomad_lowz, model_3) {
154  int model = 2;
155  compare_distances(model, data);
156 }
157 
158 CTEST2(distances_cosmomad_lowz, model_4) {
159  int model = 3;
160  compare_distances(model, data);
161 }
162 
163 CTEST2(distances_cosmomad_lowz, model_5) {
164  int model = 4;
165  compare_distances(model, data);
166 }
double Omega_g
Definition: ccl_core.h:53
static void read_chi_test_file(double z[6], double chi[5][6])
#define DM_TOLERANCE
static void compare_distances(int model, struct distances_cosmomad_lowz_data *data)
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2747
static void read_dm_test_file(double z[6], double dm[5][6])
#define CTEST_SETUP(sname)
Definition: ctest.h:73
#define CTEST_DATA(sname)
Definition: ctest.h:71
double Omega_l
Definition: ccl_core.h:63
#define DISTANCES_TOLERANCE
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
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
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
char status_message[500]
Definition: ccl_core.h:136