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

Go to the source code of this file.

Classes

struct  bbks_data
 

Macros

#define BBKS_TOLERANCE   1.0E-5
 

Functions

void __attribute__ ((weak))
 
static int linecount (FILE *f)
 
static void compare_bbks (int i_model, struct bbks_data *data)
 
void __ctest_bbks_model_1_run (struct bbks_data *data)
 
void __ctest_bbks_model_2_run (struct bbks_data *data)
 
void __ctest_bbks_model_3_run (struct bbks_data *data)
 

Variables

static struct bbks_data __ctest_bbks_data
 

Macro Definition Documentation

#define BBKS_TOLERANCE   1.0E-5

Definition at line 6 of file ccl_test_bbks.c.

Referenced by compare_bbks().

Function Documentation

void __attribute__ ( (weak)  )

Definition at line 24 of file ccl_test_bbks.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.1e-9;
29  data->n_s = 0.96;
30  data->sigma8=0.8;
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 }
void __ctest_bbks_model_1_run ( struct bbks_data data)

Definition at line 115 of file ccl_test_bbks.c.

References compare_bbks().

115  {
116  int model=1;
117  compare_bbks(model,data);
118 }
static void compare_bbks(int i_model, struct bbks_data *data)
Definition: ccl_test_bbks.c:60
void __ctest_bbks_model_2_run ( struct bbks_data data)

Definition at line 120 of file ccl_test_bbks.c.

References compare_bbks().

120  {
121  int model=2;
122  compare_bbks(model,data);
123 }
static void compare_bbks(int i_model, struct bbks_data *data)
Definition: ccl_test_bbks.c:60
void __ctest_bbks_model_3_run ( struct bbks_data data)

Definition at line 125 of file ccl_test_bbks.c.

References compare_bbks().

125  {
126  int model=3;
127  compare_bbks(model,data);
128 }
static void compare_bbks(int i_model, struct bbks_data *data)
Definition: ccl_test_bbks.c:60
static void compare_bbks ( int  i_model,
struct bbks_data data 
)
static

Definition at line 60 of file ccl_test_bbks.c.

References bbks_data::A_s, ASSERT_DBL_NEAR_TOL, ASSERT_NOT_NULL, BBKS_TOLERANCE, ccl_bbks, ccl_cosmology_create(), ccl_cosmology_free(), ccl_linear_matter_power(), ccl_parameters_create(), cl_cmbl_bm::cosmo, default_config, bbks_data::h, linecount(), bbks_data::mnu, bbks_data::mnu_type, bbks_data::n_s, bbks_data::Neff, bbks_data::Omega_b, bbks_data::Omega_c, ccl_parameters::Omega_g, bbks_data::Omega_k, ccl_parameters::Omega_l, bbks_data::Omega_v, halomod_bm::params, pow(), bbks_data::sigma8, ccl_parameters::sigma8, ccl_cosmology::status_message, ccl_configuration::transfer_function_method, bbks_data::w_0, bbks_data::w_a, and z.

Referenced by __ctest_bbks_model_1_run(), __ctest_bbks_model_2_run(), and __ctest_bbks_model_3_run().

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],data->Neff, data->mnu,data->mnu_type, data->w_0[i_model-1],data->w_a[i_model-1],data->h,data->A_s,data->n_s,-1,-1,-1,-1,NULL,NULL, &status);
70  params.Omega_g=0;
71  params.Omega_l=data->Omega_v[i_model-1];
72  params.sigma8=data->sigma8;
73  ccl_cosmology * cosmo = ccl_cosmology_create(params, config);
74  ASSERT_NOT_NULL(cosmo);
75 
76  sprintf(fname,"./tests/benchmark/model%d_pk.txt",i_model);
77  f=fopen(fname,"r");
78  if(f==NULL) {
79  fprintf(stderr,"Error opening file %s\n",fname);
80  exit(1);
81  }
82  nk=linecount(f)-1; rewind(f);
83 
84  rtn = fgets(str, 1024, f);
85  for(i=0;i<nk;i++) {
86  double k_h,k;
87  int stat;
88  stat=fscanf(f,"%lf",&k_h);
89  if(stat!=1) {
90  fprintf(stderr,"Error reading file %s, line %d\n",fname,i+2);
91  exit(1);
92  }
93  k=k_h*data->h;
94  for(j=0;j<6;j++) {
95  double pk_h,pk_bench,pk_ccl,err;
96  double z=j+0.;
97 
98  stat=fscanf(f,"%lf",&pk_h);
99  if(stat!=1) {
100  fprintf(stderr,"Error reading file %s, line %d\n",fname,i+2);
101  exit(1);
102  }
103  pk_bench=pk_h/pow(data->h,3);
104  pk_ccl=ccl_linear_matter_power(cosmo,k,1./(1+z),&status);
105  if (status) printf("%s\n",cosmo->status_message);
106  err=fabs(pk_ccl/pk_bench-1);
108  }
109  }
110  fclose(f);
111 
112  ccl_cosmology_free(cosmo);
113 }
double Omega_k[5]
Definition: ccl_test_bbks.c:19
double Omega_g
Definition: ccl_core.h:53
ccl_mnu_convention mnu_type
Definition: ccl_test_bbks.c:17
double w_0[5]
Definition: ccl_test_bbks.c:20
double h
Definition: ccl_test_bbks.c:11
double A_s
Definition: ccl_test_bbks.c:12
double * mnu
Definition: ccl_test_bbks.c:16
double Omega_l
Definition: ccl_core.h:63
transfer_function_t transfer_function_method
Definition: ccl_config.h:111
int * status
Definition: ccl_redshifts.c:41
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
double n_s
Definition: ccl_test_bbks.c:13
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
double Neff
Definition: ccl_test_bbks.c:15
dictionary params
Definition: halomod_bm.py:27
double Omega_v[5]
Definition: ccl_test_bbks.c:18
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
static double z[8]
double sigma8
Definition: ccl_core.h:62
double sigma8
Definition: ccl_test_bbks.c:14
double Omega_c
Definition: ccl_test_bbks.c:9
const ccl_configuration default_config
Definition: ccl_core.c:21
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
static int linecount(FILE *f)
Definition: ccl_test_bbks.c:48
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
#define BBKS_TOLERANCE
Definition: ccl_test_bbks.c:6
double Omega_b
Definition: ccl_test_bbks.c:10
double w_a[5]
Definition: ccl_test_bbks.c:21
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 48 of file ccl_test_bbks.c.

Referenced by compare_bbks().

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 }

Variable Documentation

static struct bbks_data __ctest_bbks_data
static

Definition at line 115 of file ccl_test_bbks.c.