Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_distances_cosmomad_hiz.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_HIZ_TOLERANCE 5.0e-7
8 
9 CTEST_DATA(distances_cosmomad_hiz) {
10  double Omega_c;
11  double Omega_b;
12  double h;
13  double A_s;
14  double n_s;
15  double Neff;
16  double* mnu;
18  double Omega_v[3];
19  double Omega_k[3];
20  double w_0[3];
21  double w_a[3];
22 
23  double z[7];
24  double chi[3][7];
25 };
26 
27 // Read the fixed format file containing all the radial comoving
28 // distance benchmarks
29 static void read_chi_test_file(double z[7], double chi[3][7])
30 {
31  //Distances are in Mpc/h
32  FILE * f = fopen("./tests/benchmark/chi_hiz_model1-3.txt", "r");
33  ASSERT_NOT_NULL(f);
34 
35  // Ignore header line
36  char str[1024];
37  fgets(str, 1024, f);
38 
39  // File is fixed format - five rows and six columns
40  for (int i=0; i<7; i++) {
41  int count = fscanf(f, "%le %le %le %le \n", &z[i],
42  &chi[0][i], &chi[1][i], &chi[2][i]);
43  // Check that all the stuff in the benchmark is there
44  ASSERT_EQUAL(4, count);
45  }
46  fclose(f);
47 }
48 
49 // Set up the cosmological parameters to be used in each of the
50 // models
51 CTEST_SETUP(distances_cosmomad_hiz) {
52  // Values that are the same for all 3 models
53  data->Omega_c = 0.25;
54  data->Omega_b = 0.05;
55  data->h = 0.7;
56  data->A_s = 2.1e-9;
57  data->n_s = 0.96;
58  data->Neff=0;
59  double mnuval = 0.;
60  data->mnu= &mnuval;
61  data->mnu_type = ccl_mnu_sum;
62 
63  // Values that are different for the different models
64  double Omega_v[3] = { 0.7, 0.7, 0.7};
65  double w_0[3] = { -1.0, -0.9, -0.9};
66  double w_a[3] = { 0.0, 0.0, 0.1};
67 
68  // Fill in the values from these constant arrays.
69  for (int i=0; i<3; i++) {
70  data->Omega_v[i] = Omega_v[i];
71  data->w_0[i] = w_0[i];
72  data->w_a[i] = w_a[i];
73  data->Omega_k[i] = 1.0 - data->Omega_c - data->Omega_b - data->Omega_v[i];
74  }
75 
76  // The file of benchmark data.
77  read_chi_test_file(data->z, data->chi);
78 }
79 
80 static void compare_distances_hiz(int model, struct distances_cosmomad_hiz_data * data)
81 {
82  int status=0;
83  // Make the parameter set from the input data
84  // Values of some parameters depend on the model index
86  data->Neff, data->mnu, data->mnu_type,
87  data->w_0[model], data->w_a[model],
88  data->h, data->A_s, data->n_s,-1,-1,-1,-1,NULL,NULL, &status);
89 
90  params.Omega_g=0; //enforce no radiation
91  params.Omega_l = 1.-params.Omega_m-params.Omega_k; //reomcpute Omega_l without radiation
92 
93  // Make a cosmology object from the parameters with the default configuration
95  ASSERT_NOT_NULL(cosmo);
96 
97  // Compare to benchmark data
98  for (int j=0; j<7; j++) {
99  double a = 1/(1.+data->z[j]);
100  double chi_ij=ccl_comoving_radial_distance(cosmo,a, &status)*data->h;
101  if (status) printf("%s\n",cosmo->status_message);
102  double absolute_tolerance = DISTANCES_HIZ_TOLERANCE*data->chi[model][j];
103  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
104  ASSERT_DBL_NEAR_TOL(data->chi[model][j], chi_ij, absolute_tolerance);
105  }
106 
107  ccl_cosmology_free(cosmo);
108 }
109 
110 CTEST2(distances_cosmomad_hiz, model_1) {
111  int model = 0;
112  compare_distances_hiz(model, data);
113 }
114 
115 CTEST2(distances_cosmomad_hiz, model_2) {
116  int model = 1;
117  compare_distances_hiz(model, data);
118 }
119 
120 CTEST2(distances_cosmomad_hiz, model_3) {
121  int model = 2;
122  compare_distances_hiz(model, data);
123 }
double Omega_g
Definition: ccl_core.h:53
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
static void compare_distances_hiz(int model, struct distances_cosmomad_hiz_data *data)
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
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
#define DISTANCES_HIZ_TOLERANCE
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
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 void read_chi_test_file(double z[7], double chi[3][7])
#define CTEST2(sname, tname)
Definition: ctest.h:107
char status_message[500]
Definition: ccl_core.h:136