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

Go to the source code of this file.

Classes

struct  emu_data
 

Macros

#define EMU_TOLERANCE   3.0E-2
 

Functions

void __attribute__ ((weak))
 
static int linecount (FILE *f)
 
static void compare_emu (int i_model, struct emu_data *data)
 
void __ctest_emu_model_1_run (struct emu_data *data)
 
void __ctest_emu_model_2_run (struct emu_data *data)
 
void __ctest_emu_model_4_run (struct emu_data *data)
 
void __ctest_emu_model_6_run (struct emu_data *data)
 

Variables

static struct emu_data __ctest_emu_data
 

Macro Definition Documentation

#define EMU_TOLERANCE   3.0E-2

Definition at line 19 of file ccl_test_emu.c.

Referenced by compare_emu().

Function Documentation

void __attribute__ ( (weak)  )

Definition at line 36 of file ccl_test_emu.c.

References ccl_mnu_sum, ccl_test_distances::h, ccl_test_distances::n_s, ccl_test_distances::Omega_b, ccl_test_distances::Omega_c, and ccl_test_power::sigma8.

36  {
37 
38  //This test corresponds to emulator cosmologies
39  //without neutrinos. Other cosmologies are
40  //implemented in ccl_test_emu_nu.c
41  data->Neff=3.04;
42  double mnuval = 0.;
43  data->mnu=&mnuval;
44  data->mnu_type=ccl_mnu_sum;
45 
46  double *sigma8;
47  double *Omega_c;
48  double *Omega_b;
49  double *n_s;
50  double *h;
51  double *w_0;
52  double *w_a;
53  int status=0;
54  char fname[256],str[1024];
55  char* rtn;
56  FILE *f;
57  int i;
58  sigma8=malloc(6*sizeof(double));
59  Omega_c=malloc(6*sizeof(double));
60  Omega_b=malloc(6*sizeof(double));
61  n_s=malloc(6*sizeof(double));
62  h=malloc(6*sizeof(double));
63  w_0=malloc(6*sizeof(double));
64  w_a=malloc(6*sizeof(double));
65 
66  //Each line of this file corresponds to the cosmological parameters for
67  //cosmologies {1,3,5,6,8,10} of the emulator set. Notice that Omega_i
68  //are big Omegas and not little omegas (Omega_i*h**2=omega_i)
69  sprintf(fname,"./tests/benchmark/emu_cosmologies.txt");
70  f=fopen(fname,"r");
71  if(f==NULL) {
72  fprintf(stderr,"Error opening file %s\n",fname);
73  exit(1);
74  }
75 
76  double tmp;
77  for(int i=0;i<6;i++) {
78 
79  status=fscanf(f,"%le %le %le %le %le %le %le\n",&Omega_c[i],&Omega_b[i],&h[i],&sigma8[i],&n_s[i],&w_0[i],&w_a[i]);
80  if(status!=7) {
81  fprintf(stderr,"Error reading file %s, line %d\n",fname,i);
82  exit(1);
83  }
84  data->w_0[i] = w_0[i];
85  data->w_a[i] = w_a[i];
86  data->h[i] = h[i];
87  data->sigma8[i] = sigma8[i];
88  data->Omega_c[i] = Omega_c[i];
89  data->Omega_b[i] = Omega_b[i];
90  data->n_s[i] = n_s[i];
91  }
92  fclose(f);
93 }
int * status
Definition: ccl_redshifts.c:41
void __ctest_emu_model_1_run ( struct emu_data data)

Definition at line 160 of file ccl_test_emu.c.

References compare_emu().

160  {
161  int model=1;
162  compare_emu(model,data);
163 }
static void compare_emu(int i_model, struct emu_data *data)
Definition: ccl_test_emu.c:107
void __ctest_emu_model_2_run ( struct emu_data data)

Definition at line 166 of file ccl_test_emu.c.

References compare_emu().

166  {
167  int model=2;
168  compare_emu(model,data);
169 }
static void compare_emu(int i_model, struct emu_data *data)
Definition: ccl_test_emu.c:107
void __ctest_emu_model_4_run ( struct emu_data data)

Definition at line 177 of file ccl_test_emu.c.

References compare_emu().

177  {
178  int model=4;
179  compare_emu(model,data);
180 }
static void compare_emu(int i_model, struct emu_data *data)
Definition: ccl_test_emu.c:107
void __ctest_emu_model_6_run ( struct emu_data data)

Definition at line 188 of file ccl_test_emu.c.

References compare_emu().

188  {
189  int model=6;
190  compare_emu(model,data);
191 }
static void compare_emu(int i_model, struct emu_data *data)
Definition: ccl_test_emu.c:107
static void compare_emu ( int  i_model,
struct emu_data data 
)
static

Definition at line 107 of file ccl_test_emu.c.

References ASSERT_DBL_NEAR_TOL, ASSERT_NOT_NULL, ccl_cosmology_create(), ccl_cosmology_free(), ccl_emu, ccl_emulator, ccl_nonlin_matter_power(), ccl_parameters_create(), cl_cmbl_bm::cosmo, default_config, EMU_TOLERANCE, emu_data::h, linecount(), ccl_configuration::matter_power_spectrum_method, emu_data::mnu, emu_data::mnu_type, emu_data::n_s, emu_data::Neff, emu_data::Omega_b, emu_data::Omega_c, ccl_parameters::Omega_g, ccl_parameters::Omega_l, halomod_bm::params, emu_data::sigma8, ccl_cosmology::status_message, ccl_configuration::transfer_function_method, emu_data::w_0, emu_data::w_a, and z.

Referenced by __ctest_emu_model_1_run(), __ctest_emu_model_2_run(), __ctest_emu_model_4_run(), and __ctest_emu_model_6_run().

108 {
109  int nk,i,j;
110  int status=0;
111  char fname[256],str[1024];
112  char* rtn;
113  FILE *f;
114  int i_model_vec[6]={1,3,5,6,8,10};
115  //The emulator cosmologies we can compare to
116  //without CLASS failing due to w(z) crossing -1.
117 
121 
122  //None of the current cosmologies being checked include neutrinos
123  ccl_parameters params = ccl_parameters_create(data->Omega_c[i_model-1],data->Omega_b[i_model-1],0.0,data->Neff, data->mnu, data->mnu_type, data->w_0[i_model-1],data->w_a[i_model-1],data->h[i_model-1],data->sigma8[i_model-1],data->n_s[i_model-1],-1,-1,-1,-1,NULL,NULL, &status);
124  params.Omega_l=params.Omega_l+params.Omega_g;
125  params.Omega_g=0;
126  ccl_cosmology * cosmo = ccl_cosmology_create(params, config);
127  ASSERT_NOT_NULL(cosmo);
128  //Each of these files has the smoothed simulated power spectrum for
129  //the corresponding cosmology, kindly provided by E. Lawrence.
130  sprintf(fname,"./tests/benchmark/emu_smooth_pk_M%d.txt",i_model_vec[i_model-1]);
131  f=fopen(fname,"r");
132  if(f==NULL) {
133  fprintf(stderr,"Error opening file %s\n",fname);
134  exit(1);
135  }
136  nk=linecount(f)-1; rewind(f);
137 
138  double k=0.,pk_bench=0.,pk_ccl,err;
139  double z=0.; //Other redshift checks are possible but not currently implemented
140  int stat=0;
141 
142  for(i=0;i<nk;i++) {
143  stat=fscanf(f,"%le %le\n",&k, &pk_bench);
144  if(stat!=2) {
145  fprintf(stderr,"Error reading file %s, line %d\n",fname,i);
146  exit(1);
147  }
148  pk_ccl=ccl_nonlin_matter_power(cosmo,k,1./(1+z),&status);
149  if (status) printf("%s\n",cosmo->status_message);
150  err=fabs(pk_ccl/pk_bench-1);
152  }
153 
154  fclose(f);
155 
156  ccl_cosmology_free(cosmo);
157 }
double w_0[6]
Definition: ccl_test_emu.c:32
double Omega_b[6]
Definition: ccl_test_emu.c:29
double Omega_g
Definition: ccl_core.h:53
double Omega_c[6]
Definition: ccl_test_emu.c:28
double * mnu
Definition: ccl_test_emu.c:25
matter_power_spectrum_t matter_power_spectrum_method
Definition: ccl_config.h:112
double ccl_nonlin_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:1562
double h[6]
Definition: ccl_test_emu.c:31
double Omega_l
Definition: ccl_core.h:63
double sigma8[6]
Definition: ccl_test_emu.c:27
double Neff
Definition: ccl_test_emu.c:24
transfer_function_t transfer_function_method
Definition: ccl_config.h:111
int * status
Definition: ccl_redshifts.c:41
static int linecount(FILE *f)
Definition: ccl_test_emu.c:95
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
double w_a[6]
Definition: ccl_test_emu.c:33
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
static double z[8]
#define EMU_TOLERANCE
Definition: ccl_test_emu.c:19
double n_s[6]
Definition: ccl_test_emu.c:30
const ccl_configuration default_config
Definition: ccl_core.c:21
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
ccl_mnu_convention mnu_type
Definition: ccl_test_emu.c:26
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
char status_message[500]
Definition: ccl_core.h:136
static int linecount ( FILE *  f)
static

Definition at line 95 of file ccl_test_emu.c.

Referenced by compare_emu().

96 {
98  // Counts #lines from file
99  int i0=0;
100  char ch[1000];
101  while((fgets(ch,sizeof(ch),f))!=NULL) {
102  i0++;
103  }
104  return i0;
105 }

Variable Documentation

static struct emu_data __ctest_emu_data
static

Definition at line 160 of file ccl_test_emu.c.