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

Go to the source code of this file.

Classes

struct  bcm_data
 

Macros

#define BCM_TOLERANCE   1e-4
 

Functions

void __attribute__ ((weak))
 
static int linecount (FILE *f)
 
static void compare_bcm (int i_model, struct bcm_data *data)
 
void __ctest_bcm_model_1_run (struct bcm_data *data)
 

Variables

static struct bcm_data __ctest_bcm_data
 

Macro Definition Documentation

#define BCM_TOLERANCE   1e-4

Definition at line 6 of file ccl_test_bcm.c.

Referenced by compare_bcm().

Function Documentation

void __attribute__ ( (weak)  )

Definition at line 24 of file ccl_test_bcm.c.

References ccl_mnu_sum.

24  {
25  data->Omega_c = 0.25;
26  data->Omega_b = 0.05;
27  data->h = 0.7;
28  data->A_s = 2.2e-9;
29  data->n_s = 0.96;
30  data->Neff = 3.046;
31  double mnuval = 0.;
32  data->m_nu= &mnuval;
33  data-> mnu_type = ccl_mnu_sum;
34 
35  double Omega_v[1]={0.7};
36  double w_0[1] = {-1.0};
37  double w_a[1] = {0.0};
38 
39  for(int i=0;i<1;i++) {
40  data->Omega_v[i] = Omega_v[i];
41  data->w_0[i] = w_0[i];
42  data->w_a[i] = w_a[i];
43  data->Omega_k[i] = 1.0 - data->Omega_c - data->Omega_b - data->Omega_v[i];
44  }
45 }
void __ctest_bcm_model_1_run ( struct bcm_data data)

Definition at line 150 of file ccl_test_bcm.c.

References compare_bcm().

150  {
151  int model=1;
152  compare_bcm(model,data);
153 }
static void compare_bcm(int i_model, struct bcm_data *data)
Definition: ccl_test_bcm.c:59
static void compare_bcm ( int  i_model,
struct bcm_data data 
)
static

Definition at line 59 of file ccl_test_bcm.c.

References bcm_data::A_s, ASSERT_DBL_NEAR_TOL, ASSERT_NOT_NULL, ccl_configuration::baryons_power_spectrum_method, BCM_TOLERANCE, ccl_bcm, ccl_bcm_model_fka(), ccl_cosmology_create(), ccl_cosmology_free(), ccl_nonlin_matter_power(), ccl_parameters_create(), cl_cmbl_bm::cosmo, default_config, bcm_data::h, linecount(), bcm_data::m_nu, bcm_data::mnu_type, bcm_data::n_s, bcm_data::Neff, bcm_data::Omega_b, bcm_data::Omega_c, ccl_parameters::Omega_g, bcm_data::Omega_k, ccl_parameters::Omega_l, halomod_bm::params, ccl_cosmology::status_message, bcm_data::w_0, and bcm_data::w_a.

Referenced by __ctest_bcm_model_1_run().

60 {
61  int nk,i,j;
62  int status =0;
63  char fname[256],str[1024];
64  char fname2[256];
65  char* rtn;
66  FILE *f,*f2;
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,14,-1,-1,-1,NULL,NULL, &status);
73 
74  params.Omega_l=params.Omega_l+params.Omega_g;
75  params.Omega_g=0;
76  ccl_cosmology * cosmo = ccl_cosmology_create(params, config);
77  ASSERT_NOT_NULL(cosmo);
78  ccl_configuration config_nobar = default_config;
79  ccl_parameters params_nobar = ccl_parameters_create(data->Omega_c,data->Omega_b,data->Omega_k[i_model-1],
80  data->Neff, data->m_nu, data->mnu_type,
81  data->w_0[i_model-1],data->w_a[i_model-1],
82  data->h,data->A_s,data->n_s,-1,-1,-1,-1,NULL,NULL, &status);
83  //params.sigma_8=data->sigma_8;
84  params_nobar.Omega_l=params_nobar.Omega_l+params_nobar.Omega_g;
85  params_nobar.Omega_g=0;
86  ccl_cosmology * cosmo_nobar = ccl_cosmology_create(params_nobar, config_nobar);
87  ASSERT_NOT_NULL(cosmo_nobar);
88 
89  sprintf(fname,"./tests/benchmark/bcm/w_baryonspk_nl.dat");
90  f=fopen(fname,"r");
91  if(f==NULL) {
92  fprintf(stderr,"Error opening file %s\n",fname);
93  exit(1);
94  }
95  sprintf(fname2,"./tests/benchmark/bcm/wo_baryonspk_nl.dat");
96  f2=fopen(fname2,"r");
97  if(f2==NULL) {
98  fprintf(stderr,"Error opening file %s\n",fname2);
99  exit(1);
100  }
101  nk=linecount(f)-1; rewind(f);
102 
103  //Skip first 4 lines
104  rtn = fgets(str, 1024, f);
105  rtn = fgets(str, 1024, f);
106  rtn = fgets(str, 1024, f);
107  rtn = fgets(str, 1024, f);
108 
109  rtn = fgets(str, 1024, f2);
110  rtn = fgets(str, 1024, f2);
111  rtn = fgets(str, 1024, f2);
112  rtn = fgets(str, 1024, f2);
113 
114  for(i=0;i<nk-4;i++) {
115  double k_h,k;
116  int stat;
117  double psbar,psnobar,fbcm_bench,err;
118  double psbar_bench,psnobar_bench;
119  stat=fscanf(f,"%le %le",&k_h,&psbar);
120  if(stat!=2) {
121  fprintf(stderr,"Error reading file %s, line %d\n",fname,i+5);
122  exit(1);
123  }
124  stat=fscanf(f2,"%*le %le",&psnobar);
125  if(stat!=1) {
126  fprintf(stderr,"Error reading file %s, line %d\n",fname2,i+5);
127  exit(1);
128  }
129  k=k_h*data->h;
130  //Check baryonic correction directly
131  fbcm_bench=ccl_bcm_model_fka(cosmo,k,1.,&status);
132  if (status) printf("%s\n",cosmo->status_message);
133  err=fabs(psbar/psnobar/fbcm_bench-1);
135  //And check the ratio between power spectra
136  psbar_bench=ccl_nonlin_matter_power(cosmo,k,1.,&status);
137  if (status) printf("%s\n",cosmo->status_message);
138  psnobar_bench=ccl_nonlin_matter_power(cosmo_nobar,k,1.,&status);
139  if (status) printf("%s\n",cosmo_nobar->status_message);
140  err=fabs(psbar/psnobar/(psbar_bench/psnobar_bench)-1);
142 
143  }
144  fclose(f);
145  fclose(f2);
146 
147  ccl_cosmology_free(cosmo);
148 }
double Omega_g
Definition: ccl_core.h:53
double Omega_k[1]
Definition: ccl_test_bcm.c:16
double A_s
Definition: ccl_test_bcm.c:12
double ccl_nonlin_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:1562
static int linecount(FILE *f)
Definition: ccl_test_bcm.c:47
double Neff
Definition: ccl_test_bcm.c:19
double Omega_l
Definition: ccl_core.h:63
#define BCM_TOLERANCE
Definition: ccl_test_bcm.c:6
double n_s
Definition: ccl_test_bcm.c:13
double * m_nu
Definition: ccl_test_bcm.c:20
int * status
Definition: ccl_redshifts.c:41
double w_0[1]
Definition: ccl_test_bcm.c:17
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
double Omega_c
Definition: ccl_test_bcm.c:9
double ccl_bcm_model_fka(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:574
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_b
Definition: ccl_test_bcm.c:10
double h
Definition: ccl_test_bcm.c:11
baryons_power_spectrum_t baryons_power_spectrum_method
Definition: ccl_config.h:113
double w_a[1]
Definition: ccl_test_bcm.c:18
const ccl_configuration default_config
Definition: ccl_core.c:21
ccl_mnu_convention mnu_type
Definition: ccl_test_bcm.c:21
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
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 47 of file ccl_test_bcm.c.

Referenced by compare_bcm().

48 {
50  // Counts #lines from file
51  int i0=0;
52  char ch[1000];
53  while((fgets(ch,sizeof(ch),f))!=NULL) {
54  i0++;
55  }
56  return i0;
57 }

Variable Documentation

struct bcm_data __ctest_bcm_data
static

Definition at line 150 of file ccl_test_bcm.c.