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

Go to the source code of this file.

Classes

struct  emu_nu_data
 

Macros

#define EMU_TOLERANCE   3.0E-2
 

Functions

void __attribute__ ((weak))
 
static int linecount (FILE *f)
 
static void compare_emu_nu (int i_model, struct emu_nu_data *data)
 
void __ctest_emu_nu_model_1_run (struct emu_nu_data *data)
 
void __ctest_emu_nu_model_2_run (struct emu_nu_data *data)
 
void __ctest_emu_nu_model_3_run (struct emu_nu_data *data)
 
void __ctest_emu_nu_model_4_run (struct emu_nu_data *data)
 

Variables

static struct emu_nu_data __ctest_emu_nu_data
 

Macro Definition Documentation

#define EMU_TOLERANCE   3.0E-2

Definition at line 19 of file ccl_test_emu_nu.c.

Referenced by compare_emu_nu().

Function Documentation

void __attribute__ ( (weak)  )

Definition at line 36 of file ccl_test_emu_nu.c.

References ccl_mnu_list, ccl_nu_equal, ccl_nu_masses(), ccl_test_distances::h, ccl_test_distances::n_s, ccl_test_distances::Omega_b, ccl_test_distances::Omega_c, halomod_bm::params, and ccl_test_power::sigma8.

36  {
37 
38  data->Neff = 3.04;
39  data->mnu_type = ccl_mnu_list;
40 
41  double *sigma8;
42  double *Omega_c;
43  double *Omega_b;
44  double *Omega_nu;
45  double *n_s;
46  double *h;
47  double *w_0;
48  double *w_a;
49  double *Mnu_out;
50  int status=0;
51  char fname[256],str[1024];
52  char* rtn;
53  FILE *f;
54  int i;
56 
57  sigma8=malloc(4*sizeof(double));
58  Omega_c=malloc(4*sizeof(double));
59  Omega_b=malloc(4*sizeof(double));
60  n_s=malloc(4*sizeof(double));
61  h=malloc(4*sizeof(double));
62  w_0=malloc(4*sizeof(double));
63  w_a=malloc(4*sizeof(double));
64  Omega_nu=malloc(4*sizeof(double));
65 
66  // Omeganuh2_to_mnu will output a pointer to an array of 3 neutrino masses.
67  Mnu_out=malloc(3*sizeof(double));
68 
69  //Each line of this file corresponds to the cosmological parameters for
70  //cosmologies {38,39,40,42} of the emulator set. Notice that Omega_i
71  //are big Omegas and not little omegas (Omega_i*h**2=omega_i)
72  sprintf(fname,"./tests/benchmark/emu_nu_cosmologies.txt");
73  f=fopen(fname,"r");
74  if(f==NULL) {
75  fprintf(stderr,"Error opening file %s\n",fname);
76  exit(1);
77  }
78 
79  double tmp;
80  int omnustatus=0;
81  for(int i=0;i<4;i++) {
82 
83  status=fscanf(f,"%le %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],&Omega_nu[i]);
84  if(status!=8) {
85  fprintf(stderr,"Error reading file %s, line %d\n",fname,i);
86  exit(1);
87  }
88  data->w_0[i] = w_0[i];
89  data->w_a[i] = w_a[i];
90  data->h[i] = h[i];
91  data->sigma8[i] = sigma8[i];
92  data->Omega_c[i] = Omega_c[i];
93  data->Omega_b[i] = Omega_b[i];
94  data->n_s[i] = n_s[i];
95  // Number of neutrino species is fixed to 3
96  Mnu_out = ccl_nu_masses(Omega_nu[i]*h[i]*h[i], ccl_nu_equal, 2.725, &omnustatus);
97  /*if (omnustatus){
98  printf("%s\n",cosmo->status_message);
99  exit(1);
100  }*/
101  data->mnu[i]=Mnu_out;
102  }
103  fclose(f);
104 }
double * ccl_nu_masses(double OmNuh2, ccl_neutrino_mass_splits mass_split, double T_CMB, int *status)
int * status
Definition: ccl_redshifts.c:41
dictionary params
Definition: halomod_bm.py:27
void __ctest_emu_nu_model_1_run ( struct emu_nu_data data)

Definition at line 177 of file ccl_test_emu_nu.c.

References compare_emu_nu().

177  {
178  int model=1;
179  compare_emu_nu(model,data);
180 }
static void compare_emu_nu(int i_model, struct emu_nu_data *data)
void __ctest_emu_nu_model_2_run ( struct emu_nu_data data)

Definition at line 183 of file ccl_test_emu_nu.c.

References compare_emu_nu().

183  {
184  int model=2;
185  compare_emu_nu(model,data);
186  }
static void compare_emu_nu(int i_model, struct emu_nu_data *data)
void __ctest_emu_nu_model_3_run ( struct emu_nu_data data)

Definition at line 188 of file ccl_test_emu_nu.c.

References compare_emu_nu().

188  {
189  int model=3;
190  compare_emu_nu(model,data);
191 }
static void compare_emu_nu(int i_model, struct emu_nu_data *data)
void __ctest_emu_nu_model_4_run ( struct emu_nu_data data)

Definition at line 193 of file ccl_test_emu_nu.c.

References compare_emu_nu().

193  {
194  int model=4;
195  compare_emu_nu(model,data);
196  }
static void compare_emu_nu(int i_model, struct emu_nu_data *data)
static void compare_emu_nu ( int  i_model,
struct emu_nu_data data 
)
static

Definition at line 118 of file ccl_test_emu_nu.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_nu_data::h, linecount(), ccl_configuration::matter_power_spectrum_method, emu_nu_data::mnu, emu_nu_data::mnu_type, emu_nu_data::n_s, emu_nu_data::Neff, emu_nu_data::Omega_b, emu_nu_data::Omega_c, ccl_parameters::Omega_g, ccl_parameters::Omega_l, halomod_bm::params, emu_nu_data::sigma8, ccl_cosmology::status_message, ccl_configuration::transfer_function_method, emu_nu_data::w_0, emu_nu_data::w_a, and z.

Referenced by __ctest_emu_nu_model_1_run(), __ctest_emu_nu_model_2_run(), __ctest_emu_nu_model_3_run(), and __ctest_emu_nu_model_4_run().

119 {
120  int nk,i,j;
121  int status=0;
122  char fname[256],str[1024];
123  char* rtn;
124  FILE *f;
125  int i_model_vec[4]={38,39,40,42}; //The emulator cosmologies we can compare to
126 
130 
131  //None of the current cosmologies being checked include neutrinos
132  ccl_parameters params = ccl_parameters_create(data->Omega_c[i_model-1],data->Omega_b[i_model-1],0.0,data->Neff, data->mnu[i_model-1], 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);
133  params.Omega_l=params.Omega_l+params.Omega_g;
134  params.Omega_g=0;
135  ccl_cosmology * cosmo = ccl_cosmology_create(params, config);
136  ASSERT_NOT_NULL(cosmo);
137 
138  //These files contain the smoothed power spectra with neutrinos
139  //These are obtained as follows:
140  // (1) Find the z=0 P(k) corresponding to M038. This would be column 304 of the
141  // 'yalt...' file (with column numbering starting in 1).
142  // (2) This column has log10(Delta_cb^2/k^1.5), so convert accordingly to Delta_cb^2.
143  // (3) Take the power spectrum in the file ‘pk_lin...' for M038 (second column for P(k) in Mpc^3)
144  // and convert to Delta_nu^2 by multiplying by k^3/(2pi^2).
145  // (4) Add to obtain Delta_tot=(sqrt(Delta_nu)+sqrt(Delta_cb))^2.
146  // (5) Convert back to P(k)
147  sprintf(fname,"./tests/benchmark/emu_nu_smooth_pk_M%d.txt",i_model_vec[i_model-1]);
148  f=fopen(fname,"r");
149  if(f==NULL) {
150  fprintf(stderr,"Error opening file %s\n",fname);
151  exit(1);
152  }
153  nk=linecount(f)-1; rewind(f);
154 
155  double k=0.,pk_bench=0.,pk_ccl,err;
156  double z=0.; //Other redshift checks are possible but not currently implemented
157  int stat=0;
158 
159  for(i=0;i<nk;i++) {
160  stat=fscanf(f,"%le %le\n",&k, &pk_bench);
161  if(stat!=2) {
162  fprintf(stderr,"Error reading file %s, line %d\n",fname,i);
163  exit(1);
164  }
165  pk_ccl=ccl_nonlin_matter_power(cosmo,k,1./(1+z),&status);
166  if (status) printf("%s\n",cosmo->status_message);
167  err=fabs(pk_ccl/pk_bench-1);
168  //printf("%le %le %le %le\n",k,pk_ccl,pk_bench,err);
170  }
171 
172  fclose(f);
173 
174  ccl_cosmology_free(cosmo);
175 }
double Omega_g
Definition: ccl_core.h:53
#define EMU_TOLERANCE
double w_a[4]
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 * mnu[4]
ccl_mnu_convention mnu_type
double w_0[4]
double Omega_l
Definition: ccl_core.h:63
double Omega_b[4]
transfer_function_t transfer_function_method
Definition: ccl_config.h:111
int * status
Definition: ccl_redshifts.c:41
static int linecount(FILE *f)
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
double h[4]
void ccl_cosmology_free(ccl_cosmology *cosmo)
Definition: ccl_core.c:829
double n_s[4]
dictionary params
Definition: halomod_bm.py:27
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
static double z[8]
const ccl_configuration default_config
Definition: ccl_core.c:21
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
double sigma8[4]
double Omega_c[4]
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 106 of file ccl_test_emu_nu.c.

Referenced by compare_emu_nu().

107 {
109  // Counts #lines from file
110  int i0=0;
111  char ch[1000];
112  while((fgets(ch,sizeof(ch),f))!=NULL) {
113  i0++;
114  }
115  return i0;
116 }

Variable Documentation

static struct emu_nu_data __ctest_emu_nu_data
static

Definition at line 177 of file ccl_test_emu_nu.c.