Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_test_sigmaM.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 SIGMAM_TOLERANCE 3.0E-5
7 
8 CTEST_DATA(sigmam) {
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(sigmam) {
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->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_sigmam(int i_model,struct sigmam_data * data)
61 {
62  int nm,i;
63  char fname[256],str[1024];
64  char* rtn;
65  FILE *f;
66  int status=0;
69  ccl_parameters params = ccl_parameters_create(data->Omega_c,data->Omega_b,data->Omega_k[i_model-1],
70  data->Neff, data->mnu, data->mnu_type,
71  data->w_0[i_model-1],data->w_a[i_model-1],data->h,
72  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 
77  ccl_cosmology * cosmo = ccl_cosmology_create(params, config);
78  ASSERT_NOT_NULL(cosmo);
79 
80  sprintf(fname,"./tests/benchmark/model%d_sm.txt",i_model);
81  f=fopen(fname,"r");
82  if(f==NULL) {
83  fprintf(stderr,"Error opening file %s\n",fname);
84  exit(1);
85  }
86  nm=linecount(f)-1; rewind(f);
87 
88  rtn = fgets(str, 1024, f);
89  for(i=0;i<nm;i++) {
90  double m,m_h,sm_bench,sm_h,err;
91  int stat;
92  stat=fscanf(f,"%lf %lf",&m_h,&sm_bench);
93  if(stat!=2) {
94  fprintf(stderr,"Error reading file %s, line %d\n",fname,i+2);
95  exit(1);
96  }
97  m=m_h/data->h;
98  sm_h=ccl_sigmaM(cosmo,m,1.,&status);
99  if (status) printf("%s\n",cosmo->status_message);
100  err=sm_h/sm_bench-1;
102  }
103  fclose(f);
104 
105  free(cosmo);
106 }
107 
108 CTEST2(sigmam,model_1) {
109  int model=1;
110  compare_sigmam(model,data);
111 }
112 
113 CTEST2(sigmam,model_2) {
114  int model=2;
115  compare_sigmam(model,data);
116 }
117 
118 CTEST2(sigmam,model_3) {
119  int model=3;
120  compare_sigmam(model,data);
121 }
double Omega_g
Definition: ccl_core.h:53
double * mnu
#define CTEST_SETUP(sname)
Definition: ctest.h:73
#define CTEST_DATA(sname)
Definition: ctest.h:71
#define SIGMAM_TOLERANCE
double Omega_v[5]
double Omega_l
Definition: ccl_core.h:63
double Omega_k[5]
double ccl_sigmaM(ccl_cosmology *cosmo, double smooth_mass, double a, int *status)
Definition: ccl_massfunc.c:624
transfer_function_t transfer_function_method
Definition: ccl_config.h:111
double w_0[5]
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
double Omega_c
double w_a[5]
ccl_mnu_convention
Definition: ccl_core.h:142
dictionary params
Definition: halomod_bm.py:27
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
double sigma8
Definition: ccl_core.h:62
static int linecount(FILE *f)
const ccl_configuration default_config
Definition: ccl_core.c:21
static int m[2]
Definition: ccl_emu17.c:25
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
static void compare_sigmam(int i_model, struct sigmam_data *data)
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
ccl_mnu_convention mnu_type