GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GIntegrals Class Reference

Integration class for set of functions. More...

#include <GIntegrals.hpp>

Inheritance diagram for GIntegrals:
GBase

Public Member Functions

 GIntegrals (void)
 Void constructor. More...
 
 GIntegrals (GFunctions *kernels)
 Vector function kernels constructor. More...
 
 GIntegrals (const GIntegrals &integral)
 Copy constructor. More...
 
virtual ~GIntegrals (void)
 Destructor. More...
 
GIntegralsoperator= (const GIntegrals &integral)
 Assignment operator. More...
 
void clear (void)
 Clear integral. More...
 
GIntegralsclone (void) const
 Clone integral. More...
 
std::string classname (void) const
 Return class name. More...
 
void max_iter (const int &iter)
 Set maximum number of iterations. More...
 
const int & max_iter (void) const
 Return maximum number of iterations. More...
 
void fixed_iter (const int &iter)
 Set fixed number of iterations. More...
 
const int & fixed_iter (void) const
 Return fixed number of iterations. More...
 
void eps (const double &eps)
 Set relative precision. More...
 
const double & eps (void) const
 Get relative precision. More...
 
void silent (const bool &silent)
 Set silence flag. More...
 
const bool & silent (void) const
 Get silence flag. More...
 
const int & iter (void) const
 Return number of iterations. More...
 
const int & calls (void) const
 Get number of function calls. More...
 
const bool & is_valid (void) const
 Signal if integration result is valid. More...
 
const std::string & message (void) const
 Return integration status message. More...
 
void kernels (GFunctions *kernels)
 Set function kernels. More...
 
const GFunctionskernels (void) const
 Get function kernels. More...
 
GVector romberg (std::vector< double > bounds, const int &order=5)
 Perform Romberg integration. More...
 
GVector romberg (const double &a, const double &b, const int &order=5)
 Perform Romberg integration. More...
 
GVector trapzd (const double &a, const double &b, const int &n, const GVector &previous_result)
 Perform Trapezoidal integration for a set of functions. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print integral information. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GIntegrals &integral)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
GVector polint (const double *xa, const GVector *ya, const int &order, const double &x, GVector *dy)
 Perform Polynomial interpolation. More...
 

Protected Attributes

GFunctionsm_kernels
 Pointer to function kernels. More...
 
double m_eps
 Requested relative integration precision. More...
 
int m_max_iter
 Maximum number of iterations. More...
 
int m_fix_iter
 Fixed number of iterations. More...
 
bool m_silent
 Suppress integration warnings in console. More...
 
int m_iter
 Number of iterations used. More...
 
int m_calls
 Number of function calls used. More...
 
bool m_isvalid
 Integration result valid (true=yes) More...
 
bool m_has_abserr
 Has absolute integration errors. More...
 
bool m_has_relerr
 Has relative integration errors. More...
 
GVector m_abserr
 Absolute integration errors. More...
 
GVector m_relerr
 Absolute integration errors. More...
 
std::string m_message
 Status message (if result is invalid) More...
 

Detailed Description

Integration class for set of functions.

This class allows to perform integration of a set of functions. The integrand is implemented by a derived class of GFunctions.

Definition at line 47 of file GIntegrals.hpp.

Constructor & Destructor Documentation

GIntegrals::GIntegrals ( void  )
explicit

Void constructor.

Definition at line 62 of file GIntegrals.cpp.

References init_members().

Referenced by clone().

GIntegrals::GIntegrals ( GFunctions kernels)
explicit

Vector function kernels constructor.

Parameters
[in]kernelsPointer to function kernels.

The vector function kernels constructor assigns the vector function kernels pointer in constructing the object.

Definition at line 80 of file GIntegrals.cpp.

References init_members(), kernels(), and m_kernels.

GIntegrals::GIntegrals ( const GIntegrals integrals)

Copy constructor.

Parameters
[in]integralsIntegrals.

Definition at line 98 of file GIntegrals.cpp.

References copy_members(), and init_members().

GIntegrals::~GIntegrals ( void  )
virtual

Destructor.

Definition at line 114 of file GIntegrals.cpp.

References free_members().

Member Function Documentation

const int & GIntegrals::calls ( void  ) const
inline

Get number of function calls.

Returns
Number of function calls.

Definition at line 229 of file GIntegrals.hpp.

References m_calls.

Referenced by print(), and romberg().

std::string GIntegrals::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GIntegrals").

Implements GBase.

Definition at line 125 of file GIntegrals.hpp.

void GIntegrals::clear ( void  )
virtual

Clear integral.

Implements GBase.

Definition at line 166 of file GIntegrals.cpp.

References free_members(), and init_members().

GIntegrals * GIntegrals::clone ( void  ) const
virtual

Clone integral.

Returns
Pointer to deep copy of integrals.

Implements GBase.

Definition at line 184 of file GIntegrals.cpp.

References GIntegrals().

void GIntegrals::copy_members ( const GIntegrals integral)
protected

Copy class members.

Parameters
[in]integralIntegral.

Definition at line 670 of file GIntegrals.cpp.

References m_abserr, m_calls, m_eps, m_fix_iter, m_has_abserr, m_has_relerr, m_isvalid, m_iter, m_kernels, m_max_iter, m_message, m_relerr, and m_silent.

Referenced by GIntegrals(), and operator=().

void GIntegrals::eps ( const double &  eps)
inline

Set relative precision.

Parameters
[in]epsRelative precision.

Definition at line 204 of file GIntegrals.hpp.

References eps(), and m_eps.

const double & GIntegrals::eps ( void  ) const
inline

Get relative precision.

Returns
Relative precision.

Definition at line 217 of file GIntegrals.hpp.

References m_eps.

Referenced by eps(), and print().

void GIntegrals::fixed_iter ( const int &  iter)
inline

Set fixed number of iterations.

Parameters
[in]iterFixed number of iterations.

If the fixed number of iterations is set, the integration algorithm will always performed the given number of iterations, irrespectively of the precision that is reached. This feature is relevant for computing numerical derivates from numerically integrated functions.

Definition at line 179 of file GIntegrals.hpp.

References iter(), and m_fix_iter.

Referenced by GResponse::convolve(), cta_psf_radial_kerns_delta::eval(), com_radial_kerns_rho::eval(), com_elliptical_kerns_rho::eval(), GCOMResponse::irf_elliptical(), GCOMResponse::irf_radial(), and GCTAResponseCube::psf_radial().

const int & GIntegrals::fixed_iter ( void  ) const
inline

Return fixed number of iterations.

Returns
Fixed number of iterations.

Definition at line 192 of file GIntegrals.hpp.

References m_fix_iter.

Referenced by print().

void GIntegrals::free_members ( void  )
protected

Delete class members.

Definition at line 697 of file GIntegrals.cpp.

Referenced by clear(), operator=(), and ~GIntegrals().

void GIntegrals::init_members ( void  )
protected

Initialise class members.

Definition at line 641 of file GIntegrals.cpp.

References GVector::clear(), m_abserr, m_calls, m_eps, m_fix_iter, m_has_abserr, m_has_relerr, m_isvalid, m_iter, m_kernels, m_max_iter, m_message, m_relerr, and m_silent.

Referenced by clear(), GIntegrals(), and operator=().

const bool & GIntegrals::is_valid ( void  ) const
inline

Signal if integration result is valid.

Returns
True is integration result is valid.

Definition at line 293 of file GIntegrals.hpp.

References m_isvalid.

Referenced by print().

const int & GIntegrals::iter ( void  ) const
inline

Return number of iterations.

Returns
Number of iterations.

Definition at line 137 of file GIntegrals.hpp.

References m_iter.

Referenced by fixed_iter(), max_iter(), and print().

void GIntegrals::kernels ( GFunctions kernels)
inline

Set function kernels.

Parameters
[in]kernelsFunction kernels.

Sets the function kernels for which the integral should be determined.

Definition at line 268 of file GIntegrals.hpp.

References kernels(), and m_kernels.

const GFunctions * GIntegrals::kernels ( void  ) const
inline

Get function kernels.

Returns
Function kernels.

Definition at line 281 of file GIntegrals.hpp.

References m_kernels.

Referenced by GIntegrals(), and kernels().

void GIntegrals::max_iter ( const int &  iter)
inline

Set maximum number of iterations.

Parameters
[in]iterMaximum number of iterations.

Definition at line 149 of file GIntegrals.hpp.

References iter(), and m_max_iter.

const int & GIntegrals::max_iter ( void  ) const
inline

Return maximum number of iterations.

Returns
Maximum number of iterations.

Definition at line 162 of file GIntegrals.hpp.

References m_max_iter.

Referenced by print(), and romberg().

const std::string & GIntegrals::message ( void  ) const
inline

Return integration status message.

Returns
Integration status message.

Definition at line 305 of file GIntegrals.hpp.

References m_message.

Referenced by print().

GIntegrals & GIntegrals::operator= ( const GIntegrals integrals)

Assignment operator.

Parameters
[in]integralsIntegrals.
Returns
Integrals.

Definition at line 136 of file GIntegrals.cpp.

References copy_members(), free_members(), and init_members().

GVector GIntegrals::polint ( const double *  xa,
const GVector ya,
const int &  order,
const double &  x,
GVector dy 
)
protected

Perform Polynomial interpolation.

Parameters
[in]xaPointer to array of X values.
[in]yaPointer to GVector of Y values.
[in]orderNumber of elements in arrays.
[in]xX value for which interpolations should be performed.
[out]dyPointer to vector of error estimates for interpolated values.
Returns
Vector of interpolated values.

Given arrays xa[1,..,n] and ya[1,..,n], and given a value x, this method returns a value y, and an error estimate dy. If P(x) is the polynomial of degree n-1, then the returned value y=P(x).

Definition at line 718 of file GIntegrals.cpp.

References abs(), G_POLINT, m_isvalid, m_message, m_silent, GVector::size(), gammalib::str(), and gammalib::warning().

Referenced by romberg().

std::string GIntegrals::print ( const GChatter chatter = NORMAL) const
virtual

Print integral information.

Parameters
[in]chatterChattiness.
Returns
String containing integral information.

Implements GBase.

Definition at line 572 of file GIntegrals.cpp.

References calls(), eps(), fixed_iter(), is_valid(), iter(), m_abserr, m_fix_iter, m_has_abserr, m_has_relerr, m_relerr, max_iter(), message(), gammalib::parformat(), GVector::print(), SILENT, silent(), and gammalib::str().

Referenced by romberg().

GVector GIntegrals::romberg ( std::vector< double >  bounds,
const int &  order = 5 
)

Perform Romberg integration.

Parameters
[in]boundsIntegration boundaries.
[in]orderIntegration order (default: 5)
Returns
Vector of integration results.

Returns the integral of the integrand, computed over a number of intervals [a0,a1], [a1,a2], ... that are given as an unordered vector by the bounds argument.

Integration is performed by Romberg's method of order 2*order, where

order=1 is equivalent to the trapezoidal rule,
order=2 is equivalent to Simpson's rule, and
order=3 is equivalent to Boole's rule.

The number of iterations is limited by m_max_iter. m_eps specifies the requested fractional accuracy. By default it is set to 1e-6.

Definition at line 210 of file GIntegrals.cpp.

References calls(), G_ROMBERG1, m_calls, m_kernels, and GFunctions::size().

Referenced by GResponse::convolve(), cta_psf_radial_kerns_delta::eval(), com_radial_kerns_rho::eval(), com_elliptical_kerns_rho::eval(), GCOMResponse::irf_elliptical(), GCOMResponse::irf_radial(), and GCTAResponseCube::psf_radial().

GVector GIntegrals::romberg ( const double &  a,
const double &  b,
const int &  order = 5 
)

Perform Romberg integration.

Parameters
[in]aLeft integration boundary.
[in]bRight integration boundary.
[in]orderIntegration order (default: 5)
Returns
Vector of integration results.
Exceptions
GException::invalid_valueFunction kernels not set.
GException::invalid_argumentIntegration order incompatible with number of iterations.

Returns the integral of the integrand from a to b. Integration is performed by Romberg's method of order 2*order, where

order=1 is equivalent to the trapezoidal rule,
order=2 is equivalent to Simpson's rule, and
order=3 is equivalent to Boole's rule.

The number of iterations is limited by m_max_iter. m_eps specifies the requested fractional accuracy. By default it is set to 1e-6.

Definition at line 265 of file GIntegrals.cpp.

References abs(), G_ROMBERG2, gammalib::is_infinite(), gammalib::is_notanumber(), m_abserr, m_calls, m_eps, m_fix_iter, m_has_abserr, m_has_relerr, m_isvalid, m_iter, m_kernels, m_max_iter, m_message, m_relerr, m_silent, max_iter(), polint(), print(), GVector::print(), GFunctions::size(), gammalib::str(), trapzd(), and gammalib::warning().

void GIntegrals::silent ( const bool &  silent)
inline

Set silence flag.

Parameters
[in]silentSilence flag.

Definition at line 241 of file GIntegrals.hpp.

References m_silent, and silent().

const bool & GIntegrals::silent ( void  ) const
inline

Get silence flag.

Returns
True is class is silent, false otherwise.

Definition at line 254 of file GIntegrals.hpp.

References m_silent.

Referenced by print(), and silent().

GVector GIntegrals::trapzd ( const double &  a,
const double &  b,
const int &  n,
const GVector previous_result 
)

Perform Trapezoidal integration for a set of functions.

Parameters
[in]aLeft integration boundary.
[in]bRight integration boundary.
[in]nNumber of steps.
[in]previous_resultResult vector from a previous trapezoidal integration step.
Returns
Vector of integration results.
Exceptions
GException::invalid_valueFunction kernels not set.

The method performs a trapezoidal integration of a set of functions for the integration interval [a,b].

If n = 1 the integral for each function \(j\) is computed using

\[ \int_a^b f_j(x) \, dx = \frac{1}{2} (b-a) (f_j(a) + f_j(b)) \]

For n > 1 the integral is computed using

\[ \int_a^b f_j(x) \, dx = \frac{1}{2} \left[{\tt previous\_result}_j + \frac{b-a}{2^{n-1}} \sum_{i=0}^{2^{n-1}-1} f_j \left( a + (0.5+i) \frac{b-a}{2^{n-1}} \right) \right] \]

where \({\tt previous\_result}_j\) is the integration result for function \(j\) from a previous call to the method with n = n - 1.

Definition at line 450 of file GIntegrals.cpp.

References GFunctions::eval(), G_TRAPZD, m_calls, m_isvalid, m_kernels, m_message, m_silent, GVector::print(), GVector::size(), gammalib::str(), and gammalib::warning().

Referenced by romberg().

Member Data Documentation

GVector GIntegrals::m_abserr
mutableprotected

Absolute integration errors.

Definition at line 113 of file GIntegrals.hpp.

Referenced by copy_members(), init_members(), print(), and romberg().

int GIntegrals::m_calls
mutableprotected

Number of function calls used.

Definition at line 109 of file GIntegrals.hpp.

Referenced by calls(), copy_members(), init_members(), romberg(), and trapzd().

double GIntegrals::m_eps
protected

Requested relative integration precision.

Definition at line 102 of file GIntegrals.hpp.

Referenced by copy_members(), eps(), init_members(), and romberg().

int GIntegrals::m_fix_iter
protected

Fixed number of iterations.

Definition at line 104 of file GIntegrals.hpp.

Referenced by copy_members(), fixed_iter(), init_members(), print(), and romberg().

bool GIntegrals::m_has_abserr
mutableprotected

Has absolute integration errors.

Definition at line 111 of file GIntegrals.hpp.

Referenced by copy_members(), init_members(), print(), and romberg().

bool GIntegrals::m_has_relerr
mutableprotected

Has relative integration errors.

Definition at line 112 of file GIntegrals.hpp.

Referenced by copy_members(), init_members(), print(), and romberg().

bool GIntegrals::m_isvalid
mutableprotected

Integration result valid (true=yes)

Definition at line 110 of file GIntegrals.hpp.

Referenced by copy_members(), init_members(), is_valid(), polint(), romberg(), and trapzd().

int GIntegrals::m_iter
mutableprotected

Number of iterations used.

Definition at line 108 of file GIntegrals.hpp.

Referenced by copy_members(), init_members(), iter(), and romberg().

GFunctions* GIntegrals::m_kernels
protected

Pointer to function kernels.

Definition at line 101 of file GIntegrals.hpp.

Referenced by copy_members(), GIntegrals(), init_members(), kernels(), romberg(), and trapzd().

int GIntegrals::m_max_iter
protected

Maximum number of iterations.

Definition at line 103 of file GIntegrals.hpp.

Referenced by copy_members(), init_members(), max_iter(), and romberg().

std::string GIntegrals::m_message
mutableprotected

Status message (if result is invalid)

Definition at line 115 of file GIntegrals.hpp.

Referenced by copy_members(), init_members(), message(), polint(), romberg(), and trapzd().

GVector GIntegrals::m_relerr
mutableprotected

Absolute integration errors.

Definition at line 114 of file GIntegrals.hpp.

Referenced by copy_members(), init_members(), print(), and romberg().

bool GIntegrals::m_silent
protected

Suppress integration warnings in console.

Definition at line 105 of file GIntegrals.hpp.

Referenced by copy_members(), init_members(), polint(), romberg(), silent(), and trapzd().


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