Skip to content

Commit

Permalink
Adjusting operator class + updating CodeQL
Browse files Browse the repository at this point in the history
  • Loading branch information
vbertone committed Feb 10, 2024
1 parent 696b226 commit bd238f3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 32 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
#- name: Autobuild
# uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -59,9 +59,10 @@ jobs:
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
- run: |
sudo apt-get update
sudo apt-get install g++ cmake valgrind
cmake -DCMAKE_CXX_FLAGS="-g -fsanitize=address -std=c++17" . && make -j8
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
14 changes: 8 additions & 6 deletions inc/apfel/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ namespace apfel

/**
* @brief Function that builds a DGLAP-like operator.
* @param expr: the expression to be transformed
* @param eps: relative accuracy of the numerical integrations
*/
void BuildOperatorDGLAP(Expression const& expr, double const& eps);
void BuildOperatorDGLAP();

/**
* @brief Function that builds a GPD-like operator.
* @param expr: the expression to be transformed
* @param eps: relative accuracy of the numerical integrations
*/
void BuildOperatorGPD(Expression const& expr, double const& eps);
void BuildOperatorGPD();

/**
* @brief Function that interpolates the operator over the first
Expand All @@ -78,6 +74,11 @@ namespace apfel
*/
Grid const& GetGrid() const { return _grid; }

/**
* @brief Function that returns the Expression object associated to the operator.
*/
Expression const& GetExpression() const { return _expr; }

/**
* @brief Function that returns the integration accuracy
*/
Expand All @@ -100,6 +101,7 @@ namespace apfel

protected:
Grid const& _grid; //!< Grid on which to compute the operator
Expression const& _expr; //!< Expression to be used
double const _eps; //!< Integration accuracy
bool const _gpd; //!< GPD switch
std::vector<matrix<double>> _Operator; //!< Operator values
Expand Down
37 changes: 19 additions & 18 deletions src/kernel/operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ namespace apfel
//_________________________________________________________________________
Operator::Operator(Grid const& gr, Expression const& expr, double const& eps, bool const& gpd):
_grid(gr),
_expr(expr),
_eps(eps),
_gpd(gpd)
{
if (gpd)
BuildOperatorGPD(expr, eps);
BuildOperatorGPD();
else
BuildOperatorDGLAP(expr, eps);
BuildOperatorDGLAP();
}

//_________________________________________________________________________
void Operator::BuildOperatorDGLAP(Expression const& expr, double const& eps)
void Operator::BuildOperatorDGLAP()
{
// Interpolator object for the interpolating functions
const LagrangeInterpolator li{_grid};

// Scaling factor
const double eta = expr.eta();
const double eta = _expr.eta();

// Number of grids
const int ng = _grid.nGrids();
Expand All @@ -56,7 +57,7 @@ namespace apfel
const double s = sg.Step();

// Local function
const double L = eta * expr.Local(1 / exp(s) / eta);
const double L = eta * _expr.Local(1 / exp(s) / eta);

// Initialise operator
_Operator[ig].resize(1, nx);
Expand Down Expand Up @@ -95,10 +96,10 @@ namespace apfel
{
const double z = y / eta;
const double wr = li.InterpolantLog(alpha, log(xg[beta] / y), sg);
return expr.Regular(z) * wr + expr.Singular(z) * ( wr - ws );
return _expr.Regular(z) * wr + _expr.Singular(z) * ( wr - ws );
}};
// Compute the integral
I += Ij.integrate(exp((beta - alpha + j - 1) * s), exp((beta - alpha + j) * s), eps);
I += Ij.integrate(exp((beta - alpha + j - 1) * s), exp((beta - alpha + j) * s), _eps);
}
// Add the local part
_Operator[ig](beta, alpha) = I + L * ws;
Expand All @@ -108,13 +109,13 @@ namespace apfel
}

//_________________________________________________________________________
void Operator::BuildOperatorGPD(Expression const& expr, double const& eps)
void Operator::BuildOperatorGPD()
{
// Interpolator object for the interpolating functions
const LagrangeInterpolator li{_grid};

// Get skewness from the expression
const double xi = 1 / expr.eta();
const double xi = 1 / _expr.eta();

// Loop over the subgrids
_Operator.resize(1);
Expand All @@ -141,7 +142,7 @@ namespace apfel
// Set xg[beta] as external variable for the computation
// of the operator (this is in general not needed but in
// the case of GPD evolution).
expr.SetExternalVariable(xg[beta]);
_expr.SetExternalVariable(xg[beta]);

// Define "kappa" variable
const double kappa = xi / xg[beta];
Expand Down Expand Up @@ -180,22 +181,22 @@ namespace apfel
{
const double wr = li.Interpolant(alpha, xg[beta] / y, jg);
const double ky = kappa * y;
return expr.Regular(y) * wr
+ expr.Singular(y) * ( wr - ws * ( 1 + (y > 1 ? ( 1 - y ) / y : 0) ) )
+ expr.SingularPV(y) * ( wr - wspv * ( 1 + (ky > 1 ? ( 1 - ky ) / ky : 0) ) );
return _expr.Regular(y) * wr
+ _expr.Singular(y) * ( wr - ws * ( 1 + (y > 1 ? ( 1 - y ) / y : 0) ) )
+ _expr.SingularPV(y) * ( wr - wspv * ( 1 + (ky > 1 ? ( 1 - ky ) / ky : 0) ) );
}};
// Compute the integral
_Operator[0](beta, alpha) += Ij.integrate(xg[beta] / xg[alpha - j + 1], xg[beta] / xg[alpha - j], eps);
_Operator[0](beta, alpha) += Ij.integrate(xg[beta] / xg[alpha - j + 1], xg[beta] / xg[alpha - j], _eps);
}
// Add PV local part from the y = 1 / kappa singularity
_Operator[0](beta, alpha) += wspv * ( expr.LocalPV(xg[beta] / xg[alpha + 1]) - expr.LocalPV(xg[std::max(0, alpha - k)] / xg[beta] / pow(kappa, 2)) );
_Operator[0](beta, alpha) += wspv * ( _expr.LocalPV(xg[beta] / xg[alpha + 1]) - _expr.LocalPV(xg[std::max(0, alpha - k)] / xg[beta] / pow(kappa, 2)) );
}
// Add the local parts: that from standard +-prescripted terms
// ("Local") and that deriving from principal-valued integrals
// at x = 1, i.e. from the ++-prescription ("LocalPP").
_Operator[0](beta, beta) += expr.Local(xg[beta] / xg[beta + 1])
+ expr.LocalPP(xg[beta] / xg[beta + 1])
- (beta == 0 ? 0 : expr.LocalPP(xg[std::max(0, beta - k)] / xg[beta]));
_Operator[0](beta, beta) += _expr.Local(xg[beta] / xg[beta + 1])
+ _expr.LocalPP(xg[beta] / xg[beta + 1])
- (beta == 0 ? 0 : _expr.LocalPP(xg[std::max(0, beta - k)] / xg[beta]));
}
}

Expand Down
15 changes: 12 additions & 3 deletions tests/operator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ class p0qq: public apfel::Expression
{
public:
p0qq(): Expression() {}
double Regular(double const& x) const { return - 2 * apfel::CF * ( 1 + x ); }
double Singular(double const& x) const { return 4 * apfel::CF / ( 1 - x ); }
double Local(double const& x) const { return 4 * apfel::CF * log( 1 - x ) + 3 * apfel::CF; }
double Regular(double const& x) const
{
return - 2 * apfel::CF * ( 1 + x );
}
double Singular(double const& x) const
{
return 4 * apfel::CF / ( 1 - x );
}
double Local(double const& x) const
{
return 4 * apfel::CF * log( 1 - x ) + 3 * apfel::CF;
}
};

int main()
Expand Down

0 comments on commit bd238f3

Please sign in to comment.