npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
AbsIntervalQuadrature1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_ABSINTERVALQUADRATURE1D_HH_
2 #define NPSTAT_ABSINTERVALQUADRATURE1D_HH_
3 
4 /*!
5 // \file AbsIntervalQuadrature1D.hh
6 //
7 // \brief Base class for quadratures on the [-1, 1] interval
8 //
9 // Author: I. Volobouev
10 //
11 // November 2020
12 */
13 
14 #include <vector>
15 #include <utility>
16 
17 namespace npstat {
19  {
20  public:
21  inline virtual ~AbsIntervalQuadrature1D() {}
22 
23  virtual unsigned npoints() const = 0;
24  virtual void getAllAbscissae(long double* absc, unsigned len) const = 0;
25  virtual void getAllWeights(long double* weights, unsigned len) const = 0;
26 
27  //@{
28  /**
29  // Weighted integration points on the given interval, suitable
30  // for constructing orthogonal polynomials w.r.t. the given weight
31  // function (in particular, by ContOrthoPoly1D class). Naturally,
32  // rule with "npoints" points must be able to calculate polynomial
33  // normalization integrals exactly.
34  */
35  template <class Functor>
36  inline std::vector<std::pair<double,double> > weightedIntegrationPoints(
37  const Functor& weight, const long double left,
38  const long double right) const
39  {
40  return weightedIntegrationPointsHlp<Functor,std::pair<double,double> >(
41  weight, left, right);
42  }
43 
44  template <class Functor>
45  inline std::vector<std::pair<long double,long double> > weightedIntegrationPointsLD(
46  const Functor& weight, const long double left,
47  const long double right) const
48  {
49  return weightedIntegrationPointsHlp<Functor,std::pair<long double,long double> >(
50  weight, left, right);
51  }
52  //@}
53 
54  private:
55  template <class Functor, class Pair>
56  inline std::vector<Pair> weightedIntegrationPointsHlp(
57  const Functor& weight, const long double left,
58  const long double right) const
59  {
60  const unsigned npt = this->npoints();
61  std::vector<long double> buf(npt*2U);
62  long double* absc = &buf[0];
63  long double* w = absc + npt;
64  this->getAllAbscissae(absc, npt);
65  this->getAllWeights(w, npt);
66  const long double midpoint = (left + right)/2.0L;
67  const long double unit = (right - left)/2.0L;
68 
69  std::vector<Pair> result(npt);
70  for (unsigned i=0; i<npt; ++i)
71  {
72  const long double x = midpoint + unit*absc[i];
73  result[i] = Pair(x, unit*w[i]*weight(x));
74  }
75 
76  return result;
77  }
78  };
79 }
80 
81 #endif // NPSTAT_ABSINTERVALQUADRATURE1D_HH_
Definition: AbsIntervalQuadrature1D.hh:19
std::vector< std::pair< double, double > > weightedIntegrationPoints(const Functor &weight, const long double left, const long double right) const
Definition: AbsIntervalQuadrature1D.hh:36
Definition: AbsArrayProjector.hh:14