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

Go to the source code of this file.

Classes

struct  halomod_data
 

Macros

#define HALOMOD_TOLERANCE   1E-3
 
#define NUMK   256
 

Functions

static void read_halomod_test_file (double k[3][2][256], double Pk[3][2][256])
 
void __attribute__ ((weak))
 
static void compare_halomod (int model, struct halomod_data *data)
 
void __ctest_halomod_model_1_run (struct halomod_data *data)
 
void __ctest_halomod_model_2_run (struct halomod_data *data)
 
void __ctest_halomod_model_3_run (struct halomod_data *data)
 

Variables

static struct halomod_data __ctest_halomod_data
 

Macro Definition Documentation

#define HALOMOD_TOLERANCE   1E-3

Definition at line 9 of file ccl_test_halomod.c.

Referenced by compare_halomod().

#define NUMK   256

Definition at line 10 of file ccl_test_halomod.c.

Referenced by compare_halomod(), and read_halomod_test_file().

Function Documentation

void __attribute__ ( (weak)  )

Definition at line 80 of file ccl_test_halomod.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 read_halomod_test_file().

80  {
81 
82  // Move the cosmological parameters to the data structure
83  data->Omega_k = 0.00;
84  data->Neff = 0.00;
85  double mnuval = 0.00;
86  data->mnu = &mnuval;
87  data->mnu_type = ccl_mnu_sum;
88  data->w_0 = -1.00;
89  data->w_a = 0.00;
90 
91  // Cosmological parameters that are different for different tests
92  double Omega_c[3] = { 0.2500, 0.2265, 0.2685 };
93  double Omega_b[3] = { 0.0500, 0.0455, 0.0490 };
94  double h[3] = { 0.7000, 0.7040, 0.6711 };
95  double sigma_8[3] = { 0.8000, 0.8100, 0.8340 };
96  double n_s[3] = { 0.9600, 0.9670, 0.9624 };
97 
98  // Fill in the values from these constant arrays
99  for (int model=0; model<3; model++){
100  data->Omega_c[model] = Omega_c[model];
101  data->Omega_b[model] = Omega_b[model];
102  data->h[model] = h[model];
103  data->sigma_8[model] = sigma_8[model];
104  data->n_s[model] = n_s[model];
105  }
106 
107  // read the file of benchmark data
108  read_halomod_test_file(data->k, data->Pk);
109 
110 }
static void read_halomod_test_file(double k[3][2][256], double Pk[3][2][256])
void __ctest_halomod_model_1_run ( struct halomod_data data)

Definition at line 169 of file ccl_test_halomod.c.

References compare_halomod().

169  {
170  int model = 0;
171  compare_halomod(model, data);
172 }
static void compare_halomod(int model, struct halomod_data *data)
void __ctest_halomod_model_2_run ( struct halomod_data data)

Definition at line 174 of file ccl_test_halomod.c.

References compare_halomod().

174  {
175  int model = 1;
176  compare_halomod(model, data);
177 }
static void compare_halomod(int model, struct halomod_data *data)
void __ctest_halomod_model_3_run ( struct halomod_data data)

Definition at line 179 of file ccl_test_halomod.c.

References compare_halomod().

179  {
180  int model = 2;
181  compare_halomod(model, data);
182 }
static void compare_halomod(int model, struct halomod_data *data)
static void compare_halomod ( int  model,
struct halomod_data data 
)
static

Definition at line 113 of file ccl_test_halomod.c.

References ASSERT_DBL_NEAR_TOL, ASSERT_NOT_NULL, ccl_cosmology_create(), ccl_duffy2008, ccl_eisenstein_hu, ccl_halomodel_matter_power(), ccl_parameters_create(), ccl_shethtormen, cl_cmbl_bm::cosmo, default_config, halomod_data::h, ccl_parameters::h, ccl_configuration::halo_concentration_method, HALOMOD_TOLERANCE, halomod_data::k, ccl_configuration::mass_function_method, halomod_data::mnu, halomod_data::mnu_type, halomod_data::n_s, halomod_data::Neff, NUMK, halomod_data::Omega_b, halomod_data::Omega_c, halomod_data::Omega_k, halomod_bm::params, halomod_data::Pk, pow(), halomod_data::sigma_8, ccl_configuration::transfer_function_method, halomod_data::w_0, and halomod_data::w_a.

Referenced by __ctest_halomod_model_1_run(), __ctest_halomod_model_2_run(), and __ctest_halomod_model_3_run().

114 {
115 
116  // Status variables
117  int stat = 0;
118  int* status = &stat;
119 
120  // Set the cosmology
121  ccl_parameters params = ccl_parameters_create(data->Omega_c[model], data->Omega_b[model],data->Omega_k,
122  data->Neff, data->mnu, data->mnu_type, data->w_0,
123  data->w_a, data->h[model],data->sigma_8[model], data->n_s[model],
124  -1, -1, -1, -1, NULL, NULL, status);
125 
126  // Set the default configuration, but with Eisenstein & Hu linear P(k) and Sheth & Tormen mass function and Duffy (2008) halo concentrations
131 
132  // Set the configuration
133  ccl_cosmology * cosmo = ccl_cosmology_create(params, config);
134 
135  // Check that the cosmology is assigned correctly
136  ASSERT_NOT_NULL(cosmo);
137 
138  // Loop over redshifts
139  for (int i=0; i<2; i++) {
140 
141  // Variables for the test
142  double a;
143 
144  if(i==0){a = 1.0;}
145  if(i==1){a = 0.5;}
146 
147  // Loop over wavenumbers
148  for (int j=0; j<NUMK; j++) {
149 
150  // Set variables inside loop, convert CCL outputs to the same units as benchmark
151  double k = data->k[model][i][j]*params.h; // Convert the benchmark data k/h to pure k
152  double Pk = data->Pk[model][i][j]/pow(params.h,3); // Convert the benchmark data Pk units to remove factors of h
153 
154  double Pk_ccl = ccl_halomodel_matter_power(cosmo, k, a, status); // Get CCL P(k)
155  double absolute_tolerance = HALOMOD_TOLERANCE*Pk; // Convert relative -> absolute tolerance
156 
157  // Do the check
158  ASSERT_DBL_NEAR_TOL(Pk, Pk_ccl, absolute_tolerance);
159 
160  }
161 
162  }
163 
164  // Free the cosmology object
165  free(cosmo);
166 
167 }
double ccl_halomodel_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_halomod.c:314
#define NUMK
halo_concentration_t halo_concentration_method
Definition: ccl_config.h:115
ccl_mnu_convention mnu_type
double Omega_c[3]
#define HALOMOD_TOLERANCE
double sigma_8[3]
double h
Definition: ccl_core.h:33
double Omega_b[3]
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
dictionary params
Definition: halomod_bm.py:27
#define ASSERT_DBL_NEAR_TOL(exp, real, tol)
Definition: ctest.h:152
double k[3][2][256]
double Pk[3][2][256]
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
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_halomod_test_file ( double  k[3][2][256],
double  Pk[3][2][256] 
)
static

Definition at line 35 of file ccl_test_halomod.c.

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

Referenced by __attribute__().

35  {
36 
37  // Variables for reading in unwanted stuff and file name
38  double spam;
39  char infile[256];
40 
41  // Loop over cosmological models
42  for (int model=0; model<3; model++){
43 
44  // Loop over redshifts
45  for (int i=0; i<2; i++){
46 
47  // File names for different redshifts and cosmological models
48  if(model==0 && i==0){strncpy(infile, "./tests/benchmark/pk_hm_c1_z0.txt", 256);}
49  if(model==0 && i==1){strncpy(infile, "./tests/benchmark/pk_hm_c1_z1.txt", 256);}
50  if(model==1 && i==0){strncpy(infile, "./tests/benchmark/pk_hm_c2_z0.txt", 256);}
51  if(model==1 && i==1){strncpy(infile, "./tests/benchmark/pk_hm_c2_z1.txt", 256);}
52  if(model==2 && i==0){strncpy(infile, "./tests/benchmark/pk_hm_c3_z0.txt", 256);}
53  if(model==2 && i==1){strncpy(infile, "./tests/benchmark/pk_hm_c3_z1.txt", 256);}
54 
55  // Open the file
56  FILE * f = fopen(infile, "r");
57  ASSERT_NOT_NULL(f);
58 
59  // Loop over wavenumbers, which are k/h in benchmark data, power is Delta^2(k)
60  for (int j=0; j<NUMK; j++) {
61 
62  // Read in data from the benchmark file
63  int count = fscanf(f, "%le\t %le\t %le\t %le\t %le\n", &k[model][i][j], &spam, &spam, &spam, &Pk[model][i][j]);
64 
65  // Check that we have read in enough columns from the benchmark file
66  ASSERT_EQUAL(5, count);
67 
68  }
69 
70  // Close the file
71  fclose(f);
72 
73  }
74 
75  }
76 
77 }
#define NUMK
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

static struct halomod_data __ctest_halomod_data
static

Definition at line 169 of file ccl_test_halomod.c.