5 #include <gsl/gsl_errno.h> 16 double dx = (xmax-
xmin)/(N -1.);
18 double *
x = malloc(
sizeof(
double)*N);
22 "ERROR: Could not allocate memory for linear-spaced array (N=%d)\n", N);
26 for (
int i=0; i<N; i++) {
48 "ERROR: Cannot make log-spaced array with %d points - need at least 2\n", Nlog);
52 if (!(xminlog>0 && xmin>0)) {
55 "ERROR: Cannot make log-spaced array xminlog or xmin non-positive (had %le, %le)\n", xminlog, xmin);
69 double *
x = malloc(
sizeof(
double)*(Nlin+Nlog-1));
73 "ERROR: Could not allocate memory for array of size (Nlin+Nlog-1)=%d)\n", (Nlin+Nlog-1));
77 double dx = (xmax-
xmin)/(Nlin -1.);
78 double log_xchange = log(xmin);
79 double log_xmin = log(xminlog);
80 double dlog_x = (log_xchange - log_xmin) / (Nlog-1.);
82 for (
int i=0; i<Nlin+Nlog-1; i++) {
84 x[i] = exp(log_xmin + dlog_x*i);
86 x[i] = xmin + dx*(i-Nlog+1);
107 "ERROR: Cannot make log-spaced array with %d points - need at least 2\n", N);
111 if (!(xmin>0 && xmax>0)) {
114 "ERROR: Cannot make log-spaced array xmax or xmax non-positive (had %le, %le)\n", xmin, xmax);
118 double log_xmax = log(xmax);
119 double log_xmin = log(xmin);
120 double dlog_x = (log_xmax - log_xmin) / (N-1.);
122 double *
x = malloc(
sizeof(
double)*N);
126 "ERROR: Could not allocate memory for log-spaced array (N=%d)\n", N);
130 double xratio = exp(dlog_x);
132 for (
int i=1; i<N-1; i++) {
133 x[i] = x[i-1] * xratio;
152 spl->
intacc=gsl_interp_accel_alloc();
153 spl->
spline=gsl_spline_alloc(gsl_interp_cspline,n);
154 int parstatus=gsl_spline_init(spl->
spline,x,y,n);
156 gsl_interp_accel_free(spl->
intacc);
157 gsl_spline_free(spl->
spline);
178 int stat=gsl_spline_eval_e(spl->
spline,x,spl->
intacc,&y);
179 if (stat!=GSL_SUCCESS) {
187 #define CCL_GAMMA1 2.6789385347077476336556 //Gamma(1/3) 188 #define CCL_GAMMA2 1.3541179394264004169452 //Gamma(2/3) 189 #define CCL_ROOTPI12 21.269446210866192327578 //12*sqrt(pi) 196 fprintf(stderr,
"CosmoMas: l>0 for Bessel function");
202 if(ax<0.1) jl=1-ax2*(1-ax2/20.)/6.;
206 if(ax<0.2) jl=ax*(1-ax2*(1-ax2/28)/10)/3;
207 else jl=(sin(x)/ax-cos(x))/ax;
210 if(ax<0.3) jl=ax2*(1-ax2*(1-ax2/36)/14)/15;
211 else jl=(-3*cos(x)/ax-sin(x)*(1-3/ax2))/ax;
215 jl=ax*ax2*(1-ax2*(1-ax2/44)/18)/105;
217 jl=(cos(x)*(1-15/ax2)-sin(x)*(6-15/ax2)/ax)/ax;
221 jl=ax2*ax2*(1-ax2*(1-ax2/52)/22)/945;
223 jl=(sin(x)*(1-(45-105/ax2)/ax2)+cos(x)*(10-105/ax2)/ax)/ax;
227 jl=ax2*ax2*ax*(1-ax2*(1-ax2/60)/26)/10395;
229 jl=(sin(x)*(15-(420-945/ax2)/ax2)/ax-
230 cos(x)*(1-(105-945/ax2)/ax2))/ax;
235 jl=ax2*ax2*ax2*(1-ax2*(1-ax2/68)/30)/135135;
237 jl=(sin(x)*(-1+(210-(4725-10395/ax2)/ax2)/ax2)+
238 cos(x)*(-21+(1260-10395/ax2)/ax2)/ax)/ax;
247 else if((ax2/l)<0.5) {
248 jl=(exp(l*log(ax/nu)-M_LN2+nu*(1-M_LN2)-(1-(1-3.5/nu2)/(30*nu2))/(12*nu))/nu)*
249 (1-ax2/(4*nu+4)*(1-ax2/(8*nu+16)*(1-ax2/(12*nu+36))));
251 else if((l*l/ax)<0.5) {
253 jl=(cos(beta)*(1-(nu2-0.25)*(nu2-2.25)/(8*ax2)*(1-(nu2-6.25)*(nu2-12.25)/(48*ax2)))-
254 sin(beta)*(nu2-0.25)/(2*ax)*(1-(nu2-2.25)*(nu2-6.25)/(24*ax2)*
255 (1-(nu2-12.25)*(nu2-20.25)/(80*ax2))))/ax;
258 double l3=
pow(nu,0.325);
261 double sx=
sqrt(nu2-ax2);
264 double beta=log(cosb+sx/ax);
265 double cot3b=cotb*cotb*cotb;
266 double cot6b=cot3b*cot3b;
267 double sec2b=secb*secb;
268 double expterm=((2+3*sec2b)*cot3b/24
269 -((4+sec2b)*sec2b*cot6b/16
270 +((16-(1512+(3654+375*sec2b)*sec2b)*sec2b)*cot3b/5760
271 +(32+(288+(232+13*sec2b)*sec2b)*sec2b)*sec2b*cot6b/(128*nu))*
273 jl=
sqrt(cotb*cosb)/(2*nu)*exp(-nu*beta+nu/cotb-expterm);
275 else if(ax>nu+1.48*l3) {
277 double sx=
sqrt(ax2-nu2);
280 double beta=acos(cosb);
281 double cot3b=cotb*cotb*cotb;
282 double cot6b=cot3b*cot3b;
283 double sec2b=secb*secb;
284 double trigarg=nu/cotb-nu*beta-0.25*
M_PI-
285 ((2+3*sec2b)*cot3b/24+(16-(1512+(3654+375*sec2b)*sec2b)*sec2b)*
286 cot3b*cot6b/(5760*nu2))/nu;
287 double expterm=((4+sec2b)*sec2b*cot6b/16-
288 (32+(288+(232+13*sec2b)*sec2b)*sec2b)*
289 sec2b*cot6b*cot6b/(128*nu2))/nu2;
290 jl=
sqrt(cotb*cosb)/nu*exp(-expterm)*cos(trigarg);
297 double secb=
pow(sx,0.3333333333333333333333);
298 double sec2b=secb*secb;
302 -((beta2-1)*beta2/36+1.0/420.0)*sx*sec2b*
CCL_GAMMA2 303 +(((beta2/1620-7.0/3240.0)*beta2+1.0/648.0)*beta2-1.0/8100.0)*sx2*secb*
CCL_GAMMA1 304 +(((beta2/4536-1.0/810.0)*beta2+19.0/11340.0)*beta2-13.0/28350.0)*beta*sx2*sec2b*
CCL_GAMMA2 305 -((((beta2/349920-1.0/29160.0)*beta2+71.0/583200.0)*beta2-121.0/874800.0)*
310 if((x<0)&&(l%2!=0)) jl=-jl;
318 gsl_spline_free(spl->
spline);
319 gsl_interp_accel_free(spl->
intacc);
#define CCL_ERROR_LINLOGSPACE
void ccl_raise_gsl_warning(int gslstatus, const char *msg,...)
static double beta2[28][8]
double * ccl_linear_spacing(double xmin, double xmax, int N)
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
static double beta[2][28][8]
static CCL_BEGIN_DECLS double x[111][8]
gsl_interp_accel * intacc
SplPar * ccl_spline_init(int n, double *x, double *y, double y0, double yf)
void ccl_raise_warning(int err, const char *msg,...)
#define CCL_ERROR_LOGSPACE
double * ccl_log_spacing(double xmin, double xmax, int N)
double ccl_spline_eval(double x, SplPar *spl)
double * ccl_linlog_spacing(double xminlog, double xmin, double xmax, int Nlog, int Nlin)
float pow(float base, unsigned long int exp)
void ccl_spline_free(SplPar *spl)
double ccl_j_bessel(int l, double x)