1 // -*- C++ -*- 2 /** 3 * @brief This class allows to compute integrals of a function over an interval 4 * using GaussKronrod method for 1D scalar function 5 * 6 * Copyright 2005-2021 Airbus-EDF-IMACS-ONERA-Phimeca 7 * 8 * This library is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with this library. If not, see <http://www.gnu.org/licenses/>. 20 * 21 */ 22 #ifndef OPENTURNS_GAUSSKRONROD_HXX 23 #define OPENTURNS_GAUSSKRONROD_HXX 24 25 #include "openturns/IntegrationAlgorithmImplementation.hxx" 26 #include "openturns/UniVariateFunction.hxx" 27 #include "openturns/GaussKronrodRule.hxx" 28 29 BEGIN_NAMESPACE_OPENTURNS 30 31 /** 32 * @class GaussKronrod 33 */ 34 35 class OT_API GaussKronrod 36 : public IntegrationAlgorithmImplementation 37 { 38 39 CLASSNAME 40 41 public: 42 43 /** Default constructor without parameters */ 44 GaussKronrod(); 45 46 /** Parameter constructor */ 47 GaussKronrod(const UnsignedInteger maximumSubIntervals, 48 const Scalar maximumError, 49 const GaussKronrodRule & rule); 50 51 /** Virtual copy constructor */ 52 GaussKronrod * clone() const override; 53 54 /** Compute an approximation of \int_{[a,b]}f(x)dx, where [a,b] 55 * is an 1D interval 56 */ 57 using IntegrationAlgorithmImplementation::integrate; 58 #ifndef SWIG 59 Scalar integrate(const UniVariateFunction & function, 60 const Scalar a, 61 const Scalar b) const; 62 63 Point integrate(const Function & function, 64 const Interval & interval, 65 Scalar & error) const override; 66 67 // This method allows to get the estimated integration error as a scalar 68 Point integrate(const Function & function, 69 const Scalar a, 70 const Scalar b, 71 Scalar & error, 72 Point & ai, 73 Point & bi, 74 Sample & fi, 75 Point & ei) const; 76 77 #endif 78 // This method allows to get the estimated integration error as a Point, 79 // needed by Python 80 Point integrate(const Function & function, 81 const Scalar a, 82 const Scalar b, 83 Point & error, 84 Point & ai, 85 Point & bi, 86 Sample & fi, 87 Point & ei) const; 88 89 /** Maximum sub-intervals accessor */ 90 UnsignedInteger getMaximumSubIntervals() const; 91 void setMaximumSubIntervals(const UnsignedInteger maximumSubIntervals); 92 93 /** Maximum error accessor */ 94 Scalar getMaximumError() const; 95 void setMaximumError(const Scalar maximumError); 96 97 /** Rule accessor */ 98 GaussKronrodRule getRule() const; 99 void setRule(const GaussKronrodRule & rule); 100 101 /** String converter */ 102 String __repr__() const override; 103 104 /** String converter */ 105 String __str__(const String & offset = "") const override; 106 107 private: 108 109 /** Compute the local GaussKronrod rule over [a, b] */ 110 Point computeRule(const Function & function, 111 const Scalar a, 112 const Scalar b, 113 Scalar & localError) const; 114 115 Scalar computeScalarRule(const UniVariateFunction & function, 116 const Scalar a, 117 const Scalar b, 118 Scalar & localError) const; 119 120 /* Maximum number of sub-intervals */ 121 UnsignedInteger maximumSubIntervals_; 122 123 /* Maximum estimated error */ 124 Scalar maximumError_; 125 126 /* Local integration rule */ 127 GaussKronrodRule rule_; 128 129 } ; /* class GaussKronrod */ 130 131 END_NAMESPACE_OPENTURNS 132 133 #endif /* OPENTURNS_GAUSSKRONROD_HXX */ 134