1 //                                               -*- C++ -*-
2 /**
3  *  @brief This class allows to compute integrals of a function over an
4  *         interval. It implements a tensorized Fejer & Clenshaw-Curtis
5  *         quadrature
6  *
7  *  Copyright 2005-2021 Airbus-EDF-IMACS-ONERA-Phimeca
8  *
9  *  This library is free software: you can redistribute it and/or modify
10  *  it under the terms of the GNU Lesser General Public License as published by
11  *  the Free Software Foundation, either version 3 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public License
20  *  along with this library.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23 #ifndef OPENTURNS_FEJERALGORITHM_HXX
24 #define OPENTURNS_FEJERALGORITHM_HXX
25 
26 #include "openturns/IntegrationAlgorithmImplementation.hxx"
27 #include "openturns/IntegrationAlgorithm.hxx"
28 
29 BEGIN_NAMESPACE_OPENTURNS
30 
31 /**
32  * @class FejerAlgorithm
33  */
34 
35 class OT_API FejerAlgorithm
36   : public IntegrationAlgorithmImplementation
37 {
38 
39   CLASSNAME
40 
41 public:
42   enum IntegrationMethod {FEJERTYPE1 = 0, FEJERTYPE2 = 1, CLENSHAWCURTIS};
43 
44   /** Default constructor */
45 
46   explicit FejerAlgorithm(const UnsignedInteger dimension = 1,
47                           const IntegrationMethod method = CLENSHAWCURTIS);
48 
49   /** Parameter constructor */
50   explicit FejerAlgorithm(const Indices & discretization,
51                           const IntegrationMethod method = CLENSHAWCURTIS);
52 
53   /** Virtual copy constructor */
54   FejerAlgorithm *clone() const override;
55 
56   /** Compute an approximation of \int_a^b f(x_1,\dots,x_n)dx_1\dotsdx_n, where [a,b] is an nD interval.*/
57   using IntegrationAlgorithmImplementation::integrate;
58   Point integrate(const Function &function,
59                   const Interval &interval) const override;
60   Point integrateWithNodes(const Function &function,
61                            const Interval &interval,
62                            Sample &adaptedNodesOut) const;
63 
64   /** Discretization accessor */
65   Indices getDiscretization() const;
66 
67   /** Nodes accessor */
68   Sample getNodes() const;
69 
70   /** Weights accessor */
71   Point getWeights() const;
72 
73   /** String converter */
74   String __repr__() const override;
75 
76   /** String converter */
77   String __str__(const String & offset = "") const override;
78 
79 private:
80   /* Generate nodes and weights */
81   void generateNodesAndWeights(const IntegrationMethod method);
82 
83   // Generate nodes and weights for ClenshawCurtis
84   void generateNodesAndWeightsClenshawCurtis(Collection<Point> & marginalNodes, Collection<Point> & marginalWeights);
85   // Generate nodes and weights for Fejer Type 1
86   void generateNodesAndWeightsFejerType1(Collection<Point> & marginalNodes, Collection<Point> & marginalWeights);
87   // Generate nodes and weights for Fejer Type 2
88   void generateNodesAndWeightsFejerType2(Collection<Point> & marginalNodes, Collection<Point> & marginalWeights);
89 
90   /* Discretization of the tensorized rule */
91   Indices discretization_;
92 
93   /* Integration nodes */
94   Sample nodes_;
95 
96   /* Integration weights */
97   Point weights_;
98 } ; /* class FejerAlgorithm */
99 
100 END_NAMESPACE_OPENTURNS
101 
102 #endif /* OPENTURNS_FEJERALGORITHM_HXX */
103