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

Go to the source code of this file.

Classes

struct  distances_cosmomad_lowz_data
 

Macros

#define DISTANCES_TOLERANCE   5.0e-7
 
#define DM_TOLERANCE   1.0E-3
 

Functions

static void read_chi_test_file (double z[6], double chi[5][6])
 
static void read_dm_test_file (double z[6], double dm[5][6])
 
void __attribute__ ((weak))
 
static void compare_distances (int model, struct distances_cosmomad_lowz_data *data)
 
void __ctest_distances_cosmomad_lowz_model_1_run (struct distances_cosmomad_lowz_data *data)
 
void __ctest_distances_cosmomad_lowz_model_2_run (struct distances_cosmomad_lowz_data *data)
 
void __ctest_distances_cosmomad_lowz_model_3_run (struct distances_cosmomad_lowz_data *data)
 
void __ctest_distances_cosmomad_lowz_model_4_run (struct distances_cosmomad_lowz_data *data)
 
void __ctest_distances_cosmomad_lowz_model_5_run (struct distances_cosmomad_lowz_data *data)
 

Variables

static struct distances_cosmomad_lowz_data __ctest_distances_cosmomad_lowz_data
 

Macro Definition Documentation

#define DISTANCES_TOLERANCE   5.0e-7

Definition at line 7 of file ccl_test_distances_cosmomad_lowz.c.

Referenced by compare_distances().

#define DM_TOLERANCE   1.0E-3

Definition at line 8 of file ccl_test_distances_cosmomad_lowz.c.

Referenced by compare_distances().

Function Documentation

void __attribute__ ( (weak)  )

Definition at line 73 of file ccl_test_distances_cosmomad_lowz.c.

References ccl_mnu_sum, read_chi_test_file(), and read_dm_test_file().

73  {
74  // Values that are the same for all 5 models
75  data->Omega_c = 0.25;
76  data->Omega_b = 0.05;
77  data->h = 0.7;
78  data->A_s = 2.1e-9;
79  data->n_s = 0.96;
80  data->Neff=0;
81  double mnuval = 0.;
82  data->mnu= &mnuval;
83  data->mnu_type = ccl_mnu_sum;
84 
85 
86  // Values that are different for the different models
87  double Omega_v[5] = { 0.7, 0.7, 0.7, 0.65, 0.75 };
88  double w_0[5] = { -1.0, -0.9, -0.9, -0.9, -0.9 };
89  double w_a[5] = { 0.0, 0.0, 0.1, 0.1, 0.1 };
90 
91  // Fill in the values from these constant arrays.
92  for (int i=0; i<5; i++) {
93  data->Omega_v[i] = Omega_v[i];
94  data->w_0[i] = w_0[i];
95  data->w_a[i] = w_a[i];
96  data->Omega_k[i] = 1.0 - data->Omega_c - data->Omega_b - data->Omega_v[i];
97  }
98 
99  // The file of benchmark data.
100  read_dm_test_file(data->z, data->dm);
101  read_chi_test_file(data->z, data->chi);
102 }
static void read_chi_test_file(double z[6], double chi[5][6])
static void read_dm_test_file(double z[6], double dm[5][6])
void __ctest_distances_cosmomad_lowz_model_1_run ( struct distances_cosmomad_lowz_data data)

Definition at line 143 of file ccl_test_distances_cosmomad_lowz.c.

References compare_distances().

143  {
144  int model = 0;
145  compare_distances(model, data);
146 }
static void compare_distances(int model, struct distances_cosmomad_lowz_data *data)
void __ctest_distances_cosmomad_lowz_model_2_run ( struct distances_cosmomad_lowz_data data)

Definition at line 148 of file ccl_test_distances_cosmomad_lowz.c.

References compare_distances().

148  {
149  int model = 1;
150  compare_distances(model, data);
151 }
static void compare_distances(int model, struct distances_cosmomad_lowz_data *data)
void __ctest_distances_cosmomad_lowz_model_3_run ( struct distances_cosmomad_lowz_data data)

Definition at line 153 of file ccl_test_distances_cosmomad_lowz.c.

References compare_distances().

153  {
154  int model = 2;
155  compare_distances(model, data);
156 }
static void compare_distances(int model, struct distances_cosmomad_lowz_data *data)
void __ctest_distances_cosmomad_lowz_model_4_run ( struct distances_cosmomad_lowz_data data)

Definition at line 158 of file ccl_test_distances_cosmomad_lowz.c.

References compare_distances().

158  {
159  int model = 3;
160  compare_distances(model, data);
161 }
static void compare_distances(int model, struct distances_cosmomad_lowz_data *data)
void __ctest_distances_cosmomad_lowz_model_5_run ( struct distances_cosmomad_lowz_data data)

Definition at line 163 of file ccl_test_distances_cosmomad_lowz.c.

References compare_distances().

163  {
164  int model = 4;
165  compare_distances(model, data);
166 }
static void compare_distances(int model, struct distances_cosmomad_lowz_data *data)
static void compare_distances ( int  model,
struct distances_cosmomad_lowz_data data 
)
static

Definition at line 104 of file ccl_test_distances_cosmomad_lowz.c.

References distances_cosmomad_lowz_data::A_s, ASSERT_DBL_NEAR_TOL, ASSERT_NOT_NULL, ccl_comoving_radial_distance(), ccl_cosmology_create(), ccl_cosmology_free(), ccl_distance_modulus(), ccl_parameters_create(), distances_cosmomad_lowz_data::chi, cl_cmbl_bm::cosmo, default_config, DISTANCES_TOLERANCE, distances_cosmomad_lowz_data::dm, DM_TOLERANCE, distances_cosmomad_lowz_data::h, distances_cosmomad_lowz_data::mnu, distances_cosmomad_lowz_data::mnu_type, distances_cosmomad_lowz_data::n_s, distances_cosmomad_lowz_data::Neff, distances_cosmomad_lowz_data::Omega_b, distances_cosmomad_lowz_data::Omega_c, ccl_parameters::Omega_g, distances_cosmomad_lowz_data::Omega_k, ccl_parameters::Omega_k, ccl_parameters::Omega_l, ccl_parameters::Omega_m, halomod_bm::params, ccl_cosmology::status_message, distances_cosmomad_lowz_data::w_0, distances_cosmomad_lowz_data::w_a, and distances_cosmomad_lowz_data::z.

Referenced by __ctest_distances_cosmomad_lowz_model_1_run(), __ctest_distances_cosmomad_lowz_model_2_run(), __ctest_distances_cosmomad_lowz_model_3_run(), __ctest_distances_cosmomad_lowz_model_4_run(), and __ctest_distances_cosmomad_lowz_model_5_run().

105 {
106  int status=0;
107  // Make the parameter set from the input data
108  // Values of some parameters depend on the model index
109  ccl_parameters params = ccl_parameters_create(data->Omega_c, data->Omega_b, data->Omega_k[model],
110  data->Neff, data->mnu, data->mnu_type,
111  data->w_0[model], data->w_a[model],
112  data->h, data->A_s, data->n_s,-1,-1,-1,-1,NULL,NULL, &status);
113 
114  params.Omega_g=0; //enforce no radiation
115  params.Omega_l = 1.-params.Omega_m-params.Omega_k; //reomcpute Omega_l without radiation
116 
117  // Make a cosmology object from the parameters with the default configuration
119  ASSERT_NOT_NULL(cosmo);
120 
121  // Compare to benchmark data
122  for (int j=0; j<6; j++) {
123  double a = 1/(1.+data->z[j]);
124  double chi_ij=ccl_comoving_radial_distance(cosmo,a, &status)*data->h;
125  if (status) printf("%s\n",cosmo->status_message);
126  double absolute_tolerance = DISTANCES_TOLERANCE*data->chi[model][j];
127  if (fabs(absolute_tolerance)<1e-12) absolute_tolerance = 1e-12;
128  ASSERT_DBL_NEAR_TOL(data->chi[model][j], chi_ij, absolute_tolerance);
129 
130  if(a!=1) { //skip this test for a=1 since it will raise an error
131  double dm_ij=ccl_distance_modulus(cosmo,a, &status);
132  if (status) printf("%s\n",cosmo->status_message);
133  //NOTE tolerances are different!
134  absolute_tolerance = DM_TOLERANCE*data->dm[model][j];
135  if (fabs(absolute_tolerance)<1e-4) absolute_tolerance = 1e-4;
136  ASSERT_DBL_NEAR_TOL(data->dm[model][j], dm_ij, absolute_tolerance);
137  }
138  }
139 
140  ccl_cosmology_free(cosmo);
141 }
double Omega_g
Definition: ccl_core.h:53
#define DM_TOLERANCE
double Omega_l
Definition: ccl_core.h:63
int * status
Definition: ccl_redshifts.c:41
#define DISTANCES_TOLERANCE
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
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
const ccl_configuration default_config
Definition: ccl_core.c:21
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
double Omega_k
Definition: ccl_core.h:22
double Omega_m
Definition: ccl_core.h:21
double ccl_distance_modulus(ccl_cosmology *cosmo, double a, int *status)
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
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
char status_message[500]
Definition: ccl_core.h:136
static void read_chi_test_file ( double  z[6],
double  chi[5][6] 
)
static

Definition at line 31 of file ccl_test_distances_cosmomad_lowz.c.

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

Referenced by __attribute__().

32 {
33  //Distances are in Mpc/h
34  FILE * f = fopen("./tests/benchmark/chi_model1-5.txt", "r");
35  ASSERT_NOT_NULL(f);
36 
37  // Ignore header line
38  char str[1024];
39  fgets(str, 1024, f);
40 
41  // File is fixed format - five rows and six columns
42  for (int i=0; i<6; i++) {
43  int count = fscanf(f, "%le %le %le %le %le %le\n", &z[i],
44  &chi[0][i], &chi[1][i], &chi[2][i], &chi[3][i], &chi[4][i]);
45  // Check that all the stuff in the benchmark is there
46  ASSERT_EQUAL(6, count);
47  }
48  fclose(f);
49 }
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2747
static double z[8]
#define ASSERT_EQUAL(exp, real)
Definition: ctest.h:121
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139
static void read_dm_test_file ( double  z[6],
double  dm[5][6] 
)
static

Definition at line 51 of file ccl_test_distances_cosmomad_lowz.c.

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

Referenced by __attribute__().

52 {
53  //Distances are in Mpc/h
54  FILE * f = fopen("./tests/benchmark/dm_model1-5.txt", "r");
55  ASSERT_NOT_NULL(f);
56 
57  // Ignore header line
58  char str[1024];
59  fgets(str, 1024, f);
60 
61  // File is fixed format - five rows and six columns
62  for (int i=0; i<6; i++) {
63  int count = fscanf(f, "%le %le %le %le %le %le\n", &z[i],
64  &dm[0][i], &dm[1][i], &dm[2][i], &dm[3][i], &dm[4][i]);
65  // Check that all the stuff in the benchmark is there
66  ASSERT_EQUAL(6, count);
67  }
68  fclose(f);
69 }
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:2747
static double z[8]
#define ASSERT_EQUAL(exp, real)
Definition: ctest.h:121
#define ASSERT_NOT_NULL(real)
Definition: ctest.h:139

Variable Documentation

static struct distances_cosmomad_lowz_data __ctest_distances_cosmomad_lowz_data
static

Definition at line 143 of file ccl_test_distances_cosmomad_lowz.c.