GammaLib 2.0.0
Loading...
Searching...
No Matches
GIntegrals.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GIntegrals.hpp - Integration class for set of functions *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2020 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GIntegrals.hpp
23 * @brief Integration class for set of functions interface definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GINTEGRALS_HPP
28#define GINTEGRALS_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include <vector>
33#include "GBase.hpp"
34#include "GVector.hpp"
35
36/* __ Forward declarations _______________________________________________ */
37class GFunctions;
38
39/***********************************************************************//**
40 * @class GIntegrals
41 *
42 * @brief Integration class for set of functions
43 *
44 * This class allows to perform integration of a set of functions. The
45 * integrand is implemented by a derived class of GFunctions.
46 ***************************************************************************/
47class GIntegrals : public GBase {
48
49public:
50
51 // Constructors and destructors
52 explicit GIntegrals(void);
53 explicit GIntegrals(GFunctions* kernels);
54 GIntegrals(const GIntegrals& integral);
55 virtual ~GIntegrals(void);
56
57 // Operators
58 GIntegrals& operator=(const GIntegrals& integral);
59
60 // Methods
61 void clear(void);
62 GIntegrals* clone(void) const;
63 std::string classname(void) const;
64 void max_iter(const int& iter);
65 const int& max_iter(void) const;
66 void fixed_iter(const int& iter);
67 const int& fixed_iter(void) const;
68 void eps(const double& eps);
69 const double& eps(void) const;
70 void silent(const bool& silent);
71 const bool& silent(void) const;
72 const int& iter(void) const;
73 const int& calls(void) const;
74 const bool& is_valid(void) const;
75 const std::string& message(void) const;
77 const GFunctions* kernels(void) const;
78 GVector romberg(std::vector<double> bounds,
79 const int& order = 5);
80 GVector romberg(const double& a,
81 const double& b,
82 const int& order = 5);
83 GVector trapzd(const double& a,
84 const double& b,
85 const int& n,
86 const GVector& previous_result);
87 std::string print(const GChatter& chatter = NORMAL) const;
88
89protected:
90 // Protected methods
91 void init_members(void);
92 void copy_members(const GIntegrals& integral);
93 void free_members(void);
94 GVector polint(const double* xa,
95 const GVector* ya,
96 const int& order,
97 const double& x,
98 GVector* dy);
99
100 // Protected data area
101 GFunctions* m_kernels; //!< Pointer to function kernels
102 double m_eps; //!< Requested relative integration precision
103 int m_max_iter; //!< Maximum number of iterations
104 int m_fix_iter; //!< Fixed number of iterations
105 bool m_silent; //!< Suppress integration warnings in console
106
107 // Integrator results
108 mutable int m_iter; //!< Number of iterations used
109 mutable int m_calls; //!< Number of function calls used
110 mutable bool m_isvalid; //!< Integration result valid (true=yes)
111 mutable bool m_has_abserr; //!< Has absolute integration errors
112 mutable bool m_has_relerr; //!< Has relative integration errors
113 mutable GVector m_abserr; //!< Absolute integration errors
114 mutable GVector m_relerr; //!< Absolute integration errors
115 mutable std::string m_message; //!< Status message (if result is invalid)
116};
117
118
119/***********************************************************************//**
120 * @brief Return class name
121 *
122 * @return String containing the class name ("GIntegrals").
123 ***************************************************************************/
124inline
125std::string GIntegrals::classname(void) const
126{
127 return ("GIntegrals");
128}
129
130
131/***********************************************************************//**
132 * @brief Return number of iterations
133 *
134 * @return Number of iterations.
135 ***************************************************************************/
136inline
137const int& GIntegrals::iter(void) const
138{
139 return m_iter;
140}
141
142
143/***********************************************************************//**
144 * @brief Set maximum number of iterations
145 *
146 * @param[in] iter Maximum number of iterations.
147 ***************************************************************************/
148inline
149void GIntegrals::max_iter(const int& iter)
150{
152 return;
153}
154
155
156/***********************************************************************//**
157 * @brief Return maximum number of iterations
158 *
159 * @return Maximum number of iterations.
160 ***************************************************************************/
161inline
162const int& GIntegrals::max_iter(void) const
163{
164 return m_max_iter;
165}
166
167
168/***********************************************************************//**
169 * @brief Set fixed number of iterations
170 *
171 * @param[in] iter Fixed number of iterations.
172 *
173 * If the fixed number of iterations is set, the integration algorithm will
174 * always performed the given number of iterations, irrespectively of the
175 * precision that is reached. This feature is relevant for computing
176 * numerical derivates from numerically integrated functions.
177 ***************************************************************************/
178inline
179void GIntegrals::fixed_iter(const int& iter)
180{
182 return;
183}
184
185
186/***********************************************************************//**
187 * @brief Return fixed number of iterations
188 *
189 * @return Fixed number of iterations.
190 ***************************************************************************/
191inline
192const int& GIntegrals::fixed_iter(void) const
193{
194 return m_fix_iter;
195}
196
197
198/***********************************************************************//**
199 * @brief Set relative precision
200 *
201 * @param[in] eps Relative precision.
202 ***************************************************************************/
203inline
204void GIntegrals::eps(const double& eps)
205{
206 m_eps = eps;
207 return;
208}
209
210
211/***********************************************************************//**
212 * @brief Get relative precision
213 *
214 * @return Relative precision.
215 ***************************************************************************/
216inline
217const double& GIntegrals::eps(void) const
218{
219 return m_eps;
220}
221
222
223/***********************************************************************//**
224 * @brief Get number of function calls
225 *
226 * @return Number of function calls.
227 ***************************************************************************/
228inline
229const int& GIntegrals::calls(void) const
230{
231 return m_calls;
232}
233
234
235/***********************************************************************//**
236 * @brief Set silence flag
237 *
238 * @param[in] silent Silence flag.
239 ***************************************************************************/
240inline
241void GIntegrals::silent(const bool& silent)
242{
244 return;
245}
246
247
248/***********************************************************************//**
249 * @brief Get silence flag
250 *
251 * @return True is class is silent, false otherwise.
252 ***************************************************************************/
253inline
254const bool& GIntegrals::silent(void) const
255{
256 return m_silent;
257}
258
259
260/***********************************************************************//**
261 * @brief Set function kernels
262 *
263 * @param[in] kernels Function kernels.
264 *
265 * Sets the function kernels for which the integral should be determined.
266 ***************************************************************************/
267inline
269{
271 return;
272}
273
274
275/***********************************************************************//**
276 * @brief Get function kernels
277 *
278 * @return Function kernels.
279 ***************************************************************************/
280inline
282{
283 return m_kernels;
284}
285
286
287/***********************************************************************//**
288 * @brief Signal if integration result is valid
289 *
290 * @return True is integration result is valid.
291 ***************************************************************************/
292inline
293const bool& GIntegrals::is_valid(void) const
294{
295 return m_isvalid;
296}
297
298
299/***********************************************************************//**
300 * @brief Return integration status message
301 *
302 * @return Integration status message.
303 ***************************************************************************/
304inline
305const std::string& GIntegrals::message(void) const
306{
307 return m_message;
308}
309
310#endif /* GINTEGRALS_HPP */
Definition of interface for all GammaLib classes.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Vector class interface definition.
Interface class for all GammaLib classes.
Definition GBase.hpp:52
Single parameter functions abstract base class.
Integration class for set of functions.
GVector polint(const double *xa, const GVector *ya, const int &order, const double &x, GVector *dy)
Perform Polynomial interpolation.
GVector romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
void copy_members(const GIntegrals &integral)
Copy class members.
GVector m_relerr
Absolute integration errors.
GFunctions * m_kernels
Pointer to function kernels.
GVector m_abserr
Absolute integration errors.
const std::string & message(void) const
Return integration status message.
void free_members(void)
Delete class members.
const bool & silent(void) const
Get silence flag.
double m_eps
Requested relative integration precision.
bool m_has_relerr
Has relative integration errors.
int m_iter
Number of iterations used.
bool m_has_abserr
Has absolute integration errors.
const bool & is_valid(void) const
Signal if integration result is valid.
const int & calls(void) const
Get number of function calls.
GIntegrals(void)
Void constructor.
int m_calls
Number of function calls used.
GIntegrals * clone(void) const
Clone integral.
const double & eps(void) const
Get relative precision.
std::string print(const GChatter &chatter=NORMAL) const
Print integral information.
GIntegrals & operator=(const GIntegrals &integral)
Assignment operator.
void clear(void)
Clear integral.
GVector trapzd(const double &a, const double &b, const int &n, const GVector &previous_result)
Perform Trapezoidal integration for a set of functions.
bool m_isvalid
Integration result valid (true=yes)
const int & fixed_iter(void) const
Return fixed number of iterations.
void init_members(void)
Initialise class members.
const GFunctions * kernels(void) const
Get function kernels.
const int & max_iter(void) const
Return maximum number of iterations.
bool m_silent
Suppress integration warnings in console.
std::string classname(void) const
Return class name.
int m_fix_iter
Fixed number of iterations.
std::string m_message
Status message (if result is invalid)
int m_max_iter
Maximum number of iterations.
const int & iter(void) const
Return number of iterations.
virtual ~GIntegrals(void)
Destructor.
Vector class.
Definition GVector.hpp:46