npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
GaussLegendreQuadratureQ.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_GAUSSLEGENDREQUADRATUREQ_HH_
2 #define NPSTAT_GAUSSLEGENDREQUADRATUREQ_HH_
3 
4 /*!
5 // \file GaussLegendreQuadratureQ.hh
6 //
7 // \brief Gauss-Legendre quadratures in quad precision
8 //
9 // Author: I. Volobouev
10 //
11 // July 2020
12 */
13 
14 #include <vector>
15 #include <utility>
16 
17 #include "npstat/nm/lapack_double.h"
19 
20 namespace npstat {
21  /**
22  // Gauss-Legendre quadrature. Internally, operations are performed
23  // in lapack_double precision.
24  */
26  {
27  public:
28  enum {interval_quadrature = 1};
29 
30  /**
31  // At the moment, the following numbers of points are supported:
32  // 2, 4, 6, 8, 10, 12, 16, 32, 64, 100, 128, 256, 512, 1024.
33  //
34  // If an unsupported number of points is given in the
35  // constructor, std::invalid_argument exception will be thrown.
36  */
37  explicit GaussLegendreQuadratureQ(unsigned npoints);
38 
39  /** Return the number of quadrature points */
40  inline unsigned npoints() const {return npoints_;}
41 
42  /**
43  // The abscissae are returned for positive points only,
44  // so the buffer length should be at least npoints/2.
45  */
46  void getAbscissae(lapack_double* abscissae, unsigned len) const;
47 
48  /** Return abscissae for all points */
49  void getAllAbscissae(lapack_double* abscissae, unsigned len) const;
50 
51  /**
52  // The weights are returned for positive points only,
53  // so the buffer length should be at least npoints/2.
54  */
55  void getWeights(lapack_double* weights, unsigned len) const;
56 
57  /** Return weights for all points */
58  void getAllWeights(lapack_double* weights, unsigned len) const;
59 
60  /** Perform the quadrature on [a, b] interval */
61  template <typename FcnResult, typename FcnArg>
62  lapack_double integrate(const Functor1<FcnResult,FcnArg>& fcn,
63  lapack_double a, lapack_double b) const;
64 
65  /**
66  // This method splits the interval [a, b] into "nsplit"
67  // subintervals of equal length, applies Gauss-Legendre
68  // quadrature to each subinterval, and sums the results.
69  */
70  template <typename FcnResult, typename FcnArg>
71  lapack_double integrate(const Functor1<FcnResult,FcnArg>& fcn,
72  lapack_double a, lapack_double b,
73  unsigned nsplit) const;
74 
75  /**
76  // Weighted integration points on the given interval, suitable
77  // for constructing orthogonal polynomials w.r.t. the given
78  // weight function (in particular, by ContOrthoPoly1D class).
79  // Naturally, rule with "npoints" points must be able to calculate
80  // polynomial normalization integrals exactly.
81  */
82  template <class Functor>
83  std::vector<std::pair<lapack_double,lapack_double> >
85  const Functor& weight, lapack_double a, lapack_double b) const;
86 
87  /** Check if the rule with the given number of points is supported */
88  static bool isAllowed(unsigned npoints);
89 
90  /** The complete set of allowed rules, in the increasing order */
91  static std::vector<unsigned> allowedNPonts();
92 
93  /**
94  // Minimum number of points, among the supported rules, which
95  // integrates a polynomial with the given degree exactly.
96  // Returns 0 if the degree is out of range.
97  */
98  static unsigned minimalExactRule(unsigned polyDegree);
99 
100  private:
102 
103  const lapack_double* a_;
104  const lapack_double* w_;
105  mutable std::vector<std::pair<lapack_double, lapack_double> > buf_;
106  unsigned npoints_;
107  };
108 }
109 
110 #include "npstat/nm/GaussLegendreQuadratureQ.icc"
111 
112 #endif // NPSTAT_GAUSSLEGENDREQUADRATUREQ_HH_
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Definition: GaussLegendreQuadratureQ.hh:26
unsigned npoints() const
Definition: GaussLegendreQuadratureQ.hh:40
lapack_double integrate(const Functor1< FcnResult, FcnArg > &fcn, lapack_double a, lapack_double b) const
static bool isAllowed(unsigned npoints)
std::vector< std::pair< lapack_double, lapack_double > > weightedIntegrationPoints(const Functor &weight, lapack_double a, lapack_double b) const
GaussLegendreQuadratureQ(unsigned npoints)
static std::vector< unsigned > allowedNPonts()
lapack_double integrate(const Functor1< FcnResult, FcnArg > &fcn, lapack_double a, lapack_double b, unsigned nsplit) const
static unsigned minimalExactRule(unsigned polyDegree)
void getAbscissae(lapack_double *abscissae, unsigned len) const
void getAllWeights(lapack_double *weights, unsigned len) const
void getAllAbscissae(lapack_double *abscissae, unsigned len) const
void getWeights(lapack_double *weights, unsigned len) const
Definition: AbsArrayProjector.hh:14
Definition: SimpleFunctors.hh:58