npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
FejerQuadrature.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_FEJERQUADRATURE_HH_
2 #define NPSTAT_FEJERQUADRATURE_HH_
3 
4 /*!
5 // \file FejerQuadrature.hh
6 //
7 // \brief Fejer quadratures in long double precision
8 //
9 // Author: I. Volobouev
10 //
11 // July 2018
12 */
13 
14 #include <map>
15 #include <vector>
16 #include <utility>
17 #include <memory>
18 
21 
22 namespace npstat {
23  /**
24  // Fejer quadrature. Internally, operations are performed
25  // in long double precision.
26  */
28  {
29  public:
30  enum {interval_quadrature = 1};
31 
32  explicit FejerQuadrature(unsigned npoints);
33 
34  inline virtual ~FejerQuadrature() {}
35 
36  /** Return the number of quadrature points */
37  inline unsigned npoints() const {return npoints_;}
38 
39  /**
40  // The abscissae of the integration rule.
41  // The buffer length should be at least npoints.
42  */
43  void getAllAbscissae(long double* abscissae, unsigned len) const;
44 
45  /**
46  // The weights of the integration rule.
47  // The buffer length should be at least npoints.
48  */
49  void getAllWeights(long double* weights, unsigned len) const;
50 
51  /** Perform the quadrature on [a, b] interval */
52  template <typename FcnResult, typename FcnArg>
53  long double integrate(const Functor1<FcnResult,FcnArg>& fcn,
54  long double a, long double b) const;
55 
56  /**
57  // Minimum number of points which integrates a polynomial
58  // with the given degree exactly
59  */
60  static unsigned minimalExactRule(unsigned polyDegree);
61 
62  private:
64 
65  std::vector<long double> a_;
66  std::vector<long double> w_;
67  mutable std::vector<std::pair<long double, long double> > buf_;
68  unsigned npoints_;
69 
70 #ifdef SWIG
71  public:
72  inline std::vector<double> abscissae2() const
73  {
74  return std::vector<double>(a_.begin(), a_.end());
75  }
76 
77  inline std::vector<double> weights2() const
78  {
79  return std::vector<double>(w_.begin(), w_.end());
80  }
81 
82  template <typename FcnResult, typename FcnArg>
83  inline double integrate2(const Functor1<FcnResult,FcnArg>& fcn,
84  const double a, const double b) const
85  {
86  return integrate(fcn, a, b);
87  }
88 #endif // SWIG
89  };
90 
91  /**
92  // Static collection of Fejer quadratures. Call FejerQuadratureSet::quad
93  // function in order to get the quadrature. The quadrature object will be
94  // either recalled or created if it does not yet exist.
95  */
97  {
98  public:
99  static std::shared_ptr<const FejerQuadrature> quad(unsigned npoints);
100 
101  private:
102  typedef std::map<unsigned,std::shared_ptr<const FejerQuadrature> > FejerMap;
103  static FejerMap& getFejerMap();
104  };
105 }
106 
107 #include "npstat/nm/FejerQuadrature.icc"
108 
109 #endif // NPSTAT_FEJERQUADRATURE_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: FejerQuadrature.hh:97
Definition: FejerQuadrature.hh:28
long double integrate(const Functor1< FcnResult, FcnArg > &fcn, long double a, long double b) const
void getAllAbscissae(long double *abscissae, unsigned len) const
static unsigned minimalExactRule(unsigned polyDegree)
unsigned npoints() const
Definition: FejerQuadrature.hh:37
void getAllWeights(long double *weights, unsigned len) const
Definition: AbsArrayProjector.hh:14
Definition: SimpleFunctors.hh:58