Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:17:14

0001 //
0002 // APFEL++ 2017
0003 //
0004 // Author: Valerio Bertone: valerio.bertone@cern.ch
0005 //
0006 
0007 #pragma once
0008 
0009 #include "apfel/grid.h"
0010 #include "apfel/matrix.h"
0011 #include "apfel/operator.h"
0012 #include "apfel/distribution.h"
0013 #include "apfel/doubleobject.h"
0014 #include "apfel/doubledistribution.h"
0015 #include "apfel/lagrangeinterpolator.h"
0016 
0017 namespace apfel
0018 {
0019   /**
0020    * @brief The OperatorDistribution class defines an object that
0021    * behaves as an operator along the first variable and as a
0022    * distribution along the second.
0023    */
0024   class OperatorDistribution
0025   {
0026   public:
0027     OperatorDistribution() = delete;
0028     OperatorDistribution(OperatorDistribution const&) = default;
0029 
0030     /**
0031      * @brief The OperatorDistribution constructor.
0032      * @param gr1: the Grid object for the first variable
0033      * @param gr2: the Grid object for the second variable
0034      */
0035     OperatorDistribution(Grid const& gr1, Grid const& gr2);
0036 
0037     /**
0038      * @brief The OperatorDistribution constructor.
0039      * @param gr1: the Grid object for the first variable
0040      * @param gr2: the Grid object for the second variable
0041      * @param OD: the OperatorDistribution container
0042      */
0043     OperatorDistribution(Grid const& gr1, Grid const& gr2, std::vector<std::vector<matrix<std::vector<double>>>> const& OD);
0044 
0045     /**
0046      * @brief The OperatorDistribution constructor.
0047      * @param O1: the operator on the first variable
0048      * @param d2: the distribution on the second variable
0049      */
0050     OperatorDistribution(Operator const& O1, Distribution const& d2);
0051 
0052     /**
0053      * @brief The OperatorDistribution constructor.
0054      * @param DObj: DoubleObject of operators and distributions
0055      */
0056     OperatorDistribution(DoubleObject<Operator, Distribution> const& DObj);
0057 
0058     /**
0059      * @brief The Operator virtual destructor.
0060      */
0061     virtual ~OperatorDistribution() {}
0062 
0063     /**
0064      * @name Evaluate functions
0065      * List of functions that perform the interpolation on the x-space
0066      * grids.
0067      */
0068     ///@{
0069     /**
0070      * @brief Function that evaluates the Distribution part in a given
0071      * point through interpolation.
0072      * @param x: the value in x where the distribution part is to be interpolated
0073      * @return the interpolated result
0074      */
0075     Operator Evaluate(double const& x) const;
0076 
0077     /**
0078      * @brief Function that evaluates the derivative of the Distribution
0079      * part in a given point through interpolation.
0080      * @param x: the value in x where the distribution part is to be interpolated
0081      * @return the derivative of the interpolated function
0082      */
0083     Operator Derive(double const& x) const;
0084 
0085     /**
0086      * @brief Function that evaluates the integral of the Distribution
0087      * part in the interval[a, b].
0088      * @param a: the lower integration bound for the first variable
0089      * @param b: the upper integration bound for the first variable
0090      * @return the integral of the interpolated function
0091      */
0092     Operator Integrate(double const& a, double const& b) const;
0093     ///@}
0094 
0095     /**
0096      * @name Binary operators
0097      */
0098     ///@{
0099     DoubleDistribution operator    *= (Distribution const& d) const;                                  //!< this *= Distribution
0100     OperatorDistribution& operator *= (Operator const& o);                                            //!< this *= Operator
0101     OperatorDistribution& operator *= (double const& s);                                              //!< this *= Scalar
0102     OperatorDistribution& operator /= (double const& s);                                              //!< this /= Scalar
0103     OperatorDistribution& operator += (OperatorDistribution const& o);                                //!< this += OperatorDistribution
0104     OperatorDistribution& operator -= (OperatorDistribution const& o);                                //!< this -= OperatorDistribution
0105     OperatorDistribution& operator  = (OperatorDistribution const& o);                                //!< this  = OperatorDistribution
0106     OperatorDistribution& operator *= (std::function<double(double const&, double const&)> const& f); //!< this *= Function of both variables
0107     OperatorDistribution& operator *= (std::function<double(double const&)> const& f);                //!< this *= Function of one variable used for both variables
0108     ///@}
0109 
0110     /**
0111      * @brief Function that returns the first Grid object.
0112      */
0113     Grid const& GetFirstGrid() const { return _grid1; }
0114 
0115     /**
0116      * @brief Function that returns the second Grid object.
0117      */
0118     Grid const& GetSecondGrid() const { return _grid2; }
0119 
0120     /**
0121      * @brief Function that returns the OperatorDistribution container.
0122      */
0123     std::vector<std::vector<matrix<std::vector<double>>>> GetOperatorDistribution() const { return _dOperator; }
0124 
0125     /**
0126      * @brief Function that prints the OperatorDistribution object
0127      */
0128     void Print() const { std::cout << *this << std::endl; }
0129 
0130   private:
0131     Grid                                           const& _grid1;      //!< First grid
0132     Grid                                           const& _grid2;      //!< Second grid
0133     LagrangeInterpolator                           const  _li2;        //!< The Lagrange interpolator on the second grid
0134     std::vector<std::vector<matrix<std::vector<double>>>> _dOperator;  //!< OperatorDistribution container
0135 
0136     friend std::ostream& operator << (std::ostream& os, OperatorDistribution const& opd);
0137   };
0138 
0139   /**
0140    * @name Ternary operators
0141    */
0142   ///@{
0143   DoubleDistribution   operator * (OperatorDistribution const& lhs, Distribution const& rhs);                               //!< OperatorDistribution*Distribution
0144   OperatorDistribution operator * (OperatorDistribution lhs, Operator const& rhs);                                          //!< OperatorDistribution*Operator
0145   OperatorDistribution operator * (double const& s, OperatorDistribution rhs);                                              //!< Scalar*OperatorDistribution
0146   OperatorDistribution operator * (OperatorDistribution lhs, double const& s);                                              //!< OperatorDistribution*Scalar
0147   OperatorDistribution operator / (OperatorDistribution lhs, double const& s);                                              //!< OperatorDistribution/Scalar
0148   OperatorDistribution operator + (OperatorDistribution lhs, OperatorDistribution const& rhs);                              //!< OperatorDistribution+Operator
0149   OperatorDistribution operator - (OperatorDistribution lhs, OperatorDistribution const& rhs);                              //!< OperatorDistribution-OperatorDistribution
0150   OperatorDistribution operator * (std::function<double(double const&, double const&)> const& f, OperatorDistribution rhs); //!< Function*OperatorDistribution
0151   OperatorDistribution operator * (OperatorDistribution lhs, std::function<double(double const&, double const&)> const& f); //!< OperatorDistribution*Function
0152   OperatorDistribution operator * (std::function<double(double const&)> const& f, OperatorDistribution rhs);                //!< Function*OperatorDistribution
0153   OperatorDistribution operator * (OperatorDistribution lhs, std::function<double(double const&)> const& f);                //!< OperatorDistribution*Function
0154   ///@}
0155 
0156   /**
0157    * @brief Method which prints OperatorDistribution with cout <<.
0158    */
0159   std::ostream& operator << (std::ostream& os, OperatorDistribution const& in);
0160 }
0161