CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
FFTlog.cpp
Go to the documentation of this file.
1 /*******************************************************************
2  * Copyright (C) 2016 by Alfonso Veropalumbo *
3  * alfonso.veropalumbo@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful,*
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  *******************************************************************/
20 
35 #include "FFTlog.h"
36 
37 using namespace std;
38 
39 
40 // ============================================================================
41 
42 
43 vector<double> cbl::wrapper::fftlog::transform_FFTlog (const std::vector<double> yy, const int dir, const std::vector<double> xx, const std::vector<double> fx, const double mu, const double q, const double kr, const int kropt)
44 {
45  vector<double> _yy, _fy;
46  cbl::wrapper::fftlog::transform_FFTlog(_yy, _fy, dir, xx, fx, mu, q, kr, kropt);
47 
48  cbl::glob::FuncGrid interp(_yy, _fy, "Spline");
49 
50  vector<double> interpolated_values = interp.eval_func(yy);
51 
52  interp.free();
53 
54  return interpolated_values;
55 }
56 
57 
58 // ============================================================================
59 
60 
61 void cbl::wrapper::fftlog::transform_FFTlog (std::vector<double> &yy, std::vector<double> &fy, const int dir, const std::vector<double> xx, const std::vector<double> fx, const double mu, const double q, const double kr, const int kropt)
62 {
63  const int NMAX = 4096;
64 
65  double fact = 1./(2*cbl::par::pi*cbl::par::pi)*sqrt(cbl::par::pi/2);
66 
67  int i_ok;
68  double wsave[2*NMAX+3*(NMAX/2)+19];
69 
70  int n = fx.size();
71  double _mu = mu+0.5;
72  double _q = q;
73  double _kr = kr;
74  int _kropt = kropt;
75  int _dir = dir;
76 
77 
78  double xmin = log10(cbl::Min(xx)), xmax = log10(cbl::Max(xx));
79  double dlogx = (xmax-xmin)/(n-1);
80  double dlnx = dlogx*log(10.);
81 
82  double ci = double(n+1)/2;
83 
84  double logxmedian = (xmax+xmin)/2;
85 
86  double ap[NMAX];
87  for (int i=0; i<n; i++)
88  ap[i] = fx[i]*xx[i];
89 
90  wrapper::fftlog::fhti_(&n, &_mu, &_q, &dlnx, &_kr, &_kropt, wsave, &i_ok);
91 
92  double logymedian = log10(_kr)-logxmedian;
93 
94  double rk = pow(10, logxmedian - logymedian);
95 
96  if (i_ok==0)
97  ErrorCBL("problems in the FFTlog computation!", "transform_FFTlog", "FFTlog.cpp");
98 
99  wrapper::fftlog::fftl_(&n, ap, &rk, &_dir, wsave);
100 
101  yy.erase(yy.begin(), yy.end()); fy.erase(fy.begin(), fy.end());
102 
103  for (int i=0; i<n; i++) {
104  double _y = pow(10., logymedian + ( i+1 - ci ) * dlogx );
105  yy.push_back(_y);
106  fy.push_back(fact*ap[i]/_y);
107  }
108 }
Wrapper for fftlog wripper.
The class FuncGrid.
Definition: FuncGrid.h:55
void free()
free the GSL objects
Definition: FuncGrid.cpp:110
std::vector< double > eval_func(const std::vector< double > xx) const
evaluate the function at the xx points
Definition: FuncGrid.cpp:153
static const double pi
: the ratio of a circle's circumference to its diameter
Definition: Constants.h:199
std::vector< double > transform_FFTlog(const std::vector< double > yy, const int dir, const std::vector< double > xx, const std::vector< double > fx, const double mu=0, const double q=0, const double kr=1, const int kropt=0)
wrapper of the FFTlog to compute the discrete Fourier sine or cosine transform of a logarithmically...
Definition: FFTlog.cpp:43
void fftl_(int *_n, double *_a, double *_rk, int *_dir, double *_wsave)
wrapper of the fftl subroutine contained in External/fftlog-f90-master/fftlog.f This subroutine compu...
void fhti_(int *_n, double *_mu, double *_q, double *_dlnr, double *_kr, int *_kropt, double *_wsave, int *_ok)
wrapper of the fhti subroutine contained in External/fftlog-f90-master/fftlog.f This is an initializa...
T Min(const std::vector< T > vect)
minimum element of a std::vector
Definition: Kernel.h:1324
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
Definition: Kernel.h:780
T Max(const std::vector< T > vect)
maximum element of a std::vector
Definition: Kernel.h:1336