Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_bbks.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 #define BBKS_TOLERANCE 1.0E-5
7 
8 CTEST_DATA(bbks) {
9  double Omega_c;
10  double Omega_b;
11  double h;
12  double A_s;
13  double n_s;
14  double sigma8;
15  double Neff;
16  double* mnu;
18  double Omega_v[5];
19  double Omega_k[5];
20  double w_0[5];
21  double w_a[5];
22 };
23 
24 CTEST_SETUP(bbks) {
25  data->Omega_c = 0.25;
26  data->Omega_b = 0.05;
27  data->h = 0.7;
28  data->A_s = 2.1e-9;
29  data->n_s = 0.96;
30  data->sigma8=0.8;
31  data->Neff=0;
32  double mnuval = 0.;
33  data->mnu=&mnuval;
34  data->mnu_type =ccl_mnu_sum;
35 
36  double Omega_v[5]={0.7, 0.7, 0.7, 0.65, 0.75};
37  double w_0[5] = {-1.0, -0.9, -0.9, -0.9, -0.9};
38  double w_a[5] = {0.0, 0.0, 0.1, 0.1, 0.1};
39 
40  for(int i=0;i<5;i++) {
41  data->Omega_v[i] = Omega_v[i];
42  data->w_0[i] = w_0[i];
43  data->w_a[i] = w_a[i];
44  data->Omega_k[i] = 1.0 - data->Omega_c - data->Omega_b - data->Omega_v[i];
45  }
46 }
47 
48 static int linecount(FILE *f)
49 {
51  // Counts #lines from file
52  int i0=0;
53  char ch[1000];
54  while((fgets(ch,sizeof(ch),f))!=NULL) {
55  i0++;
56  }
57  return i0;
58 }
59 
60 static void compare_bbks(int i_model,struct bbks_data * data)
61 {
62  int nk,i,j;
63  int status=0;
64  char fname[256],str[1024];
65  char* rtn;
66  FILE *f;
69  ccl_parameters params = ccl_parameters_create(data->Omega_c,data->Omega_b,data->Omega_k[i_model-1],data->Neff, data->mnu,data->mnu_type, data->w_0[i_model-1],data->w_a[i_model-1],data->h,data->A_s,data->n_s,-1,-1,-1,-1,NULL,NULL, &status);
70  params.Omega_g=0;
71  params.Omega_l=data->Omega_v[i_model-1];
72  params.sigma8=data->sigma8;
73  ccl_cosmology * cosmo = ccl_cosmology_create(params, config);
74  ASSERT_NOT_NULL(cosmo);
75 
76  sprintf(fname,"./tests/benchmark/model%d_pk.txt",i_model);
77  f=fopen(fname,"r");
78  if(f==NULL) {
79  fprintf(stderr,"Error opening file %s\n",fname);
80  exit(1);
81  }
82  nk=linecount(f)-1; rewind(f);
83 
84  rtn = fgets(str, 1024, f);
85  for(i=0;i<nk;i++) {
86  double k_h,k;
87  int stat;
88  stat=fscanf(f,"%lf",&k_h);
89  if(stat!=1) {
90  fprintf(stderr,"Error reading file %s, line %d\n",fname,i+2);
91  exit(1);
92  }
93  k=k_h*data->h;
94  for(j=0;j<6;j++) {
95  double pk_h,pk_bench,pk_ccl,err;
96  double z=j+0.;
97 
98  stat=fscanf(f,"%lf",&pk_h);
99  if(stat!=1) {
100  fprintf(stderr,"Error reading file %s, line %d\n",fname,i+2);
101  exit(1);
102  }
103  pk_bench=pk_h/pow(data->h,3);
104  pk_ccl=ccl_linear_matter_power(cosmo,k,1./(1+z),&status);
105  if (status) printf("%s\n",cosmo->status_message);
106  err=fabs(pk_ccl/pk_bench-1);
108  }
109  }
110  fclose(f);
111 
112  ccl_cosmology_free(cosmo);
113 }
114 
115 CTEST2(bbks,model_1) {
116  int model=1;
117  compare_bbks(model,data);
118 }
119 
120 CTEST2(bbks,model_2) {
121  int model=2;
122  compare_bbks(model,data);
123 }
124 
125 CTEST2(bbks,model_3) {
126  int model=3;
127  compare_bbks(model,data);
128 }
double Omega_k[5]
Definition: ccl_test_bbks.c:19
double Omega_g
Definition: ccl_core.h:53
ccl_mnu_convention mnu_type
Definition: ccl_test_bbks.c:17
double w_0[5]
Definition: ccl_test_bbks.c:20
double h
Definition: ccl_test_bbks.c:11
double A_s
Definition: ccl_test_bbks.c:12
#define CTEST_SETUP(sname)
Definition: ctest.h:73
#define CTEST_DATA(sname)
Definition: ctest.h:71
double * mnu
Definition: ccl_test_bbks.c:16
double Omega_l
Definition: ccl_core.h:63
transfer_function_t transfer_function_method
Definition: ccl_config.h:111
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
double n_s
Definition: ccl_test_bbks.c:13
ccl_mnu_convention
Definition: ccl_core.h:142
double ccl_linear_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:1506
void ccl_cosmology_free(ccl_cosmology *cosmo)
Definition: ccl_core.c:829
double Neff
Definition: ccl_test_bbks.c:15
dictionary params
Definition: halomod_bm.py:27
double Omega_v[5]
Definition: ccl_test_bbks.c:18
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
static void compare_bbks(int i_model, struct bbks_data *data)
Definition: ccl_test_bbks.c:60
static double z[8]
double sigma8
Definition: ccl_core.h:62
double sigma8
Definition: ccl_test_bbks.c:14
double Omega_c
Definition: ccl_test_bbks.c:9
const ccl_configuration default_config
Definition: ccl_core.c:21
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
static int linecount(FILE *f)
Definition: ccl_test_bbks.c:48
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
#define BBKS_TOLERANCE
Definition: ccl_test_bbks.c:6
double Omega_b
Definition: ccl_test_bbks.c:10
double w_a[5]
Definition: ccl_test_bbks.c: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 CTEST2(sname, tname)
Definition: ctest.h:107
char status_message[500]
Definition: ccl_core.h:136