The Gaudi Framework  v30r3 (a5ef0a68)
NumericalIndefiniteIntegral.h
Go to the documentation of this file.
1 #ifndef GAUDIMATH_NUMERICALINDEFINITEINTEGRAL_H
2 #define GAUDIMATH_NUMERICALINDEFINITEINTEGRAL_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <memory>
9 #include <string>
10 // ============================================================================
11 // GaudiKernel
12 // ============================================================================
13 #include "GaudiKernel/StatusCode.h"
14 // ============================================================================
15 // GaudiMath
16 // ============================================================================
17 #include "GaudiMath/Integration.h"
18 // ============================================================================
19 // CLHEP
20 // ============================================================================
21 #include "CLHEP/GenericFunctions/AbsFunction.hh"
22 // ============================================================================
23 #include "gsl/gsl_integration.h"
24 
25 #if defined( __clang__ ) || defined( __CLING__ )
26 #pragma clang diagnostic push
27 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
28 #elif defined( __GNUC__ ) && __GNUC__ >= 5
29 #pragma GCC diagnostic push
30 #pragma GCC diagnostic ignored "-Wsuggest-override"
31 #endif
32 
34 
35 namespace Genfun
36 {
37  namespace GaudiMathImplementation
38  {
83  class GAUDI_API NumericalIndefiniteIntegral : public AbsFunction
84  {
85  public:
86  struct _Workspace {
87  gsl_integration_workspace* ws;
88  };
89  struct _Function;
90 
91  public:
94 
95  public:
97  FUNCTION_OBJECT_DEF( NumericalIndefiniteIntegral )
98 
99  public:
164  const AbsFunction& function, const size_t index, const double a,
167  const GaudiMath::Integration::KronrodRule rule = GaudiMath::Integration::Default, const double epsabs = 1e-10,
168  const double epsrel = 1.e-7, const size_t size = 1000 );
169 
212  const AbsFunction& function, const size_t index, const double a, const Points& points,
213  const GaudiMath::Integration::Limit limit = GaudiMath::Integration::VariableHighLimit,
214  const double epsabs = 1e-9, const double epsrel = 1.e-6, const size_t size = 1000 );
215 
254  const AbsFunction& function, const size_t index,
255  const GaudiMath::Integration::Limit limit = GaudiMath::Integration::VariableHighLimit,
256  const double epsabs = 1e-9, const double epsrel = 1.e-6, const size_t size = 1000 );
257 
260 
261  public:
263  unsigned int dimensionality() const override { return m_DIM; }
264 
266  double operator()( double argument ) const override;
268  double operator()( const Argument& argument ) const override;
269 
271  bool hasAnalyticDerivative() const override { return true; }
272 
274  Genfun::Derivative partial( unsigned int index ) const override;
275 
276  public:
278  const AbsFunction& function() const { return *m_function; }
280  double a() const { return m_a; }
282  const Points& points() const { return m_points; }
284  double epsabs() const { return m_epsabs; }
286  double epsrel() const { return m_epsrel; }
287 
289  double result() const { return m_result; }
291  double error() const { return m_error; }
292 
293  // maximal number of bisection integvals for adaptive algorithms
294  size_t size() const { return m_size; }
295 
297  GaudiMath::Integration::Limit limit() const { return m_limit; }
299  GaudiMath::Integration::Type type() const { return m_type; }
301  GaudiMath::Integration::Category category() const { return m_category; }
303  GaudiMath::Integration::KronrodRule rule() const { return m_rule; }
304 
305  protected:
306  // adaptive integration on infinite intervals
307  double QAGI( _Function* fun ) const;
308  // adaptive integration with known singular points
309  double QAGP( _Function* fun ) const;
310  // non-adaptive integration
311  double QNG( _Function* fun ) const;
312  // adaptive integration
313  double QAG( _Function* fun ) const;
314  // adaptive integral with singularities
315  double QAGS( _Function* fun ) const;
316 
317  // allocate the integration workspace
318  _Workspace* allocate() const;
319  // the integration workspace
320  _Workspace* ws() const { return m_ws.get(); }
321 
322  // throw the exception
323  StatusCode Exception( const std::string& message, const StatusCode& sc = StatusCode::FAILURE ) const;
324 
325  private:
326  // default constructor is disabled
328  // assignement operator is disabled
330 
331  public:
332  struct gsl_ws_deleter {
333  void operator()( _Workspace* p ) const
334  {
335  if ( p ) gsl_integration_workspace_free( p->ws );
336  delete p;
337  }
338  };
339 
340  private:
342  size_t m_DIM;
343  size_t m_index;
344 
345  double m_a;
346 
351 
352  Points m_points;
353 
354  double m_epsabs;
355  double m_epsrel;
356 
357  mutable double m_result = GSL_NEGINF;
358  mutable double m_error = GSL_POSINF;
359 
360  size_t m_size;
362 
363  mutable Argument m_argument;
364  };
366  FUNCTION_OBJECT_IMP( NumericalIndefiniteIntegral )
367 
368  } // end of namespace GaudiMathImplementation
369 } // end of namespace Genfun
370 
371 #if defined( __clang__ ) || defined( __CLING__ )
372 #pragma clang diagnostic pop
373 #elif defined( __GNUC__ ) && __GNUC__ >= 5
374 #pragma GCC diagnostic pop
375 #endif
376 
377 // ============================================================================
378 // The END
379 // ============================================================================
380 #endif // GAUDIMATH_NUMERICALINDEFINITEINTEGRAL_H
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Category
integration category
Definition: Integration.h:26
GaudiMath::Integration::Limit limit() const
integration limit
Genfun::GaudiMathImplementation::NumericalDerivative Derivative
Definition: GaudiMath.h:27
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
GaudiMath::Integration::Category category() const
integration category
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
GaudiMath::Integration::KronrodRule rule() const
integration rule
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
Type
type of integration (for finite limits)
Definition: Integration.h:24
bool hasAnalyticDerivative() const override
Does this function have an analytic derivative?
GaudiMath::Integration::Type type() const
integration type
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
Limit
how to distinguish variable low and variable high limits
Definition: Integration.h:22
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
GaudiMath.h GaudiMath/GaudiMath.h.
KronrodRule
integration rule
Definition: Integration.h:28
std::vector< double > Points
typedef for vector of singular points
#define GAUDI_API
Definition: Kernel.h:104
Type
the list of available types for ntuples
Definition: TupleObj.h:83
collection of common types for classes NumericalIndefiniteIntegral and NumericalDefiniteIntegral ...