npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
RectangleQuadrature1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_RECTANGLEQUADRATURE1D_HH_
2 #define NPSTAT_RECTANGLEQUADRATURE1D_HH_
3 
4 /*!
5 // \file RectangleQuadrature1D.hh
6 //
7 // \brief Trivial rectangle quadrature. Works well on certain functions.
8 //
9 // Author: I. Volobouev
10 //
11 // November 2020
12 */
13 
14 #include <vector>
15 #include <utility>
16 
19 
20 namespace npstat {
22  {
23  public:
24  enum {interval_quadrature = 1};
25 
26  explicit RectangleQuadrature1D(unsigned npoints);
27 
28  inline virtual ~RectangleQuadrature1D() {}
29 
30  inline unsigned npoints() const {return npoints_;}
31  void getAllAbscissae(long double* abscissae, unsigned len) const;
32  void getAllWeights(long double* weights, unsigned len) const;
33 
34  /** Perform the quadrature on the [a, b] interval */
35  template <typename FcnResult, typename FcnArg>
36  long double integrate(const Functor1<FcnResult,FcnArg>& fcn,
37  long double a, long double b) const;
38  private:
40 
41  mutable std::vector<std::pair<long double, long double> > buf_;
42  unsigned npoints_;
43 
44 #ifdef SWIG
45  public:
46  inline std::vector<double> allabscissae2() const
47  {
48  std::vector<double> abscissae(npoints_);
49  const long double step = 2.0L/npoints_;
50  for (unsigned i=0; i<npoints_; ++i)
51  abscissae[i] = -1.0L + step*(i + 0.5L);
52  return abscissae;
53  }
54 
55  inline std::vector<double> allweights2() const
56  {
57  std::vector<double> weights(npoints_);
58  const long double w = 2.0L/npoints_;
59  for (unsigned i=0; i<npoints_; ++i)
60  weights[i] = w;
61  return weights;
62  }
63 
64  template <typename FcnResult, typename FcnArg>
65  inline double integrate2(const Functor1<FcnResult,FcnArg>& fcn,
66  const double a, const double b) const
67  {
68  return integrate(fcn, a, b);
69  }
70 #endif // SWIG
71  };
72 }
73 
74 #include "npstat/nm/RectangleQuadrature1D.icc"
75 
76 #endif // NPSTAT_RECTANGLEQUADRATURE1D_HH_
Base class for quadratures on the [-1, 1] interval.
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Definition: AbsIntervalQuadrature1D.hh:19
Definition: RectangleQuadrature1D.hh:22
long double integrate(const Functor1< FcnResult, FcnArg > &fcn, long double a, long double b) const
Definition: AbsArrayProjector.hh:14
Definition: SimpleFunctors.hh:58