Commit 17582218 authored by Christoph Grüninger's avatar Christoph Grüninger
Browse files

[cleanup] Enable ADL for std::pow etc. in dumux/common

parent 5e38b99d
......@@ -1169,8 +1169,10 @@ private:
corner = geometry.corner(vLocalIdx);
for (std::size_t dimIdx = 0; dimIdx < dimworld; ++dimIdx)
{
xMin[dimIdx] = std::min(xMin[dimIdx], corner[dimIdx]);
xMax[dimIdx] = std::max(xMax[dimIdx], corner[dimIdx]);
using std::max;
using std::min;
xMin[dimIdx] = min(xMin[dimIdx], corner[dimIdx]);
xMax[dimIdx] = max(xMax[dimIdx], corner[dimIdx]);
}
}
}
......
......@@ -27,6 +27,8 @@
#ifndef DIMENSIONLESS_NUMBERS_HH
#define DIMENSIONLESS_NUMBERS_HH
#include <cmath>
#include <dune/common/exceptions.hh>
namespace Dumux
......@@ -148,13 +150,15 @@ static Scalar nusseltNumberForced(const Scalar reynoldsNumber,
* Dittus, F.W and Boelter, L.M.K, Heat Transfer in Automobile Radiators of the Tubular Type,
* Publications in Engineering, Vol. 2, pages 443-461, 1930
*/
return 0.023 * pow(reynoldsNumber, 0.8) * pow(prandtlNumber,0.33);
using std::pow;
return 0.023 * pow(reynoldsNumber, 0.8) * pow(prandtlNumber,0.33);
}
else if (formulation == NusseltFormulation::WakaoKaguei){
/* example: flow through porous medium *single phase*, fit to many different data
* Wakao and Kaguei, Heat and mass Transfer in Packed Beds, Gordon and Breach Science Publishers, page 293
*/
using std::pow;
return 2. + 1.1 * pow(prandtlNumber,(1./3.)) * pow(reynoldsNumber, 0.6);
}
......@@ -163,6 +167,8 @@ static Scalar nusseltNumberForced(const Scalar reynoldsNumber,
* valid for 0.1<Re<10000, 0.6<Pr/Sc<10000, packed beds of perfect spheres.
*
*/
using std::sqrt;
using std::pow;
Scalar numerator = 0.037 * pow(reynoldsNumber,0.8) * prandtlNumber ;
Scalar reToMin01 = pow(reynoldsNumber,-0.1);
Scalar prTo23 = pow(prandtlNumber, (2./3. ) ) ; // MIND THE pts! :-( otherwise the integer exponent version is chosen
......
......@@ -24,6 +24,7 @@
#ifndef DUMUX_EIGENVALUES_HH
#define DUMUX_EIGENVALUES_HH
#include <algorithm>
#include <cmath>
#include "math.hh"
......@@ -50,7 +51,8 @@ double calcOffDiagonalNorm(Matrix& matrix)
norm += matrix[i][j] * matrix[i][j];
}
return std::sqrt(norm);
using std::sqrt;
return sqrt(norm);
}
//! Function to calculate eigenvalues of n x n matrices
......@@ -72,10 +74,12 @@ bool calculateEigenValues(EVVectorType &eigVel, MatrixType& matrix, double relat
eigVel[0] = (-b + sqrt(b * b - 4.0 * c)) / 2.0;
eigVel[1] = (-b - sqrt(b * b - 4.0 * c)) / 2.0;
if (std::isnan(eigVel[0]) || std::isinf(eigVel[0]))
using std::isnan;
using std::isinf;
if (isnan(eigVel[0]) || isinf(eigVel[0]))
return false;
if (std::isnan(eigVel[1]) || std::isinf(eigVel[1]))
if (isnan(eigVel[1]) || isinf(eigVel[1]))
return false;
return true;
......@@ -99,9 +103,10 @@ bool calculateEigenValues(EVVectorType &eigVel, MatrixType& matrix, double relat
double theta = (evMatrix[i][i] - evMatrix[j][j])
/ (2 * evMatrix[i][j]);
double t = sign(theta)
/ (std::abs(theta) + std::sqrt(1 + theta * theta));
double c = 1 / std::sqrt(1 + t * t);
using std::abs;
using std::sqrt;
double t = sign(theta) / (abs(theta) + sqrt(1 + theta * theta));
double c = 1 / sqrt(1 + t * t);
double s = c * t;
rotationMatrix[i][i] = c;
......@@ -125,7 +130,9 @@ bool calculateEigenValues(EVVectorType &eigVel, MatrixType& matrix, double relat
for (int i = 0; i < dim; i++)
{
eigVel[i] = evMatrix[i][i];
if (std::isnan(eigVel[i]) || std::isinf(eigVel[i]))
using std::isinf;
using std::isnan;
if (isnan(eigVel[i]) || isinf(eigVel[i]))
return false;
}
......@@ -164,9 +171,10 @@ bool calculateEigenValues(EVVectorType &eigVel, MatrixType& eigVec, MatrixType&
double theta = (evMatrix[i][i] - evMatrix[j][j])
/ (2 * evMatrix[i][j]);
double t = sign(theta)
/ (std::abs(theta) + std::sqrt(1 + theta * theta));
double c = 1 / std::sqrt(1 + t * t);
using std::abs;
using std::sqrt;
double t = sign(theta) / (abs(theta) + sqrt(1 + theta * theta));
double c = 1 / sqrt(1 + t * t);
double s = c * t;
rotationMatrix[i][i] = c;
......@@ -191,7 +199,9 @@ bool calculateEigenValues(EVVectorType &eigVel, MatrixType& eigVec, MatrixType&
for (int i = 0; i < dim; i++)
{
eigVel[i] = evMatrix[i][i];
if (std::isnan(eigVel[i]) || std::isinf(eigVel[i]))
using std::isinf;
using std::isnan;
if (isnan(eigVel[i]) || isinf(eigVel[i]))
return false;
for (int j = 0; j < dim; j++)
{
......
......@@ -23,12 +23,12 @@
#ifndef DUMUX_MATH_HH
#define DUMUX_MATH_HH
#include <algorithm>
#include <cmath>
#include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh>
#include <cmath>
#include <algorithm>
namespace Dumux
{
/*!
......@@ -58,7 +58,8 @@ Scalar geometricMean(Scalar x, Scalar y)
{
if (x*y <= 0)
return 0;
return std::sqrt(x*y)*((x < 0)?-1:1);
using std::sqrt;
return sqrt(x*y)*sign(x);
}
/*!
......@@ -147,7 +148,8 @@ int invertQuadraticPolynomial(SolContainer &sol,
if (Delta < 0)
return 0; // no real roots
Delta = std::sqrt(Delta);
using std::sqrt;
Delta = sqrt(Delta);
sol[0] = (- b + Delta)/(2*a);
sol[1] = (- b - Delta)/(2*a);
......@@ -181,7 +183,8 @@ void invertCubicPolynomialPostProcess_(SolContainer &sol,
x -= fOld/fPrime;
Scalar fNew = d + x*(c + x*(b + x*a));
if (std::abs(fNew) < std::abs(fOld))
using std::abs;
if (abs(fNew) < abs(fOld))
sol[i] = x;
}
}
......@@ -308,10 +311,12 @@ int invertCubicPolynomial(SolContainer *sol,
}
else { // the negative discriminant case:
Scalar uCubedRe = - q/2;
Scalar uCubedIm = std::sqrt(-wDisc);
using std::sqrt;
Scalar uCubedIm = sqrt(-wDisc);
// calculate the cube root of - q/2 + sqrt(q^2/4 + p^3/27)
Scalar uAbs = std::pow(std::sqrt(uCubedRe*uCubedRe + uCubedIm*uCubedIm), 1.0/3);
Scalar phi = std::atan2(uCubedIm, uCubedRe)/3;
using std::atan2;
Scalar phi = atan2(uCubedIm, uCubedRe)/3;
// calculate the length and the angle of the primitive root
......@@ -353,7 +358,8 @@ int invertCubicPolynomial(SolContainer *sol,
// values for phi which differ by 2/3*pi. This allows to
// calculate the three real roots of the polynomial:
for (int i = 0; i < 3; ++i) {
sol[i] = std::cos(phi)*(uAbs - p/(3*uAbs)) - b/3;
using std::cos;
sol[i] = cos(phi)*(uAbs - p/(3*uAbs)) - b/3;
phi += 2*M_PI/3;
}
......@@ -362,7 +368,8 @@ int invertCubicPolynomial(SolContainer *sol,
invertCubicPolynomialPostProcess_(sol, 3, a, b, c, d);
// sort the result
std::sort(sol, sol + 3);
using std::sort;
sort(sol, sol + 3);
return 3;
}
......@@ -472,7 +479,8 @@ Scalar antoine(Scalar temperature,
Scalar C)
{
const Scalar ln10 = 2.3025850929940459;
return std::exp(ln10*(A - B/(C + temperature)));
using std::exp;
return exp(ln10*(A - B/(C + temperature)));
}
/*!
......
......@@ -23,6 +23,7 @@
#ifndef DUMUX_SPLINE_COMMON__HH
#define DUMUX_SPLINE_COMMON__HH
#include <algorithm>
#include <iostream>
#include <cassert>
......@@ -88,8 +89,10 @@ public:
*/
void printCSV(Scalar xi0, Scalar xi1, int k) const
{
Scalar x0 = std::min(xi0, xi1);
Scalar x1 = std::max(xi0, xi1);
using std::max;
using std::min;
Scalar x0 = min(xi0, xi1);
Scalar x1 = max(xi0, xi1);
const int n = numSamples_() - 1;
for (int i = 0; i <= k; ++i) {
double x = i*(x1 - x0)/k + x0;
......@@ -116,7 +119,7 @@ public:
else {
y = eval(x);
dy_dx = evalDerivative(x);
mono = monotonic(std::max<Scalar>(x_(0), x), std::min<Scalar>(x_(n), x_p1));
mono = monotonic(max<Scalar>(x_(0), x), min<Scalar>(x_(n), x_p1));
}
std::cout << x << " " << y << " " << dy_dx << " " << mono << "\n";
......@@ -552,7 +555,8 @@ protected:
// not exhibit any extrema.
return (x0*(x0*3*a + 2*b) + c > 0) ? 1 : -1;
}
disc = std::sqrt(disc);
using std::sqrt;
disc = sqrt(disc);
Scalar xE1 = (-2*b + disc)/(6*a);
Scalar xE2 = (-2*b - disc)/(6*a);
......@@ -591,8 +595,9 @@ protected:
b_(segIdx) - b,
c_(segIdx) - c,
d_(segIdx) - d);
x0 = std::max(x_(segIdx), x0);
x1 = std::max(x_(segIdx+1), x1);
using std::max;
x0 = max(x_(segIdx), x0);
x1 = max(x_(segIdx+1), x1);
// filter the intersections outside of the specified intervall
int k = 0;
......
......@@ -163,8 +163,10 @@ public:
Scalar alpha = xToI(x);
Scalar beta = yToJ(y);
int i = std::max(0, std::min(m_, static_cast<int>(alpha)));
int j = std::max(0, std::min(n_, static_cast<int>(beta)));
using std::max;
using std::min;
int i = max(0, min(m_, static_cast<int>(alpha)));
int j = max(0, min(n_, static_cast<int>(beta)));
alpha -= i;
beta -= j;
......
......@@ -23,6 +23,8 @@
#ifndef DUMUX_TIME_MANAGER_HH
#define DUMUX_TIME_MANAGER_HH
#include <algorithm>
#include <dune/common/float_cmp.hh>
#include <dune/common/timer.hh>
#include <dune/common/parallel/mpihelper.hh>
......@@ -201,7 +203,10 @@ public:
* \param dt The new value for the time step size \f$\mathrm{[s]}\f$
*/
void setTimeStepSize(Scalar dt)
{ timeStepSize_ = std::min(dt, maxTimeStepSize()); }
{
using std::min;
timeStepSize_ = min(dt, maxTimeStepSize());
}
/*!
* \brief Returns the suggested time step length \f$\mathrm{[s]}\f$ so that we
......@@ -259,10 +264,11 @@ public:
if (finished())
return 0.0;
return
std::min(std::min(episodeMaxTimeStepSize(),
problem_->maxTimeStepSize()),
std::max<Scalar>(0.0, endTime() - time()));
using std::max;
using std::min;
return min(min(episodeMaxTimeStepSize(),
problem_->maxTimeStepSize()),
max<Scalar>(0.0, endTime() - time()));
}
/*
......@@ -357,9 +363,8 @@ public:
// make sure that we don't exceed the end of the
// current episode.
return
std::max<Scalar>(0.0,
episodeLength() - (time() - episodeStartTime()));
using std::max;
return max<Scalar>(0.0, episodeLength() - (time() - episodeStartTime()));
}
/*
......@@ -422,7 +427,8 @@ public:
if (Dune::FloatCmp::eq<Scalar>(dt, timeStepSize()))
{
// set the initial time step size of a an episode to the last real time step size before the episode
Scalar nextDt = std::max(previousTimeStepSize_, timeStepSize());
using std::max;
Scalar nextDt = max(previousTimeStepSize_, timeStepSize());
previousTimeStepSize_ = nextDt;
setTimeStepSize(nextDt);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment