Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_cls.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <string.h>
5 
6 #include <gsl/gsl_errno.h>
7 #include <gsl/gsl_integration.h>
8 
9 #include "ccl.h"
10 
11 #ifdef HAVE_ANGPOW
12 #include "Angpow/angpow_ccl.h"
13 #endif
14 
15 #define CCL_FRAC_RELEVANT 5E-4
16 //#define CCL_FRAC_RELEVANT 1E-3
17 //Gets the x-interval where the values of y are relevant
18 //(meaning, that the values of y for those x are at least above a fraction frac of its maximum)
19 static void get_support_interval(int n,double *x,double *y,double frac,
20  double *xmin_out,double *xmax_out)
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 }
51 
52 //Wrapper around spline_eval with GSL function syntax
53 static double speval_bis(double x,void *params)
54 {
55  return ccl_spline_eval(x,(SplPar *)params);
56 }
57 
58 
60 {
61  free(w->l_arr);
62  free(w);
63 }
64 
65 CCL_ClWorkspace *ccl_cl_workspace_new(int lmax,int l_limber,
66  double l_logstep,int l_linstep,int *status)
67 {
68  int i_l,l0,increment;
70  if(w==NULL)
71  *status=CCL_ERROR_MEMORY;
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)
98  *status=CCL_ERROR_MEMORY;
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 }
123 
124 CCL_ClWorkspace *ccl_cl_workspace_new_limber(int lmax,double l_logstep,int l_linstep,int *status)
125 {
126  return ccl_cl_workspace_new(lmax,-1,l_logstep,l_linstep,status);
127 }
128 
129 //Params for lensing kernel integrand
130 typedef struct {
131  double chi;
134  int *status;
135 } IntLensPar;
136 
137 //Integrand for lensing kernel
138 static double integrand_wl(double chip,void *params)
139 {
140  IntLensPar *p=(IntLensPar *)params;
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 }
152 
153 //Integral to compute lensing window function
154 //chi -> comoving distance
155 //cosmo -> ccl_cosmology object
156 //spl_pz -> normalized N(z) spline
157 //chi_max -> maximum comoving distance to which the integral is computed
158 //win -> result is stored here
159 static int window_lensing(double chi,ccl_cosmology *cosmo,SplPar *spl_pz,double chi_max,double *win)
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 }
191 
192 //Params for lensing kernel integrand
193 typedef struct {
194  double chi;
198  int *status;
199 } IntMagPar;
200 
201 //Integrand for magnification kernel
202 static double integrand_mag(double chip,void *params)
203 {
204  IntMagPar *p=(IntMagPar *)params;
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 }
217 
218 //Integral to compute magnification window function
219 //chi -> comoving distance
220 //cosmo -> ccl_cosmology object
221 //spl_pz -> normalized N(z) spline
222 //spl_pz -> magnification bias s(z)
223 //chi_max -> maximum comoving distance to which the integral is computed
224 //win -> result is stored here
225 static int window_magnification(double chi,ccl_cosmology *cosmo,SplPar *spl_pz,SplPar *spl_sz,
226  double chi_max,double *win)
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 }
260 
262  int nz_n,double *z_n,double *n,int *status)
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) {
275  *status=CCL_ERROR_SPLINE;
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) {
283  *status=CCL_ERROR_MEMORY;
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():");
301  *status=CCL_ERROR_INTEG;
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) {
312  *status=CCL_ERROR_SPLINE;
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 }
319 
321  int nz_b,double *z_b,double *b,int *status)
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) {
326  *status=CCL_ERROR_SPLINE;
327  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_bz(): error initializing spline for b(z)\n");
328  }
329 }
330 
332  int nz_s,double *z_s,double *s,int *status)
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) {
347  *status=CCL_ERROR_SPLINE;
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)) {
357  *status=CCL_ERROR_LINSPACE;
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) {
366  *status=CCL_ERROR_MEMORY;
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) {
376  *status=CCL_ERROR_INTEG;
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) {
384  *status=CCL_ERROR_SPLINE;
386  "ccl_cls.c: clt_init_wM(): error initializing spline for lensing window\n");
387  }
388  }
389  free(x); free(y);
390 }
391 
392 //CCL_ClTracer initializer for number counts
394  int has_rsd,int has_magnification,
395  int nz_n,double *z_n,double *n,
396  int nz_b,double *z_b,double *b,
397  int nz_s,double *z_s,double *s,int *status)
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 }
413 
415  int *status)
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)) {
432  *status=CCL_ERROR_LINSPACE;
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) {
440  *status=CCL_ERROR_MEMORY;
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) {
450  *status=CCL_ERROR_INTEG;
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) {
458  *status=CCL_ERROR_SPLINE;
460  "ccl_cls.c: clt_init_wL(): error initializing spline for lensing window\n");
461  }
462  }
463  free(x); free(y);
464 }
465 
467  int nz_rf,double *z_rf,double *rf,int *status)
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) {
472  *status=CCL_ERROR_SPLINE;
473  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_rf(): error initializing spline for b(z)\n");
474  }
475 }
476 
478  int nz_ba,double *z_ba,double *ba,int *status)
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) {
483  *status=CCL_ERROR_SPLINE;
484  ccl_cosmology_set_status_message(cosmo, "ccl_cls.c: clt_init_ba(): error initializing spline for b(z)\n");
485  }
486 }
487 
489  int has_intrinsic_alignment,
490  int nz_n,double *z_n,double *n,
491  int nz_ba,double *z_ba,double *ba,
492  int nz_rf,double *z_rf,double *rf,int *status)
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 }
503 
504 //CCL_ClTracer creator
505 //cosmo -> ccl_cosmology object
506 //tracer_type -> type of tracer. Supported: ccl_number_counts_tracer, ccl_weak_lensing_tracer
507 //nz_n -> number of points for N(z)
508 //z_n -> array of z-values for N(z)
509 //n -> corresponding N(z)-values. Normalization is irrelevant
510 // N(z) will be set to zero outside the range covered by z_n
511 //nz_b -> number of points for b(z)
512 //z_b -> array of z-values for b(z)
513 //b -> corresponding b(z)-values.
514 // b(z) will be assumed constant outside the range covered by z_n
515 static CCL_ClTracer *cl_tracer(ccl_cosmology *cosmo,int tracer_type,
516  int has_rsd,int has_magnification,int has_intrinsic_alignment,
517  int nz_n,double *z_n,double *n,
518  int nz_b,double *z_b,double *b,
519  int nz_s,double *z_s,double *s,
520  int nz_ba,double *z_ba,double *ba,
521  int nz_rf,double *z_rf,double *rf,
522  double z_source, int * status)
523 {
524  int clstatus=0;
525  CCL_ClTracer *clt=(CCL_ClTracer *)malloc(sizeof(CCL_ClTracer));
526  if(clt==NULL) {
527  *status=CCL_ERROR_MEMORY;
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);
550  *status=CCL_ERROR_INCONSISTENT;
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 }
563 
564 //CCL_ClTracer constructor with error checking
565 //cosmo -> ccl_cosmology object
566 //tracer_type -> type of tracer. Supported: ccl_number_counts_tracer, ccl_weak_lensing_tracer
567 //nz_n -> number of points for N(z)
568 //z_n -> array of z-values for N(z)
569 //n -> corresponding N(z)-values. Normalization is irrelevant
570 // N(z) will be set to zero outside the range covered by z_n
571 //nz_b -> number of points for b(z)
572 //z_b -> array of z-values for b(z)
573 //b -> corresponding b(z)-values.
574 // b(z) will be assumed constant outside the range covered by z_n
576  int has_rsd,int has_magnification,int has_intrinsic_alignment,
577  int nz_n,double *z_n,double *n,
578  int nz_b,double *z_b,double *b,
579  int nz_s,double *z_s,double *s,
580  int nz_ba,double *z_ba,double *ba,
581  int nz_rf,double *z_rf,double *rf,
582  double z_source, int * status)
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 }
590 
591 //CCL_ClTracer destructor
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 }
613 
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 }
621 
623  int has_rsd,int has_magnification,
624  int nz_n,double *z_n,double *n,
625  int nz_b,double *z_b,double *b,
626  int nz_s,double *z_s,double *s, int * status)
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 }
632 
634  int nz_n,double *z_n,double *n,
635  int nz_b,double *z_b,double *b, int * status)
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 }
641 
643  int has_alignment,
644  int nz_n,double *z_n,double *n,
645  int nz_ba,double *z_ba,double *ba,
646  int nz_rf,double *z_rf,double *rf, int * status)
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 }
652 
654  int nz_n,double *z_n,double *n, int * status)
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 }
660 
661 static double f_dens(double a,ccl_cosmology *cosmo,CCL_ClTracer *clt, int * status)
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 }
670 
671 static double f_rsd(double a,ccl_cosmology *cosmo,CCL_ClTracer *clt, int * status)
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 }
680 
681 static double f_mag(double a,double chi,ccl_cosmology *cosmo,CCL_ClTracer *clt, int * status)
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 }
690 
691 //Transfer function for number counts
692 //l -> angular multipole
693 //k -> wavenumber modulus
694 //cosmo -> ccl_cosmology object
695 //w -> CCL_ClWorskpace object
696 //clt -> CCL_ClTracer object (must be of the ccl_number_counts_tracer type)
697 static double transfer_nc(int l,double k,
698  ccl_cosmology *cosmo,CCL_ClWorkspace *w,CCL_ClTracer *clt, int * status)
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 }
725 
726 static double f_lensing(double a,double chi,ccl_cosmology *cosmo,CCL_ClTracer *clt, int * status)
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 }
735 
736 static double f_IA_NLA(double a,double chi,ccl_cosmology *cosmo,CCL_ClTracer *clt, int * status)
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 }
751 
752 //Transfer function for shear
753 //l -> angular multipole
754 //k -> wavenumber modulus
755 //cosmo -> ccl_cosmology object
756 //w -> CCL_ClWorskpace object
757 //clt -> CCL_ClTracer object (must be of the ccl_weak_lensing_tracer type)
758 static double transfer_wl(int l,double k,
759  ccl_cosmology *cosmo,CCL_ClWorkspace *w,CCL_ClTracer *clt, int * status)
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 }
775 
776 static double transfer_cmblens(int l,double k,ccl_cosmology *cosmo,CCL_ClTracer *clt,int *status)
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 }
789 
790 //Wrapper for transfer function
791 //l -> angular multipole
792 //k -> wavenumber modulus
793 //cosmo -> ccl_cosmology object
794 //clt -> CCL_ClTracer object
795 static double transfer_wrap(int il,double lk,ccl_cosmology *cosmo,
796  CCL_ClWorkspace *w,CCL_ClTracer *clt, int * status)
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 }
811 
812 //Params for power spectrum integrand
813 typedef struct {
814  int il;
819  int *status;
820 } IntClPar;
821 
822 //Integrand for integral power spectrum
823 static double cl_integrand(double lk,void *params)
824 {
825  double d1,d2;
826  IntClPar *p=(IntClPar *)params;
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 }
841 
842 //Figure out k intervals where the Limber kernel has support
843 //clt1 -> tracer #1
844 //clt2 -> tracer #2
845 //l -> angular multipole
846 //lkmin, lkmax -> log10 of the range of scales where the transfer functions have support
848  CCL_ClTracer *clt1,CCL_ClTracer *clt2,int l,
849  double *lkmin,double *lkmax)
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 }
883 
884 //Compute angular power spectrum between two bins
885 //cosmo -> ccl_cosmology object
886 //il -> index in angular multipole array
887 //clt1 -> tracer #1
888 //clt2 -> tracer #2
890  CCL_ClTracer *clt1,CCL_ClTracer *clt2,int * status)
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){
933  *status=CCL_ERROR_INTEG;
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 }
942 
944  CCL_ClTracer *clt1,CCL_ClTracer *clt2,
945  int nl_out,int *l_out,double *cl_out,int *status)
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) {
954  *status=CCL_ERROR_SPLINE_EV;
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) {
965  *status=CCL_ERROR_MEMORY;
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) {
973  *status=CCL_ERROR_MEMORY;
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) {
1016  *status=CCL_ERROR_MEMORY;
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 }
1031 
1032 static int check_clt_fa_inconsistency(CCL_ClTracer *clt,int func_code)
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 }
1047 
1048 double ccl_get_tracer_fa(ccl_cosmology *cosmo,CCL_ClTracer *clt,double a,int func_code,int *status)
1049 {
1050  SplPar *spl;
1051 
1052  if(check_clt_fa_inconsistency(clt,func_code)) {
1053  *status=CCL_ERROR_INCONSISTENT;
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 }
1090 
1091 int ccl_get_tracer_fas(ccl_cosmology *cosmo,CCL_ClTracer *clt,int na,double *a,double *fa,
1092  int func_code,int *status)
1093 {
1094  SplPar *spl;
1095 
1096  if(check_clt_fa_inconsistency(clt,func_code)) {
1097  *status=CCL_ERROR_INCONSISTENT;
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 }
ccl_cosmology * cosmo
Definition: ccl_cls.c:133
double ccl_scale_factor_of_chi(ccl_cosmology *cosmo, double chi, int *status)
static void clt_init_rf(CCL_ClTracer *clt, ccl_cosmology *cosmo, int nz_rf, double *z_rf, double *rf, int *status)
Definition: ccl_cls.c:466
#define CCL_ERROR_INTEG
Definition: ccl_error.h:15
void ccl_cl_workspace_free(CCL_ClWorkspace *w)
Definition: ccl_cls.c:59
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 double transfer_nc(int l, double k, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:697
int INTEGRATION_LIMBER_GAUSS_KRONROD_POINTS
Definition: ccl_params.h:61
static int window_lensing(double chi, ccl_cosmology *cosmo, SplPar *spl_pz, double chi_max, double *win)
Definition: ccl_cls.c:159
SplPar * spl_rf
Definition: ccl_cls.h:45
double ccl_h_over_h0(ccl_cosmology *cosmo, double a, int *status)
static double transfer_cmblens(int l, double k, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:776
static void clt_init_wL(CCL_ClTracer *clt, ccl_cosmology *cosmo, int *status)
Definition: ccl_cls.c:414
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 has_intrinsic_alignment
Definition: ccl_cls.h:41
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
int ccl_get_tracer_fas(ccl_cosmology *cosmo, CCL_ClTracer *clt, int na, double *a, double *fa, int func_code, int *status)
Definition: ccl_cls.c:1091
#define CCL_ERROR_NOT_IMPLEMENTED
Definition: ccl_error.h:25
double ccl_nonlin_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:1562
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_parameters params
Definition: ccl_core.h:124
CCL_ClTracer * clt2
Definition: ccl_cls.c:818
CCL_ClWorkspace * ccl_cl_workspace_new(int lmax, int l_limber, double l_logstep, int l_linstep, int *status)
Definition: ccl_cls.c:65
void ccl_check_status(ccl_cosmology *cosmo, int *status)
Definition: ccl_error.c:88
int has_magnification
Definition: ccl_cls.h:40
#define CCL_MAX(a, b)
Definition: ccl_utils.h:8
#define CLIGHT_HMPC
Definition: ccl_constants.h:33
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
static double f_dens(double a, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:661
static int check_clt_fa_inconsistency(CCL_ClTracer *clt, int func_code)
Definition: ccl_cls.c:1032
#define CCL_ERROR_SPLINE_EV
Definition: ccl_error.h:14
#define CCL_FRAC_RELEVANT
Definition: ccl_cls.c:15
double ccl_growth_rate(ccl_cosmology *cosmo, double a, int *status)
ccl_spline_params * ccl_splines
Definition: ccl_core.c:47
SplPar * spl_bz
Definition: ccl_cls.h:43
CCL_BEGIN_DECLS double * ccl_linear_spacing(double xmin, double xmax, int N)
Definition: ccl_utils.c:14
double h
Definition: ccl_core.h:33
static double f_IA_NLA(double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:736
int il
Definition: ccl_cls.c:814
#define CCL_ERROR_SPLINE
Definition: ccl_error.h:13
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)
Definition: ccl_cls.c:642
CCL_ClTracer * ccl_cl_tracer_cmblens(ccl_cosmology *cosmo, double z_source, int *status)
Definition: ccl_cls.c:614
SplPar * spl_sz
Definition: ccl_cls.c:196
CCL_ClTracer * ccl_cl_tracer_lensing_simple(ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int *status)
Definition: ccl_cls.c:653
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
CCL_ClTracer * clt1
Definition: ccl_cls.c:817
SplPar * spl_pz
Definition: ccl_cls.c:132
static double integrand_mag(double chip, void *params)
Definition: ccl_cls.c:202
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 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
double chi
Definition: ccl_cls.c:131
ccl_gsl_params * ccl_gsl
Definition: ccl_core.c:48
double ccl_sinn(ccl_cosmology *cosmo, double chi, int *status)
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
Definition: grid.h:231
ccl_cosmology * cosmo
Definition: ccl_cls.c:815
int has_rsd
Definition: ccl_cls.h:39
double INTEGRATION_EPSREL
Definition: ccl_params.h:59
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
static double f_mag(double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:681
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
static double f_lensing(double a, double chi, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:726
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)
Definition: ccl_cls.c:622
static double f_rsd(double a, ccl_cosmology *cosmo, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:671
void ccl_spline_free(SplPar *spl)
Definition: ccl_utils.c:316
int tracer_type
Definition: ccl_cls.h:32
double prefac_lensing
Definition: ccl_cls.h:33
int * status
Definition: ccl_cls.c:134
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
#define CCL_ERROR_MEMORY
Definition: ccl_error.h:10
size_t N_ITERATION
Definition: ccl_params.h:55
dictionary params
Definition: halomod_bm.py:27
double chi_source
Definition: ccl_cls.h:38
CCL_ClWorkspace * ccl_cl_workspace_new_limber(int lmax, double l_logstep, int l_linstep, int *status)
Definition: ccl_cls.c:124
ccl_cosmology * cosmo
Definition: ccl_cls.c:197
float sz
Definition: mk_bins.py:8
static double z[8]
double ccl_get_tracer_fa(ccl_cosmology *cosmo, CCL_ClTracer *clt, double a, int func_code, int *status)
Definition: ccl_cls.c:1048
double l_logstep
Definition: ccl_cls.h:216
#define CCL_ERROR_INCONSISTENT
Definition: ccl_error.h:12
SplPar * spl_pz
Definition: ccl_cls.c:195
static int p
Definition: ccl_emu17.c:25
void ccl_cl_tracer_free(CCL_ClTracer *clt)
Definition: ccl_cls.c:592
SplPar * spl_ba
Definition: ccl_cls.h:46
int * status
Definition: ccl_cls.c:819
double zmax
Definition: ccl_cls.h:37
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
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
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
SplPar * spl_wM
Definition: ccl_cls.h:48
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
double Omega_m
Definition: ccl_core.h:21
static double transfer_wrap(int il, double lk, ccl_cosmology *cosmo, CCL_ClWorkspace *w, CCL_ClTracer *clt, int *status)
Definition: ccl_cls.c:795
double INTEGRATION_LIMBER_EPSREL
Definition: ccl_params.h:62
double chimax
Definition: ccl_cls.h:34
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 double speval_bis(double x, void *params)
Definition: ccl_cls.c:53
CCL_ClWorkspace * w
Definition: ccl_cls.c:816
double chimin
Definition: ccl_cls.h:35
static double cl_integrand(double lk, void *params)
Definition: ccl_cls.c:823
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
double ccl_comoving_radial_distance(ccl_cosmology *cosmo, double a, int *status)
static double w[2][28][111]
Definition: ccl_emu17.c:33
static double integrand_wl(double chip, void *params)
Definition: ccl_cls.c:138
double xf
Definition: ccl_utils.h:52
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)
Definition: ccl_cls.c:943
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
Definition: ccl_utils.c:146
CCL_ClTracer * ccl_cl_tracer_number_counts_simple(ccl_cosmology *cosmo, int nz_n, double *z_n, double *n, int nz_b, double *z_b, double *b, int *status)
Definition: ccl_cls.c:633