6 #include <gsl/gsl_errno.h> 7 #include <gsl/gsl_integration.h> 12 #include "Angpow/angpow_ccl.h" 15 #define CCL_FRAC_RELEVANT 5E-4 20 double *xmin_out,
double *xmax_out)
31 if(y[ix]>ythr) ythr=y[ix];
44 for(ix=n-1;ix>=0;ix--) {
66 double l_logstep,
int l_linstep,
int *status)
83 while((l0 < w->lmax) && (increment < w->l_linstep)) {
96 w->
l_arr=(
int *)malloc(w->
n_ls*
sizeof(
int));
105 while((l0 < w->lmax) && (increment < w->l_linstep)) {
112 while(l0 < w->lmax) {
161 int gslstatus =0, status =0;
162 double result,eresult;
176 gslstatus=gsl_integration_qag(&F, chi, chi_max, 0,
179 w, &result, &eresult);
181 gsl_integration_workspace_free(w);
182 if(gslstatus!=GSL_SUCCESS || *ip.
status) {
213 return h*pz*(1-2.5*
sz);
226 double chi_max,
double *win)
228 int gslstatus =0, status =0;
229 double result,eresult;
245 gslstatus=gsl_integration_qag(&F, chi, chi_max, 0,
248 w, &result, &eresult);
250 gsl_integration_workspace_free(w);
251 if(gslstatus!=GSL_SUCCESS || *ip.
status) {
262 int nz_n,
double *z_n,
double *n,
int *status)
266 double nz_norm,nz_enorm;
267 double *nz_normalized;
281 nz_normalized=(
double *)malloc(nz_n*
sizeof(
double));
282 if(nz_normalized==NULL) {
294 gslstatus=gsl_integration_qag(&F, z_n[0], z_n[nz_n-1], 0,
297 w, &nz_norm, &nz_enorm);
298 gsl_integration_workspace_free(w);
299 if(gslstatus!=GSL_SUCCESS) {
307 for(
int ii=0;ii<nz_n;ii++)
308 nz_normalized[ii]=n[ii]/nz_norm;
321 int nz_b,
double *z_b,
double *b,
int *status)
332 int nz_s,
double *z_s,
double *s,
int *status)
349 "ccl_cls.c: clt_init_wM(): error initializing spline for s(z)\n");
353 nchi=(int)(chimax/dchi_here)+1;
355 dchi_here=chimax/nchi;
356 if(x==NULL || (fabs(x[0]-0)>1E-5) || (fabs(x[nchi-1]-chimax)>1e-5)) {
359 "ccl_cls.c: clt_init_wM(): Error creating linear spacing in chi\n");
364 y=(
double *)malloc(nchi*
sizeof(
double));
373 for(
int j=0;j<nchi;j++)
386 "ccl_cls.c: clt_init_wM(): error initializing spline for lensing window\n");
394 int has_rsd,
int has_magnification,
395 int nz_n,
double *z_n,
double *n,
396 int nz_b,
double *z_b,
double *b,
397 int nz_s,
double *z_s,
double *s,
int *status)
404 ccl_cosmology_set_status_message(cosmo,
"ccl_cls.c: ccl_cl_tracer_new(): Number counts tracers with RSD not yet implemented in cosmologies with massive neutrinos.");
428 nchi=(int)(chimax/dchi_here)+1;
430 dchi_here=chimax/nchi;
431 if(x==NULL || (fabs(x[0]-0)>1E-5) || (fabs(x[nchi-1]-chimax)>1e-5)) {
434 "ccl_cls.c: clt_init_wL(): Error creating linear spacing in chi\n");
438 y=(
double *)malloc(nchi*
sizeof(
double));
447 for(
int j=0;j<nchi;j++)
460 "ccl_cls.c: clt_init_wL(): error initializing spline for lensing window\n");
467 int nz_rf,
double *z_rf,
double *rf,
int *status)
478 int nz_ba,
double *z_ba,
double *ba,
int *status)
489 int has_intrinsic_alignment,
490 int nz_n,
double *z_n,
double *n,
491 int nz_ba,
double *z_ba,
double *ba,
492 int nz_rf,
double *z_rf,
double *rf,
int *status)
516 int has_rsd,
int has_magnification,
int has_intrinsic_alignment,
517 int nz_n,
double *z_n,
double *n,
518 int nz_b,
double *z_b,
double *b,
519 int nz_s,
double *z_s,
double *s,
520 int nz_ba,
double *z_ba,
double *ba,
521 int nz_rf,
double *z_rf,
double *rf,
522 double z_source,
int * status)
539 nz_n,z_n,n,nz_b,z_b,b,nz_s,z_s,s,status);
542 nz_n,z_n,n,nz_ba,z_ba,ba,nz_rf,z_rf,rf,status);
576 int has_rsd,
int has_magnification,
int has_intrinsic_alignment,
577 int nz_n,
double *z_n,
double *n,
578 int nz_b,
double *z_b,
double *b,
579 int nz_s,
double *z_s,
double *s,
580 int nz_ba,
double *z_ba,
double *ba,
581 int nz_rf,
double *z_rf,
double *rf,
582 double z_source,
int * status)
585 nz_n,z_n,n,nz_b,z_b,b,nz_s,z_s,s,
586 nz_ba,z_ba,ba,nz_rf,z_rf,rf,z_source,status);
618 0,NULL,NULL,0,NULL,NULL,0,NULL,NULL,
619 0,NULL,NULL,0,NULL,NULL,z_source,status);
623 int has_rsd,
int has_magnification,
624 int nz_n,
double *z_n,
double *n,
625 int nz_b,
double *z_b,
double *b,
626 int nz_s,
double *z_s,
double *s,
int * status)
629 nz_n,z_n,n,nz_b,z_b,b,nz_s,z_s,s,
630 -1,NULL,NULL,-1,NULL,NULL,0, status);
634 int nz_n,
double *z_n,
double *n,
635 int nz_b,
double *z_b,
double *b,
int * status)
638 nz_n,z_n,n,nz_b,z_b,b,-1,NULL,NULL,
639 -1,NULL,NULL,-1,NULL,NULL,0, status);
644 int nz_n,
double *z_n,
double *n,
645 int nz_ba,
double *z_ba,
double *ba,
646 int nz_rf,
double *z_rf,
double *rf,
int * status)
649 nz_n,z_n,n,-1,NULL,NULL,-1,NULL,NULL,
650 nz_ba,z_ba,ba,nz_rf,z_rf,rf,0, status);
654 int nz_n,
double *z_n,
double *n,
int * status)
657 nz_n,z_n,n,-1,NULL,NULL,-1,NULL,NULL,
658 -1,NULL,NULL,-1,NULL,NULL,0, status);
703 if(chi0<=clt->chimax) {
705 double f_all=
f_dens(a0,cosmo,clt,status);
709 if(chi1<=clt->chimax) {
713 double fg0=
f_rsd(a0,cosmo,clt,status);
714 double fg1=
f_rsd(a1,cosmo,clt,status);
715 f_all+=fg0*(1.-l*(l-1.)/(x0*x0))-fg1*2.*
sqrt((l+0.5)*pk1/((l+1.5)*pk0))/x1;
748 return pz*ba*rf*h/(chi*chi);
762 double chi=(l+0.5)/k;
763 if(chi<=clt->chimax) {
765 double f_all=
f_lensing(a,chi,cosmo,clt,status);
767 f_all+=
f_IA_NLA(a,chi,cosmo,clt,status);
772 return sqrt((l+2.)*(l+1.)*l*(l-1.))*ret/(k*k);
778 double chi=(l+0.5)/k;
782 if(chi<=clt->chimax) {
798 double transfer_out=0;
799 double k=
pow(10.,lk);
834 double k=
pow(10.,lk);
835 double chi=(p->
w->
l_arr[p->
il]+0.5)/k;
849 double *lkmin,
double *lkmax)
851 double chimin,chimax;
852 int cut_low_1=0,cut_low_2=0;
892 int clastatus=0, gslstatus;
894 double result=0,eresult;
912 gslstatus=gsl_integration_qag(&F, lkmin, lkmax, 0,
915 w, &result, &eresult);
916 gsl_integration_workspace_free(w);
920 if(gslstatus == GSL_EROUND) {
921 ccl_raise_gsl_warning(gslstatus,
"ccl_cls.c: ccl_angular_cl_native(): Default GSL integration failure, attempting backup method.");
922 gsl_integration_cquad_workspace *w_cquad= gsl_integration_cquad_workspace_alloc (
ccl_gsl->
N_ITERATION);
924 gslstatus=gsl_integration_cquad(&F, lkmin, lkmax, 0,
926 w_cquad, &result, &eresult, &nevals);
927 gsl_integration_cquad_workspace_free(w_cquad);
929 if(gslstatus!=GSL_SUCCESS || *ipar.
status) {
940 return result*M_LN10/(cw->
l_arr[il]+0.5);
945 int nl_out,
int *l_out,
double *cl_out,
int *status)
948 double *l_nodes,*cl_nodes;
952 for(ii=0;ii<nl_out;ii++) {
953 if(l_out[ii]>w->
lmax) {
956 "requested l beyond range allowed by workspace\n");
963 l_nodes=(
double *)malloc(w->
n_ls*
sizeof(
double));
971 cl_nodes=(
double *)malloc(w->
n_ls*
sizeof(
double));
979 for(ii=0;ii<w->
n_ls;ii++)
980 l_nodes[ii]=(
double)(w->
l_arr[ii]);
985 for(ii=0;ii<w->
n_ls;ii++) {
1002 ccl_angular_cls_angpow(cosmo,w,clt1,clt2,cl_nodes,status);
1008 for(ii=0;ii<w->
n_ls;ii++) {
1015 if(spcl_nodes==NULL) {
1022 for(ii=0;ii<nl_out;ii++)
1092 int func_code,
int *status)
1129 for(ia=0;ia<na;ia++) {
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
static void clt_init_rf(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_rf, double *z_rf, double *rf, int *status)
void ccl_cl_workspace_free(CCL_ClWorkspace *w)
static void clt_init_ba(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_ba, double *z_ba, double *ba, int *status)
static double transfer_nc(int l, double k, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
int INTEGRATION_LIMBER_GAUSS_KRONROD_POINTS
static int window_lensing(double chi, ccl_cosmology *cosmo, SplPar *spl_pz, double chi_max, double *win)
double ccl_h_over_h0(ccl_cosmology *cosmo, double a, int *status)
static double transfer_cmblens(int l, double k, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
static void clt_init_wL(CCL_ClTracer *clt, ccl_cosmology *cosmo, int *status)
void ccl_raise_gsl_warning(int gslstatus, const char *msg,...)
int has_intrinsic_alignment
int INTEGRATION_GAUSS_KRONROD_POINTS
static void get_support_interval(int n, double *x, double *y, double frac, double *xmin_out, double *xmax_out)
int ccl_get_tracer_fas(ccl_cosmology *cosmo, CCL_ClTracer *clt, int na, double *a, double *fa, int func_code, int *status)
#define CCL_ERROR_NOT_IMPLEMENTED
double ccl_nonlin_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
static void get_k_interval(ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt1, CCL_ClTracer *clt2, int l, double *lkmin, double *lkmax)
CCL_ClWorkspace * ccl_cl_workspace_new(int lmax, int l_limber, double l_logstep, int l_linstep, int *status)
void ccl_check_status(ccl_cosmology *cosmo, int *status)
static int window_magnification(double chi, ccl_cosmology *cosmo, SplPar *spl_pz, SplPar *spl_sz, double chi_max, double *win)
static double f_dens(double a, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
static int check_clt_fa_inconsistency(CCL_ClTracer *clt, int func_code)
#define CCL_ERROR_SPLINE_EV
#define CCL_FRAC_RELEVANT
double ccl_growth_rate(ccl_cosmology *cosmo, double a, int *status)
ccl_spline_params * ccl_splines
CCL_BEGIN_DECLS double * ccl_linear_spacing(double xmin, double xmax, int N)
static double f_IA_NLA(double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
CCL_ClTracer * ccl_cl_tracer_lensing(ccl_cosmology *cosmo, int has_alignment, int nz_n, double *z_n, double *n, int nz_ba, double *z_ba, double *ba, int nz_rf, double *z_rf, double *rf, int *status)
CCL_ClTracer * ccl_cl_tracer_cmblens(ccl_cosmology *cosmo, double z_source, int *status)
CCL_ClTracer * ccl_cl_tracer_lensing_simple(ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int *status)
static double ccl_angular_cl_native(ccl_cosmology *cosmo, CCL_ClWorkspace *cw, int il, CCL_ClTracer *clt1, CCL_ClTracer *clt2, int *status)
static double integrand_mag(double chip, void *params)
#define CCL_ERROR_LINSPACE
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
static void clt_wl_init(CCL_ClTracer *clt, ccl_cosmology *cosmo, int has_intrinsic_alignment, int nz_n, double *z_n, double *n, int nz_ba, double *z_ba, double *ba, int nz_rf, double *z_rf, double *rf, int *status)
double ccl_sinn(ccl_cosmology *cosmo, double chi, int *status)
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
double INTEGRATION_EPSREL
CCL_ClTracer * ccl_cl_tracer(ccl_cosmology *cosmo, int tracer_type, int has_rsd, int has_magnification, int has_intrinsic_alignment, int nz_n, double *z_n, double *n, int nz_b, double *z_b, double *b, int nz_s, double *z_s, double *s, int nz_ba, double *z_ba, double *ba, int nz_rf, double *z_rf, double *rf, double z_source, int *status)
static double f_mag(double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
double ccl_spline_eval(double x, SplPar *spl)
static CCL_BEGIN_DECLS double x[111][8]
static double f_lensing(double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
CCL_ClTracer * ccl_cl_tracer_number_counts(ccl_cosmology *cosmo, int has_rsd, int has_magnification, int nz_n, double *z_n, double *n, int nz_b, double *z_b, double *b, int nz_s, double *z_s, double *s, int *status)
static double f_rsd(double a, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
void ccl_spline_free(SplPar *spl)
static void clt_init_bz(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_b, double *z_b, double *b, int *status)
CCL_ClWorkspace * ccl_cl_workspace_new_limber(int lmax, double l_logstep, int l_linstep, int *status)
double ccl_get_tracer_fa(ccl_cosmology *cosmo, CCL_ClTracer *clt, double a, int func_code, int *status)
#define CCL_ERROR_INCONSISTENT
void ccl_cl_tracer_free(CCL_ClTracer *clt)
static CCL_ClTracer * cl_tracer(ccl_cosmology *cosmo, int tracer_type, int has_rsd, int has_magnification, int has_intrinsic_alignment, int nz_n, double *z_n, double *n, int nz_b, double *z_b, double *b, int nz_s, double *z_s, double *s, int nz_ba, double *z_ba, double *ba, int nz_rf, double *z_rf, double *rf, double z_source, int *status)
float pow(float base, unsigned long int exp)
static void clt_nc_init(CCL_ClTracer *clt, ccl_cosmology *cosmo, int has_rsd, int has_magnification, int nz_n, double *z_n, double *n, int nz_b, double *z_b, double *b, int nz_s, double *z_s, double *s, int *status)
static void clt_init_nz(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int *status)
static double transfer_wrap(int il, double lk, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
double INTEGRATION_LIMBER_EPSREL
static double transfer_wl(int l, double k, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
static double speval_bis(double x, void *params)
static double cl_integrand(double lk, void *params)
static void clt_init_wM(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_s, double *z_s, double *s, int *status)
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
static double w[2][28][111]
static double integrand_wl(double chip, void *params)
void ccl_angular_cls(ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt1, CCL_ClTracer *clt2, int nl_out, int *l_out, double *cl_out, int *status)
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
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)