Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_core.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include <string.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_odeiv.h>
#include <gsl/gsl_spline.h>
#include <gsl/gsl_integration.h>
#include "ccl.h"
#include "ccl_params.h"
Include dependency graph for ccl_core.c:

Go to the source code of this file.

Macros

#define EXPAND_STR(s)   STRING(s)
 
#define STRING(s)   #s
 
#define MATCH(s, action)   if (0 == strcmp(var_name, s)) { action ; continue;} do{} while(0)
 
#define WRITE_DOUBLE(name)   fprintf(f, #name ": %le\n",params->name)
 
#define WRITE_INT(name)   fprintf(f, #name ": %d\n",params->name)
 
#define READ_DOUBLE(name)   double name; *status |= (0==fscanf(f, #name ": %le\n",&name));
 
#define READ_INT(name)   int name; *status |= (0==fscanf(f, #name ": %d\n",&name))
 

Functions

void ccl_cosmology_read_config (void)
 
ccl_cosmologyccl_cosmology_create (ccl_parameters params, ccl_configuration config)
 
void ccl_parameters_fill_initial (ccl_parameters *params, 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)
 
ccl_parameters ccl_parameters_create_flat_lcdm (double Omega_c, double Omega_b, double h, double norm_pk, double n_s, int *status)
 
void ccl_parameters_write_yaml (ccl_parameters *params, const char *filename, int *status)
 
ccl_parameters ccl_parameters_read_yaml (const char *filename, int *status)
 
void ccl_data_free (ccl_data *data)
 
void ccl_cosmology_set_status_message (ccl_cosmology *cosmo, const char *message,...)
 
void ccl_parameters_free (ccl_parameters *params)
 
void ccl_cosmology_free (ccl_cosmology *cosmo)
 

Variables

const ccl_configuration default_config = {ccl_boltzmann_class, ccl_halofit, ccl_nobaryons, ccl_tinker10, ccl_duffy2008, ccl_emu_strict}
 
const ccl_gsl_params default_gsl_params
 
ccl_spline_paramsccl_splines = ((void*)0)
 
ccl_gsl_paramsccl_gsl = ((void*)0)
 

Macro Definition Documentation

#define EXPAND_STR (   s)    STRING(s)

Definition at line 17 of file ccl_core.c.

Referenced by ccl_cosmology_read_config().

#define MATCH (   s,
  action 
)    if (0 == strcmp(var_name, s)) { action ; continue;} do{} while(0)
#define READ_DOUBLE (   name)    double name; *status |= (0==fscanf(f, #name ": %le\n",&name));
#define READ_INT (   name)    int name; *status |= (0==fscanf(f, #name ": %d\n",&name))
#define STRING (   s)    #s

Definition at line 18 of file ccl_core.c.

#define WRITE_DOUBLE (   name)    fprintf(f, #name ": %le\n",params->name)
#define WRITE_INT (   name)    fprintf(f, #name ": %d\n",params->name)

Function Documentation

ccl_cosmology* ccl_cosmology_create ( ccl_parameters  params,
ccl_configuration  config 
)

Definition at line 173 of file ccl_core.c.

References ccl_data::accelerator, ccl_data::accelerator_achi, ccl_data::accelerator_d, ccl_data::accelerator_k, ccl_data::accelerator_m, ccl_data::achi, ccl_data::alphahmf, ccl_data::betahmf, ccl_cosmology_set_status_message(), ccl_data::chi, ccl_cosmology::computed_distances, ccl_cosmology::computed_growth, ccl_cosmology::computed_hmfparams, ccl_cosmology::computed_power, ccl_cosmology::computed_sigma, ccl_cosmology::config, cl_cmbl_bm::cosmo, ccl_cosmology::data, ccl_data::dlnsigma_dlogm, ccl_data::E, ccl_data::etahmf, ccl_data::fgrowth, ccl_data::gammahmf, ccl_data::growth, ccl_data::growth0, ccl_data::logsigma, ccl_data::p_lin, ccl_data::p_nl, halomod_bm::params, ccl_cosmology::params, ccl_data::phihmf, and ccl_cosmology::status.

Referenced by ccl_cosmology_create_flat_lcdm(), check_mgrowth(), compare_bbks(), compare_bcm(), compare_cls(), compare_corr(), compare_correlation_3d(), compare_distances(), compare_distances_hiz(), compare_distances_hiz_mnu(), compare_distances_mnu(), compare_eh(), compare_emu(), compare_emu_nu(), compare_growth(), compare_growth_hiz(), compare_halomod(), compare_massfunc(), compare_power_nu(), compare_power_nu_nl(), compare_sigmam(), main(), test_angpow_precision(), and write_Pk_CLASS().

174 {
175  ccl_cosmology * cosmo = malloc(sizeof(ccl_cosmology));
176  cosmo->params = params;
177  cosmo->config = config;
178 
179  cosmo->data.chi = NULL;
180  cosmo->data.growth = NULL;
181  cosmo->data.fgrowth = NULL;
182  cosmo->data.E = NULL;
183  cosmo->data.accelerator=NULL;
184  cosmo->data.accelerator_achi=NULL;
185  cosmo->data.accelerator_m=NULL;
186  cosmo->data.accelerator_d=NULL;
187  cosmo->data.accelerator_k=NULL;
188  cosmo->data.growth0 = 1.;
189  cosmo->data.achi=NULL;
190 
191  cosmo->data.logsigma = NULL;
192  cosmo->data.dlnsigma_dlogm = NULL;
193 
194  // hmf parameter for interpolation
195  cosmo->data.alphahmf = NULL;
196  cosmo->data.betahmf = NULL;
197  cosmo->data.gammahmf = NULL;
198  cosmo->data.phihmf = NULL;
199  cosmo->data.etahmf = NULL;
200 
201  cosmo->data.p_lin = NULL;
202  cosmo->data.p_nl = NULL;
203  //cosmo->data.nu_pspace_int = NULL;
204  cosmo->computed_distances = false;
205  cosmo->computed_growth = false;
206  cosmo->computed_power = false;
207  cosmo->computed_sigma = false;
208  cosmo->computed_hmfparams = false;
209  cosmo->status = 0;
211 
212  return cosmo;
213 }
gsl_interp_accel * accelerator_m
Definition: ccl_core.h:93
bool computed_power
Definition: ccl_core.h:130
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *message,...)
Definition: ccl_core.c:792
double growth0
Definition: ccl_core.h:81
ccl_parameters params
Definition: ccl_core.h:124
gsl_spline * betahmf
Definition: ccl_core.h:105
gsl_spline * alphahmf
Definition: ccl_core.h:104
gsl_interp_accel * accelerator_d
Definition: ccl_core.h:94
gsl_spline2d * p_lin
Definition: ccl_core.h:111
gsl_interp_accel * accelerator_achi
Definition: ccl_core.h:92
gsl_spline * chi
Definition: ccl_core.h:82
gsl_spline * E
Definition: ccl_core.h:85
gsl_spline * phihmf
Definition: ccl_core.h:107
gsl_spline2d * p_nl
Definition: ccl_core.h:112
dictionary params
Definition: halomod_bm.py:27
gsl_spline * achi
Definition: ccl_core.h:86
gsl_interp_accel * accelerator_k
Definition: ccl_core.h:96
gsl_spline * logsigma
Definition: ccl_core.h:100
gsl_interp_accel * accelerator
Definition: ccl_core.h:91
gsl_spline * fgrowth
Definition: ccl_core.h:84
bool computed_growth
Definition: ccl_core.h:129
gsl_spline * gammahmf
Definition: ccl_core.h:106
bool computed_hmfparams
Definition: ccl_core.h:132
gsl_spline * dlnsigma_dlogm
Definition: ccl_core.h:101
bool computed_distances
Definition: ccl_core.h:128
ccl_configuration config
Definition: ccl_core.h:125
gsl_spline * etahmf
Definition: ccl_core.h:108
gsl_spline * growth
Definition: ccl_core.h:83
ccl_data data
Definition: ccl_core.h:126
bool computed_sigma
Definition: ccl_core.h:131
void ccl_cosmology_read_config ( void  )

Definition at line 50 of file ccl_core.c.

References ccl_spline_params::A_SPLINE_MAX, ccl_spline_params::A_SPLINE_MIN, ccl_spline_params::A_SPLINE_MIN_PK, ccl_spline_params::A_SPLINE_MINLOG, ccl_spline_params::A_SPLINE_MINLOG_PK, ccl_spline_params::A_SPLINE_NA, ccl_spline_params::A_SPLINE_NA_PK, ccl_spline_params::A_SPLINE_NLOG, ccl_spline_params::A_SPLINE_NLOG_PK, CCL_ERROR_MEMORY, CCL_ERROR_MISSING_CONFIG_FILE, ccl_raise_exception(), ccl_spline_params::ELL_MAX_CORR, ccl_spline_params::ELL_MIN_CORR, ccl_gsl_params::EPSREL, EXPAND_STR, ccl_gsl_params::INTEGRATION_DISTANCE_EPSREL, ccl_gsl_params::INTEGRATION_DNDZ_EPSREL, ccl_gsl_params::INTEGRATION_EPSREL, ccl_gsl_params::INTEGRATION_GAUSS_KRONROD_POINTS, ccl_gsl_params::INTEGRATION_LIMBER_EPSREL, ccl_gsl_params::INTEGRATION_LIMBER_GAUSS_KRONROD_POINTS, ccl_gsl_params::INTEGRATION_NU_EPSABS, ccl_gsl_params::INTEGRATION_NU_EPSREL, ccl_gsl_params::INTEGRATION_SIGMAR_EPSREL, ccl_spline_params::K_MAX, ccl_spline_params::K_MAX_SPLINE, ccl_spline_params::K_MIN, ccl_spline_params::LOGM_SPLINE_DELTA, ccl_spline_params::LOGM_SPLINE_MAX, ccl_spline_params::LOGM_SPLINE_MIN, ccl_spline_params::LOGM_SPLINE_NM, MATCH, ccl_spline_params::N_ELL_CORR, ccl_gsl_params::N_ITERATION, ccl_spline_params::N_K, ccl_spline_params::N_K_3DCOR, ccl_gsl_params::ODE_GROWTH_EPSREL, ccl_gsl_params::ROOT_EPSREL, and ccl_gsl_params::ROOT_N_ITERATION.

Referenced by calculate_nu_phasespace_spline(), ccl_dNdz_tomog(), ccl_norm_integrand(), and ccl_parameters_create().

51 {
52 
53  int CONFIG_LINE_BUFFER_SIZE=100;
54  int MAX_CONFIG_VAR_LEN=100;
55  FILE *fconfig;
56  char buf[CONFIG_LINE_BUFFER_SIZE];
57  char var_name[MAX_CONFIG_VAR_LEN];
58  char* rtn;
59  double var_dbl;
60 
61  // Get parameter .ini filename from environment variable or default location
62  const char* param_file;
63  const char* param_file_env = getenv("CCL_PARAM_FILE");
64  if (param_file_env != NULL) {
65  param_file = param_file_env;
66  }
67  else {
68  // Use default ini file
69  param_file = EXPAND_STR(__CCL_DATA_DIR__) "/ccl_params.ini";
70  }
71  if ((fconfig=fopen(param_file, "r")) == NULL) {
72  ccl_raise_exception(CCL_ERROR_MISSING_CONFIG_FILE, "ccl_core.c: Failed to open config file: %s", param_file);
73  return;
74  }
75 
76  if(ccl_splines == NULL) {
77  ccl_splines = malloc(sizeof(ccl_spline_params));
78  }
79  if(ccl_gsl == NULL) {
80  ccl_gsl = malloc(sizeof(ccl_gsl_params));
81  memcpy(ccl_gsl, &default_gsl_params, sizeof(ccl_gsl_params));
82  }
83 
84  /* Exit gracefully if we couldn't allocate memory */
85  if(ccl_splines==NULL || ccl_gsl==NULL) {
86  ccl_raise_exception(CCL_ERROR_MEMORY, "ccl_core.c: Failed to allocate memory for config file data.");
87  return;
88  }
89 
90 #define MATCH(s, action) if (0 == strcmp(var_name, s)) { action ; continue;} do{} while(0)
91 
92  int lineno = 0;
93  while(! feof(fconfig)) {
94  rtn = fgets(buf, CONFIG_LINE_BUFFER_SIZE, fconfig);
95  lineno ++;
96 
97  if (buf[0]==';' || buf[0]=='[' || buf[0]=='\n') {
98  continue;
99  }
100  else {
101  sscanf(buf, "%99[^=]=%le\n",var_name, &var_dbl);
102 
103  // Spline parameters
104  MATCH("A_SPLINE_NA", ccl_splines->A_SPLINE_NA=(int) var_dbl);
105  MATCH("A_SPLINE_NLOG", ccl_splines->A_SPLINE_NLOG=(int) var_dbl);
106  MATCH("A_SPLINE_MINLOG", ccl_splines->A_SPLINE_MINLOG=var_dbl);
107  MATCH("A_SPLINE_MIN", ccl_splines->A_SPLINE_MIN=var_dbl);
108  MATCH("A_SPLINE_MINLOG_PK", ccl_splines->A_SPLINE_MINLOG_PK=var_dbl);
109  MATCH("A_SPLINE_MIN_PK", ccl_splines->A_SPLINE_MIN_PK=var_dbl);
110  MATCH("A_SPLINE_MAX", ccl_splines->A_SPLINE_MAX=var_dbl);
111  MATCH("LOGM_SPLINE_DELTA", ccl_splines->LOGM_SPLINE_DELTA=var_dbl);
112  MATCH("LOGM_SPLINE_NM", ccl_splines->LOGM_SPLINE_NM=(int) var_dbl);
113  MATCH("LOGM_SPLINE_MIN", ccl_splines->LOGM_SPLINE_MIN=var_dbl);
114  MATCH("LOGM_SPLINE_MAX", ccl_splines->LOGM_SPLINE_MAX=var_dbl);
115  MATCH("A_SPLINE_NA_PK", ccl_splines->A_SPLINE_NA_PK=(int) var_dbl);
116  MATCH("A_SPLINE_NLOG_PK", ccl_splines->A_SPLINE_NLOG_PK=(int) var_dbl);
117  MATCH("K_MAX_SPLINE", ccl_splines->K_MAX_SPLINE=var_dbl);
118  MATCH("K_MAX", ccl_splines->K_MAX=var_dbl);
119  MATCH("K_MIN", ccl_splines->K_MIN=var_dbl);
120  MATCH("N_K", ccl_splines->N_K=(int) var_dbl);
121 
122  // 3dcorr parameters
123  MATCH("N_K_3DCOR", ccl_splines->N_K_3DCOR=(int) var_dbl);
124 
125  // Angular correlation function params
126  MATCH("ELL_MIN_CORR",ccl_splines->ELL_MIN_CORR=(double) var_dbl);
127  MATCH("ELL_MAX_CORR",ccl_splines->ELL_MAX_CORR=(double) var_dbl);
128  MATCH("N_ELL_CORR",ccl_splines->N_ELL_CORR=(int) var_dbl);
129 
130  // GSL parameters
131  MATCH("GSL_EPSREL", ccl_gsl->EPSREL=var_dbl);
132  MATCH("GSL_N_ITERATION", ccl_gsl->N_ITERATION=(size_t) var_dbl);
133  MATCH("GSL_INTEGRATION_GAUSS_KRONROD_POINTS", ccl_gsl->INTEGRATION_GAUSS_KRONROD_POINTS=(int) var_dbl);
134  MATCH("GSL_INTEGRATION_EPSREL", ccl_gsl->INTEGRATION_EPSREL=var_dbl);
135  MATCH("GSL_INTEGRATION_DISTANCE_EPSREL", ccl_gsl->INTEGRATION_DISTANCE_EPSREL=var_dbl);
136  MATCH("GSL_INTEGRATION_DNDZ_EPSREL", ccl_gsl->INTEGRATION_DNDZ_EPSREL=var_dbl);
137  MATCH("GSL_INTEGRATION_SIGMAR_EPSREL", ccl_gsl->INTEGRATION_SIGMAR_EPSREL=var_dbl);
138  MATCH("GSL_INTEGRATION_NU_EPSREL", ccl_gsl->INTEGRATION_NU_EPSREL=var_dbl);
139  MATCH("GSL_INTEGRATION_NU_EPSABS", ccl_gsl->INTEGRATION_NU_EPSABS=var_dbl);
140  MATCH("GSL_INTEGRATION_LIMBER_GAUSS_KRONROD_POINTS", ccl_gsl->INTEGRATION_LIMBER_GAUSS_KRONROD_POINTS=(int) var_dbl);
141  MATCH("GSL_INTEGRATION_LIMBER_EPSREL", ccl_gsl->INTEGRATION_LIMBER_EPSREL=var_dbl);
142  MATCH("GSL_ROOT_EPSREL", ccl_gsl->ROOT_EPSREL=var_dbl);
143  MATCH("GSL_ROOT_N_ITERATION", ccl_gsl->ROOT_N_ITERATION=(int) var_dbl);
144  MATCH("GSL_ODE_GROWTH_EPSREL", ccl_gsl->ODE_GROWTH_EPSREL=var_dbl);
145 
146  ccl_raise_exception(CCL_ERROR_MISSING_CONFIG_FILE, "ccl_core.c: Failed to parse config file at line %d: %s", lineno, buf);
147  }
148  }
149 #undef MATCH
150 
151  fclose(fconfig);
152 }
double INTEGRATION_NU_EPSREL
Definition: ccl_params.h:70
int INTEGRATION_LIMBER_GAUSS_KRONROD_POINTS
Definition: ccl_params.h:61
double INTEGRATION_SIGMAR_EPSREL
Definition: ccl_params.h:68
double K_MAX_SPLINE
Definition: ccl_params.h:33
int INTEGRATION_GAUSS_KRONROD_POINTS
Definition: ccl_params.h:58
#define EXPAND_STR(s)
Definition: ccl_core.c:17
double LOGM_SPLINE_MAX
Definition: ccl_params.h:26
#define CCL_ERROR_MISSING_CONFIG_FILE
Definition: ccl_error.h:28
double INTEGRATION_DNDZ_EPSREL
Definition: ccl_params.h:66
double A_SPLINE_MINLOG
Definition: ccl_params.h:19
#define MATCH(s, action)
double INTEGRATION_NU_EPSABS
Definition: ccl_params.h:71
double ELL_MAX_CORR
Definition: ccl_params.h:41
double INTEGRATION_DISTANCE_EPSREL
Definition: ccl_params.h:64
double ROOT_EPSREL
Definition: ccl_params.h:74
ccl_gsl_params * ccl_gsl
Definition: ccl_core.c:48
double A_SPLINE_MAX
Definition: ccl_params.h:18
double INTEGRATION_EPSREL
Definition: ccl_params.h:59
double LOGM_SPLINE_DELTA
Definition: ccl_params.h:23
double ODE_GROWTH_EPSREL
Definition: ccl_params.h:78
double EPSREL
Definition: ccl_params.h:54
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
size_t N_ITERATION
Definition: ccl_params.h:55
double ELL_MIN_CORR
Definition: ccl_params.h:40
const ccl_gsl_params default_gsl_params
Definition: ccl_core.c:23
ccl_spline_params * ccl_splines
Definition: ccl_core.c:47
double A_SPLINE_MIN_PK
Definition: ccl_params.h:17
int ROOT_N_ITERATION
Definition: ccl_params.h:75
double INTEGRATION_LIMBER_EPSREL
Definition: ccl_params.h:62
double A_SPLINE_MINLOG_PK
Definition: ccl_params.h:16
double LOGM_SPLINE_MIN
Definition: ccl_params.h:25
void ccl_raise_exception(int err, const char *msg,...)
Definition: ccl_error.c:35
double A_SPLINE_MIN
Definition: ccl_params.h:15
void ccl_cosmology_set_status_message ( ccl_cosmology cosmo,
const char *  message,
  ... 
)

Definition at line 792 of file ccl_core.c.

References ccl_cosmology::status_message.

Referenced by ccl_angular_cl_native(), ccl_angular_cls(), ccl_comoving_angular_distance(), ccl_comoving_radial_distance(), ccl_correlation(), ccl_correlation_3d(), ccl_cosmology_compute_distances(), ccl_cosmology_compute_growth(), ccl_cosmology_compute_hmfparams(), ccl_cosmology_compute_power(), ccl_cosmology_compute_power_bbks(), ccl_cosmology_compute_power_class(), ccl_cosmology_compute_power_eh(), ccl_cosmology_compute_power_emu(), ccl_cosmology_compute_sigma(), ccl_cosmology_create(), ccl_cosmology_write_power_class_z(), ccl_distance_modulus(), ccl_fill_class_parameters(), ccl_free_class_structs(), ccl_get_tracer_fa(), ccl_get_tracer_fas(), ccl_growth_factor(), ccl_growth_rate(), ccl_h_over_h0(), ccl_halo_b1(), ccl_halo_bias(), ccl_halo_concentration(), ccl_linear_matter_power(), ccl_massfunc(), ccl_nonlin_matter_power(), ccl_omega_x(), ccl_pkemu(), ccl_power_extrapol_highk(), ccl_power_extrapol_lowk(), ccl_run_class(), ccl_scale_factor_of_chi(), ccl_sigmaM(), ccl_sinn(), ccl_tracer_corr_bessel(), ccl_tracer_corr_fftlog(), ccl_tracer_corr_legendre(), cl_tracer(), clt_init_ba(), clt_init_bz(), clt_init_nz(), clt_init_rf(), clt_init_wL(), clt_init_wM(), clt_nc_init(), massfunc_f(), one_halo_integral(), and two_halo_integral().

793 {
794  const int trunc = 480; /* must be < 500 - 4 */
795  va_list va;
796  va_start(va, message);
797  vsnprintf(cosmo->status_message, trunc, message, va);
798  va_end(va);
799 
800  /* if truncation happens, message[trunc - 1] is not NULL, ... will show up. */
801  strcpy(&cosmo->status_message[trunc], "...");
802 }
char status_message[500]
Definition: ccl_core.h:136
void ccl_data_free ( ccl_data data)

Definition at line 761 of file ccl_core.c.

References ccl_data::accelerator, ccl_data::accelerator_achi, ccl_data::accelerator_d, ccl_data::accelerator_k, ccl_data::accelerator_m, ccl_data::achi, ccl_data::alphahmf, ccl_data::betahmf, ccl_data::chi, ccl_data::dlnsigma_dlogm, ccl_data::E, ccl_data::etahmf, ccl_data::fgrowth, ccl_data::gammahmf, ccl_data::growth, ccl_data::logsigma, ccl_data::p_lin, ccl_data::p_nl, and ccl_data::phihmf.

Referenced by ccl_cosmology_free().

762 {
763  //We cannot assume that all of these have been allocated
764  //TODO: it would actually make more sense to do this within ccl_cosmology_free,
765  //where we could make use of the flags "computed_distances" etc. to figure out
766  //what to free up
767  gsl_spline_free(data->chi);
768  gsl_spline_free(data->growth);
769  gsl_spline_free(data->fgrowth);
770  gsl_interp_accel_free(data->accelerator);
771  gsl_interp_accel_free(data->accelerator_achi);
772  gsl_spline_free(data->E);
773  gsl_spline_free(data->achi);
774  gsl_spline_free(data->logsigma);
775  gsl_spline_free(data->dlnsigma_dlogm);
776  gsl_spline2d_free(data->p_lin);
777  gsl_spline2d_free(data->p_nl);
778  gsl_spline_free(data->alphahmf);
779  gsl_spline_free(data->betahmf);
780  gsl_spline_free(data->gammahmf);
781  gsl_spline_free(data->phihmf);
782  gsl_spline_free(data->etahmf);
783  gsl_interp_accel_free(data->accelerator_d);
784  gsl_interp_accel_free(data->accelerator_m);
785  gsl_interp_accel_free(data->accelerator_k);
786 }
gsl_interp_accel * accelerator_m
Definition: ccl_core.h:93
gsl_spline * betahmf
Definition: ccl_core.h:105
gsl_spline * alphahmf
Definition: ccl_core.h:104
gsl_interp_accel * accelerator_d
Definition: ccl_core.h:94
gsl_spline2d * p_lin
Definition: ccl_core.h:111
gsl_interp_accel * accelerator_achi
Definition: ccl_core.h:92
gsl_spline * chi
Definition: ccl_core.h:82
gsl_spline * E
Definition: ccl_core.h:85
gsl_spline * phihmf
Definition: ccl_core.h:107
gsl_spline2d * p_nl
Definition: ccl_core.h:112
gsl_spline * achi
Definition: ccl_core.h:86
gsl_interp_accel * accelerator_k
Definition: ccl_core.h:96
gsl_spline * logsigma
Definition: ccl_core.h:100
gsl_interp_accel * accelerator
Definition: ccl_core.h:91
gsl_spline * fgrowth
Definition: ccl_core.h:84
gsl_spline * gammahmf
Definition: ccl_core.h:106
gsl_spline * dlnsigma_dlogm
Definition: ccl_core.h:101
gsl_spline * etahmf
Definition: ccl_core.h:108
gsl_spline * growth
Definition: ccl_core.h:83
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 
)

Create a cosmology

Parameters
Omega_cOmega_c
Omega_bOmega_b
Omega_kOmega_k
NeffNumber of relativistic neutrino species in the early universe
mnuneutrino mass, either sum or list of length 3
mnu_typedetermines neutrino mass convention (ccl_mnu_list, ccl_mnu_sum, ccl_mnu_sum_inverted, ccl_mnu_sum_equal)
w0Dark energy EoS parameter
waDark energy EoS parameter
hHubble constant in units of 100 km/s/Mpc
norm_pkthe normalization of the power spectrum, either A_s or sigma8
n_sthe power-law index of the power spectrum
bcm_log10Mclog10 cluster mass, one of the parameters of the BCM model
bcm_etabejection radius parameter, one of the parameters of the BCM model
bcm_kswavenumber for the stellar profile, one of the parameters of the BCM model
nz_mgrowththe number of redshifts where the modified growth is provided
zarr_mgrowththe array of redshifts where the modified growth is provided
dfarr_mgrowththe modified growth function vector provided
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
void

Definition at line 294 of file ccl_core.c.

References ccl_parameters::A_s, ccl_parameters::bcm_etab, ccl_parameters::bcm_ks, ccl_parameters::bcm_log10Mc, ccl_check_status_nocosmo(), ccl_cosmology_read_config(), CCL_ERROR_MNU_UNPHYSICAL, CCL_ERROR_NOT_IMPLEMENTED, ccl_mnu_list, ccl_mnu_sum, ccl_mnu_sum_equal, ccl_mnu_sum_inverted, ccl_parameters_fill_initial(), DELTAM12_sq, DELTAM13_sq_neg, DELTAM13_sq_pos, ccl_parameters::df_mgrowth, ccl_test_distances::h, ccl_parameters::h, ccl_parameters::H0, ccl_parameters::has_mgrowth, ccl_test_distances::mnu, ccl_parameters::mnu, ccl_parameters::N_nu_mass, ccl_test_distances::n_s, ccl_parameters::n_s, ccl_test_distances::Neff, ccl_parameters::Neff, ccl_parameters::nz_mgrowth, ccl_parameters::Omega_b, ccl_test_distances::Omega_b, ccl_parameters::Omega_c, ccl_test_distances::Omega_c, ccl_parameters::Omega_k, halomod_bm::params, ccl_parameters::sigma8, sqrt(), ccl_parameters::sum_nu_masses, ccl_parameters::w0, ccl_parameters::wa, and ccl_parameters::z_mgrowth.

Referenced by __ctest_create_mnu_create_mnu_inv_run(), __ctest_parameters_create_general_nu_list_run(), __ctest_parameters_create_general_nu_sum_equal_run(), __ctest_parameters_create_general_nu_sum_inverted_run(), __ctest_parameters_create_general_nu_sum_run(), ccl_cosmology_create_flat_lcdm(), ccl_parameters_create_flat_lcdm(), ccl_parameters_read_yaml(), check_mgrowth(), compare_bbks(), compare_bcm(), compare_correlation_3d(), compare_distances(), compare_distances_hiz(), compare_distances_hiz_mnu(), compare_distances_mnu(), compare_eh(), compare_emu(), compare_emu_nu(), compare_growth(), compare_growth_hiz(), compare_halomod(), compare_massfunc(), compare_power_nu(), compare_power_nu_nl(), compare_sigmam(), main(), test_angpow_precision(), and write_Pk_CLASS().

301 {
302  #ifndef USE_GSL_ERROR
303  gsl_set_error_handler_off ();
304  #endif
305 
307  // Initialize params
308  params.mnu = NULL;
309  params.z_mgrowth=NULL;
310  params.df_mgrowth=NULL;
311  params.sigma8 = NAN;
312  params.A_s = NAN;
313  params.Omega_c = Omega_c;
314  params.Omega_b = Omega_b;
315  params.Omega_k = Omega_k;
316  params.Neff = Neff;
317 
318  // Set the sum of neutrino masses
319  params.sum_nu_masses = *mnu;
320  double mnusum = *mnu;
321  double *mnu_in = NULL;
322 
323  /* Check whether ccl_splines and ccl_gsl exist. If either is not set yet, load
324  parameters from the config file. */
325  if(ccl_splines==NULL || ccl_gsl==NULL) {
327  }
328 
329  // Decide how to split sum of neutrino masses between 3 neutrinos. We use
330  // a Newton's rule numerical solution (thanks M. Jarvis).
331 
332  if (mnu_type==ccl_mnu_sum){
333  // Normal hierarchy
334 
335  mnu_in = malloc(3*sizeof(double));
336 
337  // Check if the sum is zero
338  if (*mnu<1e-15){
339  mnu_in[0] = 0.;
340  mnu_in[1] = 0.;
341  mnu_in[2] = 0.;
342  } else{
343 
344  mnu_in[0] = 0.; // This is a starting guess.
345 
346  double sum_check;
347  // Check that sum is consistent
348  mnu_in[1] = sqrt(DELTAM12_sq);
349  mnu_in[2] = sqrt(DELTAM13_sq_pos);
350  sum_check = mnu_in[0] + mnu_in[1] + mnu_in[2];
351  if (ccl_mnu_sum < sum_check){
353  }
354 
355  double dsdm1;
356  // This is the Newton's method
357  while (fabs(*mnu - sum_check) > 1e-15){
358 
359  dsdm1 = 1. + mnu_in[0] / mnu_in[1] + mnu_in[0] / mnu_in[2];
360  mnu_in[0] = mnu_in[0] - (sum_check - *mnu) / dsdm1;
361  mnu_in[1] = sqrt(mnu_in[0]*mnu_in[0] + DELTAM12_sq);
362  mnu_in[2] = sqrt(mnu_in[0]*mnu_in[0] + DELTAM13_sq_pos);
363  sum_check = mnu_in[0] + mnu_in[1] + mnu_in[2];
364  }
365  }
366 
367  } else if (mnu_type==ccl_mnu_sum_inverted){
368  // Inverted hierarchy
369 
370  mnu_in = malloc(3*sizeof(double));
371 
372  // Check if the sum is zero
373  if (*mnu<1e-15){
374  mnu_in[0] = 0.;
375  mnu_in[1] = 0.;
376  mnu_in[2] = 0.;
377  } else{
378 
379  mnu_in[0] = 0.; // This is a starting guess.
380 
381  double sum_check;
382  // Check that sum is consistent
383  mnu_in[1] = sqrt(-1.* DELTAM13_sq_neg - DELTAM12_sq);
384  mnu_in[2] = sqrt(-1.* DELTAM13_sq_neg);
385  sum_check = mnu_in[0] + mnu_in[1] + mnu_in[2];
386  if (ccl_mnu_sum < sum_check){
388  }
389 
390 
391  double dsdm1;
392  // This is the Newton's method
393  while (fabs(*mnu- sum_check) > 1e-15){
394  dsdm1 = 1. + (mnu_in[0] / mnu_in[1]) + (mnu_in[0] / mnu_in[2]);
395  mnu_in[0] = mnu_in[0] - (sum_check - *mnu) / dsdm1;
396  mnu_in[1] = sqrt(mnu_in[0]*mnu_in[0] + DELTAM12_sq);
397  mnu_in[2] = sqrt(mnu_in[0]*mnu_in[0] + DELTAM13_sq_neg);
398  sum_check = mnu_in[0] + mnu_in[1] + mnu_in[2];
399  }
400 
401  }
402 
403  } else if (mnu_type==ccl_mnu_sum_equal){
404  // Split the sum of masses equally
405  mnu_in = malloc(3*sizeof(double));
406  mnu_in[0] = params.sum_nu_masses / 3.;
407  mnu_in[1] = params.sum_nu_masses / 3.;
408  mnu_in[2] = params.sum_nu_masses / 3.;
409  } else if (mnu_type == ccl_mnu_list){
410  // A list of neutrino masses was already passed in
411  params.sum_nu_masses = mnu[0] + mnu[1] + mnu[2];
412  mnu_in = malloc(3*sizeof(double));
413  for(int i=0; i<3; i++) mnu_in[i] = mnu[i];
414  } else {
416  }
417  // Check for errors in the neutrino set up (e.g. unphysical mnu)
419 
420  // Check which of the neutrino species are non-relativistic today
421  int N_nu_mass = 0;
422  for(int i = 0; i<3; i=i+1){
423  if (mnu_in[i] > 0.00017){ // Limit taken from Lesgourges et al. 2012
424  N_nu_mass = N_nu_mass + 1;
425  }
426  }
427  params.N_nu_mass = N_nu_mass;
428 
429  // Fill the array of massive neutrinos
430  if (N_nu_mass>0){
431  params.mnu = malloc(params.N_nu_mass*sizeof(double));
432  int relativistic[3] = {0, 0, 0};
433  for (int i = 0; i < N_nu_mass; i = i + 1){
434  for (int j = 0; j<3; j = j +1){
435  if ((mnu_in[j]>0.00017) && (relativistic[j]==0)){
436  relativistic[j]=1;
437  params.mnu[i] = mnu_in[j];
438  break;
439  }
440  } // end loop over neutrinos
441  } // end loop over massive neutrinos
442  } else{
443  params.mnu = malloc(sizeof(double));
444  params.mnu[0] = 0.;
445  }
446  // Free mnu_in
447  if (mnu_in != NULL) free(mnu_in);
448 
449  // Dark Energy
450  params.w0 = w0;
451  params.wa = wa;
452 
453  // Hubble parameters
454  params.h = h;
455  params.H0 = h*100;
456 
457  // Primordial power spectra
458  if(norm_pk<1E-5)
459  params.A_s=norm_pk;
460  else
461  params.sigma8=norm_pk;
462  params.n_s = n_s;
463 
464  //Baryonic params
465  if(bcm_log10Mc<0)
466  params.bcm_log10Mc=log10(1.2e14);
467  else
468  params.bcm_log10Mc=bcm_log10Mc;
469  if(bcm_etab<0)
470  params.bcm_etab=0.5;
471  else
472  params.bcm_etab=bcm_etab;
473  if(bcm_ks<0)
474  params.bcm_ks=55.0;
475  else
476  params.bcm_ks=bcm_ks;
477 
478  // Set remaining standard and easily derived parameters
480 
481  //Trigger modified growth function if nz>0
482  if(nz_mgrowth>0) {
483  params.has_mgrowth=true;
484  params.nz_mgrowth=nz_mgrowth;
485  params.z_mgrowth=malloc(params.nz_mgrowth*sizeof(double));
486  params.df_mgrowth=malloc(params.nz_mgrowth*sizeof(double));
487  memcpy(params.z_mgrowth,zarr_mgrowth,params.nz_mgrowth*sizeof(double));
488  memcpy(params.df_mgrowth,dfarr_mgrowth,params.nz_mgrowth*sizeof(double));
489  }
490  else {
491  params.has_mgrowth=false;
492  params.nz_mgrowth=0;
493  params.z_mgrowth=NULL;
494  params.df_mgrowth=NULL;
495  }
496 
497  return params;
498 }
double * df_mgrowth
Definition: ccl_core.h:70
void ccl_parameters_fill_initial(ccl_parameters *params, int *status)
Definition: ccl_core.c:226
double * mnu
Definition: ccl_core.h:40
#define DELTAM12_sq
#define CCL_ERROR_NOT_IMPLEMENTED
Definition: ccl_error.h:25
bool has_mgrowth
Definition: ccl_core.h:67
double Omega_b
Definition: ccl_core.h:20
double H0
Definition: ccl_core.h:32
double n_s
Definition: ccl_core.h:50
double h
Definition: ccl_core.h:33
double w0
Definition: ccl_core.h:28
double bcm_ks
Definition: ccl_core.h:59
double * z_mgrowth
Definition: ccl_core.h:69
double Neff
Definition: ccl_core.h:37
ccl_gsl_params * ccl_gsl
Definition: ccl_core.c:48
double sum_nu_masses
Definition: ccl_core.h:41
#define DELTAM13_sq_pos
double A_s
Definition: ccl_core.h:49
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
Definition: grid.h:231
dictionary params
Definition: halomod_bm.py:27
#define DELTAM13_sq_neg
void ccl_check_status_nocosmo(int *status)
Definition: ccl_error.c:116
void ccl_cosmology_read_config(void)
Definition: ccl_core.c:50
double sigma8
Definition: ccl_core.h:62
#define CCL_ERROR_MNU_UNPHYSICAL
Definition: ccl_error.h:26
double bcm_etab
Definition: ccl_core.h:58
double Omega_c
Definition: ccl_core.h:19
ccl_spline_params * ccl_splines
Definition: ccl_core.c:47
int nz_mgrowth
Definition: ccl_core.h:68
double bcm_log10Mc
Definition: ccl_core.h:57
double Omega_k
Definition: ccl_core.h:22
double wa
Definition: ccl_core.h:29
ccl_parameters ccl_parameters_create_flat_lcdm ( double  Omega_c,
double  Omega_b,
double  h,
double  norm_pk,
double  n_s,
int *  status 
)

Definition at line 505 of file ccl_core.c.

References ccl_mnu_sum, ccl_parameters_create(), ccl_test_distances::mnu, ccl_test_distances::Neff, and halomod_bm::params.

Referenced by __ctest_parameters_read_write_run(), compare_cls(), compare_corr(), and main().

507 {
508  double Omega_k = 0.0;
509  double Neff = 3.046;
510  double w0 = -1.0;
511  double wa = 0.0;
512  double *mnu;
513  double mnuval = 0.; // a pointer to the variable is not kept past the lifetime of this function
514  mnu = &mnuval;
515  ccl_mnu_convention mnu_type = ccl_mnu_sum;
516 
518  mnu, mnu_type, w0, wa, h, norm_pk, n_s, -1, -1, -1, -1, NULL, NULL, status);
519 
520  return params;
521 
522 }
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
ccl_mnu_convention
Definition: ccl_core.h:142
dictionary params
Definition: halomod_bm.py:27
void ccl_parameters_fill_initial ( ccl_parameters params,
int *  status 
)

Definition at line 226 of file ccl_core.c.

References ccl_parameters::A_s, ccl_check_status_nocosmo(), ccl_Omeganuh2(), CLIGHT, CLIGHT_HMPC, ccl_parameters::h, ccl_parameters::k_sign, ccl_parameters::mnu, MPC_TO_METER, ccl_parameters::N_nu_mass, ccl_parameters::N_nu_rel, ccl_parameters::Neff, ccl_parameters::Omega_b, ccl_test_distances::Omega_c, ccl_parameters::Omega_g, ccl_parameters::Omega_k, ccl_parameters::Omega_l, ccl_parameters::Omega_m, ccl_parameters::Omega_n_mass, ccl_parameters::Omega_n_rel, pow(), RHO_CRITICAL, ccl_parameters::sigma8, SOLAR_MASS, sqrt(), ccl_parameters::sqrtk, STBOLTZ, ccl_parameters::T_CMB, TCMB, TNCDM, and ccl_parameters::z_star.

Referenced by ccl_parameters_create().

227 {
228  // Fixed radiation parameters
229  // Omega_g * h**2 is known from T_CMB
230  params->T_CMB = TCMB;
231  // kg / m^3
232  double rho_g = 4. * STBOLTZ / pow(CLIGHT, 3) * pow(params->T_CMB, 4);
233  // kg / m^3
234  double rho_crit = RHO_CRITICAL * SOLAR_MASS/pow(MPC_TO_METER, 3) * pow(params->h, 2);
235  params->Omega_g = rho_g/rho_crit;
236 
237  // Get the N_nu_rel from Neff and N_nu_mass
238  params->N_nu_rel = params->Neff - params->N_nu_mass * pow(TNCDM, 4) / pow(4./11.,4./3.);
239 
240  // Temperature of the relativistic neutrinos in K
241  double T_nu= (params->T_CMB) * pow(4./11.,1./3.);
242  // in kg / m^3
243  double rho_nu_rel = params->N_nu_rel* 7.0/8.0 * 4. * STBOLTZ / pow(CLIGHT, 3) * pow(T_nu, 4);
244  params-> Omega_n_rel = rho_nu_rel/rho_crit;
245 
246  // If non-relativistic neutrinos are present, calculate the phase_space integral.
247  if((params->N_nu_mass)>0) {
248  // Pass NULL for the accelerator here because we don't have our cosmology object defined yet.
249  params->Omega_n_mass = ccl_Omeganuh2(1.0, params->N_nu_mass, params->mnu, params->T_CMB, NULL, status) / ((params->h)*(params->h));
251  }
252  else{
253  params->Omega_n_mass = 0.;
254  }
255 
256  params->Omega_m = params->Omega_b + params-> Omega_c;
257  params->Omega_l = 1.0 - params->Omega_m - params->Omega_g - params->Omega_n_rel -params->Omega_n_mass- params->Omega_k;
258  // Initially undetermined parameters - set to nan to trigger
259  // problems if they are mistakenly used.
260  if (isfinite(params->A_s)) {params->sigma8 = NAN;}
261  if (isfinite(params->sigma8)) {params->A_s = NAN;}
262  params->z_star = NAN;
263 
264  if(fabs(params->Omega_k)<1E-6)
265  params->k_sign=0;
266  else if(params->Omega_k>0)
267  params->k_sign=-1;
268  else
269  params->k_sign=1;
270  params->sqrtk=sqrt(fabs(params->Omega_k))*params->h/CLIGHT_HMPC;
271 }
double Omega_g
Definition: ccl_core.h:53
double * mnu
Definition: ccl_core.h:40
double Omega_b
Definition: ccl_core.h:20
double N_nu_rel
Definition: ccl_core.h:39
#define CLIGHT_HMPC
Definition: ccl_constants.h:33
double Omega_n_mass
Definition: ccl_core.h:42
#define TNCDM
double h
Definition: ccl_core.h:33
double Omega_l
Definition: ccl_core.h:63
double Neff
Definition: ccl_core.h:37
double A_s
Definition: ccl_core.h:49
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
Definition: grid.h:231
double sqrtk
Definition: ccl_core.h:23
#define TCMB
Definition: ccl_constants.h:95
double Omega_n_rel
Definition: ccl_core.h:43
double T_CMB
Definition: ccl_core.h:54
void ccl_check_status_nocosmo(int *status)
Definition: ccl_error.c:116
double ccl_Omeganuh2(double a, int N_nu_mass, double *mnu, double T_CMB, gsl_interp_accel *accel, int *status)
double sigma8
Definition: ccl_core.h:62
#define MPC_TO_METER
Definition: ccl_constants.h:51
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
#define SOLAR_MASS
Definition: ccl_constants.h:47
#define STBOLTZ
Definition: ccl_constants.h:73
double Omega_k
Definition: ccl_core.h:22
double Omega_m
Definition: ccl_core.h:21
#define CLIGHT
Definition: ccl_constants.h:84
#define RHO_CRITICAL
Definition: ccl_constants.h:61
double z_star
Definition: ccl_core.h:64
void ccl_parameters_free ( ccl_parameters params)

Free a parameters struct

Parameters
paramsccl_parameters struct
Returns
void

Definition at line 808 of file ccl_core.c.

References ccl_parameters::df_mgrowth, ccl_parameters::mnu, and ccl_parameters::z_mgrowth.

809 {
810  if (params->mnu != NULL){
811  free(params->mnu);
812  params->mnu = NULL;
813  }
814  if (params->z_mgrowth != NULL){
815  free(params->z_mgrowth);
816  params->z_mgrowth = NULL;
817  }
818  if (params->df_mgrowth != NULL){
819  free(params->df_mgrowth);
820  params->df_mgrowth = NULL;
821  }
822 }
double * df_mgrowth
Definition: ccl_core.h:70
double * mnu
Definition: ccl_core.h:40
double * z_mgrowth
Definition: ccl_core.h:69
ccl_parameters ccl_parameters_read_yaml ( const char *  filename,
int *  status 
)

Write a cosmology parameters object to a file in yaml format.

Parameters
cosmoCosmological parameters
fFILE* pointer opened for reading
Returns
void

Definition at line 624 of file ccl_core.c.

References ccl_test_distances::A_s, CCL_ERROR_FILE_READ, ccl_mnu_list, ccl_parameters_create(), ccl_raise_exception(), ccl_test_distances::h, ccl_test_distances::mnu, ccl_test_distances::n_s, ccl_test_distances::Neff, ccl_test_distances::Omega_b, ccl_test_distances::Omega_c, halomod_bm::params, READ_DOUBLE, READ_INT, and ccl_test_power::sigma8.

Referenced by __ctest_parameters_read_write_run().

625 {
626 
627  FILE * f = fopen(filename, "r");
628 
629  if (!f){
631  ccl_parameters bad_params;
632 
633  ccl_raise_exception(CCL_ERROR_FILE_READ, "ccl_core.c: Failed to read parameters from file.");
634 
635  return bad_params;
636  }
637 
638 #define READ_DOUBLE(name) double name; *status |= (0==fscanf(f, #name ": %le\n",&name));
639 #define READ_INT(name) int name; *status |= (0==fscanf(f, #name ": %d\n",&name))
640 
641  // Densities: CDM, baryons, total matter, curvature
644  READ_DOUBLE(Omega_m);
645  READ_DOUBLE(Omega_k);
646  READ_INT(k_sign);
647 
648  // Dark Energy
649  READ_DOUBLE(w0);
650  READ_DOUBLE(wa);
651 
652  // Hubble parameters
653  READ_DOUBLE(H0);
654  READ_DOUBLE(h);
655 
656  // Neutrino properties
657  READ_DOUBLE(Neff);
658  READ_INT(N_nu_mass);
659  READ_DOUBLE(N_nu_rel);
660 
661  double mnu[3] = {0.0, 0.0, 0.0};
662  if (N_nu_mass>0){
663  *status |= (0==fscanf(f, "mnu: ["));
664  for (int i=0; i<N_nu_mass; i++){
665  *status |= (0==fscanf(f, "%le, ", mnu+i));
666  }
667  *status |= (0==fscanf(f, "]\n"));
668  }
669 
670  READ_DOUBLE(sum_nu_masses);
671  READ_DOUBLE(Omega_n_mass);
672  READ_DOUBLE(Omega_n_rel);
673 
674  // Primordial power spectra
675  READ_DOUBLE(A_s);
676  READ_DOUBLE(n_s);
677 
678  // Radiation parameters
679  READ_DOUBLE(Omega_g);
680  READ_DOUBLE(T_CMB);
681 
682  // BCM baryonic model parameters
683  READ_DOUBLE(bcm_log10Mc);
684  READ_DOUBLE(bcm_etab);
685  READ_DOUBLE(bcm_ks);
686 
687  // Derived parameters
689  READ_DOUBLE(Omega_l);
690  READ_DOUBLE(z_star);
691 
692  READ_INT(has_mgrowth);
693  READ_INT(nz_mgrowth);
694 
695  double *z_mgrowth;
696  double *df_mgrowth;
697 
698 
699  if (has_mgrowth){
700  z_mgrowth = malloc(nz_mgrowth*sizeof(double));
701  df_mgrowth = malloc(nz_mgrowth*sizeof(double));
702  *status |= (0==fscanf(f, "z_mgrowth: ["));
703  for (int i=0; i<nz_mgrowth; i++){
704  *status |= (0==fscanf(f, "%le, ", z_mgrowth+i));
705  }
706  *status |= (0==fscanf(f, "]\n"));
707 
708  *status |= (0==fscanf(f, "df_mgrowth: ["));
709  for (int i=0; i<nz_mgrowth; i++){
710  *status |= (0==fscanf(f, "%le, ", df_mgrowth+i));
711  }
712  *status |= (0==fscanf(f, "]\n"));
713  }
714  else{
715  z_mgrowth = NULL;
716  df_mgrowth = NULL;
717  }
718 
719 #undef READ_DOUBLE
720 #undef READ_INT
721 
722  fclose(f);
723 
724 
725  if (status){
726  char msg[256];
727  snprintf(msg, 256, "ccl_core.c: Structure of YAML file incorrect: %s", filename);
729  }
730 
731  double norm_pk;
732 
733  if (isnan(A_s)){
734  norm_pk = sigma8;
735  }
736  else{
737  norm_pk = A_s;
738  }
739 
741  Omega_c, Omega_b, Omega_k,
742  Neff, mnu, ccl_mnu_list,
743  w0, wa, h, norm_pk,
744  n_s, bcm_log10Mc, bcm_etab,
745  bcm_ks, nz_mgrowth, z_mgrowth,
746  df_mgrowth, status);
747 
748  if(z_mgrowth) free(z_mgrowth);
749  if (df_mgrowth) free(df_mgrowth);
750 
751  return params;
752 
753 }
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
#define CCL_ERROR_FILE_READ
Definition: ccl_error.h:36
#define READ_DOUBLE(name)
dictionary params
Definition: halomod_bm.py:27
#define READ_INT(name)
void ccl_raise_exception(int err, const char *msg,...)
Definition: ccl_error.c:35
void ccl_parameters_write_yaml ( ccl_parameters params,
const char *  filename,
int *  status 
)

Write a cosmology parameters object to a file in yaml format.

Parameters
cosmoCosmological parameters
fFILE* pointer opened for reading
Returns
void

Definition at line 531 of file ccl_core.c.

References ccl_test_distances::A_s, CCL_ERROR_FILE_WRITE, ccl_parameters::df_mgrowth, ccl_test_distances::h, ccl_parameters::has_mgrowth, ccl_parameters::mnu, ccl_parameters::N_nu_mass, ccl_test_distances::n_s, ccl_test_distances::Neff, ccl_parameters::nz_mgrowth, ccl_test_distances::Omega_b, ccl_test_distances::Omega_c, ccl_test_power::sigma8, WRITE_DOUBLE, WRITE_INT, and ccl_parameters::z_mgrowth.

Referenced by __ctest_parameters_read_write_run().

532 {
533 
534  FILE * f = fopen(filename, "w");
535 
536  if (!f){
538  return;
539  }
540 
541 #define WRITE_DOUBLE(name) fprintf(f, #name ": %le\n",params->name)
542 #define WRITE_INT(name) fprintf(f, #name ": %d\n",params->name)
543 
544  // Densities: CDM, baryons, total matter, curvature
547  WRITE_DOUBLE(Omega_m);
548  WRITE_DOUBLE(Omega_k);
549  WRITE_INT(k_sign);
550 
551  // Dark Energy
552  WRITE_DOUBLE(w0);
553  WRITE_DOUBLE(wa);
554 
555  // Hubble parameters
556  WRITE_DOUBLE(H0);
557  WRITE_DOUBLE(h);
558 
559  // Neutrino properties
561  WRITE_INT(N_nu_mass);
562  WRITE_DOUBLE(N_nu_rel);
563 
564  if (params->N_nu_mass>0){
565  fprintf(f, "mnu: [");
566  for (int i=0; i<params->N_nu_mass; i++){
567  fprintf(f, "%le, ", params->mnu[i]);
568  }
569  fprintf(f, "]\n");
570  }
571 
572  WRITE_DOUBLE(sum_nu_masses);
573  WRITE_DOUBLE(Omega_n_mass);
574  WRITE_DOUBLE(Omega_n_rel);
575 
576  // Primordial power spectra
577  WRITE_DOUBLE(A_s);
578  WRITE_DOUBLE(n_s);
579 
580  // Radiation parameters
581  WRITE_DOUBLE(Omega_g);
582  WRITE_DOUBLE(T_CMB);
583 
584  // BCM baryonic model parameters
585  WRITE_DOUBLE(bcm_log10Mc);
586  WRITE_DOUBLE(bcm_etab);
587  WRITE_DOUBLE(bcm_ks);
588 
589  // Derived parameters
591  WRITE_DOUBLE(Omega_l);
592  WRITE_DOUBLE(z_star);
593 
594  WRITE_INT(has_mgrowth);
595  WRITE_INT(nz_mgrowth);
596 
597  if (params->has_mgrowth){
598  fprintf(f, "z_mgrowth: [");
599  for (int i=0; i<params->nz_mgrowth; i++){
600  fprintf(f, "%le, ", params->z_mgrowth[i]);
601  }
602  fprintf(f, "]\n");
603 
604  fprintf(f, "df_mgrowth: [");
605  for (int i=0; i<params->nz_mgrowth; i++){
606  fprintf(f, "%le, ", params->df_mgrowth[i]);
607  }
608  fprintf(f, "]\n");
609  }
610 
611 #undef WRITE_DOUBLE
612 #undef WRITE_INT
613 
614  fclose(f);
615 
616 }
double * df_mgrowth
Definition: ccl_core.h:70
double * mnu
Definition: ccl_core.h:40
bool has_mgrowth
Definition: ccl_core.h:67
#define WRITE_INT(name)
double * z_mgrowth
Definition: ccl_core.h:69
#define CCL_ERROR_FILE_WRITE
Definition: ccl_error.h:35
int nz_mgrowth
Definition: ccl_core.h:68
#define WRITE_DOUBLE(name)

Variable Documentation

const ccl_gsl_params default_gsl_params
Initial value:
}
#define GSL_EPSABS_NU
#define GSL_EPSREL_DIST
#define GSL_EPSREL_DNDZ
#define GSL_EPSREL_SIGMAR
#define GSL_EPSREL_NU
#define GSL_INTEGRATION_GAUSS_KRONROD_POINTS
#define GSL_N_ITERATION
#define GSL_EPSREL
#define GSL_EPSREL_GROWTH

Definition at line 23 of file ccl_core.c.