Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_growth_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 D(z) for all the
7 #define GROWTH_TOLERANCE 1.0e-4
8 
9 #define N_Z 10
10 #define N_MODEL 5
11 
13  double Omega_c;
14  double Omega_b;
15  double h;
16  double A_s;
17  double n_s;
18  double Neff;
19  double* mnu;
20  double Omega_v[N_MODEL];
21  double Omega_k[N_MODEL];
22  double w_0[N_MODEL];
23  double w_a[N_MODEL];
25 
26  double z[N_Z];
27  double gf[N_Z][N_MODEL];
28 };
29 
30 // Read the fixed format file containing all the growth factor
31 // benchmarks
32 static void read_growth_test_file(const char* filename, double z[N_Z], double gf[N_Z][N_MODEL])
33 {
34  //Growth is normalized to ~a at early times
35  FILE * f = fopen(filename, "r");
36  ASSERT_NOT_NULL(f);
37 
38  // Ignore header line
39  fscanf(f, "%*[^\n]\n", NULL);
40 
41  double val;
42  // Read the file
43  for(int i_z=0; i_z<N_Z; i_z++) {
44  for(int i_model=0; i_model<N_MODEL+1; i_model++) {
45  int count = fscanf(f, "%le", &val);
46  // Check that all the value was read successfully
47  ASSERT_EQUAL(1, count);
48  if(i_model == 0) {
49  // The first column holds the redshift values
50  z[i_z] = val;
51  }
52  else {
53  gf[i_z][i_model-1] = val;
54  }
55  }
56  }
57  fclose(f);
58 }
59 
60 // Set up the cosmological parameters to be used in each of the
61 // models
63  // Values that are the same for all 5 models
64  data->Omega_c = 0.25;
65  data->Omega_b = 0.05;
66  data->h = 0.7;
67  data->A_s = 2.1e-9;
68  data->n_s = 0.96;
69  data->Neff=0;
70  double mnuval = 0.;
71  data->mnu= &mnuval;
72  data-> mnu_type = ccl_mnu_sum;
73 
74 
75  // Values that are different for the different models
76  double Omega_v[N_MODEL] = { 0.7, 0.7, 0.7, 0.65, 0.75 };
77  double w_0[N_MODEL] = { -1.0, -0.9, -0.9, -0.9, -0.9 };
78  double w_a[N_MODEL] = { 0.0, 0.0, 0.1, 0.1, 0.1 };
79 
80  // Fill in the values from these constant arrays.
81  for (int i=0; i<N_MODEL; i++) {
82  data->Omega_v[i] = Omega_v[i];
83  data->w_0[i] = w_0[i];
84  data->w_a[i] = w_a[i];
85  data->Omega_k[i] = 1.0 - data->Omega_c - data->Omega_b - data->Omega_v[i];
86  }
87 
88  // The file of benchmark data.
89  read_growth_test_file("./tests/benchmark/growth_cosmomad_allz.txt", data->z, data->gf);
90 }
91 
92 static void compare_growth(int model, struct growth_allz_data * data)
93 {
94  int status=0;
95  // Make the parameter set from the input data
96  // Values of some parameters depend on the model index
97  ccl_parameters params = ccl_parameters_create(data->Omega_c, data->Omega_b, data->Omega_k[model],
98  data->Neff, data->mnu, data->mnu_type,
99  data->w_0[model], data->w_a[model],
100  data->h, data->A_s, data->n_s,
101  -1,-1,-1,-1,NULL,NULL, &status);
102  params.Omega_g=0;
103  // Make a cosmology object from the parameters with the default configuration
105  ASSERT_NOT_NULL(cosmo);
106 
107  // Compare to benchmark data
108  for (int i=0; i<N_Z; i++) {
109  double a = 1/(1.+data->z[i]);
110  double gf_ccl=ccl_growth_factor_unnorm(cosmo, a, &status);
111  if (status) printf("%s\n",cosmo->status_message);
112 
113  double absolute_tolerance = GROWTH_TOLERANCE*data->gf[i][model];
114  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
115  ASSERT_DBL_NEAR_TOL(data->gf[i][model], gf_ccl, absolute_tolerance);
116  }
117 
118  ccl_cosmology_free(cosmo);
119 }
120 
121 CTEST2(growth_allz, model_1) {
122  int model = 0;
123  compare_growth(model, data);
124 }
125 
126 CTEST2(growth_allz, model_2) {
127  int model = 1;
128  compare_growth(model, data);
129 }
130 
131 CTEST2(growth_allz, model_3) {
132  int model = 2;
133  compare_growth(model, data);
134 }
135 
136 CTEST2(growth_allz, model_4) {
137  int model = 3;
138  compare_growth(model, data);
139 }
140 
141 CTEST2(growth_allz, model_5) {
142  int model = 4;
143  compare_growth(model, data);
144 }
double Omega_g
Definition: ccl_core.h:53
static void read_growth_test_file(const char *filename, double z[10], double gf[10][5])
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2747
ccl_mnu_convention mnu_type
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
#define N_MODEL
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
ccl_mnu_convention
Definition: ccl_core.h:142
#define GROWTH_TOLERANCE
void ccl_cosmology_free(ccl_cosmology *cosmo)
Definition: ccl_core.c:829
dictionary params
Definition: halomod_bm.py:27
#define N_Z
#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
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
static void compare_growth(int model, struct growth_allz_data *data)
char status_message[500]
Definition: ccl_core.h:136