CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
cbl::glob::FuncGrid Class Reference

The class FuncGrid. More...

#include "Headers/FuncGrid_Bspline.h"

Public Member Functions

Constructors/destructors
 FuncGrid ()=default
 default constructor
 
 FuncGrid (const std::vector< double > x, const std::vector< double > y, const std::string interpType, const BinType bin_type=BinType::_linear_)
 constructor More...
 
 ~FuncGrid ()=default
 default destructor
 
Functions to get the private members of the class
std::vector< double > x () const
 get the private member FuncGrid::m_x More...
 
double x (const int i) const
 get the i-th element of the private member FuncGrid::m_x More...
 
std::vector< double > y () const
 get the private member FuncGrid::m_y More...
 
double y (const int i) const
 get the i-th element of the private member FuncGrid::m_y More...
 
double size () const
 get the private member FuncGrid::m_size More...
 
double xmin () const
 get the private member FuncGrid::m_xmin More...
 
double xmax () const
 get the private member FuncGrid::m_xmax More...
 
Functions of generic usage
void free ()
 free the GSL objects
 
double operator() (const double xx) const
 overloading of the () operator More...
 
std::vector< double > eval_func (const std::vector< double > xx) const
 evaluate the function at the xx points More...
 
double D1v (const double xx) const
 compute the first derivative at xx More...
 
double D2v (const double xx) const
 compute the second derivative at xx More...
 
double integrate_qag (const double a, const double b, const double rel_err=1.e-2, const double abs_err=1.e-6, const int limit_size=1000, const int rule=6)
 compute the definite integral with GSL qag method More...
 
double integrate_cquad (const double a, const double b, const double rel_err=1.e-2, const double abs_err=1.e-6, const int nevals=100)
 compute the definite integral with GSL cquad method More...
 
double integrate_qaws (const double a, const double b, const double alpha=0, const double beta=0, const int mu=0, const int nu=0, const double rel_err=1.e-2, const double abs_err=1.e-6, const int limit_size=1000)
 compute the definite integral with GSL qaws method More...
 
double root (const double x_low, const double x_up, const double fx0=0, const double rel_err=1.e-2, const double abs_err=1.e-6)
 find roots with GSL brent method More...
 
double root_D1v (const double x_low, const double x_up, const double fx0=0, const double rel_err=1.e-2, const double abs_err=1.e-6)
 find roots with GSL brent method for the first derivative More...
 
double root_D2v (const double x_low, const double x_up, const double fx0=0, const double rel_err=1.e-2, const double abs_err=1.e-6)
 find roots with GSL brent method for the second derivative More...
 

Private Attributes

std::vector< double > m_x
 x values
 
std::vector< double > m_y
 y values
 
size_t m_size
 size of the x,y vectors, i.e. the grid size
 
std::string m_interpType
 method used to interpolate
 
std::shared_ptr< gsl_spline > m_spline
 GSL object used to interpolate.
 
const gsl_interp_type * m_type
 GSL object used to set the interpolation type.
 
std::shared_ptr< gsl_interp_accel > m_acc
 GSL accelerator object.
 
double m_xmin
 minimum x value
 
double m_xmax
 maximum x value
 
BinType m_binType
 bin type
 

Detailed Description

The class FuncGrid.

The class FuncGrid_Bspline.

This class is used to handle functions stored on a grid. Specifically, it contains member functions to interpolate, find minima, compute derivatives and integrals.

This class is used to handle functions interpolated using a basis spline (http://mathworld.wolfram.com/B-Spline.html) In particular this class wraps the GSL Bspline implementation. For further details, please refer to https://www.gnu.org/software/gsl/doc/html/bspline.html

Definition at line 54 of file FuncGrid.h.

Constructor & Destructor Documentation

◆ FuncGrid()

cbl::glob::FuncGrid::FuncGrid ( const std::vector< double >  x,
const std::vector< double >  y,
const std::string  interpType,
const BinType  bin_type = BinType::_linear_ 
)

constructor

Parameters
xvector containing the x values
yvector containing the y values
interpTypeinterpolation method
bin_typethe binning type

Definition at line 45 of file FuncGrid.cpp.

Member Function Documentation

◆ D1v()

double cbl::glob::FuncGrid::D1v ( const double  xx) const

compute the first derivative at xx

Parameters
xxthe value at which the derivative is computed
Returns
the first derivative

Definition at line 167 of file FuncGrid.cpp.

◆ D2v()

double cbl::glob::FuncGrid::D2v ( const double  xx) const

compute the second derivative at xx

Parameters
xxthe value at which the derivative is computed
Returns
the second derivative

Definition at line 178 of file FuncGrid.cpp.

◆ eval_func()

std::vector< double > cbl::glob::FuncGrid::eval_func ( const std::vector< double >  xx) const

evaluate the function at the xx points

Parameters
xxthe values at which the function will be evaluated
Returns
the function evaluated at the xx points

Definition at line 153 of file FuncGrid.cpp.

◆ integrate_cquad()

double cbl::glob::FuncGrid::integrate_cquad ( const double  a,
const double  b,
const double  rel_err = 1.e-2,
const double  abs_err = 1.e-6,
const int  nevals = 100 
)

compute the definite integral with GSL cquad method

Parameters
athe lower limit of the integral
bthe upper limit of the integral
rel_errthe relative error
abs_errthe absolute error
nevalsthe number of intervals
Returns
the definite integral of the function

Definition at line 198 of file FuncGrid.cpp.

◆ integrate_qag()

double cbl::glob::FuncGrid::integrate_qag ( const double  a,
const double  b,
const double  rel_err = 1.e-2,
const double  abs_err = 1.e-6,
const int  limit_size = 1000,
const int  rule = 6 
)

compute the definite integral with GSL qag method

Parameters
athe lower limit of the integral
bthe upper limit of the integral
rel_errthe relative error
abs_errthe absolute error
limit_sizethe maximum size of workspace
rulethe rule of integration
Returns
the definite integral of the function

Definition at line 187 of file FuncGrid.cpp.

◆ integrate_qaws()

double cbl::glob::FuncGrid::integrate_qaws ( const double  a,
const double  b,
const double  alpha = 0,
const double  beta = 0,
const int  mu = 0,
const int  nu = 0,
const double  rel_err = 1.e-2,
const double  abs_err = 1.e-6,
const int  limit_size = 1000 
)

compute the definite integral with GSL qaws method

Parameters
athe lower limit of the integral
bthe upper limit of the integral
alphaα
betaβ
muμ
nuν
rel_errthe relative error
abs_errthe absolute error
limit_sizethe maximum size of workspace
Returns
the definite integral of the function

Definition at line 209 of file FuncGrid.cpp.

◆ operator()()

double cbl::glob::FuncGrid::operator() ( const double  xx) const

overloading of the () operator

Parameters
xxthe value at which the function will be evaluated
Returns
the function evaluated at xx

Definition at line 120 of file FuncGrid.cpp.

◆ root()

double cbl::glob::FuncGrid::root ( const double  x_low,
const double  x_up,
const double  fx0 = 0,
const double  rel_err = 1.e-2,
const double  abs_err = 1.e-6 
)

find roots with GSL brent method

Parameters
x_lowthe lower limit
x_upthe upper limit
fx0fx0
rel_errthe relative error
abs_errthe absolute error
Returns
the root

Definition at line 220 of file FuncGrid.cpp.

◆ root_D1v()

double cbl::glob::FuncGrid::root_D1v ( const double  x_low,
const double  x_up,
const double  fx0 = 0,
const double  rel_err = 1.e-2,
const double  abs_err = 1.e-6 
)

find roots with GSL brent method for the first derivative

Parameters
x_lowthe lower limit
x_upthe upper limit
fx0fx0
rel_errthe relative error
abs_errthe absolute error
Returns
the root

Definition at line 231 of file FuncGrid.cpp.

◆ root_D2v()

double cbl::glob::FuncGrid::root_D2v ( const double  x_low,
const double  x_up,
const double  fx0 = 0,
const double  rel_err = 1.e-2,
const double  abs_err = 1.e-6 
)

find roots with GSL brent method for the second derivative

Parameters
x_lowthe lower limit
x_upthe upper limit
fx0fx0
rel_errthe relative error
abs_errthe absolute error
Returns
the root

Definition at line 242 of file FuncGrid.cpp.

◆ size()

double cbl::glob::FuncGrid::size ( ) const
inline

get the private member FuncGrid::m_size

Returns
the size of the x,y vectors, i.e. the grid size

Definition at line 159 of file FuncGrid.h.

◆ x() [1/2]

std::vector<double> cbl::glob::FuncGrid::x ( ) const
inline

get the private member FuncGrid::m_x

Returns
the vector containing the x values

Definition at line 131 of file FuncGrid.h.

◆ x() [2/2]

double cbl::glob::FuncGrid::x ( const int  i) const
inline

get the i-th element of the private member FuncGrid::m_x

Parameters
ithe i-th index
Returns
the i-th value of x

Definition at line 139 of file FuncGrid.h.

◆ xmax()

double cbl::glob::FuncGrid::xmax ( ) const
inline

get the private member FuncGrid::m_xmax

Returns
maximum x value

Definition at line 171 of file FuncGrid.h.

◆ xmin()

double cbl::glob::FuncGrid::xmin ( ) const
inline

get the private member FuncGrid::m_xmin

Returns
minimum x value

Definition at line 165 of file FuncGrid.h.

◆ y() [1/2]

std::vector<double> cbl::glob::FuncGrid::y ( ) const
inline

get the private member FuncGrid::m_y

Returns
the vector containing the y values

Definition at line 145 of file FuncGrid.h.

◆ y() [2/2]

double cbl::glob::FuncGrid::y ( const int  i) const
inline

get the i-th element of the private member FuncGrid::m_y

Parameters
ithe i-th index
Returns
the i-th value of y

Definition at line 153 of file FuncGrid.h.


The documentation for this class was generated from the following files: