Back to home page

EIC code displayed by LXR

 
 

    


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

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 DistributionOperator class defines an object that
0021    * behaves as a distribution along the first variable and as an
0022    * operator along the second.
0023    */
0024   class DistributionOperator
0025   {
0026   public:
0027     DistributionOperator() = delete;
0028     DistributionOperator(DistributionOperator const&) = default;
0029 
0030     /**
0031      * @brief The DistributionOperator constructor.
0032      * @param gr1: the Grid object for the first variable
0033      * @param gr2: the Grid object for the second variable
0034      */
0035     DistributionOperator(Grid const& gr1, Grid const& gr2);
0036 
0037     /**
0038      * @brief The DistributionOperator constructor.
0039      * @param gr1: the Grid object for the first variable
0040      * @param gr2: the Grid object for the second variable
0041      * @param DO: the DistributionOperator container
0042      */
0043     DistributionOperator(Grid const& gr1, Grid const& gr2, std::vector<std::vector<std::vector<matrix<double>>>> const& DO);
0044 
0045     /**
0046      * @brief The DistributionOperator constructor.
0047      * @param d1: the distribution on the first variable
0048      * @param O2: the operator on the second variable
0049      */
0050     DistributionOperator(Distribution const& d1, Operator const& O2);
0051 
0052     /**
0053      * @brief The DistributionOperator constructor.
0054      * @param DObj: DoubleObject of distributions and operators
0055      */
0056     DistributionOperator(DoubleObject<Distribution, Operator> const& DObj);
0057 
0058     /**
0059      * @brief The Operator virtual destructor.
0060      */
0061     virtual ~DistributionOperator() {}
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     DistributionOperator& operator *= (Operator const& o);                                            //!< this *= Operator
0101     DistributionOperator& operator *= (double const& s);                                              //!< this *= Scalar
0102     DistributionOperator& operator /= (double const& s);                                              //!< this /= Scalar
0103     DistributionOperator& operator += (DistributionOperator const& o);                                //!< this += DistributionOperator
0104     DistributionOperator& operator -= (DistributionOperator const& o);                                //!< this -= DistributionOperator
0105     DistributionOperator& operator  = (DistributionOperator const& o);                                //!< this  = DistributionOperator
0106     DistributionOperator& operator *= (std::function<double(double const&, double const&)> const& f); //!< this *= Function of both variables
0107     DistributionOperator& 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 DistributionOperator container.
0122      */
0123     std::vector<std::vector<std::vector<matrix<double>>>> GetDistributionOperator() const { return _dOperator; }
0124 
0125     /**
0126      * @brief Function that prints the DistributionOperator 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  _li1;        //!< The Lagrange interpolator on the first grid
0134     std::vector<std::vector<std::vector<matrix<double>>>> _dOperator;  //!< DistributionOperator container
0135 
0136     friend std::ostream& operator << (std::ostream& os, DistributionOperator const& dop);
0137   };
0138 
0139   /**
0140    * @name Ternary operators
0141    */
0142   ///@{
0143   DoubleDistribution   operator * (DistributionOperator const& lhs, Distribution const& rhs);                               //!< DistributionOperator*Distribution
0144   DistributionOperator operator * (DistributionOperator lhs, Operator const& rhs);                                          //!< DistributionOperator*Operator
0145   DistributionOperator operator * (double const& s, DistributionOperator rhs);                                              //!< Scalar*DistributionOperator
0146   DistributionOperator operator * (DistributionOperator lhs, double const& s);                                              //!< DistributionOperator*Scalar
0147   DistributionOperator operator / (DistributionOperator lhs, double const& s);                                              //!< DistributionOperator/Scalar
0148   DistributionOperator operator + (DistributionOperator lhs, DistributionOperator const& rhs);                              //!< DistributionOperator+Operator
0149   DistributionOperator operator - (DistributionOperator lhs, DistributionOperator const& rhs);                              //!< DistributionOperator-DistributionOperator
0150   DistributionOperator operator * (std::function<double(double const&, double const&)> const& f, DistributionOperator rhs); //!< Function*DistributionOperator
0151   DistributionOperator operator * (DistributionOperator lhs, std::function<double(double const&, double const&)> const& f); //!< DistributionOperator*Function
0152   DistributionOperator operator * (std::function<double(double const&)> const& f, DistributionOperator rhs);                //!< Function*DistributionOperator
0153   DistributionOperator operator * (DistributionOperator lhs, std::function<double(double const&)> const& f);                //!< DistributionOperator*Function
0154   ///@}
0155 
0156   /**
0157    * @brief Method which prints DistributionOperator with cout <<.
0158    */
0159   std::ostream& operator << (std::ostream& os, DistributionOperator const& in);
0160 }
0161