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

Go to the source code of this file.

Classes

struct  massfunc_data
 

Macros

#define SIGMA_TOLERANCE   3e-5
 
#define INVSIGMA_TOLERANCE   1e-3
 
#define MASSFUNC_TOLERANCE   5e-5
 

Functions

static void read_massfunc_test_file (double mass[13], double massfunc[3][13])
 
void __attribute__ ((weak))
 
static void compare_massfunc (int model, struct massfunc_data *data)
 
void __ctest_massfunc_model_1_run (struct massfunc_data *data)
 

Variables

static struct massfunc_data __ctest_massfunc_data
 

Macro Definition Documentation

#define INVSIGMA_TOLERANCE   1e-3

Definition at line 9 of file ccl_test_massfunc.c.

Referenced by compare_massfunc().

#define MASSFUNC_TOLERANCE   5e-5

Definition at line 10 of file ccl_test_massfunc.c.

Referenced by compare_massfunc().

#define SIGMA_TOLERANCE   3e-5

Definition at line 8 of file ccl_test_massfunc.c.

Referenced by compare_massfunc().

Function Documentation

void __attribute__ ( (weak)  )

Definition at line 53 of file ccl_test_massfunc.c.

References ccl_mnu_sum, and read_massfunc_test_file().

53  {
54  // only single model at tihs point
55  data->Omega_c = 0.25;
56  data->Omega_b = 0.05;
57  data->h = 0.7;
58  data->A_s = 2.1e-9;
59  data->n_s = 0.96;
60  data->sigma8 = 0.8;
61  data->Neff=0;
62  double mnuval = 0.;
63  data->mnu=&mnuval;
64  data->mnu_type = ccl_mnu_sum;
65 
66  double Omega_v[1] = { 0.7 };
67  double w_0[1] = {-1.0 };
68  double w_a[1] = { 0.0 };
69  for (int i=0; i<1; i++) {
70  data->Omega_v[i] = Omega_v[i];
71  data->w_0[i] = w_0[i];
72  data->w_a[i]= w_a[i];
73  data->Omega_k[i] = 1.0 - data->Omega_c - data->Omega_b - data->Omega_v[i];
74  }
75 
76  // read the file of benchmark data
77  read_massfunc_test_file(data->mass, data->massfunc);
78 }
static void read_massfunc_test_file(double mass[13], double massfunc[3][13])
void __ctest_massfunc_model_1_run ( struct massfunc_data data)

Definition at line 130 of file ccl_test_massfunc.c.

References compare_massfunc().

130  {
131  int model = 0;
132  compare_massfunc(model, data);
133 }
static void compare_massfunc(int model, struct massfunc_data *data)
static void compare_massfunc ( int  model,
struct massfunc_data data 
)
static

Definition at line 80 of file ccl_test_massfunc.c.

References massfunc_data::A_s, ASSERT_DBL_NEAR_TOL, ASSERT_NOT_NULL, ccl_bbks, ccl_cosmology_create(), ccl_massfunc(), ccl_parameters_create(), ccl_sigmaM(), ccl_tinker, cl_cmbl_bm::cosmo, default_config, massfunc_data::h, ccl_parameters::h, INVSIGMA_TOLERANCE, ccl_configuration::mass_function_method, massfunc_data::massfunc, MASSFUNC_TOLERANCE, massfunc_data::mnu, massfunc_data::n_s, massfunc_data::Neff, massfunc_data::Omega_b, massfunc_data::Omega_c, ccl_parameters::Omega_g, massfunc_data::Omega_k, ccl_parameters::Omega_l, ccl_parameters::Omega_m, massfunc_data::Omega_v, halomod_bm::params, ccl_cosmology::params, pow(), RHO_CRITICAL, massfunc_data::sigma8, ccl_parameters::sigma8, SIGMA_TOLERANCE, ccl_configuration::transfer_function_method, massfunc_data::w_0, and massfunc_data::w_a.

Referenced by __ctest_massfunc_model_1_run().

81 {
82  int stat = 0;
83  int* status = &stat;
84 
86  data->Neff, data->mnu, data-> mnu_type, data->w_0[model],
87  data->w_a[model], data->h,data->A_s, data->n_s,
88  -1, -1, -1, -1, NULL, NULL, status);
89 
90  params.sigma8 = data->sigma8;
91  params.Omega_g=0.;
92  params.Omega_l=data->Omega_v[model];
95  // test file generated using tinker 2008 currently
97  ccl_cosmology * cosmo = ccl_cosmology_create(params, config);
98 
99  ASSERT_NOT_NULL(cosmo);
100 
101  double a = 1.0;
102  double logmass = 10;
103  double odelta = 200;
104  double rho_m = RHO_CRITICAL*cosmo->params.Omega_m*cosmo->params.h*cosmo->params.h;
105 
106  // compare to benchmark data
107  for (int j=0; j<13; j++) {
108  double mass = pow(10,logmass);
109  double sigma_j = ccl_sigmaM(cosmo, mass, a, status);
110  double loginvsigma_j = log10(1./sigma_j);
111  double logmassfunc_j = log10(ccl_massfunc(cosmo, mass, a, odelta, status)*mass/(rho_m*log(10.)));
112 
113  double absolute_tolerance = SIGMA_TOLERANCE*data->massfunc[0][j];
114  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
115  ASSERT_DBL_NEAR_TOL(data->massfunc[0][j], sigma_j, absolute_tolerance);
116 
117  absolute_tolerance = INVSIGMA_TOLERANCE*fabs(data->massfunc[1][j]);
118  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
119  ASSERT_DBL_NEAR_TOL(fabs(data->massfunc[1][j]), fabs(loginvsigma_j), absolute_tolerance);
120 
121  absolute_tolerance = MASSFUNC_TOLERANCE*fabs(data->massfunc[2][j]);
122  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
123  ASSERT_DBL_NEAR_TOL(fabs(data->massfunc[2][j]), fabs(logmassfunc_j), absolute_tolerance);
124 
125  logmass += 0.5;
126  }
127  free(cosmo);
128 }
double Omega_g
Definition: ccl_core.h:53
ccl_parameters params
Definition: ccl_core.h:124
double ccl_massfunc(ccl_cosmology *cosmo, double smooth_mass, double a, double odelta, int *status)
Definition: ccl_massfunc.c:562
double h
Definition: ccl_core.h:33
double Omega_l
Definition: ccl_core.h:63
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
#define MASSFUNC_TOLERANCE
int * status
Definition: ccl_redshifts.c:41
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
double massfunc[3][13]
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
mass_function_t mass_function_method
Definition: ccl_config.h:114
const ccl_configuration default_config
Definition: ccl_core.c:21
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
#define SIGMA_TOLERANCE
#define INVSIGMA_TOLERANCE
double Omega_m
Definition: ccl_core.h:21
#define RHO_CRITICAL
Definition: ccl_constants.h:61
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
static void read_massfunc_test_file ( double  mass[13],
double  massfunc[3][13] 
)
static

Definition at line 31 of file ccl_test_massfunc.c.

References ASSERT_EQUAL, ASSERT_NOT_NULL, and Catch::Matchers::Vector::Detail::count().

Referenced by __attribute__().

32 {
33  // Masses are in Msun/h
34  FILE * f = fopen("./tests/benchmark/model1_hmf.txt", "r");
35  ASSERT_NOT_NULL(f);
36 
37  // Ignore header line
38  char str[1024];
39  char* rtn;
40  rtn = fgets(str, 1024, f);
41 
42  // file is in fixed format - logmass, sigma, invsigma, and hmf, w/ 13 rows
43  for (int i=0; i<13; i++) {
44  int count = fscanf(f, "%le %le %le %le\n", &mass[i],
45  &massfunc[0][i], &massfunc[1][i], &massfunc[2][i]);
46  // Check that all the stuff in the benchmark is there
47  ASSERT_EQUAL(4, count);
48  }
49  fclose(f);
50 }
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2747
#define ASSERT_EQUAL(exp, real)
Definition: ctest.h:121
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139

Variable Documentation

struct massfunc_data __ctest_massfunc_data
static

Definition at line 130 of file ccl_test_massfunc.c.