Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:48:23

0001 #ifndef INTEGRATOR_1D_H
0002 #define INTEGRATOR_1D_H
0003 
0004 /**
0005  * @file Integrator1D.h
0006  * @author Bryan BERTHOU (SPhN / CEA Saclay)
0007  * @date February 15, 2016
0008  * @version 1.0
0009  */
0010 
0011 #include <string>
0012 #include <vector>
0013 
0014 #include "../../functor/one_dimension/Functor1D.h"
0015 #include "../../utils/Errors.h"
0016 #include "../../utils/Tolerances.h"
0017 #include "IntegratorType1D.h"
0018 
0019 namespace ElemUtils {
0020 class Parameters;
0021 } /* namespace ElemUtils */
0022 
0023 namespace NumA {
0024 
0025 /**
0026  * @class Integrator1D
0027  *
0028  * @brief Abstract class for all integration routines.
0029  *
0030  * Example:
0031  * ```cpp
0032  * NumA::Integrator1D* integrator = NumA::Integrator1D::newIntegrator(NumA::IntegratorType1D::GaussLegendre); // Using Gauss-Legendre quadrature.
0033  * NumA::FunctionType1D* functor = NumA::FunctorUtils::newFunctor1D(pointerMyClass, &MyClass::myFunction); // See FunctionType1D documentation.
0034  * double integral = integrator.integrate(functor, -1., 1.); // We integrate a function on [-1,1].
0035  * ```
0036  */
0037 
0038 class Integrator1D {
0039 public:
0040     static const std::string PARAM_NAME_ABSOLUTE_TOLERANCE; ///< Parameter used in the configure() to set the absolute tolerance.
0041     static const std::string PARAM_NAME_RELATIVE_TOLERANCE; ///< Parameter used in the configure() to set the relative tolerance.
0042 
0043     /**
0044      * Default constructor.
0045      */
0046     Integrator1D();
0047 
0048     /**
0049      * Default destructor.
0050      */
0051     virtual ~Integrator1D();
0052 
0053     virtual Integrator1D* clone() const = 0;
0054 
0055     /**
0056      * Integration routine.
0057      * @param pFunction Functor representing the one-dimensional function to integrate.
0058      * @param a Lower bound.
0059      * @param b Upper bound.
0060      * @param parameters Parameters that can be passed to the function.
0061      * @return Integral.
0062      */
0063     virtual double integrate(FunctionType1D* pFunction, double a, double b,
0064             std::vector<double> &parameters) = 0;
0065 
0066     /**
0067      * Provides a generic method to configure all types of integrations by passing a Parameters object.
0068      * Parameters class represents a list of couples key/value (see Parameters class documentation for more info).
0069      *
0070      * @param parameters ElemUtils::Parameters object.
0071      */
0072     virtual void configure(const ElemUtils::Parameters &parameters);
0073 
0074     //TODO moved to FunctorUtils ; remove this definition
0075     /**
0076      * Use FunctorUtils::newFunctor1D instead.
0077      *
0078      * TODO: Remove this method.
0079      */
0080     template<typename PointerToObj, typename PointerToMemFn>
0081     static Functor1D<PointerToObj, PointerToMemFn>* newIntegrationFunctor(
0082             PointerToObj* object, PointerToMemFn function) {
0083         return new Functor1D<PointerToObj, PointerToMemFn>(object, function);
0084     }
0085 
0086     /**
0087      * Instantiates an Integrator object.
0088      * Will be replaced by a Factory/Registry system in the future.
0089      * @param oneDimIntegratorType Type of integrator.
0090      * @return Integrator1D pointer.
0091      */
0092     static Integrator1D* newIntegrator(
0093             const IntegratorType1D::Type &oneDimIntegratorType);
0094 
0095     // ##### GETTERS & SETTERS #####
0096 
0097     /**
0098      *
0099      * @return Absolute and relative tolerances.
0100      */
0101     const Tolerances& getTolerances() const;
0102     /**
0103      *
0104      * @param tolerances Absolute and relative tolerances.
0105      */
0106     void setTolerances(const Tolerances& tolerances);
0107     /**
0108      *
0109      * @return Absolute and relative errors estimations.
0110      */
0111     const Errors& getErrors() const;
0112     /**
0113      *
0114      * @param errors Absolute and relative errors estimations.
0115      */
0116     void setErrors(const Errors& errors);
0117 
0118 protected:
0119     Tolerances m_tolerances; ///< Absolute and relative tolerances.
0120     Errors m_errors; ///< Absolute and relative errors estimations.
0121 
0122     /**
0123      * Copy constructor.
0124      * Called by clone().
0125      * @param other Integrator1D object to copy.
0126      */
0127     Integrator1D(const Integrator1D &other);
0128 };
0129 
0130 } // namespace NumA
0131 
0132 #endif /* INTEGRATOR_1D_H */