Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_corr_sample.c
Go to the documentation of this file.
1 #include "ccl.h"
2 #include "ccl_correlation.h"
3 #include "ccl_utils.h"
4 #include "ctest.h"
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <math.h>
8 #include <time.h>
9 #include <string.h>
10 
11 // Define cosmological parameter values
12 #define OC 0.25
13 #define OB 0.05
14 #define OK 0.00
15 #define ON 0.00
16 #define HH 0.70
17 #define W0 -1.0
18 #define WA 0.00
19 #define NS 0.96
20 #define NORMPS 0.80
21 #define ZD 0.5
22 #define NZ 128
23 #define Z0_GC 0.50
24 #define SZ_GC 0.05
25 #define NL 512
26 #define PS 0.1
27 #define NEFF 3.046
28 #define ELL_MAX_CL 20000
29 
30 
31 int main(int argc,char **argv)
32 {
33  // Use the default configuration, plus the cosmological parameters that were
34  // defined above
35  int status=0;
36 
37  double mnuval=0.;
38  double* mnu;
39  mnu = &mnuval;
41 
44  W0, WA, HH, NORMPS, NS, -1, -1, -1, -1,
45  NULL, NULL, &status);
46  ccl_cosmology *cosmo = ccl_cosmology_create(params,config);
47 
48  // Create example number density and bias for tracer
49  double z_arr_gc[NZ], nz_arr_gc[NZ], bz_arr[NZ];
50  for(int i=0; i < NZ; i++) {
51  z_arr_gc[i] = Z0_GC - 5.*SZ_GC + 10.*SZ_GC*(i + 0.5)/NZ;
52  nz_arr_gc[i] = exp(-0.5*pow((z_arr_gc[i] - Z0_GC) / SZ_GC, 2));
53  bz_arr[i] = 1. + z_arr_gc[i];
54  }
55 
56  // Define a galaxy clustering tracer and calculate C_ell's
57  double l_logstep = 1.05;
58  double l_linstep = 5.;
59  CCL_ClWorkspace *w=ccl_cl_workspace_new_limber(ELL_MAX_CL+1,l_logstep,l_linstep,&status);
60  //CCL_ClTracer *tr_nc_1=ccl_cl_tracer_number_counts_simple(cosmo,nz,zarr_1,pzarr_1,nz,zarr_1,bzarr,&status);
62  NZ, z_arr_gc, nz_arr_gc,
63  NZ, z_arr_gc, bz_arr,
64  &status);
65  int il;
66  double *clarr = malloc(ELL_MAX_CL*sizeof(double));
67  int *ilarr = malloc(ELL_MAX_CL*sizeof(int));
68  double *larr = malloc(ELL_MAX_CL*sizeof(double));
69  for(il=0; il < ELL_MAX_CL; il++)
70  // Calculate auto-correlation of this tracer
71  larr[il] = il;
72  ccl_angular_cls(cosmo, w, ct_gc, ct_gc, ELL_MAX_CL, ilarr, clarr, &status);
73 
74  // Define cosine tapering, to reduce ringing. The first two numbers are
75  // [lmin, lmax] for the low-ell taper, and the last two are [lmin, lmax] for
76  // the high-ell taper.
77  double taper_cl_limits[4] = {1, 2, 10000, 15000};
78 
79  double *clustering_corr, *theta;
80  int ntheta = 15;
81  theta = ccl_log_spacing(0.01, 5., ntheta); // New array with log spacing
82  clustering_corr = malloc(ntheta*sizeof(double));
83 
84  // Calculate correlation function from angular power spectrum
85  ccl_correlation(cosmo, ELL_MAX_CL, larr, clarr,
86  ntheta, theta, clustering_corr,
87  CCL_CORR_GG, 0, taper_cl_limits,
88  CCL_CORR_FFTLOG, &status);
89 
90  // Print results
91  for(int it=0; it < ntheta; it++)
92  printf("%le %le\n", theta[it], clustering_corr[it]);
93 
94  // Free tracers and other allocated memory
96  ccl_cl_tracer_free(ct_gc);
97  ccl_cosmology_free(cosmo);
98  free(clustering_corr);
99  free(ilarr);
100  free(larr);
101  free(clarr);
102 
103  return 0;
104 }
#define W0
#define OC
#define Z0_GC
#define SZ_GC
#define ELL_MAX_CL
double * ccl_log_spacing(double xmin, double xmax, int N)
Definition: ccl_utils.c:102
#define WA
void ccl_cl_tracer_free(CCL_ClTracer *clt)
Definition: ccl_cls.c:592
#define OK
CCL_ClWorkspace * ccl_cl_workspace_new_limber(int lmax, double l_logstep, int l_linstep, int *status)
Definition: ccl_cls.c:124
void ccl_angular_cls(ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt1, CCL_ClTracer *clt2, int nl_out, int *l, double *cl, int *status)
Definition: ccl_cls.c:943
ccl_cosmology * ccl_cosmology_create(ccl_parameters params, ccl_configuration config)
Definition: ccl_core.c:173
ccl_mnu_convention
Definition: ccl_core.h:142
int main(int argc, char **argv)
CCL_ClTracer * ccl_cl_tracer_number_counts_simple(ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int nz_b, double *z_b, double *b, int *status)
Definition: ccl_cls.c:633
void ccl_cosmology_free(ccl_cosmology *cosmo)
Definition: ccl_core.c:829
dictionary params
Definition: halomod_bm.py:27
#define CCL_CORR_GG
#define CCL_CORR_FFTLOG
CCL_BEGIN_DECLS void ccl_correlation(ccl_cosmology *cosmo, int n_ell, double *ell, double *cls, int n_theta, double *theta, double *wtheta, int corr_type, int do_taper_cl, double *taper_cl_limits, int flag_method, int *status)
#define NZ
#define NORMPS
const ccl_configuration default_config
Definition: ccl_core.c:21
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
void ccl_cl_workspace_free(CCL_ClWorkspace *w)
Definition: ccl_cls.c:59
#define OB
#define NEFF
#define NS
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 double w[2][28][111]
Definition: ccl_emu17.c:33
#define HH