Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
core_power.cpp
Go to the documentation of this file.
1 
9 #include "core_power.h"
10 #include "class_data_vec.hpp"
11 #include "params.hpp"
12 #include <ccl_background.h>
13 #include <ccl_power.h>
14 #include <gsl/gsl_deriv.h>
15 #include <gsl/gsl_errno.h>
16 #include <gsl/gsl_fit.h>
17 #include <gsl/gsl_integration.h>
18 #include <gsl/gsl_odeiv2.h>
19 #include <gsl/gsl_spline.h>
20 
21 /*****************************/
24 namespace{
25 
31 template <class P>
33 {
34  integrand_param(double r, const P& P_k): r(r), P_k(P_k) {}
35  double r;
36  const P& P_k;
37 };
38 
50 {
51 public:
52  // CONSTRUCTOR
53  Integr_obj(double(*f) (double, void*), const double a, const double b,
54  const double epsabs, const double epsrel, const size_t limit):
55  a(a), b(b), L(b-a), epsabs(epsabs), epsrel(epsrel), limit(limit)
56  {
57  w = gsl_integration_workspace_alloc(limit);
58  F.function = f;
59  }
60  // DESTRUCTOR
62  {
63  gsl_integration_workspace_free (w);
64  }
65  // METHODS
66  void set_a(double a_new) { a = a_new; L = a -b; }
67  void set_b(double b_new) { b = b_new; L = a -b; }
68 
69 protected:
70  // VARIABLES
71  double result, error;
72  double a, b, L;
73  double epsabs, epsrel;
74  size_t limit;
75  gsl_function F;
76  gsl_integration_workspace* w;
77  int gsl_errno;
78 };
79 
86 class Integr_obj_qag : public Integr_obj
87 {
88 public:
89  // CONSTRUCTOR
90  Integr_obj_qag(double(*f) (double, void*), const double a, const double b,
91  const double epsabs, const double epsrel, size_t limit, int key):
92  Integr_obj(f, a, b, epsabs, epsrel, limit), key(key) {}
93 
94  // METHODS
95  double operator()(double r, void* params)
96  {
97  F.params = params;
98  gsl_errno = gsl_integration_qag(&F, a, b, epsabs, epsrel, limit, key, w, &result, &error);
99  if (gsl_errno) throw std::runtime_error("GSL integration error: " + std::string(gsl_strerror(gsl_errno)));
100  else return result;
101  }
102 
103  double operator()(void* params)
104  {
105  return this->operator()(0, params);
106  }
107 
108 protected:
109  // VARIABLES
110  int key;
111 };
112 
119 {
120 public:
121  // CONSTRUCTOR
122  Integr_obj_qagiu(double(*f) (double, void*), const double a,
123  const double epsabs, const double epsrel, size_t limit):
124  Integr_obj(f, a, 0, epsabs, epsrel, limit) {}
125 
126  // METHODS
127  double operator()(double r, void* params)
128  {
129  F.params = params;
130  gsl_errno = gsl_integration_qagiu(&F, a, epsabs, epsrel, limit, w, &result, &error);
131  if (gsl_errno) throw std::runtime_error("GSL integration error: " + std::string(gsl_strerror(gsl_errno)));
132  else return result;
133  }
134 
135  double operator()(void* params)
136  {
137  return this->operator()(0, params);
138  }
139 };
140 
149 {
150 public:
151  // CONSTRUCTOR
152  Integr_obj_qawo(double(*f) (double, void*), const double a, const double b,
153  const double epsabs, const double epsrel, size_t limit, size_t n):
154  Integr_obj(f, a, b, epsabs, epsrel, limit)
155  {
156  wf = gsl_integration_qawo_table_alloc(1, 1, GSL_INTEG_SINE, n);
157  }
158  // DESTRUCTOR
160  {
161  gsl_integration_qawo_table_free(wf);
162  }
163  // METHODS
164  double operator()(double r, void* params)
165  {
166  gsl_integration_qawo_table_set(wf, r, L, GSL_INTEG_SINE);
167  F.params = params;
168  gsl_errno = gsl_integration_qawo(&F, a, epsabs, epsrel, limit, w, wf, &result, &error);
169  if (gsl_errno) throw std::runtime_error("GSL integration error: " + std::string(gsl_strerror(gsl_errno)));
170  else return result;
171  }
172 protected:
173  gsl_integration_qawo_table* wf;
174 };
175 
182 {
183 public:
184  // CONSTRUCTOR
185  Integr_obj_qawf(double(*f) (double, void*), const double a,
186  const double epsabs, size_t limit, size_t n):
187  Integr_obj_qawo(f, a, 0, epsabs, 0, limit, n)
188  {
189  wc = gsl_integration_workspace_alloc (limit);
190  }
191  // DESTRUCTOR
193  {
194  gsl_integration_workspace_free (wc);
195  }
196  // METHODS
197  double operator()(double r, void* params)
198  {
199  gsl_integration_qawo_table_set(wf, r, L, GSL_INTEG_SINE);
200  F.params = params;
201  gsl_errno = gsl_integration_qawf(&F, a, epsabs, limit, w, wc, wf, &result, &error);
202  if (gsl_errno) throw std::runtime_error("GSL integration error: " + std::string(gsl_strerror(gsl_errno)));
203  else return result;
204  }
205 protected:
206  gsl_integration_workspace* wc;
207 };
208 
215 {
216 public:
217  ODE_Solver(int (* function) (double t, const double y[], double dydt[], void * params), size_t dim, void* params,
218  const double hstart = 1e-6, const double epsabs = 1e-6, const double epsrel = 0):
219  sys({function, NULL, dim, params}),
220  d(gsl_odeiv2_driver_alloc_y_new(&sys, gsl_odeiv2_step_rk8pd, hstart, epsabs, epsrel)) {}
221 
223  {
224  gsl_odeiv2_driver_free (d);
225  }
226 
227  void update(double &t, const double t1, double y[])
228  {
229  status = gsl_odeiv2_driver_apply (d, &t, t1, y);
230  if (status) throw std::runtime_error("GSL ODE error: " + std::string(gsl_strerror(status)));
231  }
232 
233  int status;
234  gsl_odeiv2_system sys;
235  gsl_odeiv2_driver* d;
236 };
237 
238 template<typename T>
240 { // hubble normalize to H(a = 1) == 1
241  return sqrt(cosmo.Omega_m/pow(a, 3) + cosmo.Omega_L());
242 }
243 
244 double growth_factor_integrand(double a, void* params)
245 {
246  return pow(a*hubble_param(a, *static_cast<const Cosmo_Param*>(params)), -3);
247 }
248 
249 double growth_factor(double a, void* params)
250 {
251  return growth_factor(a, *static_cast<const Cosmo_Param*>(params));
252 }
253 
254 double ln_growth_factor(double log_a, void* parameters)
255 {
256  return log(growth_factor(exp(log_a), parameters));
257 }
258 
259 template<typename T>
260 size_t get_nearest(const T val, const std::vector<T>& vec)
261 { // assume data in 'vec' are ordered, vec[0] < vec[1] < ...
262  return lower_bound(vec.begin(), vec.end(), val) - vec.begin();
263 }
264 
273 template <class P>
274 double xi_integrand_W(double k, void* params){
275  integrand_param<P>* my_par = (integrand_param<P>*) params;
276  const double r = my_par->r;
277  const P& P_k = my_par->P_k;
278  return 1/(2*PI*PI)*k/r*P_k(k);
279 };
280 
289 template <class P>
290 double xi_integrand_G(double k, void* params){
291  integrand_param<P>* my_par = (integrand_param<P>*) params;
292  const double kr = k*my_par->r;
293  double j0 = kr < 1e-6 ? 1 - kr*kr/6. : sin(kr) / (kr);
294  const P& P_k = my_par->P_k;
295  return 1/(2*PI*PI)*k*k*j0*P_k(k);
296 };
297 
306 template <class P>
307 double sigma_integrand_G(double k, void* params){
308  integrand_param<P>* my_par = (integrand_param<P>*) params;
309  const double kr = k*my_par->r;
310  const double w = kr < 0.1 ?
311  1.-0.1*kr*kr+0.003571429*kr*kr*kr*kr
312  -6.61376E-5*kr*kr*kr*kr*kr*kr
313  +7.51563E-7*kr*kr*kr*kr*kr*kr*kr*kr
314  :
315  3.*(sin(kr) - kr*cos(kr))/(kr*kr*kr);
316 
317  const P& P_k = my_par->P_k;
318  return 1/(2*PI*PI)*k*k*w*w*P_k(k);
319 };
320 
334 template <class P, class T>
335 void gen_fce_r_binned_gsl(const double x_min, const double x_max, const double lin_bin, const P& P_k, Data_Vec<FTYPE_t, 2>& fce_binned, T& fce_r)
336 {
337  const size_t req_size = (size_t)ceil((x_max - x_min)/lin_bin);
338 
339  fce_binned.resize(req_size);
340  integrand_param<P> my_param(0, P_k);
341 
342  for(size_t i = 0; i < req_size; i++){
343  double r = x_min + i*lin_bin;
344  my_param.r = r;
345  fce_binned[0][i] = r;
346  fce_binned[1][i] = fce_r(r, &my_param);
347  }
348 }
349 
361 template <class P, class T> // both callable with 'operator()(double)'
362 void gen_corr_func_binned_gsl(const Sim_Param &sim, const P& P_k, Data_Vec<FTYPE_t, 2>& corr_func_binned, T& xi_r)
363 {
364  const double x_min = sim.other_par.x_corr.lower;
365  const double x_max = sim.other_par.x_corr.upper;
366  const double lin_bin = 10./sim.out_opt.points_per_10_Mpc;
367  gen_fce_r_binned_gsl(x_min, x_max, lin_bin, P_k, corr_func_binned, xi_r);
368 }
369 
381 template <class P, class T> // both callable with 'operator()(double)'
382 void gen_sigma_func_binned_gsl(const Sim_Param &sim, const P& P_k, Data_Vec<FTYPE_t, 2>& sigma_binned, T& sigma_r)
383 {
384  const double x_min = sim.other_par.x_corr.lower;
385  const double x_max = sim.other_par.x_corr.upper;
386  const double lin_bin = 10./sim.out_opt.points_per_10_Mpc;
387  gen_fce_r_binned_gsl(x_min, x_max, lin_bin, P_k, sigma_binned, sigma_r);
388 }
389 
390 constexpr double GSL_EPSABS = 1e-7;
391 constexpr size_t GSL_LIMIT = 1000;
392 constexpr size_t GSL_N = 100;
393 
394 }
395 
396 /****************************/
401 {
402  BOOST_LOG_TRIVIAL(debug) << "Initializing CCL power spectrum...";
403  int status = 0;
404  ccl_sigma8(cosmo.cosmo, &status);
405  if (status) throw std::runtime_error(cosmo.cosmo->status_message);
406 }
407 
409 {
410  Integr_obj_qag D(&growth_factor_integrand, 0, 1, 0, 1e-12, 1000, GSL_INTEG_GAUSS61);
411  return D(static_cast<void*>(cosmo));
412 }
413 
414 FTYPE_t growth_factor(FTYPE_t a, const Cosmo_Param& cosmo)
415 {
416  // D(0) == 0; D(1) == 1, do not check (not often, better performance)
417  if (!a) return 0;
418 
419  // try ccl range
420  int status = 0;
421  FTYPE_t D_ccl = ccl_growth_factor(cosmo.cosmo, a, &status);
422  if (!status) return D_ccl;
423 
424  // integrate outside range
425  Integr_obj_qag D(&growth_factor_integrand, 0, a, 0, 1e-12, 1000, GSL_INTEG_GAUSS61);
426  return hubble_param(a, cosmo)*D(static_cast<void*>(cosmo))/cosmo.D_norm;
427 }
428 
429 FTYPE_t growth_rate(FTYPE_t a, const Cosmo_Param& cosmo)
430 {
431  // f(0) == 1
432  if (!a) return 1;
433 
434  // try ccl range
435  int status = 0;
436  double f = ccl_growth_rate(cosmo.cosmo, a, &status);
437  if (!status) return f;
438 
439  // logarithmic derivative outside range
440  gsl_function F = {&ln_growth_factor, static_cast<void*>(cosmo)};
441  double error;
442  status = gsl_deriv_central(&F, log(a), 1e-12, &f, &error);
443  if (!status) return f;
444  else throw std::runtime_error("GSL ODE error: " + std::string(gsl_strerror(status)));
445 }
446 
447 FTYPE_t growth_change(FTYPE_t a, const Cosmo_Param& cosmo)
448 {
449  if (a){
450  // compute with growth rate
451  return growth_rate(a, cosmo)*growth_factor(a, cosmo)/a;
452  }
453  else{
454  gsl_function F = {&growth_factor, static_cast<void*>(cosmo)};
455  double dDda, error;
456  int status = gsl_deriv_forward(&F, a, 1e-12, &dDda, &error);
457  if (!status) return dDda;
458  else throw std::runtime_error("GSL ODE error: " + std::string(gsl_strerror(status)));
459  }
460 }
461 
462 FTYPE_t Omega_lambda(FTYPE_t a, const Cosmo_Param& cosmo)
463 {
464  // try ccl range
465  int status = 0;
466  FTYPE_t OL = ccl_omega_x(cosmo.cosmo, a, ccl_species_l_label, &status);
467  if(!status) return OL;
468 
469  // compute outside range
470  OL = cosmo.Omega_L();
471  return OL/(cosmo.Omega_m/pow(a, 3) + OL);
472 }
473 
474 FTYPE_t lin_pow_spec(FTYPE_t a, FTYPE_t k, const Cosmo_Param& cosmo)
475 {
476  int status = 0;
477  FTYPE_t pk = ccl_linear_matter_power(cosmo.cosmo, k*cosmo.h, a, &status)*pow(cosmo.h, 3);
478  if (!status) return pk;
479  status = 0;
480  pk = ccl_linear_matter_power(cosmo.cosmo, k*cosmo.h, 1, &status)*pow(cosmo.h, 3);
481  FTYPE_t D = growth_factor(a, cosmo);
482  if (!status) return D*D*pk;
483  else throw std::runtime_error(cosmo.cosmo->status_message);
484 }
485 
486 FTYPE_t non_lin_pow_spec(FTYPE_t a, FTYPE_t k, const Cosmo_Param& cosmo)
487 {
488  if (a < 1e-3) return lin_pow_spec(a, k, cosmo);
489  int status = 0;
490  FTYPE_t pk = ccl_nonlin_matter_power(cosmo.cosmo, k*cosmo.h, a, &status)*pow(cosmo.h, 3);
491  if (!status) return pk;
492  else throw std::runtime_error(cosmo.cosmo->status_message);
493 }
494 
495 template <typename T, size_t N>
497 {
498  is_init = true;
499  acc = gsl_interp_accel_alloc ();
500  spline = gsl_spline_alloc (gsl_interp_steffen, data.size());
501 
502  std::vector<double> tmp_x(data[0].begin(), data[0].end());
503  std::vector<double> tmp_y(data[1].begin(), data[1].end());
504 
505  gsl_spline_init (spline, tmp_x.data(), tmp_y.data(), data.size());
506 
507  x_min = data[0].front();
508  x_max = data[0].back();
509 }
510 
512 {
513  if (is_init)
514  {
515  gsl_spline_free(spline);
516  gsl_interp_accel_free (acc);
517  }
518 }
519 
520 double Interp_obj::operator()(double x) const{ return gsl_spline_eval(spline, x, acc); }
521 
522 template <typename T, size_t N>
523 Extrap_Pk<T, N>::Extrap_Pk(const Data_Vec<T, N>& data, const Sim_Param& sim, const size_t m_l, const size_t n_l,
524  const size_t m_u, const size_t n_u):
525  cosmo(sim.cosmo)
526 {
527  this->init(data);//< initialize Interp_obj
528  // LOWER RANGE -- fit linear power spectrum to data[m_l:n_l)
529  BOOST_LOG_TRIVIAL(debug) << "Fitting amplitude of P(k) in lower range.";
530  k_min = data[0][m_l]; // first k in data
531  fit_lin(data, m_l, n_l, A_low);
532 
533  // UPPER RANGE -- fit Ak^ns to data[m_u,n_u)
534  BOOST_LOG_TRIVIAL(debug) << "Fitting amplitude of P(k) in upper range.";
535  k_max = data[0][n_u-1]; // last k in data
536  fit_power_law(data, m_u, n_u, A_up, n_s);
537 }
538 
539 template <typename T, size_t N>
540 Extrap_Pk<T, N>::Extrap_Pk(const Data_Vec<T, N>& data, const Sim_Param& sim, const size_t m_l, const size_t n_u):
541  Extrap_Pk(data, sim,
542  // fit over first and last half of a decade
543  m_l, m_l + sim.out_opt.bins_per_decade/2,
544  n_u - sim.out_opt.bins_per_decade/2, n_u
545  ) {}
546 
547 template <typename T, size_t N>
549  Extrap_Pk(data, sim,
550  // trust simulation up to HALF k_nq
551  0, get_nearest(sim.other_par.nyquist.at("particle")/2, data[0]) + 1
552  ) {}
553 
554 static FTYPE_t truncation_fce(FTYPE_t k, FTYPE_t k2_G)
555 {
556  return exp(-k*k/k2_G);
557 }
558 
559 template <typename T, size_t N>
560 void Extrap_Pk<T, N>::fit_lin(const Data_Vec<T, N>& data, const size_t m, const size_t n, double &A)
561 {
562  // FIT linear power spectrum to data[m:n)
563  // fit 'P(k) = A * P_lin(k)' via A
564  // for TZA correct for truncation
565  // for N = 2 perform non-weighted least-square fitting
566  // for N = 3 use data[2] as sigma, w = 1/sigma^2
567  double Pk;
568  std::vector<double> Pk_res, w;
569  Pk_res.reserve(n-m);
570  if (N == 3){
571  w.reserve(n-m);
572  }
573  std::vector<double> A_vec(n-m, 1);
574 
575  if (cosmo.truncated_pk)
576  {
577  const FTYPE_t k2_G = cosmo.k2_G;
578  for(size_t i = m; i < n; i++){
579  FTYPE_t k = data[0][i];
580  Pk = lin_pow_spec(1, k, cosmo) * truncation_fce(k, k2_G);;
581  Pk_res.push_back(data[1][i] / Pk);
582  if (N == 3) w.push_back(pow2(Pk/data[2][i]));
583  }
584  }
585  else
586  {
587  for(size_t i = m; i < n; i++){
588  Pk = lin_pow_spec(1, data[0][i], cosmo);
589  Pk_res.push_back(data[1][i] / Pk);
590  if (N == 3) w.push_back(pow2(Pk/data[2][i]));
591  }
592  }
593 
594 
595  double A_sigma2, sumsq;
596 
597  int gsl_errno;
598  if (N == 3) gsl_errno = gsl_fit_wmul(A_vec.data(), 1, w.data(), 1, Pk_res.data(), 1, n-m, &A, &A_sigma2, &sumsq);
599  else gsl_errno = gsl_fit_mul(A_vec.data(), 1, Pk_res.data(), 1, n-m, &A, &A_sigma2, &sumsq);
600  if (gsl_errno) throw std::runtime_error("GSL integration error: " + std::string(gsl_strerror(gsl_errno)));
601 
602  BOOST_LOG_TRIVIAL(debug) << "\t[" << (N == 3 ? "weighted-" : "") << "fit A = " << A << ", err = " << 100*sqrt(A_sigma2)/A << "%%]";
603 }
604 
605 template <typename T, size_t N>
606 void Extrap_Pk<T, N>::fit_power_law(const Data_Vec<T, N>& data, const size_t m, const size_t n, double &A, double &n_s)
607 {
608  // FIT scale-free power spectrum to data[m,n)
609  // fit 'log P(k) = log A + n_s * log k' via A, n_s
610  // for N = 2 perform non-weighted least-square fitting
611  // for N = 3 use data[2] as sigma, w = 1/sigma^2
612  std::vector<double> k, Pk, w; //< need double for GSL
613  k.reserve(n-m);
614  Pk.reserve(n-m);
615  if (N == 3){
616  w.reserve(n-m);
617  }
618  for(size_t i = m; i < n; i++){
619  k.push_back(log(data[0][i]));
620  Pk.push_back(log(data[1][i]));
621  if (N == 3)w.push_back(pow2(data[1][i]/data[2][i])); // weight = 1/sigma^2, approx log(1+x) = x for x rel. error
622  }
623  double cov00, cov01, cov11, sumsq;
624  int gsl_errno;
625  if (N == 3) gsl_errno = gsl_fit_wlinear(k.data(), 1, w.data(), 1, Pk.data(), 1, n-m, &A, &n_s, &cov00, &cov01, &cov11, &sumsq);
626  else gsl_errno = gsl_fit_linear(k.data(), 1, Pk.data(), 1, n-m, &A, &n_s, &cov00, &cov01, &cov11, &sumsq);
627  if (gsl_errno) throw std::runtime_error("GSL integration error: " + std::string(gsl_strerror(gsl_errno)));
628 
629  A = exp(A); // log A => A
630  BOOST_LOG_TRIVIAL(debug) << "\t[" << (N == 3 ? "weighted-" : "") << "fit A = " << A << ", err = " << 100*sqrt(cov00) << "%%"
631  << "n_s = " << n_s << ", err = " << 100*sqrt(cov11)/std::abs(n_s) << "%%, corr = " << 100*cov01/sqrt(cov00*cov11) << "%%]";
632 }
633 
634 template <typename T, size_t N>
635 double Extrap_Pk<T, N>::operator()(double k) const
636 {
637  if (k < k_min)
638  {
639  return A_low*lin_pow_spec(1, k, cosmo);
640  }
641  else if (k <= k_max) return Interp_obj::operator()(k);
642  else return A_up*pow(k, n_s);
643 }
644 
645 template <typename T, size_t N>
646 Extrap_Pk_Nl<T, N>::Extrap_Pk_Nl(const Data_Vec<T, N>& data, const Sim_Param &sim, T A_nl, T a_eff):
647  Extrap_Pk<T, N>(data, sim), A_nl(A_nl), a_eff(a_eff), k_split(this->k_max) {}
648 
649 template <typename T, size_t N>
650 double Extrap_Pk_Nl<T, N>::operator()(double k) const {
651  if (k < k_split) return Extrap_Pk<T, N>::operator()(k);
652  else return (1-A_nl)*lin_pow_spec(a_eff, k, this->cosmo) + A_nl*non_lin_pow_spec(a_eff, k, this->cosmo);
653 }
654 
655 template<class P>
656 static double get_gsl_error(const Cosmo_Param& cosmo, const P& P_k)
657 {
658  const FTYPE_t k_ref = 0.1;
659  double ratio = P_k(k_ref) / lin_pow_spec(1, k_ref, cosmo);
660  BOOST_LOG_TRIVIAL(debug) << "\tSet absolute error to " << GSL_EPSABS*ratio;
661  return GSL_EPSABS*ratio;
662 }
663 
664 template<class P>
665 void gen_corr_func_binned_gsl_qawf(const Sim_Param &sim, const P& P_k, Data_Vec<FTYPE_t, 2>& corr_func_binned)
666 {
667  BOOST_LOG_TRIVIAL(debug) << "Computing correlation function via GSL integration QAWF...";
668  const double gsp_epsabs = get_gsl_error(sim.cosmo, P_k);
669  Integr_obj_qawf xi_r(&xi_integrand_W<P>, 0, gsp_epsabs, GSL_LIMIT, GSL_N);
670  gen_corr_func_binned_gsl(sim, P_k, corr_func_binned, xi_r);
671 }
672 
673 void gen_corr_func_binned_gsl_qawf_lin(const Sim_Param &sim, FTYPE_t a, Data_Vec<FTYPE_t, 2>& corr_func_binned)
674 {
675  auto P_k = [&](FTYPE_t k){ return lin_pow_spec(a, k, sim.cosmo); };
676  gen_corr_func_binned_gsl_qawf(sim, P_k, corr_func_binned);
677 }
678 
679 void gen_corr_func_binned_gsl_qawf_nl(const Sim_Param &sim, FTYPE_t a, Data_Vec<FTYPE_t, 2>& corr_func_binned)
680 {
681  auto P_k = [&](FTYPE_t k){ return non_lin_pow_spec(a, k, sim.cosmo); };
682  gen_corr_func_binned_gsl_qawf(sim, P_k, corr_func_binned);
683 }
684 
685 template<class P>
686 void gen_sigma_binned_gsl_qawf(const Sim_Param &sim, const P& P_k, Data_Vec<FTYPE_t, 2>& sigma_binned)
687 {
688  BOOST_LOG_TRIVIAL(debug) << "Computing mass fluctuations via GSL integration QAWF...";
689  const double gsp_epsabs = get_gsl_error(sim.cosmo, P_k);
690  Integr_obj_qagiu sigma_r(&sigma_integrand_G<P>, 0, gsp_epsabs, GSL_LIMIT, GSL_N);
691  gen_sigma_func_binned_gsl(sim, P_k, sigma_binned, sigma_r);
692 }
693 
694 void gen_sigma_func_binned_gsl_qawf_lin(const Sim_Param &sim, FTYPE_t a, Data_Vec<FTYPE_t, 2>& sigma_binned)
695 {
696  auto P_k = [&](FTYPE_t k){ return lin_pow_spec(a, k, sim.cosmo); };
697  gen_sigma_binned_gsl_qawf(sim, P_k, sigma_binned);
698 }
699 
700 void gen_sigma_func_binned_gsl_qawf_nl(const Sim_Param &sim, FTYPE_t a, Data_Vec<FTYPE_t, 2>& sigma_binned)
701 {
702  auto P_k = [&](FTYPE_t k){ return non_lin_pow_spec(a, k, sim.cosmo); };
703  gen_sigma_binned_gsl_qawf(sim, P_k, sigma_binned);
704 }
705 
706 /**********************/
710 template void Interp_obj::init(const Data_Vec<FTYPE_t, 2>& data);
711 template void Interp_obj::init(const Data_Vec<FTYPE_t, 3>& data);
712 
713 template class Extrap_Pk<FTYPE_t, 2>;
714 template class Extrap_Pk<FTYPE_t, 3>;
715 template class Extrap_Pk_Nl<FTYPE_t, 2>;
716 template class Extrap_Pk_Nl<FTYPE_t, 3>;
717 
722 
ccl_cosmology * cosmo
Definition: params.hpp:32
void gen_sigma_func_binned_gsl(const Sim_Param &sim, const P &P_k, Data_Vec< double, 2 > &sigma_binned, T &sigma_r)
compute amplitude of density fluctuation and store results
Definition: core_power.cpp:382
void gen_corr_func_binned_gsl_qawf_lin(const Sim_Param &sim, double a, Data_Vec< double, 2 > &corr_func_binned)
compute linear correlation function and store results
Definition: core_power.cpp:673
const T k_split
Definition: core_power.h:150
Integr_obj_qagiu(double(*f)(double, void *), const double a, const double epsabs, const double epsrel, size_t limit)
Definition: core_power.cpp:122
double lin_pow_spec(double a, double k, const Cosmo_Param &cosmo)
Definition: core_power.cpp:474
double growth_factor(double a, const Cosmo_Param &cosmo)
Definition: core_power.cpp:414
const T A_nl
Definition: core_power.h:150
void norm_pwr(Cosmo_Param &cosmo)
< end of anonymous namespace (private definitions)
Definition: core_power.cpp:400
double h
Definition: params.hpp:36
handle cosmological functions like power spectrum, growth, etc.
double ccl_omega_x(ccl_cosmology *cosmo, double a, ccl_species_x_label label, int *status)
not_this_one end(...)
double D_norm
Definition: params.hpp:44
Integr_obj_qawf(double(*f)(double, void *), const double a, const double epsabs, size_t limit, size_t n)
Definition: core_power.cpp:185
double ccl_nonlin_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:1562
void gen_fce_r_binned_gsl(const double x_min, const double x_max, const double lin_bin, const P &P_k, Data_Vec< double, 2 > &fce_binned, T &fce_r)
compute given function in linear range and store results
Definition: core_power.cpp:335
: class storing simulation parameters
Definition: params.hpp:193
size_t size() const noexcept
double ccl_growth_factor(ccl_cosmology *cosmo, double a, int *status)
T hubble_param(T a, const Cosmo_Param &cosmo)
Definition: core_power.cpp:239
void fit_power_law(const Data_Vec< T, N > &data, const size_t m, const size_t n, double &A, double &n_s)
Definition: core_power.cpp:606
void gen_corr_func_binned_gsl_qawf(const Sim_Param &sim, const P &P_k, Data_Vec< double, 2 > &corr_func_binned)
compute correlation function and store results
Definition: core_power.cpp:665
size_t points_per_10_Mpc
Definition: params.hpp:85
double ccl_growth_rate(ccl_cosmology *cosmo, double a, int *status)
define container Data_Vec
double non_lin_pow_spec(double a, double k, const Cosmo_Param &cosmo)
Definition: core_power.cpp:486
constexpr double GSL_EPSABS
absolute error at z = 0, scales for higher redshifts
Definition: core_power.cpp:390
double xi_integrand_W(double k, void *params)
integrand for correlation function when weight-function &#39;sin(kr)&#39; is used in integration ...
Definition: core_power.cpp:274
double operator()(double k) const
Definition: core_power.cpp:650
basic integration object, wrapper for GSL integration functions
Definition: core_power.cpp:49
void fit_lin(const Data_Vec< T, N > &data, const size_t m, const size_t n, double &A)
Definition: core_power.cpp:560
double sigma_integrand_G(double k, void *params)
integrand for amplitude of mass fluctuaton when non-weighted integration is used
Definition: core_power.cpp:307
T pow2(T base)
Definition: precision.hpp:52
void resize(size_t n)
QAWO adaptive integration for oscillatory functions.
Definition: core_power.cpp:148
double operator()(double k) const
Definition: core_power.cpp:635
not_this_one begin(...)
void gen_sigma_func_binned_gsl_qawf_nl(const Sim_Param &sim, double a, Data_Vec< double, 2 > &sigma_binned)
compute non-linear amplitude of density fluctuation and store results
Definition: core_power.cpp:700
void update(double &t, const double t1, double y[])
Definition: core_power.cpp:227
double ln_growth_factor(double log_a, void *parameters)
Definition: core_power.cpp:254
constexpr size_t GSL_LIMIT
max. number of subintervals for adaptive integration
Definition: core_power.cpp:391
QAWF adaptive integration for Fourier integrals.
Definition: core_power.cpp:181
void init(const Data_Vec< T, N > &data)
Definition: core_power.cpp:496
double A_low
amplitude of linear power in lower range
Definition: core_power.h:134
declaration in params.hpp
Definition: core_power.h:19
double Omega_L() const
Definition: params.hpp:38
cosmological & CCL parameters
Definition: params.hpp:22
Cosmo_Param cosmo
Definition: params.hpp:206
general integrand with callable function and one parameter
Definition: core_power.cpp:32
double upper
Definition: params.hpp:163
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
Definition: grid.h:231
static double get_gsl_error(const Cosmo_Param &cosmo, const P &P_k)
Definition: core_power.cpp:656
ODE_Solver(int(*function)(double t, const double y[], double dydt[], void *params), size_t dim, void *params, const double hstart=1e-6, const double epsabs=1e-6, const double epsrel=0)
Definition: core_power.cpp:217
static CCL_BEGIN_DECLS double x[111][8]
: creates Extrapolate object (linear power spectrum) from data and store non-linear parameters call &#39;...
Definition: core_power.h:146
Out_Opt out_opt
Definition: params.hpp:204
size_t get_nearest(const T val, const std::vector< T > &vec)
Definition: core_power.cpp:260
Range x_corr
Definition: params.hpp:174
double Omega_lambda(double a, const Cosmo_Param &cosmo)
Definition: core_power.cpp:462
double ccl_linear_matter_power(ccl_cosmology *cosmo, double k, double a, int *status)
Definition: ccl_power.c:1506
various simulation parameters
void gen_sigma_func_binned_gsl_qawf_lin(const Sim_Param &sim, double a, Data_Vec< double, 2 > &sigma_binned)
compute linear amplitude of density fluctuation and store results
Definition: core_power.cpp:694
Integr_obj(double(*f)(double, void *), const double a, const double b, const double epsabs, const double epsrel, const size_t limit)
Definition: core_power.cpp:53
dictionary params
Definition: halomod_bm.py:27
Integr_obj_qag(double(*f)(double, void *), const double a, const double b, const double epsabs, const double epsrel, size_t limit, int key)
Definition: core_power.cpp:90
void gen_corr_func_binned_gsl(const Sim_Param &sim, const P &P_k, Data_Vec< double, 2 > &corr_func_binned, T &xi_r)
compute correlation function and store results
Definition: core_power.cpp:362
double lower
Definition: params.hpp:163
constexpr double PI
Definition: precision.hpp:37
void gen_corr_func_binned_gsl_qawf_nl(const Sim_Param &sim, double a, Data_Vec< double, 2 > &corr_func_binned)
compute non-linear correlation function and store results
Definition: core_power.cpp:679
double k2_G
Definition: params.hpp:35
T k_max
interpolation range
Definition: core_power.h:137
: linear interpolation of data [k, P(k)] within &#39;useful&#39; range fit to primordial P_i(k) below the &#39;us...
Definition: core_power.h:122
const Cosmo_Param & cosmo
Definition: core_power.h:135
double n_s
scale-free power spectrum in upper range
Definition: core_power.h:136
double operator()(double x) const
Definition: core_power.cpp:520
Integr_obj_qawo(double(*f)(double, void *), const double a, const double b, const double epsabs, const double epsrel, size_t limit, size_t n)
Definition: core_power.cpp:152
constexpr size_t GSL_N
max. number of bisections of integration interval (QAWO / QAWF)
Definition: core_power.cpp:392
double ccl_sigma8(ccl_cosmology *cosmo, int *status)
Definition: ccl_power.c:1777
bool truncated_pk
Definition: params.hpp:41
double Omega_m
Definition: params.hpp:36
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39
static int m[2]
Definition: ccl_emu17.c:25
double growth_rate(double a, const Cosmo_Param &cosmo)
Definition: core_power.cpp:429
Extrap_Pk_Nl(const Data_Vec< T, N > &data, const Sim_Param &sim, T A_nl, T a_eff)
Definition: core_power.cpp:646
QAGI adaptive integration on infinite intervals.
Definition: core_power.cpp:118
double A_up
Definition: core_power.h:136
Other_par other_par
Definition: params.hpp:209
double xi_integrand_G(double k, void *params)
integrand for correlation function when non-weighted integration is used
Definition: core_power.cpp:290
: Explicit embedded Runge-Kutta Prince-Dormand (8, 9) method.
Definition: core_power.cpp:214
double growth_factor_integrand(double a, void *params)
Definition: core_power.cpp:244
const T a_eff
Definition: core_power.h:150
void gen_sigma_binned_gsl_qawf(const Sim_Param &sim, const P &P_k, Data_Vec< double, 2 > &sigma_binned)
compute amplitude of density fluctuation and store results
Definition: core_power.cpp:686
static double w[2][28][111]
Definition: ccl_emu17.c:33
Extrap_Pk(const Data_Vec< T, N > &data, const Sim_Param &sim)
Definition: core_power.cpp:548
static double truncation_fce(double k, double k2_G)
Definition: core_power.cpp:554
char status_message[500]
Definition: ccl_core.h:136
double norm_growth_factor(const Cosmo_Param &cosmo)
when computing growth factor outside CCL range we need to normalize the growth factor; ...
Definition: core_power.cpp:408
double growth_change(double a, const Cosmo_Param &cosmo)
Definition: core_power.cpp:447