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/doubleexpression.h"
0010 #include "apfel/grid.h"
0011 #include "apfel/matrix.h"
0012 #include "apfel/operator.h"
0013 #include "apfel/doubledistribution.h"
0014 #include "apfel/distributionoperator.h"
0015 #include "apfel/operatordistribution.h"
0016 #include "apfel/config.h"
0017 
0018 // Include yaml-cpp header only if it has been found at configuration
0019 // time.
0020 #ifdef WITH_YAML_CPP
0021 #include <yaml-cpp/yaml.h>
0022 #endif
0023 
0024 namespace apfel
0025 {
0026   /**
0027    * @brief This class defines the basic object DoubleOperator which
0028    * essentially contains the convolution bewteen a "DoubleExpression"
0029    * object and two sets of interpolanting functions defined on two
0030    * independent grids. This is the two-dimensional generalisation of
0031    * the object "Operator".
0032    * @note For the moment, only the inclusive massless case can be
0033    * handled within this class.
0034    */
0035   class DoubleOperator
0036   {
0037   public:
0038     DoubleOperator() = delete;
0039     DoubleOperator(DoubleOperator const&) = default;
0040 
0041     /**
0042      * @brief The DoubleOperator constructor.
0043      * @param gr1: the Grid object for the first variable
0044      * @param gr2: the Grid object for the second variable
0045      * @param dexpr: the double expression to be convoluted
0046      * @param eps: relative accuracy of the numerical integrations (default: 10<SUP>-3</SUP>)
0047      */
0048     DoubleOperator(Grid const& gr1, Grid const& gr2, DoubleExpression const& dexpr, double const& eps = 1e-3);
0049 
0050     /**
0051      * @brief The DoubleOperator constructor.
0052      * @param O1: the first single operator
0053      * @param O2: the second single operator
0054      */
0055     DoubleOperator(Operator const& O1, Operator const& O2);
0056 
0057     /**
0058      * @brief The DoubleOperator constructor.
0059      * @param DObj: double object of operators
0060      */
0061     DoubleOperator(DoubleObject<Operator> const& DObj);
0062 
0063 // #if WITH_YAML_CPP == 1
0064 #ifdef WITH_YAML_CPP
0065     /**
0066      * @brief The DoubleOperator constructor.
0067      * @param Node: YAML Node where the DoubleOperator object is strored
0068      * @param gr1: the Grid object for the first variable
0069      * @param gr2: the Grid object for the second variable
0070      * @param dexpr: the double expression to be convoluted needed to compare names
0071      */
0072     DoubleOperator(YAML::Node const& Node, Grid const& gr1, Grid const& gr2, DoubleExpression const& dexpr);
0073 
0074     /**
0075      * @brief Function the encapsulate a DoubleOperator object in a
0076      * YAML::Emitter objects such that it can be written on file.
0077      */
0078     std::string EmitDoubleOperator() const;
0079 #endif
0080 
0081     /**
0082      * @brief The Operator virtual destructor.
0083      */
0084     virtual ~DoubleOperator() {}
0085 
0086     /**
0087      * @name Binary operators
0088      */
0089     ///@{
0090     DistributionOperator MultiplyFirstBy(Distribution const& d) const;                      //!< this times a distribution convoluted with the first variable
0091     OperatorDistribution MultiplySecondBy(Distribution const& d) const;                     //!< this times a distribution convoluted with the second variable
0092     DoubleDistribution operator *= (DoubleDistribution const& d) const;                     //!< this *= DoubleDistribution
0093     DoubleOperator&    operator *= (double const& s);                                       //!< this *= Scalar
0094     DoubleOperator&    operator /= (double const& s);                                       //!< this /= Scalar
0095     DoubleOperator&    operator += (DoubleOperator const& o);                               //!< this += DoubleOperator
0096     DoubleOperator&    operator -= (DoubleOperator const& o);                               //!< this -= DoubleOperator
0097     DoubleOperator&    operator *= (DoubleOperator const& o);                               //!< this *= DoubleOperator
0098     DoubleOperator&    operator  = (DoubleOperator const& o);                               //!< this  = DoubleOperator
0099     DoubleOperator&    operator *= (std::function<double(double const&, double const&)> f); //!< this *= 2D-function
0100     DoubleOperator&    operator *= (std::function<double(double const&)> f);                //!< this *= 1D-Function
0101     ///@}
0102 
0103     /**
0104      * @brief Function that returns the first Grid object associated
0105      * with the double operator.
0106      */
0107     Grid const& GetFirstGrid() const { return _grid1; }
0108 
0109     /**
0110      * @brief Function that returns the second Grid object associated
0111      * with the double operator.
0112      */
0113     Grid const& GetSecondGrid() const { return _grid2; }
0114 
0115     /**
0116      * @brief Function that returns the integration accuracy.
0117      */
0118     double const& GetIntegrationAccuracy() const { return _eps; }
0119 
0120     /**
0121      * @brief Function that returns the name of the DoubleExpression
0122      * object associated with the operator.
0123      */
0124     std::string const& GetDoubleExpressionName() const { return _dexprName; }
0125 
0126     /**
0127      * @brief Function that returns the DoubleOperator container.
0128      */
0129     std::vector<std::vector<matrix<matrix<double>>>> GetDoubleOperator() const { return _dOperator; }
0130 
0131     /**
0132      * @brief Function that prints the DoubleOperator object.
0133      */
0134     void Print() const { std::cout << *this << std::endl; }
0135 
0136   protected:
0137     Grid                                      const& _grid1;      //!< First grid on which to compute the operator
0138     Grid                                      const& _grid2;      //!< Second grid on which to compute the operator
0139     double                                    const  _eps;        //!< Integration accuracy
0140     std::string                               const  _dexprName;  //!< Name of the double expression
0141     std::vector<std::vector<matrix<matrix<double>>>> _dOperator;  //!< DoubleOperator container
0142 
0143     friend std::ostream& operator << (std::ostream& os, DoubleOperator const& dop);
0144   };
0145 
0146   /**
0147    * @name Ternary operators
0148    */
0149   ///@{
0150   DoubleDistribution   operator * (DoubleOperator const& lhs, DoubleDistribution const& rhs);                 //!< DoubleOperator*DoubleDistribution
0151   DistributionOperator operator * (Distribution const& lhs, DoubleOperator const& rhs);                       //!< Distribution*DoubleOperator = DistributionOperator
0152   OperatorDistribution operator * (DoubleOperator const& lhs, Distribution const& rhs);                       //!< DoubleOperator*Distribution = OperatorDistribution
0153   DoubleOperator       operator * (DoubleOperator lhs, DoubleOperator const& rhs);                            //!< DoubleOperator*DoubleOperator
0154   DoubleOperator       operator * (double const& s, DoubleOperator rhs);                                      //!< Scalar*DoubleOperator
0155   DoubleOperator       operator * (DoubleOperator lhs, double const& s);                                      //!< DoubleOperator*Scalar
0156   DoubleOperator       operator * (std::function<double(double const&, double const)> f, DoubleOperator rhs); //!< 2D-function*DoubleOperator
0157   DoubleOperator       operator * (DoubleOperator lhs, std::function<double(double const&, double const)> f); //!< DoubleOperator*2D-function
0158   DoubleOperator       operator * (std::function<double(double const&)> f, DoubleOperator rhs);               //!< 1D-function*DoubleOperator
0159   DoubleOperator       operator * (DoubleOperator lhs, std::function<double(double const&)> f);               //!< DoubleOperator*1D-function
0160   DoubleOperator       operator / (DoubleOperator lhs, double const& s);                                      //!< DoubleOperator/Scalar
0161   DoubleOperator       operator + (DoubleOperator lhs, DoubleOperator const& rhs);                            //!< DoubleOperator+DoubleOperator
0162   DoubleOperator       operator - (DoubleOperator lhs, DoubleOperator const& rhs);                            //!< DoubleOperator-DoubleOperator
0163   ///@}
0164 
0165   /**
0166    * @brief Method which prints DoubleOperator with std::cout <<.
0167    */
0168   std::ostream& operator << (std::ostream& os, DoubleOperator const& dop);
0169 }
0170