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

Go to the source code of this file.

Classes

struct  corr_int_par
 

Functions

static int taper_cl (int n_ell, double *ell, double *cl, double *ell_limits)
 
static void ccl_tracer_corr_fftlog (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 *status)
 
static double corr_bessel_integrand (double l, void *params)
 
static void ccl_tracer_corr_bessel (ccl_cosmology *cosmo, int n_ell, double *ell, double *cls, int n_theta, double *theta, double *wtheta, int corr_type, int *status)
 
static void ccl_compute_legendre_polynomial (int corr_type, double theta, int ell_max, double *Pl_theta)
 
static void ccl_tracer_corr_legendre (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 *status)
 
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)
 
void ccl_correlation_3d (ccl_cosmology *cosmo, double a, int n_r, double *r, double *xi, int do_taper_pk, double *taper_pk_limits, int *status)
 

Function Documentation

static void ccl_compute_legendre_polynomial ( int  corr_type,
double  theta,
int  ell_max,
double Pl_theta 
)
static

Definition at line 267 of file ccl_correlation.c.

References CCL_CORR_GG, CCL_CORR_GL, and M_PI.

Referenced by ccl_tracer_corr_legendre().

268 {
269  int i,j;
270  double k=0;
271  double cth=cos(theta*M_PI/180);
272 
273  //Initialize Pl_theta
274  for (j=0;j<=ell_max;j++)
275  Pl_theta[j]=0.;
276 
277  if(corr_type==CCL_CORR_GG) {
278  gsl_sf_legendre_Pl_array(ell_max,cth,Pl_theta);
279  for (j=0;j<=ell_max;j++)
280  Pl_theta[j]*=(2*j+1);
281  }
282  else if(corr_type==CCL_CORR_GL) {
283  for (j=2;j<=ell_max;j++) {//https://arxiv.org/pdf/1007.4809.pdf
284  Pl_theta[j]=gsl_sf_legendre_Plm(j,2,cth);
285  Pl_theta[j]*=(2*j+1.)/((j+0.)*(j+1.));
286  }
287  }
288 }
#define M_PI
Definition: ccl_constants.h:22
#define CCL_CORR_GL
#define CCL_CORR_GG
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 
)

Computes the correlation function (wrapper)

Parameters
cosmo:Cosmological parameters
n_ell: number of multipoles in the input power spectrum
ell: multipoles at which the power spectrum is evaluated
cls: input power spectrum
n_theta: number of output values of the separation angle (theta)
theta: values of the separation angle in degrees.
wtheta: the values of the correlation function at the angles above will be returned in this array, which should be pre-allocated
do_taper_cl:
taper_cl_limits
flag_method: method to compute the correlation function. Choose between:
  • CCL_CORR_FFTLOG : fast integration with FFTLog
  • CCL_CORR_BESSEL : direct integration over the Bessel function
  • CCL_CORR_LGNDRE : brute-force sum over legendre polynomials
corr_type: type of correlation function. Choose between:
  • CCL_CORR_GG : spin0-spin0
  • CCL_CORR_GL : spin0-spin2
  • CCL_CORR_LP : spin2-spin2 (xi+)
  • CCL_CORR_LM : spin2-spin2 (xi-) Currently supported spin-0 fields are number counts and CMB lensing. The only spin-2 is currently shear.

Definition at line 391 of file ccl_correlation.c.

References ccl_check_status(), CCL_CORR_BESSEL, CCL_CORR_FFTLOG, CCL_CORR_LGNDRE, ccl_cosmology_set_status_message(), CCL_ERROR_INCONSISTENT, ccl_tracer_corr_bessel(), ccl_tracer_corr_fftlog(), and ccl_tracer_corr_legendre().

Referenced by compare_corr(), and main().

396 {
397  switch(flag_method) {
398  case CCL_CORR_FFTLOG :
399  ccl_tracer_corr_fftlog(cosmo,n_ell,ell,cls,n_theta,theta,wtheta,corr_type,
400  do_taper_cl,taper_cl_limits,status);
401  break;
402  case CCL_CORR_LGNDRE :
403  ccl_tracer_corr_legendre(cosmo,n_ell,ell,cls,n_theta,theta,wtheta,corr_type,
404  do_taper_cl,taper_cl_limits,status);
405  break;
406  case CCL_CORR_BESSEL :
407  ccl_tracer_corr_bessel(cosmo,n_ell,ell,cls,n_theta,theta,wtheta,corr_type,status);
408  break;
409  default :
411  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_correlation. Unknown algorithm\n");
412  }
413 
414  ccl_check_status(cosmo,status);
415 }
static void ccl_tracer_corr_bessel(ccl_cosmology *cosmo, int n_ell, double *ell, double *cls, int n_theta, double *theta, double *wtheta, int corr_type, int *status)
void ccl_check_status(ccl_cosmology *cosmo, int *status)
Definition: ccl_error.c:88
static void ccl_tracer_corr_legendre(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 *status)
void ccl_cosmology_set_status_message(ccl_cosmology *cosmo, const char *status_message,...)
Definition: ccl_core.c:792
#define CCL_CORR_BESSEL
static void ccl_tracer_corr_fftlog(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 *status)
#define CCL_CORR_FFTLOG
#define CCL_ERROR_INCONSISTENT
Definition: ccl_error.h:12
#define CCL_CORR_LGNDRE
void ccl_correlation_3d ( ccl_cosmology cosmo,
double  a,
int  n_r,
double r,
double xi,
int  do_taper_pk,
double taper_pk_limits,
int *  status 
)

Computes the 3dcorrelation function (wrapper)

Parameters
cosmo:Cosmological parameters
a: scale factor
n_r: number of output values of distance r
r: values of the distance in Mpc
xi: the values of the correlation function at the distances above will be returned in this array, which should be pre-allocated
do_taper_pk: key for tapering (using cosine tapering by default)
taper_pk_limitslimits of tapering

Definition at line 427 of file ccl_correlation.c.

References ccl_check_status(), ccl_cosmology_set_status_message(), CCL_ERROR_MEMORY, ccl_log_spacing(), ccl_nonlin_matter_power(), ccl_spline_eval(), ccl_spline_free(), ccl_spline_init(), ccl_splines, ccl_spline_params::K_MAX, ccl_spline_params::K_MIN, ccl_spline_params::N_K_3DCOR, pk2xi(), and taper_cl().

Referenced by compare_correlation_3d(), and main().

431 {
432  int i,N_ARR;
433  double *k_arr,*pk_arr,*r_arr,*xi_arr;
434 
435  //number of data points for k and pk array
436  N_ARR=(int)(ccl_splines->N_K_3DCOR*log10(ccl_splines->K_MAX/ccl_splines->K_MIN));
437 
439  if(k_arr==NULL) {
441  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_correlation_3d ran out of memory\n");
442  return;
443  }
444 
445  pk_arr=malloc(N_ARR*sizeof(double));
446  if(pk_arr==NULL) {
447  free(k_arr);
449  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_correlation_3d ran out of memory\n");
450  return;
451  }
452 
453  for (i=0; i<N_ARR; i++)
454  pk_arr[i] = ccl_nonlin_matter_power(cosmo, k_arr[i], a, status);
455 
456  if (do_taper_pk)
457  taper_cl(N_ARR,k_arr,pk_arr,taper_pk_limits);
458 
459  r_arr=malloc(sizeof(double)*N_ARR);
460  if(r_arr==NULL) {
461  free(k_arr);
462  free(pk_arr);
464  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_correlation_3d ran out of memory\n");
465  return;
466  }
467  xi_arr=malloc(sizeof(double)*N_ARR);
468  if(xi_arr==NULL) {
469  free(k_arr); free(pk_arr); free(r_arr);
471  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_correlation_3d ran out of memory\n");
472  return;
473  }
474 
475  for(i=0;i<N_ARR;i++)
476  r_arr[i]=0;
477 
478  pk2xi(N_ARR,k_arr,pk_arr,r_arr,xi_arr);
479 
480  // Interpolate to output values of r
481  SplPar *xi_spl=ccl_spline_init(N_ARR,r_arr,xi_arr,xi_arr[0],0);
482  for(i=0;i<n_r;i++)
483  xi[i]=ccl_spline_eval(r[i],xi_spl);
484  ccl_spline_free(xi_spl);
485 
486  free(k_arr); free(pk_arr);
487  free(r_arr); free(xi_arr);
488 
489  ccl_check_status(cosmo,status);
490 
491  return;
492 }
double ccl_nonlin_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:1562
double * ccl_log_spacing(double xmin, double xmax, int N)
Definition: ccl_utils.c:102
void ccl_check_status(ccl_cosmology *cosmo, int *status)
Definition: ccl_error.c:88
ccl_spline_params * ccl_splines
Definition: ccl_core.c:47
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
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
void pk2xi(int N, const double k[], const double pk[], double r[], double xi[])
Definition: fftlog.c:176
static int taper_cl(int n_ell, double *ell, double *cl, double *ell_limits)
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
static void ccl_tracer_corr_bessel ( ccl_cosmology cosmo,
int  n_ell,
double ell,
double cls,
int  n_theta,
double theta,
double wtheta,
int  corr_type,
int *  status 
)
static

Definition at line 184 of file ccl_correlation.c.

References CCL_CORR_GG, CCL_CORR_GL, CCL_CORR_LM, CCL_CORR_LP, ccl_cosmology_set_status_message(), CCL_ERROR_MEMORY, ccl_gsl, ccl_raise_gsl_warning(), ccl_spline_free(), ccl_spline_init(), ccl_splines, corr_int_par::cl0, corr_int_par::cl_spl, corr_int_par::clf, corr_bessel_integrand(), corr_int_par::ell0, ccl_spline_params::ELL_MAX_CORR, corr_int_par::ellf, corr_int_par::extrapol_0, corr_int_par::extrapol_f, corr_int_par::i_bessel, ccl_gsl_params::INTEGRATION_EPSREL, ccl_gsl_params::INTEGRATION_GAUSS_KRONROD_POINTS, M_PI, ccl_gsl_params::N_ITERATION, corr_int_par::nell, corr_int_par::th, corr_int_par::tilt0, corr_int_par::tiltf, and w.

Referenced by ccl_correlation().

188 {
189  corr_int_par *cp=malloc(sizeof(corr_int_par));
190  if(cp==NULL) {
192  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_bessel ran out of memory\n");
193  return;
194  }
195 
196  cp->nell=n_ell;
197  cp->ell0=ell[0];
198  cp->ellf=ell[n_ell-1];
199  cp->cl0=cls[0];
200  cp->clf=cls[n_ell-1];
201  cp->cl_spl=ccl_spline_init(n_ell,ell,cls,cls[0],0);
202  if(cp->cl_spl==NULL) {
203  free(cp);
205  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_bessel ran out of memory\n");
206  return;
207  }
208  switch(corr_type) {
209  case CCL_CORR_GG :
210  cp->i_bessel=0;
211  break;
212  case CCL_CORR_GL :
213  cp->i_bessel=2;
214  break;
215  case CCL_CORR_LP :
216  cp->i_bessel=0;
217  break;
218  case CCL_CORR_LM :
219  cp->i_bessel=4;
220  break;
221  }
222 
223  if(cls[0]*cls[1]<=0)
224  cp->extrapol_0=0;
225  else {
226  cp->extrapol_0=1;
227  cp->tilt0=log10(cls[1]/cls[0])/log10(ell[1]/ell[0]);
228  }
229 
230  if(cls[n_ell-2]*cls[n_ell-1]<=0)
231  cp->extrapol_f=0;
232  else {
233  cp->extrapol_f=1;
234  cp->tiltf=log10(cls[n_ell-1]/cls[n_ell-2])/log10(ell[n_ell-1]/ell[n_ell-2]);
235  }
236 
237  int ith, gslstatus;
238  double result,eresult;
239  gsl_function F;
240  gsl_integration_workspace *w=gsl_integration_workspace_alloc(ccl_gsl->N_ITERATION);
241  for(ith=0;ith<n_theta;ith++) {
242  cp->th=theta[ith]*M_PI/180;
243  F.function=&corr_bessel_integrand;
244  F.params=cp;
245  //TODO: Split into intervals between first bessel zeros before integrating
246  //This will help both speed and accuracy of the integral.
247  gslstatus = gsl_integration_qag(&F, 0, ccl_splines->ELL_MAX_CORR, 0,
250  w, &result, &eresult);
251  if(gslstatus != GSL_SUCCESS) {
252  ccl_raise_gsl_warning(gslstatus, "ccl_correlation.c: ccl_tracer_corr_bessel():");
253  *status |= gslstatus;
254  }
255  wtheta[ith]=result/(2*M_PI);
256  }
257  gsl_integration_workspace_free(w);
258  ccl_spline_free(cp->cl_spl);
259  free(cp);
260 }
#define CCL_CORR_LP
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
ccl_spline_params * ccl_splines
Definition: ccl_core.c:47
#define M_PI
Definition: ccl_constants.h:22
double ELL_MAX_CORR
Definition: ccl_params.h:41
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
#define CCL_CORR_GL
void ccl_spline_free(SplPar *spl)
Definition: ccl_utils.c:316
#define CCL_CORR_LM
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
size_t N_ITERATION
Definition: ccl_params.h:55
#define CCL_CORR_GG
static double corr_bessel_integrand(double l, void *params)
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 ccl_tracer_corr_fftlog ( 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 *  status 
)
static

Definition at line 50 of file ccl_correlation.c.

References CCL_CORR_GG, CCL_CORR_GL, CCL_CORR_LM, CCL_CORR_LP, ccl_cosmology_set_status_message(), CCL_ERROR_LINSPACE, CCL_ERROR_MEMORY, ccl_log_spacing(), ccl_spline_eval(), ccl_spline_free(), ccl_spline_init(), ccl_splines, ccl_spline_params::ELL_MAX_CORR, ccl_spline_params::ELL_MIN_CORR, fftlog_ComputeXi2D(), M_PI, ccl_spline_params::N_ELL_CORR, pow(), and taper_cl().

Referenced by ccl_correlation().

55 {
56  int i;
57  double *l_arr,*cl_arr,*th_arr,*wth_arr;
58 
60  if(l_arr==NULL) {
62  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_fftlog ran out of memory\n");
63  return;
64  }
65  cl_arr=malloc(ccl_splines->N_ELL_CORR*sizeof(double));
66  if(cl_arr==NULL) {
67  free(l_arr);
69  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_fftlog ran out of memory\n");
70  return;
71  }
72 
73  //Interpolate input Cl into array needed for FFTLog
74  SplPar *cl_spl=ccl_spline_init(n_ell,ell,cls,cls[0],0);
75  if(cl_spl==NULL) {
76  free(l_arr);
77  free(cl_arr);
79  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_fftlog ran out of memory\n");
80  return;
81  }
82 
83  double cl_tilt,l_edge,cl_edge;
84  l_edge=ell[n_ell-1];
85  if((cls[n_ell-1]*cls[n_ell-2]<0) || (cls[n_ell-2]==0)) {
86  cl_tilt=0;
87  cl_edge=0;
88  }
89  else {
90  cl_tilt=log(cls[n_ell-1]/cls[n_ell-2])/log(ell[n_ell-1]/ell[n_ell-2]);
91  cl_edge=cls[n_ell-1];
92  }
93  for(i=0;i<ccl_splines->N_ELL_CORR;i++) {
94  if(l_arr[i]>=l_edge)
95  cl_arr[i]=cl_edge*pow(l_arr[i]/l_edge,cl_tilt);
96  else
97  cl_arr[i]=ccl_spline_eval(l_arr[i],cl_spl);
98  }
99  ccl_spline_free(cl_spl);
100 
101  if (do_taper_cl)
102  taper_cl(ccl_splines->N_ELL_CORR,l_arr,cl_arr,taper_cl_limits);
103 
104  th_arr=malloc(sizeof(double)*ccl_splines->N_ELL_CORR);
105  if(th_arr==NULL) {
106  free(l_arr);
107  free(cl_arr);
109  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_fftlog ran out of memory\n");
110  return;
111  }
112  wth_arr=(double *)malloc(sizeof(double)*ccl_splines->N_ELL_CORR);
113  if(wth_arr==NULL) {
114  free(l_arr); free(cl_arr); free(th_arr);
116  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_fftlog ran out of memory\n");
117  return;
118  }
119 
120  for(i=0;i<ccl_splines->N_ELL_CORR;i++)
121  th_arr[i]=0;
122  //Although set here to 0, theta is modified by FFTlog to obtain the correlation at ~1/l
123 
124  int i_bessel=0;
125  if(corr_type==CCL_CORR_GG) i_bessel=0;
126  if(corr_type==CCL_CORR_GL) i_bessel=2;
127  if(corr_type==CCL_CORR_LP) i_bessel=0;
128  if(corr_type==CCL_CORR_LM) i_bessel=4;
129  fftlog_ComputeXi2D(i_bessel,ccl_splines->N_ELL_CORR,l_arr,cl_arr,th_arr,wth_arr);
130 
131  // Interpolate to output values of theta
132  SplPar *wth_spl=ccl_spline_init(ccl_splines->N_ELL_CORR,th_arr,wth_arr,wth_arr[0],0);
133  for(i=0;i<n_theta;i++)
134  wtheta[i]=ccl_spline_eval(theta[i]*M_PI/180.,wth_spl);
135  ccl_spline_free(wth_spl);
136 
137  free(l_arr); free(cl_arr);
138  free(th_arr); free(wth_arr);
139 
140  return;
141 }
#define CCL_CORR_LP
double * ccl_log_spacing(double xmin, double xmax, int N)
Definition: ccl_utils.c:102
void fftlog_ComputeXi2D(double bessel_order, int N, const double l[], const double cl[], double th[], double xi[])
Definition: fftlog.c:144
ccl_spline_params * ccl_splines
Definition: ccl_core.c:47
#define M_PI
Definition: ccl_constants.h:22
double ELL_MAX_CORR
Definition: ccl_params.h:41
#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
double ccl_spline_eval(double x, SplPar *spl)
Definition: ccl_utils.c:170
#define CCL_CORR_GL
void ccl_spline_free(SplPar *spl)
Definition: ccl_utils.c:316
#define CCL_CORR_LM
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
double ELL_MIN_CORR
Definition: ccl_params.h:40
#define CCL_CORR_GG
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
static int taper_cl(int n_ell, double *ell, double *cl, double *ell_limits)
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
static void ccl_tracer_corr_legendre ( 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 *  status 
)
static

Definition at line 295 of file ccl_correlation.c.

References ccl_compute_legendre_polynomial(), CCL_CORR_LM, CCL_CORR_LP, ccl_cosmology_set_status_message(), CCL_ERROR_MEMORY, CCL_ERROR_NOT_IMPLEMENTED, ccl_spline_eval(), ccl_spline_free(), ccl_spline_init(), ccl_splines, ccl_spline_params::ELL_MAX_CORR, cl_cmbl_bm::l, M_PI, pow(), and taper_cl().

Referenced by ccl_correlation().

300 {
301  int i;
302  double *l_arr,*cl_arr,*Pl_theta;
303  SplPar *cl_spl;
304 
305  if(corr_type==CCL_CORR_LM || corr_type==CCL_CORR_LP){
307  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: CCL does not support full-sky xi+- calcuations.\nhttps://arxiv.org/abs/1702.05301 indicates flat-sky to be sufficient.\n");
308  }
309 
310  if(*status==0) {
311  l_arr=malloc(((int)(ccl_splines->ELL_MAX_CORR)+1)*sizeof(double));
312  if(l_arr==NULL) {
314  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_legendre ran out of memory\n");
315  }
316  }
317 
318  if(*status==0) {
319  cl_arr=malloc(((int)(ccl_splines->ELL_MAX_CORR)+1)*sizeof(double));
320  if(cl_arr==NULL) {
322  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_legendre ran out of memory\n");
323  }
324  }
325 
326  if(*status==0) {
327  //Interpolate input Cl into
328  cl_spl=ccl_spline_init(n_ell,ell,cls,cls[0],0);
329  if(cl_spl==NULL) {
331  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_legendre ran out of memory\n");
332  }
333  }
334 
335  if(*status==0) {
336  double cl_tilt,l_edge,cl_edge;
337  l_edge=ell[n_ell-1];
338  if((cls[n_ell-1]*cls[n_ell-2]<0) || (cls[n_ell-2]==0)) {
339  cl_tilt=0;
340  cl_edge=0;
341  }
342  else {
343  cl_tilt=log(cls[n_ell-1]/cls[n_ell-2])/log(ell[n_ell-1]/ell[n_ell-2]);
344  cl_edge=cls[n_ell-1];
345  }
346  for(i=0;i<=(int)(ccl_splines->ELL_MAX_CORR);i++) {
347  double l=(double)i;
348  l_arr[i]=l;
349  if(l>=l_edge)
350  cl_arr[i]=cl_edge*pow(l/l_edge,cl_tilt);
351  else
352  cl_arr[i]=ccl_spline_eval(l,cl_spl);
353  }
354  ccl_spline_free(cl_spl);
355 
356  if (do_taper_cl)
357  *status=taper_cl((int)(ccl_splines->ELL_MAX_CORR)+1,l_arr,cl_arr,taper_cl_limits);
358  }
359 
360  if(*status==0) {
361  Pl_theta=malloc(sizeof(double)*((int)(ccl_splines->ELL_MAX_CORR)+1));
362  if(Pl_theta==NULL) {
364  ccl_cosmology_set_status_message(cosmo, "ccl_correlation.c: ccl_tracer_corr_legendre ran out of memory\n");
365  }
366  }
367 
368  if(*status==0) {
369  for (int i=0;i<n_theta;i++) {
370  wtheta[i]=0;
371  ccl_compute_legendre_polynomial(corr_type,theta[i],(int)(ccl_splines->ELL_MAX_CORR),Pl_theta);
372  for(int i_L=1;i_L<(int)(ccl_splines->ELL_MAX_CORR);i_L+=1)
373  wtheta[i]+=cl_arr[i_L]*Pl_theta[i_L];
374  wtheta[i]/=(M_PI*4);
375  }
376  }
377 
378  free(Pl_theta);
379  free(l_arr);
380  free(cl_arr);
381 }
#define CCL_CORR_LP
double double
Definition: precision.hpp:19
#define CCL_ERROR_NOT_IMPLEMENTED
Definition: ccl_error.h:25
ccl_spline_params * ccl_splines
Definition: ccl_core.c:47
#define M_PI
Definition: ccl_constants.h:22
static void ccl_compute_legendre_polynomial(int corr_type, double theta, int ell_max, double *Pl_theta)
double ELL_MAX_CORR
Definition: ccl_params.h:41
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
#define CCL_CORR_LM
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
static int taper_cl(int n_ell, double *ell, double *cl, double *ell_limits)
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
static double corr_bessel_integrand ( double  l,
void *  params 
)
static

Definition at line 158 of file ccl_correlation.c.

References ccl_spline_eval(), corr_int_par::cl0, corr_int_par::cl_spl, corr_int_par::clf, corr_int_par::ell0, corr_int_par::ellf, corr_int_par::extrapol_0, corr_int_par::extrapol_f, corr_int_par::i_bessel, p, pow(), corr_int_par::th, corr_int_par::tilt0, corr_int_par::tiltf, and x.

Referenced by ccl_tracer_corr_bessel().

159 {
160  double cl,jbes;
162  double x=l*p->th;
163 
164  if(l<p->ell0) {
165  if(p->extrapol_0)
166  cl=p->cl0*pow(l/p->ell0,p->tilt0);
167  else
168  cl=0;
169  }
170  else if(l>p->ellf) {
171  if(p->extrapol_f)
172  cl=p->clf*pow(l/p->ellf,p->tiltf);
173  else
174  cl=0;
175  }
176  else
177  cl=ccl_spline_eval(l,p->cl_spl);
178 
179  jbes=gsl_sf_bessel_Jn(p->i_bessel,x);
180 
181  return l*jbes*cl;
182 }
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 int p
Definition: ccl_emu17.c:25
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
static int taper_cl ( int  n_ell,
double ell,
double cl,
double ell_limits 
)
static

Definition at line 23 of file ccl_correlation.c.

References M_PI.

Referenced by ccl_correlation_3d(), ccl_tracer_corr_fftlog(), and ccl_tracer_corr_legendre().

24 {
25 
26  for(int i=0;i<n_ell;i++) {
27  if(ell[i]<ell_limits[0] || ell[i]>ell_limits[3]) {
28  cl[i]=0;//ell outside desirable range
29  continue;
30  }
31  if(ell[i]>=ell_limits[1] && ell[i]<=ell_limits[2])
32  continue;//ell within good ell range
33 
34  if(ell[i]<ell_limits[1])//tapering low ell
35  cl[i]*=cos((ell[i]-ell_limits[1])/(ell_limits[1]-ell_limits[0])*M_PI/2.);
36 
37  if(ell[i]>ell_limits[2])//tapering high ell
38  cl[i]*=cos((ell[i]-ell_limits[2])/(ell_limits[3]-ell_limits[2])*M_PI/2.);
39  }
40 
41  return 0;
42 }
#define M_PI
Definition: ccl_constants.h:22