CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
GSLwrapper.h
Go to the documentation of this file.
1 /*******************************************************************
2  * Copyright (C) 2010 by Federico Marulli *
3  * federico.marulli3@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 #ifndef __GSLwrap__
36 #define __GSLwrap__
37 
38 #include "Kernel.h"
39 
40 namespace cbl {
41 
48  namespace wrapper {
49 
56  namespace gsl {
57 
58  struct STR_generic_func_GSL
59  {
61  double xx0;
62 
64 
65  FunctionDoubleVectorRef fmin_return;
66  std::vector<double> parameters_return;
67  };
68 
83  void check_GSL_fail (const int status, const bool exit, const std::string CBLfunction, const std::string GSLroutine);
84 
91  double generic_function (const double xx, void *params);
92 
99  double generic_roots (double xx, void *params);
100 
107  double generic_minimizer (const gsl_vector * xx, void * params);
108 
115  double generic_minimizer_return (const gsl_vector * xx, void * params);
116 
145  double GSL_derivative (gsl_function Func, const double xx, const double hh, const double prec=1.e-2);
146 
166  double GSL_integrate_romberg (gsl_function Func, const double a, const double b, const int npoints, const double eps_rel=1.e-4, const double eps_abs=1.e-12);
167 
184  double GSL_integrate_cquad (gsl_function func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int nevals=100);
185 
197  double GSL_integrate_qag (gsl_function Func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000, const int rule=6);
198 
209  double GSL_integrate_qags (gsl_function Func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000);
210 
225  double GSL_integrate_qaws (gsl_function Func, const double a, const double b, const double alpha=0, const double beta=0, const int mu=1, const int nu =0, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000);
226 
236  double GSL_integrate_qagiu (gsl_function Func, const double a, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000);
237 
270  double GSL_derivative (FunctionDoubleDouble func, const double xx, const double hh, const double prec=1.e-2);
271 
291  double GSL_integrate_romberg (FunctionDoubleDouble Func, const double a, const double b, const int npoints, const double eps_rel=1.e-4, const double eps_abs=1.e-12);
292 
309  double GSL_integrate_cquad (FunctionDoubleDouble func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int nevals=100);
310 
327  double GSL_integrate_qag (FunctionDoubleDouble func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000, const int rule=6);
328 
344  double GSL_integrate_qags (FunctionDoubleDouble func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000);
345 
361  double GSL_integrate_qagiu (FunctionDoubleDouble func, const double a, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000);
362 
377  double GSL_integrate_qaws (FunctionDoubleDouble func, const double a, const double b, const double alpha=0, const double beta=0, const int mu=1, const int nu =0, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000);
378 
397  double GSL_integrate_cquad (FunctionDoubleDoublePtrVectorRef func, std::shared_ptr<void> pp, std::vector<double> par, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int nevals=100);
398 
418  double GSL_integrate_qag (FunctionDoubleDoublePtrVectorRef func, std::shared_ptr<void> pp, std::vector<double> par, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000, const int rule=6);
419 
438  double GSL_integrate_qags (FunctionDoubleDoublePtrVectorRef func, std::shared_ptr<void> pp, std::vector<double> par, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000);
439 
457  double GSL_integrate_qagiu (FunctionDoubleDoublePtrVectorRef func, std::shared_ptr<void> pp, std::vector<double> par, const double a, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000);
458 
475  double GSL_integrate_qaws (FunctionDoubleDoublePtrVectorRef func, std::shared_ptr<void> pp, std::vector<double> par, const double a, const double b, const double alpha=0, const double beta=0, const int mu=1, const int nu =0, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000);
476 
486  double GSL_root_brent (gsl_function Func, const double low_guess, const double up_guess, const double rel_err=1.e-3, const double abs_err=0);
487 
498  double GSL_root_brent (FunctionDoubleDouble func, double xx0, const double low_guess, const double up_guess, const double rel_err=1.e-3, const double abs_err=0);
499 
512  std::vector<double> GSL_minimize_nD (FunctionDoubleVector func, const std::vector<double> start, const std::vector<std::vector<double>> ranges, const unsigned int max_iter=1000, const double tol=1.e-6, const double epsilon=0.1);
513 
526  std::vector<double> GSL_minimize_nD (FunctionDoubleVectorRef func, const std::vector<double> start, const std::vector<std::vector<double>> ranges, const unsigned int max_iter=1000, const double tol=1.e-6, const double epsilon=0.1);
527 
540  double GSL_minimize_1D (FunctionDoubleDouble func, const double start, double min=par::defaultDouble, double max=-par::defaultDouble, const int max_iter=1000, const bool verbose=false);
541 
552  double GSL_polynomial_eval (const double x, const std::shared_ptr<void> fixed_parameters, const std::vector<double> coeff);
553 
562  void GSL_polynomial_root (const std::vector<double> coeff, std::vector<std::vector<double>> &root);
563 
564  }
565  }
566 }
567 
568 #endif
Useful generic functions.
static const double defaultDouble
default double value
Definition: Constants.h:348
static const double alpha
: the fine-structure constant
Definition: Constants.h:233
double GSL_minimize_1D(FunctionDoubleDouble func, const double start, double min=par::defaultDouble, double max=-par::defaultDouble, const int max_iter=1000, const bool verbose=false)
minimize the provided function using GSL procedure
Definition: GSLwrapper.cpp:658
double generic_function(const double xx, void *params)
function used to integrate interpolated function
Definition: GSLwrapper.cpp:60
double generic_roots(double xx, void *params)
generic roots
Definition: GSLwrapper.cpp:70
std::vector< double > GSL_minimize_nD(FunctionDoubleVector func, const std::vector< double > start, const std::vector< std::vector< double >> ranges, const unsigned int max_iter=1000, const double tol=1.e-6, const double epsilon=0.1)
minimize the provided function using GSL procedure
Definition: GSLwrapper.cpp:497
double generic_minimizer(const gsl_vector *xx, void *params)
generic roots
Definition: GSLwrapper.cpp:80
double GSL_derivative(gsl_function Func, const double xx, const double hh, const double prec=1.e-2)
the derivative of a function
Definition: GSLwrapper.cpp:114
double GSL_integrate_qagiu(gsl_function Func, const double a, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000)
integral, computed using the GSL qagiu method
Definition: GSLwrapper.cpp:220
void GSL_polynomial_root(const std::vector< double > coeff, std::vector< std::vector< double >> &root)
find polynomial roots
Definition: GSLwrapper.cpp:725
double GSL_integrate_qags(gsl_function Func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000)
integral, computed using the GSL qags method
Definition: GSLwrapper.cpp:200
double GSL_integrate_romberg(gsl_function Func, const double a, const double b, const int npoints, const double eps_rel=1.e-4, const double eps_abs=1.e-12)
integral, using the gsl romberg method
Definition: GSLwrapper.cpp:130
double GSL_integrate_cquad(gsl_function func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int nevals=100)
integral, using the gsl cquad method
Definition: GSLwrapper.cpp:159
void check_GSL_fail(const int status, const bool exit, const std::string CBLfunction, const std::string GSLroutine)
Function used to check output of the wrapped GSL routines.
Definition: GSLwrapper.cpp:45
double generic_minimizer_return(const gsl_vector *xx, void *params)
generic roots
Definition: GSLwrapper.cpp:96
double GSL_integrate_qaws(gsl_function Func, const double a, const double b, const double alpha=0, const double beta=0, const int mu=1, const int nu=0, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000)
integral, computed using the GSL qaws method
Definition: GSLwrapper.cpp:240
double GSL_polynomial_eval(const double x, const std::shared_ptr< void > fixed_parameters, const std::vector< double > coeff)
evaluate a polynomial
Definition: GSLwrapper.cpp:715
double GSL_root_brent(gsl_function Func, const double low_guess, const double up_guess, const double rel_err=1.e-3, const double abs_err=0)
function to find roots using GSL qag method
Definition: GSLwrapper.cpp:430
double GSL_integrate_qag(gsl_function Func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000, const int rule=6)
integral, computed using the GSL qag method
Definition: GSLwrapper.cpp:180
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
std::function< double(std::vector< double >)> FunctionDoubleVector
typedef of a function returning a double with a vector in input
Definition: Kernel.h:690
std::function< double(double)> FunctionDoubleDouble
typedef of a function returning a double with a double in input
Definition: Kernel.h:687
std::function< double(double, std::shared_ptr< void >, std::vector< double > &)> FunctionDoubleDoublePtrVectorRef
typedef of a function returning a double with a double, a pointer and a vector reference in input
Definition: Kernel.h:696
std::function< double(std::vector< double > &)> FunctionDoubleVectorRef
typedef of a function returning a double with a vector reference in input
Definition: Kernel.h:693