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

Go to the source code of this file.

Classes

struct  IntLensPar
 
struct  IntMagPar
 
struct  IntClPar
 

Macros

#define CCL_FRAC_RELEVANT   5E-4
 

Functions

static void get_support_interval (int n, double *x, double *y, double frac, double *xmin_out, double *xmax_out)
 
static double speval_bis (double x, void *params)
 
void ccl_cl_workspace_free (CCL_ClWorkspace *w)
 
CCL_ClWorkspaceccl_cl_workspace_new (int lmax, int l_limber, double l_logstep, int l_linstep, int *status)
 
CCL_ClWorkspaceccl_cl_workspace_new_limber (int lmax, double l_logstep, int l_linstep, int *status)
 
static double integrand_wl (double chip, void *params)
 
static int window_lensing (double chi, ccl_cosmology *cosmo, SplPar *spl_pz, double chi_max, double *win)
 
static double integrand_mag (double chip, void *params)
 
static int window_magnification (double chi, ccl_cosmology *cosmo, SplPar *spl_pz, SplPar *spl_sz, double chi_max, double *win)
 
static void clt_init_nz (CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int *status)
 
static void clt_init_bz (CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_b, double *z_b, double *b, int *status)
 
static void clt_init_wM (CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_s, double *z_s, double *s, int *status)
 
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_wL (CCL_ClTracer *clt, ccl_cosmology *cosmo, int *status)
 
static void clt_init_rf (CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_rf, double *z_rf, double *rf, int *status)
 
static void clt_init_ba (CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_ba, double *z_ba, double *ba, int *status)
 
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)
 
static CCL_ClTracercl_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)
 
CCL_ClTracerccl_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)
 
void ccl_cl_tracer_free (CCL_ClTracer *clt)
 
CCL_ClTracerccl_cl_tracer_cmblens (ccl_cosmology *cosmo, double z_source, int *status)
 
CCL_ClTracerccl_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)
 
CCL_ClTracerccl_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)
 
CCL_ClTracerccl_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_ClTracerccl_cl_tracer_lensing_simple (ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int *status)
 
static double f_dens (double a, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
 
static double f_rsd (double a, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
 
static double f_mag (double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
 
static double transfer_nc (int l, double k, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
 
static double f_lensing (double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
 
static double f_IA_NLA (double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
 
static double transfer_wl (int l, double k, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
 
static double transfer_cmblens (int l, double k, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
 
static double transfer_wrap (int il, double lk, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
 
static double cl_integrand (double lk, void *params)
 
static void get_k_interval (ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt1, CCL_ClTracer *clt2, int l, double *lkmin, double *lkmax)
 
static double ccl_angular_cl_native (ccl_cosmology *cosmo, CCL_ClWorkspace *cw, int il, CCL_ClTracer *clt1, CCL_ClTracer *clt2, int *status)
 
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)
 
static int check_clt_fa_inconsistency (CCL_ClTracer *clt, int func_code)
 
double ccl_get_tracer_fa (ccl_cosmology *cosmo, CCL_ClTracer *clt, double a, int func_code, int *status)
 
int ccl_get_tracer_fas (ccl_cosmology *cosmo, CCL_ClTracer *clt, int na, double *a, double *fa, int func_code, int *status)
 

Macro Definition Documentation

#define CCL_FRAC_RELEVANT   5E-4

Definition at line 15 of file ccl_cls.c.

Referenced by clt_init_nz().

Function Documentation

static double ccl_angular_cl_native ( ccl_cosmology cosmo,
CCL_ClWorkspace cw,
int  il,
CCL_ClTracer clt1,
CCL_ClTracer clt2,
int *  status 
)
static

Definition at line 889 of file ccl_cls.c.

References ccl_check_status(), ccl_cosmology_set_status_message(), CCL_ERROR_INTEG, ccl_gsl, ccl_raise_gsl_warning(), cl_integrand(), IntClPar::clt1, IntClPar::clt2, cl_cmbl_bm::cosmo, IntClPar::cosmo, get_k_interval(), IntClPar::il, ccl_gsl_params::INTEGRATION_LIMBER_EPSREL, ccl_gsl_params::INTEGRATION_LIMBER_GAUSS_KRONROD_POINTS, CCL_ClWorkspace::l_arr, ccl_gsl_params::N_ITERATION, IntClPar::status, w, and IntClPar::w.

Referenced by ccl_angular_cls().

891 {
892  int clastatus=0, gslstatus;
893  IntClPar ipar;
894  double result=0,eresult;
895  double lkmin,lkmax;
896  gsl_function F;
897  gsl_integration_workspace *w=gsl_integration_workspace_alloc(ccl_gsl->N_ITERATION);
898 
899  ipar.il=il;
900  ipar.cosmo=cosmo;
901  ipar.w=cw;
902  ipar.clt1=clt1;
903  ipar.clt2=clt2;
904  ipar.status = &clastatus;
905  F.function=&cl_integrand;
906  F.params=&ipar;
907  get_k_interval(cosmo,cw,clt1,clt2,cw->l_arr[il],&lkmin,&lkmax);
908  // This computes the angular power spectra in the Limber approximation between two quantities a and b:
909  // C_ell^ab = 2/(2*ell+1) * Integral[ Delta^a_ell(k) Delta^b_ell(k) * P(k) , k_min < k < k_max ]
910  // Note that we use log10(k) as an integration variable, and the ell-dependent prefactor is included
911  // at the end of this function.
912  gslstatus=gsl_integration_qag(&F, lkmin, lkmax, 0,
915  w, &result, &eresult);
916  gsl_integration_workspace_free(w);
917 
918  // Test if a round-off error occured in the evaluation of the integral
919  // If so, try another integration function, more robust but potentially slower
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);
923  size_t nevals=0;
924  gslstatus=gsl_integration_cquad(&F, lkmin, lkmax, 0,
926  w_cquad, &result, &eresult, &nevals);
927  gsl_integration_cquad_workspace_free(w_cquad);
928  }
929  if(gslstatus!=GSL_SUCCESS || *ipar.status) {
930  ccl_raise_gsl_warning(gslstatus, "ccl_cls.c: ccl_angular_cl_native():");
931  // If an error status was already set, don't overwrite it.
932  if(*status == 0){
934  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: ccl_angular_cl_native(): error integrating over k\n");
935  }
936  return -1;
937  }
938  ccl_check_status(cosmo,status);
939 
940  return result*M_LN10/(cw->l_arr[il]+0.5);
941 }
#define CCL_ERROR_INTEG
Definition: ccl_error.h:15
int INTEGRATION_LIMBER_GAUSS_KRONROD_POINTS
Definition: ccl_params.h:61
void ccl_raise_gsl_warning(int gslstatus, const char *msg,...)
Definition: ccl_error.c:75
static void get_k_interval(ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt1, CCL_ClTracer *clt2, int l, double *lkmin, double *lkmax)
Definition: ccl_cls.c:847
CCL_ClTracer * clt2
Definition: ccl_cls.c:818
void ccl_check_status(ccl_cosmology *cosmo, int *status)
Definition: ccl_error.c:88
int il
Definition: ccl_cls.c:814
CCL_ClTracer * clt1
Definition: ccl_cls.c:817
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
ccl_gsl_params * ccl_gsl
Definition: ccl_core.c:48
ccl_cosmology * cosmo
Definition: ccl_cls.c:815
size_t N_ITERATION
Definition: ccl_params.h:55
int * status
Definition: ccl_cls.c:819
double INTEGRATION_LIMBER_EPSREL
Definition: ccl_params.h:62
CCL_ClWorkspace * w
Definition: ccl_cls.c:816
static double cl_integrand(double lk, void *params)
Definition: ccl_cls.c:823
static double w[2][28][111]
Definition: ccl_emu17.c:33
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 
)

Computes limber or non-limber power spectrum for two different tracers

Parameters
cosmoCosmological parameters
wa ClWorkspace
clt1a Cltracer
clt2a Cltracer
nl_outthe maximum to ell to compute C_ell
lan array of ell values
clthe C_ell output array
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
void

Definition at line 943 of file ccl_cls.c.

References ccl_angular_cl_native(), ccl_check_status(), ccl_cosmology_set_status_message(), CCL_ERROR_MEMORY, CCL_ERROR_SPLINE_EV, ccl_spline_eval(), ccl_spline_free(), ccl_spline_init(), ccl_weak_lensing_tracer, CCL_ClTracer::has_magnification, CCL_ClWorkspace::l_arr, CCL_ClWorkspace::l_limber, CCL_ClWorkspace::lmax, CCL_ClWorkspace::n_ls, and CCL_ClTracer::tracer_type.

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

946 {
947  int ii,do_angpow;
948  double *l_nodes,*cl_nodes;
949  SplPar *spcl_nodes;
950 
951  //First check if ell range is within workspace
952  for(ii=0;ii<nl_out;ii++) {
953  if(l_out[ii]>w->lmax) {
955  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: ccl_angular_cls(); "
956  "requested l beyond range allowed by workspace\n");
957  return;
958  }
959  }
960 
961  if(*status==0) {
962  //Allocate array for power spectrum at interpolation nodes
963  l_nodes=(double *)malloc(w->n_ls*sizeof(double));
964  if(l_nodes==NULL) {
966  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: ccl_angular_cls(); memory allocation\n");
967  }
968  }
969 
970  if(*status==0) {
971  cl_nodes=(double *)malloc(w->n_ls*sizeof(double));
972  if(cl_nodes==NULL) {
974  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: ccl_cl_angular_cls(); memory allocation\n");
975  }
976  }
977 
978  if(*status==0) {
979  for(ii=0;ii<w->n_ls;ii++)
980  l_nodes[ii]=(double)(w->l_arr[ii]);
981 
982  do_angpow=0;
983  //Now check if angpow is needed at all
984  if(w->l_limber>0) {
985  for(ii=0;ii<w->n_ls;ii++) {
986  if(w->l_arr[ii]<=w->l_limber)
987  do_angpow=1;
988  }
989  }
990 #ifndef HAVE_ANGPOW
991  do_angpow=0;
992 #endif //HAVE_ANGPOW
993 
994  //Resort to Limber if we have lensing (this will hopefully only be temporary)
996  clt1->has_magnification || clt2->has_magnification) {
997  do_angpow=0;
998  }
999 
1000  //Use angpow if non-limber is needed
1001  if(do_angpow)
1002  ccl_angular_cls_angpow(cosmo,w,clt1,clt2,cl_nodes,status);
1003  ccl_check_status(cosmo,status);
1004  }
1005 
1006  if(*status==0) {
1007  //Compute limber nodes
1008  for(ii=0;ii<w->n_ls;ii++) {
1009  if((!do_angpow) || (w->l_arr[ii]>w->l_limber))
1010  cl_nodes[ii]=ccl_angular_cl_native(cosmo,w,ii,clt1,clt2,status);
1011  }
1012 
1013  //Interpolate into ells requested by user
1014  spcl_nodes=ccl_spline_init(w->n_ls,l_nodes,cl_nodes,0,0);
1015  if(spcl_nodes==NULL) {
1017  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: ccl_cl_angular_cls(); memory allocation\n");
1018  }
1019  }
1020 
1021  if(*status==0) {
1022  for(ii=0;ii<nl_out;ii++)
1023  cl_out[ii]=ccl_spline_eval((double)(l_out[ii]),spcl_nodes);
1024  }
1025 
1026  //Cleanup
1027  ccl_spline_free(spcl_nodes);
1028  free(cl_nodes);
1029  free(l_nodes);
1030 }
void ccl_check_status(ccl_cosmology *cosmo, int *status)
Definition: ccl_error.c:88
int has_magnification
Definition: ccl_cls.h:40
#define CCL_ERROR_SPLINE_EV
Definition: ccl_error.h:14
static double ccl_angular_cl_native(ccl_cosmology *cosmo, CCL_ClWorkspace *cw, int il, CCL_ClTracer *clt1, CCL_ClTracer *clt2, int *status)
Definition: ccl_cls.c:889
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
void ccl_spline_free(SplPar *spl)
Definition: ccl_utils.c:316
int tracer_type
Definition: ccl_cls.h:32
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
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 
)

Constructor for a ClTracer.

Parameters
Tracer_typepass ccl_number_counts_tracer (number counts), ccl_weak_lensing_tracer (weak lensing) or ccl_cmb_lensing_tracer (CMB lensing)
has_rsdSet to 1 if you want to compute the RSD contribution to number counts (0 otherwise)
has_magnificationSet to 1 if you want to compute the magnification contribution to number counts (0 otherwise)
has_intrinsic_alignmentSet to 1 if you want to compute the IA contribution to shear
nz_nNumber of bins in z_n and n
z_nRedshifts for each redshift interval of n
nNumber count of objects per redshift interval (Note: arbitrary normalization - renormalized inside)
nz_bNumber of bins in z_b and b
z_bRedshifts for each redshift interval of b
bClustering bias in each redshift bin
nz_sNumber of bins in z_s and s
z_sRedshifts for each redshift interval of s
sMagnification bias in each redshift bin
nz_baNumber of bins in z_ba and ba
z_baRedshifts for each redshift interval of ba
baAlignment bias in each redshift bin
nz_rfNumber of bins in z_f and f
z_rfRedshifts for each redshift interval of rf
rfAligned red fraction in each redshift bin
z_sourceRedshift of source plane for CMB lensing (z~1100 for CMB lensing).
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
CCL_ClTracer object

Definition at line 575 of file ccl_cls.c.

References ccl_check_status(), and cl_tracer().

Referenced by ccl_cl_tracer_cmblens(), ccl_cl_tracer_lensing(), ccl_cl_tracer_lensing_simple(), ccl_cl_tracer_number_counts(), and ccl_cl_tracer_number_counts_simple().

583 {
584  CCL_ClTracer *clt=cl_tracer(cosmo,tracer_type,has_rsd,has_magnification,has_intrinsic_alignment,
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);
587  ccl_check_status(cosmo,status);
588  return clt;
589 }
void ccl_check_status(ccl_cosmology *cosmo, int *status)
Definition: ccl_error.c:88
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)
Definition: ccl_cls.c:515
CCL_ClTracer* ccl_cl_tracer_cmblens ( ccl_cosmology cosmo,
double  z_source,
int *  status 
)

Simplified constructor for a CMB lensing ClTracer.

Parameters
z_sourceRedshift of source plane (z~1100 for CMB lensing).
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
CCL_ClTracer object

Definition at line 614 of file ccl_cls.c.

References ccl_cl_tracer(), and ccl_cmb_lensing_tracer.

Referenced by compare_cls(), and main().

615 {
617  0,0,0,
618  0,NULL,NULL,0,NULL,NULL,0,NULL,NULL,
619  0,NULL,NULL,0,NULL,NULL,z_source,status);
620 }
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)
Definition: ccl_cls.c:575
void ccl_cl_tracer_free ( CCL_ClTracer clt)

Destructor for a Cltracer

Parameters
clta Cltracer
Returns
void

Definition at line 592 of file ccl_cls.c.

References ccl_number_counts_tracer, ccl_spline_free(), ccl_weak_lensing_tracer, CCL_ClTracer::has_intrinsic_alignment, CCL_ClTracer::has_magnification, CCL_ClTracer::spl_ba, CCL_ClTracer::spl_bz, CCL_ClTracer::spl_nz, CCL_ClTracer::spl_rf, CCL_ClTracer::spl_sz, CCL_ClTracer::spl_wL, CCL_ClTracer::spl_wM, and CCL_ClTracer::tracer_type.

Referenced by compare_cls(), main(), and test_angpow_precision().

593 {
595  ccl_spline_free(clt->spl_nz);
596 
598  ccl_spline_free(clt->spl_bz);
599  if(clt->has_magnification) {
600  ccl_spline_free(clt->spl_sz);
601  ccl_spline_free(clt->spl_wM);
602  }
603  }
604  else if(clt->tracer_type==ccl_weak_lensing_tracer) {
605  ccl_spline_free(clt->spl_wL);
606  if(clt->has_intrinsic_alignment) {
607  ccl_spline_free(clt->spl_ba);
608  ccl_spline_free(clt->spl_rf);
609  }
610  }
611  free(clt);
612 }
SplPar * spl_rf
Definition: ccl_cls.h:45
int has_intrinsic_alignment
Definition: ccl_cls.h:41
int has_magnification
Definition: ccl_cls.h:40
SplPar * spl_nz
Definition: ccl_cls.h:42
SplPar * spl_bz
Definition: ccl_cls.h:43
SplPar * spl_sz
Definition: ccl_cls.h:44
SplPar * spl_wL
Definition: ccl_cls.h:47
void ccl_spline_free(SplPar *spl)
Definition: ccl_utils.c:316
int tracer_type
Definition: ccl_cls.h:32
SplPar * spl_ba
Definition: ccl_cls.h:46
SplPar * spl_wM
Definition: ccl_cls.h:48
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 
)

Simplified constructor for a lensing ClTracer.

Parameters
has_intrinsic_alignmentSet to 1 if you want to compute the IA contribution to shear
nz_nNumber of bins in z_n and n
z_nRedshifts for each redshift interval of n
nNumber count of objects per redshift interval (Note: arbitrary normalization - renormalized inside)
nz_baNumber of bins in z_ba and ba
z_baRedshifts for each redshift interval of ba
baAlignment bias in each redshift bin
nz_rfNumber of bins in z_f and f
z_rfRedshifts for each redshift interval of rf
rfAligned red fraction in each redshift bin
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
CCL_ClTracer object

Definition at line 642 of file ccl_cls.c.

References ccl_cl_tracer(), and ccl_weak_lensing_tracer.

Referenced by compare_cls(), and compare_corr().

647 {
648  return ccl_cl_tracer(cosmo,ccl_weak_lensing_tracer,0,0,has_alignment,
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);
651 }
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)
Definition: ccl_cls.c:575
CCL_ClTracer* ccl_cl_tracer_lensing_simple ( ccl_cosmology cosmo,
int  nz_n,
double z_n,
double n,
int *  status 
)

Simplified constructor for a lensing ClTracer without intrinsic alignment.

Parameters
nz_nNumber of bins in z_n and n
z_nRedshifts for each redshift interval of n
nNumber count of objects per redshift interval (Note: arbitrary normalization - renormalized inside)
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
CCL_ClTracer object

Definition at line 653 of file ccl_cls.c.

References ccl_cl_tracer(), and ccl_weak_lensing_tracer.

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

655 {
656  return ccl_cl_tracer(cosmo,ccl_weak_lensing_tracer,0,0,0,
657  nz_n,z_n,n,-1,NULL,NULL,-1,NULL,NULL,
658  -1,NULL,NULL,-1,NULL,NULL,0, status);
659 }
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)
Definition: ccl_cls.c:575
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 
)

Simplified constructor for a clustering ClTracer.

Parameters
cosmoCosmological parameters
has_rsdSet to 1 if you want to compute the RSD contribution to number counts (0 otherwise)
has_magnificationSet to 1 if you want to compute the magnification contribution to number counts (0 otherwise)
nz_nNumber of bins in z_n and n
z_nRedshifts for each redshift interval of n
nNumber count of objects per redshift interval (Note: arbitrary normalization - renormalized inside)
nz_bNumber of bins in z_b and b
z_bRedshifts for each redshift interval of b
bClustering bias in each redshift bin
nz_sNumber of bins in z_s and s
z_sRedshifts for each redshift interval of s
sMagnification bias in each redshift bin
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
CCL_ClTracer object

Definition at line 622 of file ccl_cls.c.

References ccl_cl_tracer(), and ccl_number_counts_tracer.

Referenced by main(), and test_angpow_precision().

627 {
628  return ccl_cl_tracer(cosmo,ccl_number_counts_tracer,has_rsd,has_magnification,0,
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);
631 }
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)
Definition: ccl_cls.c:575
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 
)

Simplified constructor for a ClTracer without magnification nor RSD.

Parameters
nz_nNumber of bins in z_n and n
z_nRedshifts for each redshift interval of n
nNumber count of objects per redshift interval (Note: arbitrary normalization - renormalized inside)
nz_bNumber of bins in z_b and b
z_bRedshifts for each redshift interval of b
bClustering bias in each redshift bin
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
CCL_ClTracer object

Definition at line 633 of file ccl_cls.c.

References ccl_cl_tracer(), and ccl_number_counts_tracer.

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

636 {
637  return ccl_cl_tracer(cosmo,ccl_number_counts_tracer,0,0,0,
638  nz_n,z_n,n,nz_b,z_b,b,-1,NULL,NULL,
639  -1,NULL,NULL,-1,NULL,NULL,0, status);
640 }
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)
Definition: ccl_cls.c:575
void ccl_cl_workspace_free ( CCL_ClWorkspace w)

Definition at line 59 of file ccl_cls.c.

References CCL_ClWorkspace::l_arr.

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

60 {
61  free(w->l_arr);
62  free(w);
63 }
CCL_ClWorkspace* ccl_cl_workspace_new ( int  lmax,
int  l_limber,
double  l_logstep,
int  l_linstep,
int *  status 
)

Definition at line 65 of file ccl_cls.c.

References CCL_ERROR_MEMORY, CCL_MAX, CCL_ClWorkspace::l_arr, CCL_ClWorkspace::l_limber, CCL_ClWorkspace::l_linstep, CCL_ClWorkspace::l_logstep, CCL_ClWorkspace::lmax, CCL_ClWorkspace::n_ls, and w.

Referenced by ccl_cl_workspace_new_limber(), and test_angpow_precision().

67 {
68  int i_l,l0,increment;
70  if(w==NULL)
72 
73  if(*status==0) {
74  //Set params
75  w->lmax=lmax;
76  w->l_limber=l_limber;
77  w->l_logstep=l_logstep;
78  w->l_linstep=l_linstep;
79 
80  //Compute number of multipoles
81  i_l=0; l0=0;
82  increment=CCL_MAX(((int)(l0*(w->l_logstep-1.))),1);
83  while((l0 < w->lmax) && (increment < w->l_linstep)) {
84  i_l++;
85  l0+=increment;
86  increment=CCL_MAX(((int)(l0*(w->l_logstep-1))),1);
87  }
88  increment=w->l_linstep;
89  while(l0 < w->lmax) {
90  i_l++;
91  l0+=increment;
92  }
93 
94  //Allocate array of multipoles
95  w->n_ls=i_l+1;
96  w->l_arr=(int *)malloc(w->n_ls*sizeof(int));
97  if(w->l_arr==NULL)
99  }
100 
101  if(*status==0) {
102  //Redo the computation above and store values of ell
103  i_l=0; l0=0;
104  increment=CCL_MAX(((int)(l0*(w->l_logstep-1.))),1);
105  while((l0 < w->lmax) && (increment < w->l_linstep)) {
106  w->l_arr[i_l]=l0;
107  i_l++;
108  l0+=increment;
109  increment=CCL_MAX(((int)(l0*(w->l_logstep-1))),1);
110  }
111  increment=w->l_linstep;
112  while(l0 < w->lmax) {
113  w->l_arr[i_l]=l0;
114  i_l++;
115  l0+=increment;
116  }
117  //Don't go further than lmaw
118  w->l_arr[w->n_ls-1]=w->lmax;
119  }
120 
121  return w;
122 }
#define CCL_MAX(a, b)
Definition: ccl_utils.h:8
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
double l_logstep
Definition: ccl_cls.h:216
static double w[2][28][111]
Definition: ccl_emu17.c:33
CCL_ClWorkspace* ccl_cl_workspace_new_limber ( int  lmax,
double  l_logstep,
int  l_linstep,
int *  status 
)

Definition at line 124 of file ccl_cls.c.

References ccl_cl_workspace_new().

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

125 {
126  return ccl_cl_workspace_new(lmax,-1,l_logstep,l_linstep,status);
127 }
CCL_ClWorkspace * ccl_cl_workspace_new(int lmax, int l_limber, double l_logstep, int l_linstep, int *status)
Definition: ccl_cls.c:65
double ccl_get_tracer_fa ( ccl_cosmology cosmo,
CCL_ClTracer clt,
double  a,
int  func_code,
int *  status 
)

Method to return certain redshift or distance-dependent internal quantities for a given tracer.

Parameters
cosmoCosmological parameters
cltClTracer object
ascale factor at which the function is to be evaluated
func_codeinteger defining which internal function to evaluate. Choose between: ccl_trf_nz (redshift distribution), ccl_trf_bz (clustering bias), ccl_trf_sz (magnification bias), ccl_trf_rf (aligned fraction), ccl_trf_ba (alignment bias), ccl_trf_wL (weak lensing window function), ccl_trf_wM (magnification window function)
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
interpolated value of the requested function

Definition at line 1048 of file ccl_cls.c.

References ccl_comoving_radial_distance(), ccl_cosmology_set_status_message(), CCL_ERROR_INCONSISTENT, ccl_spline_eval(), ccl_trf_ba, ccl_trf_bz, ccl_trf_nz, ccl_trf_rf, ccl_trf_sz, ccl_trf_wL, ccl_trf_wM, check_clt_fa_inconsistency(), CCL_ClTracer::spl_ba, CCL_ClTracer::spl_bz, CCL_ClTracer::spl_nz, CCL_ClTracer::spl_rf, CCL_ClTracer::spl_sz, CCL_ClTracer::spl_wL, CCL_ClTracer::spl_wM, and x.

1049 {
1050  SplPar *spl;
1051 
1052  if(check_clt_fa_inconsistency(clt,func_code)) {
1054  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: inconsistent combination of tracer and internal function to be evaluated");
1055  return -1;
1056  }
1057 
1058  switch(func_code) {
1059  case ccl_trf_nz :
1060  spl=clt->spl_nz;
1061  break;
1062  case ccl_trf_bz :
1063  spl=clt->spl_bz;
1064  break;
1065  case ccl_trf_sz :
1066  spl=clt->spl_sz;
1067  break;
1068  case ccl_trf_rf :
1069  spl=clt->spl_rf;
1070  break;
1071  case ccl_trf_ba :
1072  spl=clt->spl_ba;
1073  break;
1074  case ccl_trf_wL :
1075  spl=clt->spl_wL;
1076  break;
1077  case ccl_trf_wM :
1078  spl=clt->spl_wM;
1079  break;
1080  }
1081 
1082  double x;
1083  if((func_code==ccl_trf_wL) || (func_code==ccl_trf_wM))
1084  x=ccl_comoving_radial_distance(cosmo,a,status); //x-variable is comoving distance for lensing kernels
1085  else
1086  x=1./a-1; //x-variable is redshift by default
1087 
1088  return ccl_spline_eval(x,spl);
1089 }
SplPar * spl_rf
Definition: ccl_cls.h:45
SplPar * spl_nz
Definition: ccl_cls.h:42
static int check_clt_fa_inconsistency(CCL_ClTracer *clt, int func_code)
Definition: ccl_cls.c:1032
SplPar * spl_bz
Definition: ccl_cls.h:43
SplPar * spl_sz
Definition: ccl_cls.h:44
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
static CCL_BEGIN_DECLS double x[111][8]
SplPar * spl_wL
Definition: ccl_cls.h:47
#define CCL_ERROR_INCONSISTENT
Definition: ccl_error.h:12
SplPar * spl_ba
Definition: ccl_cls.h:46
SplPar * spl_wM
Definition: ccl_cls.h:48
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
int ccl_get_tracer_fas ( ccl_cosmology cosmo,
CCL_ClTracer clt,
int  na,
double a,
double fa,
int  func_code,
int *  status 
)

Method to return certain redshift or distance-dependent internal quantities for a given tracer.

Parameters
cosmoCosmological parameters
cltClTracer object
nanumber of points at which the function will be evaluated
ana values of the scale factor at which the function is to be evaluated
faoutput array with na values that will store the interpolated function values
func_codeinteger defining which internal function to evaluate. Choose between: ccl_trf_nz (redshift distribution), ccl_trf_bz (clustering bias), ccl_trf_sz (magnification bias), ccl_trf_rf (aligned fraction), ccl_trf_ba (alignment bias), ccl_trf_wL (weak lensing window function), ccl_trf_wM (magnification window function)
statusStatus flag. 0 if there are no errors, nonzero otherwise. For specific cases see documentation for ccl_error.c
Returns
void

Definition at line 1091 of file ccl_cls.c.

References ccl_comoving_radial_distance(), ccl_cosmology_set_status_message(), CCL_ERROR_INCONSISTENT, ccl_spline_eval(), ccl_trf_ba, ccl_trf_bz, ccl_trf_nz, ccl_trf_rf, ccl_trf_sz, ccl_trf_wL, ccl_trf_wM, check_clt_fa_inconsistency(), CCL_ClTracer::spl_ba, CCL_ClTracer::spl_bz, CCL_ClTracer::spl_nz, CCL_ClTracer::spl_rf, CCL_ClTracer::spl_sz, CCL_ClTracer::spl_wL, CCL_ClTracer::spl_wM, and x.

Referenced by main().

1093 {
1094  SplPar *spl;
1095 
1096  if(check_clt_fa_inconsistency(clt,func_code)) {
1098  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: inconsistent combination of tracer and internal function to be evaluated");
1099  return -1;
1100  }
1101 
1102  switch(func_code) {
1103  case ccl_trf_nz :
1104  spl=clt->spl_nz;
1105  break;
1106  case ccl_trf_bz :
1107  spl=clt->spl_bz;
1108  break;
1109  case ccl_trf_sz :
1110  spl=clt->spl_sz;
1111  break;
1112  case ccl_trf_rf :
1113  spl=clt->spl_rf;
1114  break;
1115  case ccl_trf_ba :
1116  spl=clt->spl_ba;
1117  break;
1118  case ccl_trf_wL :
1119  spl=clt->spl_wL;
1120  break;
1121  case ccl_trf_wM :
1122  spl=clt->spl_wM;
1123  break;
1124  }
1125 
1126  int compchi = (func_code==ccl_trf_wL) || (func_code==ccl_trf_wM);
1127 
1128  int ia;
1129  for(ia=0;ia<na;ia++) {
1130  double x;
1131  if(compchi) //x-variable is comoving distance for lensing kernels
1132  x=ccl_comoving_radial_distance(cosmo,a[ia],status);
1133  else //x-variable is redshift by default
1134  x=1./a[ia]-1;
1135  fa[ia]=ccl_spline_eval(x,spl);
1136  }
1137 
1138  return 0;
1139 }
SplPar * spl_rf
Definition: ccl_cls.h:45
SplPar * spl_nz
Definition: ccl_cls.h:42
static int check_clt_fa_inconsistency(CCL_ClTracer *clt, int func_code)
Definition: ccl_cls.c:1032
SplPar * spl_bz
Definition: ccl_cls.h:43
SplPar * spl_sz
Definition: ccl_cls.h:44
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
static CCL_BEGIN_DECLS double x[111][8]
SplPar * spl_wL
Definition: ccl_cls.h:47
#define CCL_ERROR_INCONSISTENT
Definition: ccl_error.h:12
SplPar * spl_ba
Definition: ccl_cls.h:46
SplPar * spl_wM
Definition: ccl_cls.h:48
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
static int check_clt_fa_inconsistency ( CCL_ClTracer clt,
int  func_code 
)
static

Definition at line 1032 of file ccl_cls.c.

References ccl_cmb_lensing_tracer, ccl_number_counts_tracer, ccl_trf_ba, ccl_trf_bz, ccl_trf_nz, ccl_trf_rf, ccl_trf_sz, ccl_trf_wL, ccl_trf_wM, ccl_weak_lensing_tracer, CCL_ClTracer::has_intrinsic_alignment, CCL_ClTracer::has_magnification, and CCL_ClTracer::tracer_type.

Referenced by ccl_get_tracer_fa(), and ccl_get_tracer_fas().

1033 {
1034  if(((func_code==ccl_trf_nz) && (clt->tracer_type==ccl_cmb_lensing_tracer)) || //lensing has no n(z)
1035  (((func_code==ccl_trf_bz) || (func_code==ccl_trf_sz) || (func_code==ccl_trf_wM)) &&
1036  (clt->tracer_type!=ccl_number_counts_tracer)) || //bias and magnification only for clustering
1037  (((func_code==ccl_trf_rf) || (func_code==ccl_trf_ba) || (func_code==ccl_trf_wL)) &&
1038  (clt->tracer_type!=ccl_weak_lensing_tracer))) //IAs only for weak lensing
1039  return 1;
1040  if((((func_code==ccl_trf_sz) || (func_code==ccl_trf_wM)) &&
1041  (clt->has_magnification==0)) || //correct combination, but no magnification
1042  (((func_code==ccl_trf_rf) || (func_code==ccl_trf_ba)) &&
1043  (clt->has_intrinsic_alignment==0))) //Correct combination, but no IAs
1044  return 1;
1045  return 0;
1046 }
int has_intrinsic_alignment
Definition: ccl_cls.h:41
int has_magnification
Definition: ccl_cls.h:40
int tracer_type
Definition: ccl_cls.h:32
static double cl_integrand ( double  lk,
void *  params 
)
static

Definition at line 823 of file ccl_cls.c.

References ccl_nonlin_matter_power(), ccl_scale_factor_of_chi(), IntClPar::clt1, IntClPar::clt2, IntClPar::cosmo, IntClPar::il, CCL_ClWorkspace::l_arr, p, pow(), IntClPar::status, transfer_wrap(), and IntClPar::w.

Referenced by ccl_angular_cl_native().

824 {
825  double d1,d2;
827  d1=transfer_wrap(p->il,lk,p->cosmo,p->w,p->clt1,p->status);
828  if(d1==0)
829  return 0;
830  d2=transfer_wrap(p->il,lk,p->cosmo,p->w,p->clt2,p->status);
831  if(d2==0)
832  return 0;
833 
834  double k=pow(10.,lk);
835  double chi=(p->w->l_arr[p->il]+0.5)/k;
836  double a=ccl_scale_factor_of_chi(p->cosmo,chi,p->status);
837  double pk=ccl_nonlin_matter_power(p->cosmo,k,a,p->status);
838 
839  return k*pk*d1*d2;
840 }
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
double ccl_nonlin_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:1562
CCL_ClTracer * clt2
Definition: ccl_cls.c:818
int il
Definition: ccl_cls.c:814
CCL_ClTracer * clt1
Definition: ccl_cls.c:817
ccl_cosmology * cosmo
Definition: ccl_cls.c:815
dictionary params
Definition: halomod_bm.py:27
static int p
Definition: ccl_emu17.c:25
int * status
Definition: ccl_cls.c:819
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
static double transfer_wrap(int il, double lk, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:795
CCL_ClWorkspace * w
Definition: ccl_cls.c:816
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 
)
static

Definition at line 515 of file ccl_cls.c.

References ccl_cmb_lensing_tracer, ccl_comoving_radial_distance(), ccl_cosmology_set_status_message(), CCL_ERROR_INCONSISTENT, CCL_ERROR_MEMORY, ccl_h_over_h0(), ccl_number_counts_tracer, ccl_weak_lensing_tracer, CCL_ClTracer::chi_source, CCL_ClTracer::chimax, CCL_ClTracer::chimin, CLIGHT_HMPC, clt_nc_init(), clt_wl_init(), ccl_parameters::h, ccl_parameters::Omega_m, ccl_cosmology::params, CCL_ClTracer::prefac_lensing, and CCL_ClTracer::tracer_type.

Referenced by ccl_cl_tracer().

523 {
524  int clstatus=0;
525  CCL_ClTracer *clt=(CCL_ClTracer *)malloc(sizeof(CCL_ClTracer));
526  if(clt==NULL) {
528  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: ccl_cl_tracer(): memory allocation\n");
529  }
530 
531  if(*status==0) {
532  clt->tracer_type=tracer_type;
533 
534  double hub=cosmo->params.h*ccl_h_over_h0(cosmo,1.,status)/CLIGHT_HMPC;
535  clt->prefac_lensing=1.5*hub*hub*cosmo->params.Omega_m;
536 
537  if(tracer_type==ccl_number_counts_tracer)
538  clt_nc_init(clt,cosmo,has_rsd,has_magnification,
539  nz_n,z_n,n,nz_b,z_b,b,nz_s,z_s,s,status);
540  else if(tracer_type==ccl_weak_lensing_tracer)
541  clt_wl_init(clt,cosmo,has_intrinsic_alignment,
542  nz_n,z_n,n,nz_ba,z_ba,ba,nz_rf,z_rf,rf,status);
543  else if(tracer_type==ccl_cmb_lensing_tracer) {
544  clt->chi_source=ccl_comoving_radial_distance(cosmo,1./(1+z_source),status);
545  clt->chimax=clt->chi_source;
546  clt->chimin=0;
547  }
548  else {
549  free(clt);
551  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: ccl_cl_tracer(): unknown tracer type\n");
552  return NULL;
553  }
554  }
555 
556  if(*status) {
557  free(clt);
558  clt=NULL;
559  }
560 
561  return clt;
562 }
double ccl_h_over_h0(ccl_cosmology *cosmo, double a, int *status)
ccl_parameters params
Definition: ccl_core.h:124
#define CLIGHT_HMPC
Definition: ccl_constants.h:33
double h
Definition: ccl_core.h:33
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
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)
Definition: ccl_cls.c:488
int tracer_type
Definition: ccl_cls.h:32
double prefac_lensing
Definition: ccl_cls.h:33
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
double chi_source
Definition: ccl_cls.h:38
#define CCL_ERROR_INCONSISTENT
Definition: ccl_error.h:12
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)
Definition: ccl_cls.c:393
double Omega_m
Definition: ccl_core.h:21
double chimax
Definition: ccl_cls.h:34
double chimin
Definition: ccl_cls.h:35
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
static void clt_init_ba ( CCL_ClTracer clt,
ccl_cosmology cosmo,
int  nz_ba,
double z_ba,
double ba,
int *  status 
)
static

Definition at line 477 of file ccl_cls.c.

References ccl_cosmology_set_status_message(), CCL_ERROR_SPLINE, ccl_spline_init(), and CCL_ClTracer::spl_ba.

Referenced by clt_wl_init().

479 {
480  //Initialize bias spline
481  clt->spl_ba=ccl_spline_init(nz_ba,z_ba,ba,ba[0],ba[nz_ba-1]);
482  if(clt->spl_ba==NULL) {
484  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_ba(): error initializing spline for b(z)\n");
485  }
486 }
#define CCL_ERROR_SPLINE
Definition: ccl_error.h:13
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
SplPar * spl_ba
Definition: ccl_cls.h:46
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
static void clt_init_bz ( CCL_ClTracer clt,
ccl_cosmology cosmo,
int  nz_b,
double z_b,
double b,
int *  status 
)
static

Definition at line 320 of file ccl_cls.c.

References ccl_cosmology_set_status_message(), CCL_ERROR_SPLINE, ccl_spline_init(), and CCL_ClTracer::spl_bz.

Referenced by clt_nc_init().

322 {
323  //Initialize bias spline
324  clt->spl_bz=ccl_spline_init(nz_b,z_b,b,b[0],b[nz_b-1]);
325  if(clt->spl_bz==NULL) {
327  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_bz(): error initializing spline for b(z)\n");
328  }
329 }
SplPar * spl_bz
Definition: ccl_cls.h:43
#define CCL_ERROR_SPLINE
Definition: ccl_error.h:13
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
static void clt_init_nz ( CCL_ClTracer clt,
ccl_cosmology cosmo,
int  nz_n,
double z_n,
double n,
int *  status 
)
static

Definition at line 261 of file ccl_cls.c.

References ccl_comoving_radial_distance(), ccl_cosmology_set_status_message(), CCL_ERROR_INTEG, CCL_ERROR_MEMORY, CCL_ERROR_SPLINE, CCL_FRAC_RELEVANT, ccl_gsl, ccl_raise_gsl_warning(), ccl_spline_free(), ccl_spline_init(), CCL_ClTracer::chimax, CCL_ClTracer::chimin, get_support_interval(), ccl_gsl_params::INTEGRATION_EPSREL, ccl_gsl_params::INTEGRATION_GAUSS_KRONROD_POINTS, ccl_gsl_params::N_ITERATION, speval_bis(), CCL_ClTracer::spl_nz, w, CCL_ClTracer::zmax, and CCL_ClTracer::zmin.

Referenced by clt_nc_init(), and clt_wl_init().

263 {
264  int gslstatus;
265  gsl_function F;
266  double nz_norm,nz_enorm;
267  double *nz_normalized;
268 
269  //Find redshift range where the N(z) has support
270  get_support_interval(nz_n,z_n,n,CCL_FRAC_RELEVANT,&(clt->zmin),&(clt->zmax));
271  clt->chimax=ccl_comoving_radial_distance(cosmo,1./(1+clt->zmax),status);
272  clt->chimin=ccl_comoving_radial_distance(cosmo,1./(1+clt->zmin),status);
273  clt->spl_nz=ccl_spline_init(nz_n,z_n,n,0,0);
274  if(clt->spl_nz==NULL) {
276  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_nz(): error initializing spline for N(z)\n");
277  }
278 
279  if(*status==0) {
280  //Normalize n(z)
281  nz_normalized=(double *)malloc(nz_n*sizeof(double));
282  if(nz_normalized==NULL) {
284  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_nz(): memory allocation\n");
285  return;
286  }
287  }
288 
289  if(*status==0) {
290  gsl_integration_workspace *w=gsl_integration_workspace_alloc(ccl_gsl->N_ITERATION);
291  F.function=&speval_bis;
292  F.params=clt->spl_nz;
293  //Here we're just integrating the N(z) to normalize it to unit probability.
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) {
300  ccl_raise_gsl_warning(gslstatus, "ccl_cls.c: clt_init_nz():");
302  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_nz(): integration error when normalizing N(z)\n");
303  }
304  }
305 
306  if(*status==0) {
307  for(int ii=0;ii<nz_n;ii++)
308  nz_normalized[ii]=n[ii]/nz_norm;
309  ccl_spline_free(clt->spl_nz);
310  clt->spl_nz=ccl_spline_init(nz_n,z_n,nz_normalized,0,0);
311  if(clt->spl_nz==NULL) {
313  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_nz(): error initializing normalized spline for N(z)\n");
314  }
315  }
316 
317  free(nz_normalized);
318 }
#define CCL_ERROR_INTEG
Definition: ccl_error.h:15
void ccl_raise_gsl_warning(int gslstatus, const char *msg,...)
Definition: ccl_error.c:75
int INTEGRATION_GAUSS_KRONROD_POINTS
Definition: ccl_params.h:58
static void get_support_interval(int n, double *x, double *y, double frac, double *xmin_out, double *xmax_out)
Definition: ccl_cls.c:19
SplPar * spl_nz
Definition: ccl_cls.h:42
double zmin
Definition: ccl_cls.h:36
#define CCL_FRAC_RELEVANT
Definition: ccl_cls.c:15
#define CCL_ERROR_SPLINE
Definition: ccl_error.h:13
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
ccl_gsl_params * ccl_gsl
Definition: ccl_core.c:48
double INTEGRATION_EPSREL
Definition: ccl_params.h:59
void ccl_spline_free(SplPar *spl)
Definition: ccl_utils.c:316
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
size_t N_ITERATION
Definition: ccl_params.h:55
double zmax
Definition: ccl_cls.h:37
double chimax
Definition: ccl_cls.h:34
static double speval_bis(double x, void *params)
Definition: ccl_cls.c:53
double chimin
Definition: ccl_cls.h:35
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
static double w[2][28][111]
Definition: ccl_emu17.c:33
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
static void clt_init_rf ( CCL_ClTracer clt,
ccl_cosmology cosmo,
int  nz_rf,
double z_rf,
double rf,
int *  status 
)
static

Definition at line 466 of file ccl_cls.c.

References ccl_cosmology_set_status_message(), CCL_ERROR_SPLINE, ccl_spline_init(), and CCL_ClTracer::spl_rf.

Referenced by clt_wl_init().

468 {
469  //Initialize bias spline
470  clt->spl_rf=ccl_spline_init(nz_rf,z_rf,rf,rf[0],rf[nz_rf-1]);
471  if(clt->spl_rf==NULL) {
473  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_rf(): error initializing spline for b(z)\n");
474  }
475 }
SplPar * spl_rf
Definition: ccl_cls.h:45
#define CCL_ERROR_SPLINE
Definition: ccl_error.h:13
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
static void clt_init_wL ( CCL_ClTracer clt,
ccl_cosmology cosmo,
int *  status 
)
static

Definition at line 414 of file ccl_cls.c.

References ccl_comoving_radial_distance(), ccl_cosmology_set_status_message(), CCL_ERROR_INTEG, CCL_ERROR_LINSPACE, CCL_ERROR_MEMORY, CCL_ERROR_SPLINE, ccl_linear_spacing(), ccl_spline_init(), CCL_ClTracer::chimin, CCL_ClTracer::spl_nz, CCL_ClTracer::spl_wL, window_lensing(), x, SplPar::xf, and CCL_ClTracer::zmin.

Referenced by clt_wl_init().

416 {
417  //Compute weak lensing kernel
418  int nchi;
419  double *x,*y;
420  double dchi_here=5.;
421  double zmax=clt->spl_nz->xf;
422  double chimax=ccl_comoving_radial_distance(cosmo,1./(1+zmax),status);
423  //TODO: The interval in chi (5. Mpc) should be made a macro
424 
425  //In this case we need to integrate all the way to z=0. Reset zmin and chimin
426  clt->zmin=0;
427  clt->chimin=0;
428  nchi=(int)(chimax/dchi_here)+1;
429  x=ccl_linear_spacing(0.,chimax,nchi);
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");
435  }
436 
437  if(*status==0) {
438  y=(double *)malloc(nchi*sizeof(double));
439  if(y==NULL) {
441  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_wL(): memory allocation\n");
442  }
443  }
444 
445  if(*status==0) {
446  int clstatus=0;
447  for(int j=0;j<nchi;j++)
448  clstatus|=window_lensing(x[j],cosmo,clt->spl_nz,chimax,&(y[j]));
449  if(clstatus) {
451  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_wL(): error computing lensing window\n");
452  }
453  }
454 
455  if(*status==0) {
456  clt->spl_wL=ccl_spline_init(nchi,x,y,y[0],0);
457  if(clt->spl_wL==NULL) {
460  "ccl_cls.c: clt_init_wL(): error initializing spline for lensing window\n");
461  }
462  }
463  free(x); free(y);
464 }
#define CCL_ERROR_INTEG
Definition: ccl_error.h:15
static int window_lensing(double chi, ccl_cosmology *cosmo, SplPar *spl_pz, double chi_max, double *win)
Definition: ccl_cls.c:159
SplPar * spl_nz
Definition: ccl_cls.h:42
double zmin
Definition: ccl_cls.h:36
CCL_BEGIN_DECLS double * ccl_linear_spacing(double xmin, double xmax, int N)
Definition: ccl_utils.c:14
#define CCL_ERROR_SPLINE
Definition: ccl_error.h:13
#define CCL_ERROR_LINSPACE
Definition: ccl_error.h:11
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
static CCL_BEGIN_DECLS double x[111][8]
SplPar * spl_wL
Definition: ccl_cls.h:47
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
double chimin
Definition: ccl_cls.h:35
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
double xf
Definition: ccl_utils.h:52
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
static void clt_init_wM ( CCL_ClTracer clt,
ccl_cosmology cosmo,
int  nz_s,
double z_s,
double s,
int *  status 
)
static

Definition at line 331 of file ccl_cls.c.

References ccl_comoving_radial_distance(), ccl_cosmology_set_status_message(), CCL_ERROR_INTEG, CCL_ERROR_LINSPACE, CCL_ERROR_MEMORY, CCL_ERROR_SPLINE, ccl_linear_spacing(), ccl_spline_init(), CCL_ClTracer::chimin, CCL_ClTracer::spl_nz, CCL_ClTracer::spl_sz, CCL_ClTracer::spl_wM, window_magnification(), x, SplPar::xf, and CCL_ClTracer::zmin.

Referenced by clt_nc_init().

333 {
334  //Compute magnification kernel
335  int nchi;
336  double *x,*y;
337  double dchi_here=5.;
338  double zmax=clt->spl_nz->xf;
339  double chimax=ccl_comoving_radial_distance(cosmo,1./(1+zmax),status);
340  //TODO: The interval in chi (5. Mpc) should be made a macro
341 
342  //In this case we need to integrate all the way to z=0. Reset zmin and chimin
343  clt->zmin=0;
344  clt->chimin=0;
345  clt->spl_sz=ccl_spline_init(nz_s,z_s,s,s[0],s[nz_s-1]);
346  if(clt->spl_sz==NULL) {
349  "ccl_cls.c: clt_init_wM(): error initializing spline for s(z)\n");
350  }
351 
352  if(*status==0) {
353  nchi=(int)(chimax/dchi_here)+1;
354  x=ccl_linear_spacing(0.,chimax,nchi);
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");
360  }
361  }
362 
363  if(*status==0) {
364  y=(double *)malloc(nchi*sizeof(double));
365  if(y==NULL) {
367  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_wM(): memory allocation\n");
368  }
369  }
370 
371  if(*status==0) {
372  int clstatus=0;
373  for(int j=0;j<nchi;j++)
374  clstatus|=window_magnification(x[j],cosmo,clt->spl_nz,clt->spl_sz,chimax,&(y[j]));
375  if(clstatus) {
377  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_wM(): error computing lensing window\n");
378  }
379  }
380 
381  if(*status==0) {
382  clt->spl_wM=ccl_spline_init(nchi,x,y,y[0],0);
383  if(clt->spl_wM==NULL) {
386  "ccl_cls.c: clt_init_wM(): error initializing spline for lensing window\n");
387  }
388  }
389  free(x); free(y);
390 }
#define CCL_ERROR_INTEG
Definition: ccl_error.h:15
SplPar * spl_nz
Definition: ccl_cls.h:42
static int window_magnification(double chi, ccl_cosmology *cosmo, SplPar *spl_pz, SplPar *spl_sz, double chi_max, double *win)
Definition: ccl_cls.c:225
double zmin
Definition: ccl_cls.h:36
CCL_BEGIN_DECLS double * ccl_linear_spacing(double xmin, double xmax, int N)
Definition: ccl_utils.c:14
#define CCL_ERROR_SPLINE
Definition: ccl_error.h:13
SplPar * spl_sz
Definition: ccl_cls.h:44
#define CCL_ERROR_LINSPACE
Definition: ccl_error.h:11
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
static CCL_BEGIN_DECLS double x[111][8]
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
SplPar * spl_wM
Definition: ccl_cls.h:48
double chimin
Definition: ccl_cls.h:35
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
double xf
Definition: ccl_utils.h:52
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
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

Definition at line 393 of file ccl_cls.c.

References ccl_cosmology_set_status_message(), CCL_ERROR_NOT_IMPLEMENTED, clt_init_bz(), clt_init_nz(), clt_init_wM(), CCL_ClTracer::has_magnification, CCL_ClTracer::has_rsd, ccl_parameters::N_nu_mass, and ccl_cosmology::params.

Referenced by cl_tracer().

398 {
399  clt->has_rsd=has_rsd;
400  clt->has_magnification=has_magnification;
401 
402  if ( ((cosmo->params.N_nu_mass)>0) && clt->has_rsd){
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.");
405  return;
406  }
407 
408  clt_init_nz(clt,cosmo,nz_n,z_n,n,status);
409  clt_init_bz(clt,cosmo,nz_b,z_b,b,status);
410  if(clt->has_magnification)
411  clt_init_wM(clt,cosmo,nz_s,z_s,s,status);
412 }
#define CCL_ERROR_NOT_IMPLEMENTED
Definition: ccl_error.h:25
ccl_parameters params
Definition: ccl_core.h:124
int has_magnification
Definition: ccl_cls.h:40
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
int has_rsd
Definition: ccl_cls.h:39
static void clt_init_bz(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_b, double *z_b, double *b, int *status)
Definition: ccl_cls.c:320
static void clt_init_nz(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int *status)
Definition: ccl_cls.c:261
static void clt_init_wM(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_s, double *z_s, double *s, int *status)
Definition: ccl_cls.c:331
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 
)
static

Definition at line 488 of file ccl_cls.c.

References clt_init_ba(), clt_init_nz(), clt_init_rf(), clt_init_wL(), and CCL_ClTracer::has_intrinsic_alignment.

Referenced by cl_tracer().

493 {
494  clt->has_intrinsic_alignment=has_intrinsic_alignment;
495 
496  clt_init_nz(clt,cosmo,nz_n,z_n,n,status);
497  clt_init_wL(clt,cosmo,status);
498  if(clt->has_intrinsic_alignment) {
499  clt_init_rf(clt,cosmo,nz_rf,z_rf,rf,status);
500  clt_init_ba(clt,cosmo,nz_ba,z_ba,ba,status);
501  }
502 }
static void clt_init_rf(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_rf, double *z_rf, double *rf, int *status)
Definition: ccl_cls.c:466
static void clt_init_ba(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_ba, double *z_ba, double *ba, int *status)
Definition: ccl_cls.c:477
static void clt_init_wL(CCL_ClTracer *clt, ccl_cosmology *cosmo, int *status)
Definition: ccl_cls.c:414
int has_intrinsic_alignment
Definition: ccl_cls.h:41
static void clt_init_nz(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int *status)
Definition: ccl_cls.c:261
static double f_dens ( double  a,
ccl_cosmology cosmo,
CCL_ClTracer clt,
int *  status 
)
static

Definition at line 661 of file ccl_cls.c.

References ccl_h_over_h0(), ccl_spline_eval(), CLIGHT_HMPC, ccl_test_distances::h, ccl_parameters::h, ccl_cosmology::params, CCL_ClTracer::spl_bz, CCL_ClTracer::spl_nz, and z.

Referenced by transfer_nc().

662 {
663  double z=1./a-1;
664  double pz=ccl_spline_eval(z,clt->spl_nz);
665  double bz=ccl_spline_eval(z,clt->spl_bz);
666  double h=cosmo->params.h*ccl_h_over_h0(cosmo,a,status)/CLIGHT_HMPC;
667 
668  return pz*bz*h;
669 }
double ccl_h_over_h0(ccl_cosmology *cosmo, double a, int *status)
ccl_parameters params
Definition: ccl_core.h:124
#define CLIGHT_HMPC
Definition: ccl_constants.h:33
SplPar * spl_nz
Definition: ccl_cls.h:42
SplPar * spl_bz
Definition: ccl_cls.h:43
double h
Definition: ccl_core.h:33
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
static double z[8]
static double f_IA_NLA ( double  a,
double  chi,
ccl_cosmology cosmo,
CCL_ClTracer clt,
int *  status 
)
static

Definition at line 736 of file ccl_cls.c.

References ccl_h_over_h0(), ccl_scale_factor_of_chi(), ccl_spline_eval(), CLIGHT_HMPC, ccl_test_distances::h, ccl_parameters::h, ccl_cosmology::params, CCL_ClTracer::spl_ba, CCL_ClTracer::spl_nz, CCL_ClTracer::spl_rf, and z.

Referenced by transfer_wl().

737 {
738  if(chi<=1E-10)
739  return 0;
740  else {
741  double a=ccl_scale_factor_of_chi(cosmo,chi, status);
742  double z=1./a-1;
743  double pz=ccl_spline_eval(z,clt->spl_nz);
744  double ba=ccl_spline_eval(z,clt->spl_ba);
745  double rf=ccl_spline_eval(z,clt->spl_rf);
746  double h=cosmo->params.h*ccl_h_over_h0(cosmo,a,status)/CLIGHT_HMPC;
747 
748  return pz*ba*rf*h/(chi*chi);
749  }
750 }
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
SplPar * spl_rf
Definition: ccl_cls.h:45
double ccl_h_over_h0(ccl_cosmology *cosmo, double a, int *status)
ccl_parameters params
Definition: ccl_core.h:124
#define CLIGHT_HMPC
Definition: ccl_constants.h:33
SplPar * spl_nz
Definition: ccl_cls.h:42
double h
Definition: ccl_core.h:33
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
static double z[8]
SplPar * spl_ba
Definition: ccl_cls.h:46
static double f_lensing ( double  a,
double  chi,
ccl_cosmology cosmo,
CCL_ClTracer clt,
int *  status 
)
static

Definition at line 726 of file ccl_cls.c.

References ccl_spline_eval(), CCL_ClTracer::prefac_lensing, and CCL_ClTracer::spl_wL.

Referenced by transfer_wl().

727 {
728  double wL=ccl_spline_eval(chi,clt->spl_wL);
729 
730  if(wL<=0)
731  return 0;
732  else
733  return clt->prefac_lensing*wL/(a*chi);
734 }
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
SplPar * spl_wL
Definition: ccl_cls.h:47
double prefac_lensing
Definition: ccl_cls.h:33
static double f_mag ( double  a,
double  chi,
ccl_cosmology cosmo,
CCL_ClTracer clt,
int *  status 
)
static

Definition at line 681 of file ccl_cls.c.

References ccl_spline_eval(), and CCL_ClTracer::spl_wM.

Referenced by transfer_nc().

682 {
683  double wM=ccl_spline_eval(chi,clt->spl_wM);
684 
685  if(wM<=0)
686  return 0;
687  else
688  return wM/(a*chi);
689 }
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
SplPar * spl_wM
Definition: ccl_cls.h:48
static double f_rsd ( double  a,
ccl_cosmology cosmo,
CCL_ClTracer clt,
int *  status 
)
static

Definition at line 671 of file ccl_cls.c.

References ccl_growth_rate(), ccl_h_over_h0(), ccl_spline_eval(), CLIGHT_HMPC, ccl_test_distances::h, ccl_parameters::h, ccl_cosmology::params, CCL_ClTracer::spl_nz, and z.

Referenced by transfer_nc().

672 {
673  double z=1./a-1;
674  double pz=ccl_spline_eval(z,clt->spl_nz);
675  double fg=ccl_growth_rate(cosmo,a,status);
676  double h=cosmo->params.h*ccl_h_over_h0(cosmo,a,status)/CLIGHT_HMPC;
677 
678  return pz*fg*h;
679 }
double ccl_h_over_h0(ccl_cosmology *cosmo, double a, int *status)
ccl_parameters params
Definition: ccl_core.h:124
#define CLIGHT_HMPC
Definition: ccl_constants.h:33
SplPar * spl_nz
Definition: ccl_cls.h:42
double ccl_growth_rate(ccl_cosmology *cosmo, double a, int *status)
double h
Definition: ccl_core.h:33
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
static double z[8]
static void get_k_interval ( ccl_cosmology cosmo,
CCL_ClWorkspace w,
CCL_ClTracer clt1,
CCL_ClTracer clt2,
int  l,
double lkmin,
double lkmax 
)
static

Definition at line 847 of file ccl_cls.c.

References ccl_number_counts_tracer, ccl_splines, CCL_ClTracer::chimax, CCL_ClTracer::chimin, CCL_ClTracer::has_magnification, ccl_spline_params::K_MAX, ccl_spline_params::K_MIN, and CCL_ClTracer::tracer_type.

Referenced by ccl_angular_cl_native().

850 {
851  double chimin,chimax;
852  int cut_low_1=0,cut_low_2=0;
853 
854  //Define a minimum distance only if no lensing is needed
855  if((clt1->tracer_type==ccl_number_counts_tracer) && (clt1->has_magnification==0)) cut_low_1=1;
856  if((clt2->tracer_type==ccl_number_counts_tracer) && (clt2->has_magnification==0)) cut_low_2=1;
857 
858  if(cut_low_1) {
859  if(cut_low_2) {
860  chimin=fmax(clt1->chimin,clt2->chimin);
861  chimax=fmin(clt1->chimax,clt2->chimax);
862  }
863  else {
864  chimin=clt1->chimin;
865  chimax=clt1->chimax;
866  }
867  }
868  else if(cut_low_2) {
869  chimin=clt2->chimin;
870  chimax=clt2->chimax;
871  }
872  else {
873  chimin=0.5*(l+0.5)/ccl_splines->K_MAX;
874  chimax=2*(l+0.5)/ccl_splines->K_MIN;
875  }
876 
877  if(chimin<=0)
878  chimin=0.5*(l+0.5)/ccl_splines->K_MAX;
879 
880  *lkmax=log10(fmin( ccl_splines->K_MAX ,2 *(l+0.5)/chimin));
881  *lkmin=log10(fmax( ccl_splines->K_MIN ,0.5*(l+0.5)/chimax));
882 }
int has_magnification
Definition: ccl_cls.h:40
ccl_spline_params * ccl_splines
Definition: ccl_core.c:47
int tracer_type
Definition: ccl_cls.h:32
double chimax
Definition: ccl_cls.h:34
double chimin
Definition: ccl_cls.h:35
static void get_support_interval ( int  n,
double x,
double y,
double  frac,
double xmin_out,
double xmax_out 
)
static

Definition at line 19 of file ccl_cls.c.

Referenced by clt_init_nz().

21 {
22  int ix;
23  double ythr=-1000;
24 
25  //Initialize as the original edges in case we don't find an interval
26  *xmin_out=x[0];
27  *xmax_out=x[n-1];
28 
29  //Find threshold
30  for(ix=0;ix<n;ix++) {
31  if(y[ix]>ythr) ythr=y[ix];
32  }
33  ythr*=frac;
34 
35  //Find minimum
36  for(ix=0;ix<n;ix++) {
37  if(y[ix]>=ythr) {
38  *xmin_out=x[ix];
39  break;
40  }
41  }
42 
43  //Find maximum
44  for(ix=n-1;ix>=0;ix--) {
45  if(y[ix]>=ythr) {
46  *xmax_out=x[ix];
47  break;
48  }
49  }
50 }
static CCL_BEGIN_DECLS double x[111][8]
static double integrand_mag ( double  chip,
void *  params 
)
static

Definition at line 202 of file ccl_cls.c.

References ccl_h_over_h0(), ccl_scale_factor_of_chi(), ccl_sinn(), ccl_spline_eval(), IntMagPar::chi, CLIGHT_HMPC, IntMagPar::cosmo, ccl_test_distances::h, ccl_parameters::h, p, ccl_cosmology::params, IntMagPar::spl_pz, IntMagPar::spl_sz, IntMagPar::status, mk_bins::sz, and z.

Referenced by window_magnification().

203 {
205  double chi=p->chi;
206  double a=ccl_scale_factor_of_chi(p->cosmo,chip, p->status);
207  double z=1./a-1;
208  double pz=ccl_spline_eval(z,p->spl_pz);
209  double sz=ccl_spline_eval(z,p->spl_sz);
210  double h=p->cosmo->params.h*ccl_h_over_h0(p->cosmo,a, p->status)/CLIGHT_HMPC;
211 
212  if(chi==0)
213  return h*pz*(1-2.5*sz);
214  else
215  return h*pz*(1-2.5*sz)*ccl_sinn(p->cosmo,chip-chi,p->status)/ccl_sinn(p->cosmo,chip,p->status);
216 }
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
double ccl_h_over_h0(ccl_cosmology *cosmo, double a, int *status)
int * status
Definition: ccl_cls.c:198
double chi
Definition: ccl_cls.c:194
ccl_parameters params
Definition: ccl_core.h:124
#define CLIGHT_HMPC
Definition: ccl_constants.h:33
double h
Definition: ccl_core.h:33
SplPar * spl_sz
Definition: ccl_cls.c:196
double ccl_sinn(ccl_cosmology *cosmo, double chi, int *status)
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
dictionary params
Definition: halomod_bm.py:27
ccl_cosmology * cosmo
Definition: ccl_cls.c:197
float sz
Definition: mk_bins.py:8
static double z[8]
SplPar * spl_pz
Definition: ccl_cls.c:195
static int p
Definition: ccl_emu17.c:25
static double integrand_wl ( double  chip,
void *  params 
)
static

Definition at line 138 of file ccl_cls.c.

References ccl_h_over_h0(), ccl_scale_factor_of_chi(), ccl_sinn(), ccl_spline_eval(), IntLensPar::chi, CLIGHT_HMPC, IntLensPar::cosmo, ccl_test_distances::h, ccl_parameters::h, p, ccl_cosmology::params, IntLensPar::spl_pz, IntLensPar::status, and z.

Referenced by window_lensing().

139 {
141  double chi=p->chi;
142  double a=ccl_scale_factor_of_chi(p->cosmo,chip, p->status);
143  double z=1./a-1;
144  double pz=ccl_spline_eval(z,p->spl_pz);
145  double h=p->cosmo->params.h*ccl_h_over_h0(p->cosmo,a, p->status)/CLIGHT_HMPC;
146 
147  if(chi==0)
148  return h*pz;
149  else
150  return h*pz*ccl_sinn(p->cosmo,chip-chi,p->status)/ccl_sinn(p->cosmo,chip,p->status);
151 }
ccl_cosmology * cosmo
Definition: ccl_cls.c:133
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
double ccl_h_over_h0(ccl_cosmology *cosmo, double a, int *status)
ccl_parameters params
Definition: ccl_core.h:124
#define CLIGHT_HMPC
Definition: ccl_constants.h:33
double h
Definition: ccl_core.h:33
SplPar * spl_pz
Definition: ccl_cls.c:132
double chi
Definition: ccl_cls.c:131
double ccl_sinn(ccl_cosmology *cosmo, double chi, int *status)
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
int * status
Definition: ccl_cls.c:134
dictionary params
Definition: halomod_bm.py:27
static double z[8]
static int p
Definition: ccl_emu17.c:25
static double speval_bis ( double  x,
void *  params 
)
static

Definition at line 53 of file ccl_cls.c.

References ccl_spline_eval().

Referenced by clt_init_nz().

54 {
55  return ccl_spline_eval(x,(SplPar *)params);
56 }
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
static CCL_BEGIN_DECLS double x[111][8]
dictionary params
Definition: halomod_bm.py:27
static double transfer_cmblens ( int  l,
double  k,
ccl_cosmology cosmo,
CCL_ClTracer clt,
int *  status 
)
static

Definition at line 776 of file ccl_cls.c.

References ccl_scale_factor_of_chi(), CCL_ClTracer::chi_source, CCL_ClTracer::prefac_lensing, and w.

Referenced by transfer_wrap().

777 {
778  double chi=(l+0.5)/k;
779  if(chi>=clt->chi_source)
780  return 0;
781 
782  if(chi<=clt->chimax) {
783  double a=ccl_scale_factor_of_chi(cosmo,chi,status);
784  double w=1-chi/clt->chi_source;
785  return clt->prefac_lensing*l*(l+1.)*w/(a*chi*k*k);
786  }
787  return 0;
788 }
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
double prefac_lensing
Definition: ccl_cls.h:33
double chi_source
Definition: ccl_cls.h:38
static double w[2][28][111]
Definition: ccl_emu17.c:33
static double transfer_nc ( int  l,
double  k,
ccl_cosmology cosmo,
CCL_ClWorkspace w,
CCL_ClTracer clt,
int *  status 
)
static

Definition at line 697 of file ccl_cls.c.

References ccl_nonlin_matter_power(), ccl_scale_factor_of_chi(), f_dens(), f_mag(), f_rsd(), CCL_ClTracer::has_magnification, CCL_ClTracer::has_rsd, CCL_ClTracer::prefac_lensing, and sqrt().

Referenced by transfer_wrap().

699 {
700  double ret=0;
701  double x0=(l+0.5);
702  double chi0=x0/k;
703  if(chi0<=clt->chimax) {
704  double a0=ccl_scale_factor_of_chi(cosmo,chi0,status);
705  double f_all=f_dens(a0,cosmo,clt,status);
706  if(clt->has_rsd) {
707  double x1=(l+1.5);
708  double chi1=x1/k;
709  if(chi1<=clt->chimax) {
710  double a1=ccl_scale_factor_of_chi(cosmo,chi1,status);
711  double pk0=ccl_nonlin_matter_power(cosmo,k,a0,status);
712  double pk1=ccl_nonlin_matter_power(cosmo,k,a1,status);
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;
716  }
717  }
718  if(clt->has_magnification)
719  f_all+=-2*clt->prefac_lensing*l*(l+1)*f_mag(a0,chi0,cosmo,clt,status)/(k*k);
720  ret=f_all;
721  }
722 
723  return ret;
724 }
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
double ccl_nonlin_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:1562
int has_magnification
Definition: ccl_cls.h:40
static double f_dens(double a, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:661
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
Definition: grid.h:231
int has_rsd
Definition: ccl_cls.h:39
static double f_mag(double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:681
static double f_rsd(double a, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:671
double prefac_lensing
Definition: ccl_cls.h:33
static double transfer_wl ( int  l,
double  k,
ccl_cosmology cosmo,
CCL_ClWorkspace w,
CCL_ClTracer clt,
int *  status 
)
static

Definition at line 758 of file ccl_cls.c.

References ccl_scale_factor_of_chi(), f_IA_NLA(), f_lensing(), CCL_ClTracer::has_intrinsic_alignment, and sqrt().

Referenced by transfer_wrap().

760 {
761  double ret=0;
762  double chi=(l+0.5)/k;
763  if(chi<=clt->chimax) {
764  double a=ccl_scale_factor_of_chi(cosmo,chi,status);
765  double f_all=f_lensing(a,chi,cosmo,clt,status);
766  if(clt->has_intrinsic_alignment)
767  f_all+=f_IA_NLA(a,chi,cosmo,clt,status);
768 
769  ret=f_all;
770  }
771 
772  return sqrt((l+2.)*(l+1.)*l*(l-1.))*ret/(k*k);
773  //return (l+1.)*l*ret/(k*k);
774 }
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
int has_intrinsic_alignment
Definition: ccl_cls.h:41
static double f_IA_NLA(double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:736
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
Definition: grid.h:231
static double f_lensing(double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:726
static double transfer_wrap ( int  il,
double  lk,
ccl_cosmology cosmo,
CCL_ClWorkspace w,
CCL_ClTracer clt,
int *  status 
)
static

Definition at line 795 of file ccl_cls.c.

References ccl_cmb_lensing_tracer, ccl_number_counts_tracer, ccl_weak_lensing_tracer, CCL_ClWorkspace::l_arr, pow(), CCL_ClTracer::tracer_type, transfer_cmblens(), transfer_nc(), and transfer_wl().

Referenced by cl_integrand().

797 {
798  double transfer_out=0;
799  double k=pow(10.,lk);
800 
802  transfer_out=transfer_nc(w->l_arr[il],k,cosmo,w,clt,status);
803  else if(clt->tracer_type==ccl_weak_lensing_tracer)
804  transfer_out=transfer_wl(w->l_arr[il],k,cosmo,w,clt,status);
805  else if(clt->tracer_type==ccl_cmb_lensing_tracer)
806  transfer_out=transfer_cmblens(w->l_arr[il],k,cosmo,clt,status);
807  else
808  transfer_out=-1;
809  return transfer_out;
810 }
static double transfer_nc(int l, double k, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:697
static double transfer_cmblens(int l, double k, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:776
int tracer_type
Definition: ccl_cls.h:32
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
static double transfer_wl(int l, double k, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:758
static int window_lensing ( double  chi,
ccl_cosmology cosmo,
SplPar spl_pz,
double  chi_max,
double win 
)
static

Definition at line 159 of file ccl_cls.c.

References ccl_gsl, ccl_raise_gsl_warning(), IntLensPar::chi, cl_cmbl_bm::cosmo, IntLensPar::cosmo, integrand_wl(), ccl_gsl_params::INTEGRATION_EPSREL, ccl_gsl_params::INTEGRATION_GAUSS_KRONROD_POINTS, ccl_gsl_params::N_ITERATION, IntLensPar::spl_pz, IntLensPar::status, and w.

Referenced by clt_init_wL().

160 {
161  int gslstatus =0, status =0;
162  double result,eresult;
163  IntLensPar ip;
164  gsl_function F;
165  gsl_integration_workspace *w=gsl_integration_workspace_alloc(ccl_gsl->N_ITERATION);
166 
167  ip.chi=chi;
168  ip.cosmo=cosmo;
169  ip.spl_pz=spl_pz;
170  ip.status = &status;
171  F.function=&integrand_wl;
172  F.params=&ip;
173  // This conputes the lensing kernel:
174  // w_L(chi) = Integral[ dN/dchi(chi') * f(chi'-chi)/f(chi') , chi < chi' < chi_horizon ]
175  // Where f(chi) is the comoving angular distance (which is just chi for zero curvature).
176  gslstatus=gsl_integration_qag(&F, chi, chi_max, 0,
179  w, &result, &eresult);
180  *win=result;
181  gsl_integration_workspace_free(w);
182  if(gslstatus!=GSL_SUCCESS || *ip.status) {
183  ccl_raise_gsl_warning(gslstatus, "ccl_cls.c: window_lensing():");
184  return 1;
185  }
186  //TODO: chi_max should be changed to chi_horizon
187  //we should precompute this quantity and store it in cosmo by default
188 
189  return 0;
190 }
ccl_cosmology * cosmo
Definition: ccl_cls.c:133
void ccl_raise_gsl_warning(int gslstatus, const char *msg,...)
Definition: ccl_error.c:75
int INTEGRATION_GAUSS_KRONROD_POINTS
Definition: ccl_params.h:58
SplPar * spl_pz
Definition: ccl_cls.c:132
double chi
Definition: ccl_cls.c:131
ccl_gsl_params * ccl_gsl
Definition: ccl_core.c:48
double INTEGRATION_EPSREL
Definition: ccl_params.h:59
int * status
Definition: ccl_cls.c:134
size_t N_ITERATION
Definition: ccl_params.h:55
static double w[2][28][111]
Definition: ccl_emu17.c:33
static double integrand_wl(double chip, void *params)
Definition: ccl_cls.c:138
static int window_magnification ( double  chi,
ccl_cosmology cosmo,
SplPar spl_pz,
SplPar spl_sz,
double  chi_max,
double win 
)
static

Definition at line 225 of file ccl_cls.c.

References ccl_gsl, ccl_raise_gsl_warning(), IntMagPar::chi, cl_cmbl_bm::cosmo, IntMagPar::cosmo, integrand_mag(), ccl_gsl_params::INTEGRATION_EPSREL, ccl_gsl_params::INTEGRATION_GAUSS_KRONROD_POINTS, ccl_gsl_params::N_ITERATION, IntMagPar::spl_pz, IntMagPar::spl_sz, IntMagPar::status, and w.

Referenced by clt_init_wM().

227 {
228  int gslstatus =0, status =0;
229  double result,eresult;
230  IntMagPar ip;
231  gsl_function F;
232  gsl_integration_workspace *w=gsl_integration_workspace_alloc(ccl_gsl->N_ITERATION);
233 
234  ip.chi=chi;
235  ip.cosmo=cosmo;
236  ip.spl_pz=spl_pz;
237  ip.spl_sz=spl_sz;
238  ip.status = &status;
239  F.function=&integrand_mag;
240  F.params=&ip;
241  // This conputes the magnification lensing kernel:
242  // w_M(chi) = Integral[ dN/dchi(chi') * (1-5/2 * s(chi)) * f(chi'-chi)/f(chi') , chi < chi' < chi_horizon ]
243  // Where f(chi) is the comoving angular distance (which is just chi for zero curvature)
244  // and s(chi) is the magnification bias parameter.
245  gslstatus=gsl_integration_qag(&F, chi, chi_max, 0,
248  w, &result, &eresult);
249  *win=result;
250  gsl_integration_workspace_free(w);
251  if(gslstatus!=GSL_SUCCESS || *ip.status) {
252  ccl_raise_gsl_warning(gslstatus, "ccl_cls.c: window_magnification():");
253  return 1;
254  }
255  //TODO: chi_max should be changed to chi_horizon
256  //we should precompute this quantity and store it in cosmo by default
257 
258  return 0;
259 }
int * status
Definition: ccl_cls.c:198
void ccl_raise_gsl_warning(int gslstatus, const char *msg,...)
Definition: ccl_error.c:75
double chi
Definition: ccl_cls.c:194
int INTEGRATION_GAUSS_KRONROD_POINTS
Definition: ccl_params.h:58
SplPar * spl_sz
Definition: ccl_cls.c:196
static double integrand_mag(double chip, void *params)
Definition: ccl_cls.c:202
ccl_gsl_params * ccl_gsl
Definition: ccl_core.c:48
double INTEGRATION_EPSREL
Definition: ccl_params.h:59
size_t N_ITERATION
Definition: ccl_params.h:55
ccl_cosmology * cosmo
Definition: ccl_cls.c:197
SplPar * spl_pz
Definition: ccl_cls.c:195
static double w[2][28][111]
Definition: ccl_emu17.c:33