7 #include <gsl/gsl_errno.h> 8 #include <gsl/gsl_odeiv.h> 9 #include <gsl/gsl_spline.h> 10 #include <gsl/gsl_integration.h> 17 #define EXPAND_STR(s) STRING(s) 53 int CONFIG_LINE_BUFFER_SIZE=100;
54 int MAX_CONFIG_VAR_LEN=100;
56 char buf[CONFIG_LINE_BUFFER_SIZE];
57 char var_name[MAX_CONFIG_VAR_LEN];
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;
69 param_file =
EXPAND_STR(__CCL_DATA_DIR__)
"/ccl_params.ini";
71 if ((fconfig=fopen(param_file,
"r")) == NULL) {
76 if(ccl_splines == NULL) {
85 if(ccl_splines==NULL || ccl_gsl==NULL) {
90 #define MATCH(s, action) if (0 == strcmp(var_name, s)) { action ; continue;} do{} while(0) 93 while(! feof(fconfig)) {
94 rtn = fgets(buf, CONFIG_LINE_BUFFER_SIZE, fconfig);
97 if (buf[0]==
';' || buf[0]==
'[' || buf[0]==
'\n') {
101 sscanf(buf,
"%99[^=]=%le\n",var_name, &var_dbl);
120 MATCH(
"N_K", ccl_splines->
N_K=(
int) var_dbl);
182 cosmo->
data.
E = NULL;
235 params->
Omega_g = rho_g/rho_crit;
241 double T_nu= (params->
T_CMB) *
pow(4./11.,1./3.);
244 params-> Omega_n_rel = rho_nu_rel/rho_crit;
260 if (isfinite(params->
A_s)) {params->
sigma8 = NAN;}
261 if (isfinite(params->
sigma8)) {params->
A_s = NAN;}
297 double w0,
double wa,
double h,
double norm_pk,
298 double n_s,
double bcm_log10Mc,
double bcm_etab,
299 double bcm_ks,
int nz_mgrowth,
double *zarr_mgrowth,
300 double *dfarr_mgrowth,
int *status)
302 #ifndef USE_GSL_ERROR 303 gsl_set_error_handler_off ();
320 double mnusum = *
mnu;
321 double *mnu_in = NULL;
325 if(ccl_splines==NULL || ccl_gsl==NULL) {
335 mnu_in = malloc(3*
sizeof(
double));
350 sum_check = mnu_in[0] + mnu_in[1] + mnu_in[2];
357 while (fabs(*mnu - sum_check) > 1e-15){
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;
363 sum_check = mnu_in[0] + mnu_in[1] + mnu_in[2];
370 mnu_in = malloc(3*
sizeof(
double));
385 sum_check = mnu_in[0] + mnu_in[1] + mnu_in[2];
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;
398 sum_check = mnu_in[0] + mnu_in[1] + mnu_in[2];
405 mnu_in = malloc(3*
sizeof(
double));
412 mnu_in = malloc(3*
sizeof(
double));
413 for(
int i=0; i<3; i++) mnu_in[i] = mnu[i];
422 for(
int i = 0; i<3; i=i+1){
423 if (mnu_in[i] > 0.00017){
424 N_nu_mass = N_nu_mass + 1;
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)){
437 params.
mnu[i] = mnu_in[j];
443 params.
mnu = malloc(
sizeof(
double));
447 if (mnu_in != NULL) free(mnu_in);
506 double norm_pk,
double n_s,
int *status)
508 double Omega_k = 0.0;
518 mnu, mnu_type, w0, wa, h, norm_pk, n_s, -1, -1, -1, -1, NULL, NULL, status);
534 FILE * f = fopen(filename,
"w");
541 #define WRITE_DOUBLE(name) fprintf(f, #name ": %le\n",params->name) 542 #define WRITE_INT(name) fprintf(f, #name ": %d\n",params->name) 565 fprintf(f,
"mnu: [");
567 fprintf(f,
"%le, ", params->
mnu[i]);
598 fprintf(f,
"z_mgrowth: [");
600 fprintf(f,
"%le, ", params->
z_mgrowth[i]);
604 fprintf(f,
"df_mgrowth: [");
627 FILE * f = fopen(filename,
"r");
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)) 661 double mnu[3] = {0.0, 0.0, 0.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));
667 *status |= (0==fscanf(f,
"]\n"));
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));
706 *status |= (0==fscanf(f,
"]\n"));
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));
712 *status |= (0==fscanf(f,
"]\n"));
727 snprintf(msg, 256,
"ccl_core.c: Structure of YAML file incorrect: %s", filename);
744 n_s, bcm_log10Mc, bcm_etab,
745 bcm_ks, nz_mgrowth, z_mgrowth,
748 if(z_mgrowth) free(z_mgrowth);
749 if (df_mgrowth) free(df_mgrowth);
767 gsl_spline_free(data->
chi);
768 gsl_spline_free(data->
growth);
769 gsl_spline_free(data->
fgrowth);
772 gsl_spline_free(data->
E);
773 gsl_spline_free(data->
achi);
776 gsl_spline2d_free(data->
p_lin);
777 gsl_spline2d_free(data->
p_nl);
779 gsl_spline_free(data->
betahmf);
781 gsl_spline_free(data->
phihmf);
782 gsl_spline_free(data->
etahmf);
794 const int trunc = 480;
796 va_start(va, message);
810 if (params->
mnu != NULL){
gsl_interp_accel * accelerator_m
double INTEGRATION_NU_EPSREL
int INTEGRATION_LIMBER_GAUSS_KRONROD_POINTS
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *message,...)
double INTEGRATION_SIGMAR_EPSREL
const ccl_configuration default_config
int INTEGRATION_GAUSS_KRONROD_POINTS
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)
#define CCL_ERROR_NOT_IMPLEMENTED
#define GSL_EPSREL_SIGMAR
#define CCL_ERROR_MISSING_CONFIG_FILE
void ccl_parameters_write_yaml(ccl_parameters *params, const char *filename, int *status)
double INTEGRATION_DNDZ_EPSREL
#define CCL_ERROR_FILE_READ
#define READ_DOUBLE(name)
double INTEGRATION_NU_EPSABS
gsl_interp_accel * accelerator_d
#define GSL_INTEGRATION_GAUSS_KRONROD_POINTS
double INTEGRATION_DISTANCE_EPSREL
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
gsl_interp_accel * accelerator_achi
double INTEGRATION_EPSREL
void ccl_cosmology_free(ccl_cosmology *cosmo)
#define CCL_ERROR_FILE_WRITE
gsl_interp_accel * accelerator_k
ccl_parameters ccl_parameters_read_yaml(const char *filename, int *status)
void ccl_data_free(ccl_data *data)
gsl_interp_accel * accelerator
void ccl_check_status_nocosmo(int *status)
double ccl_Omeganuh2(double a, int N_nu_mass, double *mnu, double T_CMB, gsl_interp_accel *accel, int *status)
void ccl_cosmology_read_config(void)
#define CCL_ERROR_MNU_UNPHYSICAL
void ccl_parameters_free(ccl_parameters *params)
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
const ccl_gsl_params default_gsl_params
float pow(float base, unsigned long int exp)
gsl_spline * dlnsigma_dlogm
ccl_spline_params * ccl_splines
#define GSL_EPSREL_GROWTH
double INTEGRATION_LIMBER_EPSREL
double A_SPLINE_MINLOG_PK
void ccl_raise_exception(int err, const char *msg,...)
ccl_parameters ccl_parameters_create_flat_lcdm(double Omega_c, double Omega_b, double h, double norm_pk, double n_s, int *status)
#define WRITE_DOUBLE(name)