COMP: resolve clamp() float/double ambiguity (SPDP compilation)

- pass by value instead of reference, add functional casts in some
  places. Can still rely on integer promotions though.

  OK:   clamp(value, 2, 20)   ==> (float, int, int)
  OK:   clamp(value, scalar(2), scalar(20))  ==> (float, float, float)
  NOK:  clamp(value, 2.0, 20) ==> (float, double, int)
This commit is contained in:
Mark Olesen 2023-02-23 14:38:19 +01:00
parent 28b492bd54
commit cdcbd05587
15 changed files with 29 additions and 30 deletions

View File

@ -1,7 +1,2 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -28,7 +28,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "argList.H"
#include "Time.H"
#include "BitOps.H"
#include "HashOps.H"

View File

@ -100,8 +100,8 @@ void Foam::adaptiveSolver::solve
// If the error is small increase the step-size
if (err > pow(maxScale_/safeScale_, -1.0/alphaInc_))
{
dxTry =
clamp(safeScale_*pow(err, -alphaInc_), minScale_, maxScale_)*dx;
scalar scale = safeScale_*pow(err, -alphaInc_);
dxTry = clamp(scale, minScale_, maxScale_)*dx;
}
else
{

View File

@ -334,7 +334,7 @@ inline Foam::scalar Foam::triangle<Point, PointRef>::circumRadius() const
}
const scalar a = (d1 + d2)*(d2 + d3)*(d3 + d1) / denom;
return 0.5*Foam::sqrt(clamp(a, 0, GREAT));
return 0.5*Foam::sqrt(clamp(a, scalar(0), scalar(GREAT)));
}

View File

@ -302,7 +302,7 @@ inline Scalar clamp(const Scalar val, const Foam::zero_one)
// Fast implementation, and with scalar promotion of upper/lower limits
inline Scalar clamp(const Scalar& val, const Scalar& lower, const Scalar& upper)
inline Scalar clamp(const Scalar val, const Scalar lower, const Scalar upper)
{
return (val < lower) ? lower : (upper < val) ? upper : val;
}

View File

@ -41,12 +41,12 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define MAXMINPOW(retType, type1, type2) \
#define MAXMINPOW(RetType, Type1, Type2) \
\
MAXMIN(retType, type1, type2) \
MAXMIN(RetType, Type1, Type2) \
\
/*! \brief Raise base to the power expon */ \
inline double pow(const type1 base, const type2 expon) \
inline double pow(const Type1 base, const Type2 expon) \
{ \
return ::pow(double(base), double(expon)); \
}

View File

@ -47,16 +47,16 @@ SourceFiles
namespace Foam
{
#define MAXMIN(retType, type1, type2) \
#define MAXMIN(RetType, Type1, Type2) \
\
/*! \brief Floating/integral min. Use stdFoam::min() to preserve references */ \
inline retType min(const type1 s1, const type2 s2) \
inline RetType min(const Type1 s1, const Type2 s2) \
{ \
return (s1 < s2) ? s1 : s2; \
} \
\
/*! \brief Floating integral max. Use stdFoam::max() to preserve references */ \
inline retType max(const type1 s1, const type2 s2) \
inline RetType max(const Type1 s1, const Type2 s2) \
{ \
return (s2 < s1) ? s1 : s2; \
}

View File

@ -48,16 +48,16 @@ SourceFiles
namespace Foam
{
#define MAXMIN(retType, type1, type2) \
#define MAXMIN(RetType, Type1, Type2) \
\
/*! \brief Floating/integral min. Use stdFoam::min() to preserve references */ \
inline retType min(const type1 s1, const type2 s2) \
inline RetType min(const Type1 s1, const Type2 s2) \
{ \
return (s1 < s2) ? s1 : s2; \
} \
\
/*! \brief Floating/integral max. Use stdFoam::max() to preserve references */ \
inline retType max(const type1 s1, const type2 s2) \
inline RetType max(const Type1 s1, const Type2 s2) \
{ \
return (s2 < s1) ? s1 : s2; \
}

View File

@ -310,7 +310,7 @@ tmp<volScalarField::Internal> kOmegaSSTLM<BasicTurbulenceModel>::ReThetat0
}
lambda = sqr(thetat)/nu[celli]*dUsds[celli];
lambda = clamp(lambda, -0.1, 0.1);
lambda = clamp(lambda, scalar(-0.1), scalar(0.1));
lambdaErr = mag(lambda - lambda0);

View File

@ -108,14 +108,17 @@ void Foam::combustionModels::EDC<ReactionThermo>::correct()
{
const scalar nu = mu[i]/(rho[i] + SMALL);
const scalar Da =
clamp(sqrt(nu/(epsilon[i] + SMALL))/tc[i], 1e-10, 10);
const scalar Da = clamp
(
sqrt(nu/(epsilon[i] + SMALL))/tc[i],
scalar(1e-10), scalar(10)
);
const scalar ReT = sqr(k[i])/(nu*epsilon[i] + SMALL);
const scalar CtauI = min(C1_/(Da*sqrt(ReT + 1)), 2.1377);
const scalar CgammaI =
clamp(C2_*sqrt(Da*(ReT + 1)), 0.4082, 5);
clamp(C2_*sqrt(Da*(ReT + 1)), scalar(0.4082), scalar(5));
const scalar gammaL =
CgammaI*pow025(nu*epsilon[i]/(sqr(k[i]) + SMALL));

View File

@ -259,7 +259,7 @@ void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
*(orientation_*sign(forceDiff))
);
openFraction_ = clamp(openFraction_, 1e-6, 1 - 1e-6);
openFraction_ = clamp(openFraction_, scalar(1e-6), scalar(1 - 1e-6));
Info<< "openFraction = " << openFraction_ << endl;

View File

@ -310,7 +310,7 @@ void Foam::activePressureForceBaffleVelocityFvPatchVectorField::updateCoeffs()
baffleActivated_ = true;
}
openFraction_ = clamp(openFraction_, 1e-6, 1 - 1e-6);
openFraction_ = clamp(openFraction_, scalar(1e-6), scalar(1 - 1e-6));
if (Pstream::master())
{

View File

@ -82,7 +82,7 @@ public:
faceFlux, phiP, phiN, gradcP, gradcN, d
);
scalar limitPhict = clamp(phict, 0, 0.5);
scalar limitPhict = clamp(phict, scalar(0), scalar(0.5));
return limitPhict/(1 - limitPhict);
}
};

View File

@ -93,7 +93,7 @@ public:
/(max(mag(dcP), mag(dcN)) + SMALL);
// Limit the limiter between linear and 20% upwind
return clamp(limiter, 0.8, 1);
return clamp(limiter, scalar(0.8), scalar(1));
}
};

View File

@ -167,7 +167,8 @@ void Foam::lineSearch::reset()
// step_ = 2*(oldMeritValue_-prevMeritValue_)/directionalDeriv_;
// Interpolate in order to get same improvement with the previous
// optimisation cycle
step_ = clamp(step_*prevMeritDeriv_/directionalDeriv_, minStep_, 1);
step_ =
clamp(step_*prevMeritDeriv_/directionalDeriv_, minStep_, scalar(1));
Info<< "\n------- Computing initial step-------" << endl;
Info<< "old dphi(0) " << prevMeritDeriv_ << endl;
Info<< "dphi(0) " << directionalDeriv_ << endl;