Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_growth_lowz.c File Reference
#include "ccl.h"
#include "ctest.h"
#include <stdio.h>
#include <math.h>
Include dependency graph for ccl_test_growth_lowz.c:

Go to the source code of this file.

Classes

struct  growth_lowz_data
 

Macros

#define GROWTH_TOLERANCE   6e-6
 
#define MGROWTH_TOLERANCE   5.0e-5
 

Functions

static void read_growth_test_file (double z[6], double gf[5][6])
 
void __attribute__ ((weak))
 
static void compare_growth (int model, struct growth_lowz_data *data)
 
static void check_mgrowth (void)
 
void __ctest_growth_lowz_model_1_run (struct growth_lowz_data *data)
 
void __ctest_growth_lowz_model_2_run (struct growth_lowz_data *data)
 
void __ctest_growth_lowz_model_3_run (struct growth_lowz_data *data)
 
void __ctest_growth_lowz_model_4_run (struct growth_lowz_data *data)
 
void __ctest_growth_lowz_model_5_run (struct growth_lowz_data *data)
 
void __ctest_growth_lowz_mgrowth_run (struct growth_lowz_data *data)
 

Variables

static struct growth_lowz_data __ctest_growth_lowz_data
 

Macro Definition Documentation

#define GROWTH_TOLERANCE   6e-6

Definition at line 7 of file ccl_test_growth_lowz.c.

Referenced by compare_growth().

#define MGROWTH_TOLERANCE   5.0e-5

Definition at line 8 of file ccl_test_growth_lowz.c.

Referenced by check_mgrowth().

Function Documentation

void __attribute__ ( (weak)  )

Definition at line 53 of file ccl_test_growth_lowz.c.

References ccl_mnu_sum, and read_growth_test_file().

53  {
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 }
static void read_growth_test_file(double z[6], double gf[5][6])
void __ctest_growth_lowz_mgrowth_run ( struct growth_lowz_data data)

Definition at line 181 of file ccl_test_growth_lowz.c.

References check_mgrowth().

181  {
182  check_mgrowth();
183 }
static void check_mgrowth(void)
void __ctest_growth_lowz_model_1_run ( struct growth_lowz_data data)

Definition at line 156 of file ccl_test_growth_lowz.c.

References compare_growth().

156  {
157  int model = 0;
158  compare_growth(model, data);
159 }
static void compare_growth(int model, struct growth_lowz_data *data)
void __ctest_growth_lowz_model_2_run ( struct growth_lowz_data data)

Definition at line 161 of file ccl_test_growth_lowz.c.

References compare_growth().

161  {
162  int model = 1;
163  compare_growth(model, data);
164 }
static void compare_growth(int model, struct growth_lowz_data *data)
void __ctest_growth_lowz_model_3_run ( struct growth_lowz_data data)

Definition at line 166 of file ccl_test_growth_lowz.c.

References compare_growth().

166  {
167  int model = 2;
168  compare_growth(model, data);
169 }
static void compare_growth(int model, struct growth_lowz_data *data)
void __ctest_growth_lowz_model_4_run ( struct growth_lowz_data data)

Definition at line 171 of file ccl_test_growth_lowz.c.

References compare_growth().

171  {
172  int model = 3;
173  compare_growth(model, data);
174 }
static void compare_growth(int model, struct growth_lowz_data *data)
void __ctest_growth_lowz_model_5_run ( struct growth_lowz_data data)

Definition at line 176 of file ccl_test_growth_lowz.c.

References compare_growth().

176  {
177  int model = 4;
178  compare_growth(model, data);
179 }
static void compare_growth(int model, struct growth_lowz_data *data)
static void check_mgrowth ( void  )
static

Definition at line 110 of file ccl_test_growth_lowz.c.

References ASSERT_DBL_NEAR_TOL, ccl_cosmology_create(), ccl_cosmology_free(), ccl_growth_factor(), ccl_growth_rate(), ccl_parameters_create(), default_config, MGROWTH_TOLERANCE, ccl_parameters::Omega_g, ccl_parameters::Omega_k, ccl_parameters::Omega_l, and ccl_parameters::Omega_m.

Referenced by __ctest_growth_lowz_mgrowth_run().

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 }
double Omega_g
Definition: ccl_core.h:53
double ccl_growth_factor(ccl_cosmology *cosmo, double a, int *status)
double ccl_growth_rate(ccl_cosmology *cosmo, double a, int *status)
double Omega_l
Definition: ccl_core.h:63
int * status
Definition: ccl_redshifts.c:41
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
void ccl_cosmology_free(ccl_cosmology *cosmo)
Definition: ccl_core.c:829
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
const ccl_configuration default_config
Definition: ccl_core.c:21
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
static void compare_growth ( int  model,
struct growth_lowz_data data 
)
static

Definition at line 83 of file ccl_test_growth_lowz.c.

References growth_lowz_data::A_s, ASSERT_DBL_NEAR_TOL, ASSERT_NOT_NULL, ccl_cosmology_create(), ccl_cosmology_free(), ccl_growth_factor_unnorm(), ccl_parameters_create(), cl_cmbl_bm::cosmo, default_config, growth_lowz_data::gf, GROWTH_TOLERANCE, growth_lowz_data::h, growth_lowz_data::mnu, growth_lowz_data::mnu_type, growth_lowz_data::n_s, growth_lowz_data::Neff, growth_lowz_data::Omega_b, growth_lowz_data::Omega_c, ccl_parameters::Omega_g, growth_lowz_data::Omega_k, ccl_parameters::Omega_k, ccl_parameters::Omega_l, ccl_parameters::Omega_m, halomod_bm::params, ccl_cosmology::status_message, growth_lowz_data::w_0, growth_lowz_data::w_a, and growth_lowz_data::z.

Referenced by __ctest_growth_lowz_model_1_run(), __ctest_growth_lowz_model_2_run(), __ctest_growth_lowz_model_3_run(), __ctest_growth_lowz_model_4_run(), and __ctest_growth_lowz_model_5_run().

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 }
double Omega_g
Definition: ccl_core.h:53
ccl_mnu_convention mnu_type
double ccl_growth_factor_unnorm(ccl_cosmology *cosmo, double a, int *status)
double Omega_l
Definition: ccl_core.h:63
int * status
Definition: ccl_redshifts.c:41
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
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
const ccl_configuration default_config
Definition: ccl_core.c:21
#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
#define GROWTH_TOLERANCE
char status_message[500]
Definition: ccl_core.h:136
static void read_growth_test_file ( double  z[6],
double  gf[5][6] 
)
static

Definition at line 30 of file ccl_test_growth_lowz.c.

References ASSERT_EQUAL, ASSERT_NOT_NULL, and Catch::Matchers::Vector::Detail::count().

Referenced by __attribute__().

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 }
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2747
static double z[8]
#define ASSERT_EQUAL(exp, real)
Definition: ctest.h:121
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139

Variable Documentation

static struct growth_lowz_data __ctest_growth_lowz_data
static

Definition at line 156 of file ccl_test_growth_lowz.c.