Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_eh.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 EH_TOLERANCE 1.0E-5
7 
8 CTEST_DATA(eh) {
9  double Omega_c;
10  double Omega_b;
11  double h;
12  double A_s;
13  double n_s;
14  double sigma8;
15  double Omega_v[1];
16  double Omega_k[1];
17  double w_0[1];
18  double w_a[1];
19  double Neff;
20  double* m_nu;
22 };
23 
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->sigma8=0.8;
30  data->n_s = 0.96;
31  data->Neff = 0.;
32  double mnuval = 0.;
33  data->m_nu= &mnuval;
34  data-> mnu_type = ccl_mnu_sum;
35 
36  double Omega_v[1]={0.7};
37  double w_0[1] = {-1.0};
38  double w_a[1] = {0.0};
39 
40  for(int i=0;i<1;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_eh(int i_model,struct eh_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],
70  data->Neff, data->m_nu, data->mnu_type,
71  data->w_0[i_model-1],data->w_a[i_model-1],
72  data->h,data->A_s,data->n_s,-1,-1,-1,-1,NULL,NULL, &status);
73  params.sigma8=data->sigma8;
74  params.Omega_g=0;
75  params.Omega_l=data->Omega_v[i_model-1];
76  ccl_cosmology * cosmo = ccl_cosmology_create(params, config);
77  ASSERT_NOT_NULL(cosmo);
78 
79  sprintf(fname,"./tests/benchmark/model%d_pk_eh.txt",i_model);
80  f=fopen(fname,"r");
81  if(f==NULL) {
82  fprintf(stderr,"Error opening file %s\n",fname);
83  exit(1);
84  }
85  nk=linecount(f)-1; rewind(f);
86 
87  rtn = fgets(str, 1024, f);
88  for(i=0;i<nk;i++) {
89  double k_h,k;
90  int stat;
91  stat=fscanf(f,"%lf",&k_h);
92  if(stat!=1) {
93  fprintf(stderr,"Error reading file %s, line %d\n",fname,i+2);
94  exit(1);
95  }
96  k=k_h*data->h;
97  for(j=0;j<1;j++) {
98  double pk_h,pk_bench,pk_ccl,err;
99  double z=2*j+0.;
100  int status=0;
101  stat=fscanf(f,"%lf",&pk_h);
102  if(stat!=1) {
103  fprintf(stderr,"Error reading file %s, line %d\n",fname,i+2);
104  exit(1);
105  }
106  pk_bench=pk_h/pow(data->h,3);
107  pk_ccl=ccl_linear_matter_power(cosmo,k,1./(1+z),&status);
108  if (status) printf("%s\n",cosmo->status_message);
109  err=fabs(pk_ccl/pk_bench-1);
111  }
112  }
113  fclose(f);
114 
115  ccl_cosmology_free(cosmo);
116 }
117 
118 CTEST2(eh,model_1) {
119  int model=1;
120  compare_eh(model,data);
121 }
static int linecount(FILE *f)
Definition: ccl_test_eh.c:48
double Omega_k[1]
Definition: ccl_test_eh.c:16
double w_0[1]
Definition: ccl_test_eh.c:17
double Omega_g
Definition: ccl_core.h:53
double n_s
Definition: ccl_test_eh.c:13
double h
Definition: ccl_test_eh.c:11
double Omega_v[1]
Definition: ccl_test_eh.c:15
#define CTEST_SETUP(sname)
Definition: ctest.h:73
double w_a[1]
Definition: ccl_test_eh.c:18
#define CTEST_DATA(sname)
Definition: ctest.h:71
double A_s
Definition: ccl_test_eh.c:12
double Omega_l
Definition: ccl_core.h:63
transfer_function_t transfer_function_method
Definition: ccl_config.h:111
double Neff
Definition: ccl_test_eh.c:19
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
double sigma8
Definition: ccl_test_eh.c:14
ccl_mnu_convention
Definition: ccl_core.h:142
static void compare_eh(int i_model, struct eh_data *data)
Definition: ccl_test_eh.c:60
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
dictionary params
Definition: halomod_bm.py:27
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
double Omega_c
Definition: ccl_test_eh.c:9
static double z[8]
double sigma8
Definition: ccl_core.h:62
double Omega_b
Definition: ccl_test_eh.c:10
double * m_nu
Definition: ccl_test_eh.c:20
const ccl_configuration default_config
Definition: ccl_core.c:21
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
ccl_mnu_convention mnu_type
Definition: ccl_test_eh.c:21
#define EH_TOLERANCE
Definition: ccl_test_eh.c:6
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