GammaLib
2.0.0
|
Integration class for set of functions. More...
#include <GIntegrals.hpp>
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... | |
GIntegrals & | operator= (const GIntegrals &integral) |
Assignment operator. More... | |
void | clear (void) |
Clear integral. More... | |
GIntegrals * | clone (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 GFunctions * | kernels (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 | |
GFunctions * | m_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... | |
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.
|
explicit |
Void constructor.
Definition at line 62 of file GIntegrals.cpp.
References init_members().
Referenced by clone().
|
explicit |
Vector function kernels constructor.
[in] | kernels | Pointer 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.
[in] | integrals | Integrals. |
Definition at line 98 of file GIntegrals.cpp.
References copy_members(), and init_members().
|
virtual |
|
inline |
Get number of function calls.
Definition at line 229 of file GIntegrals.hpp.
References m_calls.
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 125 of file GIntegrals.hpp.
|
virtual |
Clear integral.
Implements GBase.
Definition at line 166 of file GIntegrals.cpp.
References free_members(), and init_members().
|
virtual |
Clone integral.
Implements GBase.
Definition at line 184 of file GIntegrals.cpp.
References GIntegrals().
|
protected |
Copy class members.
[in] | integral | Integral. |
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=().
|
inline |
Set relative precision.
[in] | eps | Relative precision. |
Definition at line 204 of file GIntegrals.hpp.
|
inline |
Get relative precision.
Definition at line 217 of file GIntegrals.hpp.
References m_eps.
|
inline |
Set fixed number of iterations.
[in] | iter | Fixed 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().
|
inline |
Return fixed number of iterations.
Definition at line 192 of file GIntegrals.hpp.
References m_fix_iter.
Referenced by print().
|
protected |
Delete class members.
Definition at line 697 of file GIntegrals.cpp.
Referenced by clear(), operator=(), and ~GIntegrals().
|
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=().
|
inline |
Signal if integration result is valid.
Definition at line 293 of file GIntegrals.hpp.
References m_isvalid.
Referenced by print().
|
inline |
Return number of iterations.
Definition at line 137 of file GIntegrals.hpp.
References m_iter.
Referenced by fixed_iter(), max_iter(), and print().
|
inline |
Set function kernels.
[in] | kernels | Function kernels. |
Sets the function kernels for which the integral should be determined.
Definition at line 268 of file GIntegrals.hpp.
|
inline |
Get function kernels.
Definition at line 281 of file GIntegrals.hpp.
References m_kernels.
Referenced by GIntegrals(), and kernels().
|
inline |
Set maximum number of iterations.
[in] | iter | Maximum number of iterations. |
Definition at line 149 of file GIntegrals.hpp.
References iter(), and m_max_iter.
|
inline |
Return maximum number of iterations.
Definition at line 162 of file GIntegrals.hpp.
References m_max_iter.
|
inline |
Return 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.
[in] | integrals | Integrals. |
Definition at line 136 of file GIntegrals.cpp.
References copy_members(), free_members(), and init_members().
|
protected |
Perform Polynomial interpolation.
[in] | xa | Pointer to array of X values. |
[in] | ya | Pointer to GVector of Y values. |
[in] | order | Number of elements in arrays. |
[in] | x | X value for which interpolations should be performed. |
[out] | dy | Pointer to vector of error estimates for 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().
Print integral information.
[in] | chatter | Chattiness. |
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.
[in] | bounds | Integration boundaries. |
[in] | order | Integration order (default: 5) |
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.
[in] | a | Left integration boundary. |
[in] | b | Right integration boundary. |
[in] | order | Integration order (default: 5) |
GException::invalid_value | Function kernels not set. |
GException::invalid_argument | Integration 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().
|
inline |
|
inline |
Get silence flag.
Definition at line 254 of file GIntegrals.hpp.
References m_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.
[in] | a | Left integration boundary. |
[in] | b | Right integration boundary. |
[in] | n | Number of steps. |
[in] | previous_result | Result vector from a previous trapezoidal integration step. |
GException::invalid_value | Function 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().
|
mutableprotected |
Absolute integration errors.
Definition at line 113 of file GIntegrals.hpp.
Referenced by copy_members(), init_members(), print(), and romberg().
|
mutableprotected |
Number of function calls used.
Definition at line 109 of file GIntegrals.hpp.
Referenced by calls(), copy_members(), init_members(), romberg(), and trapzd().
|
protected |
Requested relative integration precision.
Definition at line 102 of file GIntegrals.hpp.
Referenced by copy_members(), eps(), init_members(), and romberg().
|
protected |
Fixed number of iterations.
Definition at line 104 of file GIntegrals.hpp.
Referenced by copy_members(), fixed_iter(), init_members(), print(), and romberg().
|
mutableprotected |
Has absolute integration errors.
Definition at line 111 of file GIntegrals.hpp.
Referenced by copy_members(), init_members(), print(), and romberg().
|
mutableprotected |
Has relative integration errors.
Definition at line 112 of file GIntegrals.hpp.
Referenced by copy_members(), init_members(), print(), and romberg().
|
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().
|
mutableprotected |
Number of iterations used.
Definition at line 108 of file GIntegrals.hpp.
Referenced by copy_members(), init_members(), iter(), and romberg().
|
protected |
Pointer to function kernels.
Definition at line 101 of file GIntegrals.hpp.
Referenced by copy_members(), GIntegrals(), init_members(), kernels(), romberg(), and trapzd().
|
protected |
Maximum number of iterations.
Definition at line 103 of file GIntegrals.hpp.
Referenced by copy_members(), init_members(), max_iter(), and romberg().
|
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().
|
mutableprotected |
Absolute integration errors.
Definition at line 114 of file GIntegrals.hpp.
Referenced by copy_members(), init_members(), print(), and romberg().
|
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().