The Gaudi Framework  v30r1 (5d4f4ae2)
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 <string>
9 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
12 #include "GaudiKernel/StatusCode.h"
13 // ============================================================================
14 // GaudiMath
15 // ============================================================================
16 #include "GaudiMath/Integration.h"
17 // ============================================================================
18 // CLHEP
19 // ============================================================================
20 #include "CLHEP/GenericFunctions/AbsFunction.hh"
21 // ============================================================================
22 #include "gsl/gsl_integration.h"
23 
24 #if defined( __clang__ ) || defined( __CLING__ )
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
27 #elif defined( __GNUC__ ) && __GNUC__ >= 5
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Wsuggest-override"
30 #endif
31 
33 
34 namespace Genfun
35 {
36  namespace GaudiMathImplementation
37  {
82  class GAUDI_API NumericalIndefiniteIntegral : public AbsFunction
83  {
84  public:
85  struct _Workspace {
86  gsl_integration_workspace* ws;
87  };
88  struct _Function;
89 
90  public:
93 
94  public:
96  FUNCTION_OBJECT_DEF( NumericalIndefiniteIntegral )
97 
98  public:
163  const AbsFunction& function, const size_t index, const double a,
166  const GaudiMath::Integration::KronrodRule rule = GaudiMath::Integration::Default, const double epsabs = 1e-10,
167  const double epsrel = 1.e-7, const size_t size = 1000 );
168 
211  const AbsFunction& function, const size_t index, const double a, const Points& points,
212  const GaudiMath::Integration::Limit limit = GaudiMath::Integration::VariableHighLimit,
213  const double epsabs = 1e-9, const double epsrel = 1.e-6, const size_t size = 1000 );
214 
253  const AbsFunction& function, const size_t index,
254  const GaudiMath::Integration::Limit limit = GaudiMath::Integration::VariableHighLimit,
255  const double epsabs = 1e-9, const double epsrel = 1.e-6, const size_t size = 1000 );
256 
259 
260  public:
262  unsigned int dimensionality() const override { return m_DIM; }
263 
265  double operator()( double argument ) const override;
267  double operator()( const Argument& argument ) const override;
268 
270  bool hasAnalyticDerivative() const override { return true; }
271 
273  Genfun::Derivative partial( unsigned int index ) const override;
274 
275  public:
277  const AbsFunction& function() const { return *m_function; }
279  double a() const { return m_a; }
281  const Points& points() const { return m_points; }
283  double epsabs() const { return m_epsabs; }
285  double epsrel() const { return m_epsrel; }
286 
288  double result() const { return m_result; }
290  double error() const { return m_error; }
291 
292  // maximal number of bisection integvals for adaptive algorithms
293  size_t size() const { return m_size; }
294 
296  GaudiMath::Integration::Limit limit() const { return m_limit; }
298  GaudiMath::Integration::Type type() const { return m_type; }
300  GaudiMath::Integration::Category category() const { return m_category; }
302  GaudiMath::Integration::KronrodRule rule() const { return m_rule; }
303 
304  protected:
305  // adaptive integration on infinite intervals
306  double QAGI( _Function* fun ) const;
307  // adaptive integration with known singular points
308  double QAGP( _Function* fun ) const;
309  // non-adaptive integration
310  double QNG( _Function* fun ) const;
311  // adaptive integration
312  double QAG( _Function* fun ) const;
313  // adaptive integral with singularities
314  double QAGS( _Function* fun ) const;
315 
316  // allocate the integration workspace
317  _Workspace* allocate() const;
318  // the integration workspace
319  _Workspace* ws() const { return m_ws.get(); }
320 
321  // throw the exception
322  StatusCode Exception( const std::string& message, const StatusCode& sc = StatusCode::FAILURE ) const;
323 
324  private:
325  // default constructor is disabled
327  // assignement operator is disabled
329 
330  public:
331  struct gsl_ws_deleter {
332  void operator()( _Workspace* p ) const
333  {
334  if ( p ) gsl_integration_workspace_free( p->ws );
335  delete p;
336  }
337  };
338 
339  private:
341  size_t m_DIM;
342  size_t m_index;
343 
344  double m_a;
345 
350 
351  Points m_points;
352 
353  double m_epsabs;
354  double m_epsrel;
355 
356  mutable double m_result = GSL_NEGINF;
357  mutable double m_error = GSL_POSINF;
358 
359  size_t m_size;
361 
362  mutable Argument m_argument;
363  };
365  FUNCTION_OBJECT_IMP( NumericalIndefiniteIntegral )
366 
367  } // end of namespace GaudiMathImplementation
368 } // end of namespace Genfun
369 
370 #if defined( __clang__ ) || defined( __CLING__ )
371 #pragma clang diagnostic pop
372 #elif defined( __GNUC__ ) && __GNUC__ >= 5
373 #pragma GCC diagnostic pop
374 #endif
375 
376 // ============================================================================
377 // The END
378 // ============================================================================
379 #endif // GAUDIMATH_NUMERICALINDEFINITEINTEGRAL_H
380 // ============================================================================
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:26
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.
Definition: Adapters.h:13
KronrodRule
integration rule
Definition: Integration.h:28
std::vector< double > Points
typedef for vector of singular points
CLHEP.
Definition: IEqSolver.h:13
#define GAUDI_API
Definition: Kernel.h:110
Type
the list of available types for ntuples
Definition: TupleObj.h:84
collection of common types for classes NumericalIndefiniteIntegral and NumericalDefiniteIntegral ...