OpenFOAM: Replaced hard-coded scalar limits with C++11 numeric_limits

This change simplifies maintenance and improved portability
This commit is contained in:
Henry Weller
2018-01-24 14:43:32 +00:00
parent 0222535462
commit c902c7a396
15 changed files with 144 additions and 108 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -113,7 +113,7 @@ public:
{
forAll(sf, i)
{
if (mag(sf[i]) >= scalar(floatScalarVSMALL))
if (mag(sf[i]) >= scalar(floatScalarVSmall))
{
str_ << setw(12) << sf[i] << nl;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -33,10 +33,10 @@ namespace Foam
const char* const pTraits<Scalar>::typeName = "scalar";
const Scalar pTraits<Scalar>::zero = 0.0;
const Scalar pTraits<Scalar>::one = 1.0;
const Scalar pTraits<Scalar>::min = -ScalarVGREAT;
const Scalar pTraits<Scalar>::max = ScalarVGREAT;
const Scalar pTraits<Scalar>::rootMin = -ScalarROOTVGREAT;
const Scalar pTraits<Scalar>::rootMax = ScalarROOTVGREAT;
const Scalar pTraits<Scalar>::min = -ScalarVGreat;
const Scalar pTraits<Scalar>::max = ScalarVGreat;
const Scalar pTraits<Scalar>::rootMin = -ScalarRootVGreat;
const Scalar pTraits<Scalar>::rootMax = ScalarRootVGreat;
const char* const pTraits<Scalar>::componentNames[] = { "" };

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -208,13 +208,13 @@ inline Scalar negPart(const Scalar s)
inline bool equal(const Scalar& s1, const Scalar& s2)
{
return mag(s1 - s2) <= ScalarVSMALL;
return mag(s1 - s2) <= ScalarVSmall;
}
inline bool notEqual(const Scalar s1, const Scalar s2)
{
return mag(s1 - s2) > ScalarVSMALL;
return mag(s1 - s2) > ScalarVSmall;
}
@ -343,7 +343,7 @@ inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
}
else
{
return magb < ScalarVSMALL ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
return magb < ScalarVSmall ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -31,17 +31,17 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define Scalar doubleScalar
#define ScalarVGREAT doubleScalarVGREAT
#define ScalarVSMALL doubleScalarVSMALL
#define ScalarROOTVGREAT doubleScalarROOTVGREAT
#define ScalarROOTVSMALL doubleScalarROOTVSMALL
#define ScalarVGreat doubleScalarVGreat
#define ScalarVSmall doubleScalarVSmall
#define ScalarRootVGreat doubleScalarRootVGreat
#define ScalarRootVSmall doubleScalarRootVSmall
#define readScalar readDoubleScalar
#include "Scalar.C"
#undef Scalar
#undef ScalarVGREAT
#undef ScalarVSMALL
#undef ScalarROOTVGREAT
#undef ScalarROOTVSMALL
#undef ScalarVGreat
#undef ScalarVSmall
#undef ScalarRootVGreat
#undef ScalarRootVSmall
#undef readScalar
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -39,6 +39,9 @@ SourceFiles
#include "direction.H"
#include "word.H"
#include <limits>
using std::numeric_limits;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -49,15 +52,17 @@ namespace Foam
typedef double doubleScalar;
// Largest and smallest scalar values allowed in certain parts of the code.
// (15 is the number of significant figures in an
// IEEE double precision number. See limits.h or float.h)
static const doubleScalar doubleScalarGREAT = 1.0e+15;
static const doubleScalar doubleScalarVGREAT = 1.0e+300;
static const doubleScalar doubleScalarROOTVGREAT = 1.0e+150;
static const doubleScalar doubleScalarSMALL = 1.0e-15;
static const doubleScalar doubleScalarROOTSMALL = 3.0e-8;
static const doubleScalar doubleScalarVSMALL = 1.0e-300;
static const doubleScalar doubleScalarROOTVSMALL = 1.0e-150;
static const doubleScalar doubleScalarVGreat = numeric_limits<double>::max();
static const doubleScalar doubleScalarVSmall = numeric_limits<double>::min();
static const doubleScalar doubleScalarSmall = numeric_limits<double>::epsilon();
static const doubleScalar doubleScalarGreat = 1.0/doubleScalarSmall;
static const doubleScalar doubleScalarRootVGreat = ::sqrt(doubleScalarVGreat);
static const doubleScalar doubleScalarRootVSmall = ::sqrt(doubleScalarVSmall);
static const doubleScalar doubleScalarRootGreat = ::sqrt(doubleScalarGreat);
static const doubleScalar doubleScalarRootSmall = ::sqrt(doubleScalarSmall);
//- Read whole of buf as a scalar. Return true if succesful.
inline bool readScalar(const char* buf, doubleScalar& s)
@ -69,10 +74,10 @@ inline bool readScalar(const char* buf, doubleScalar& s)
}
#define Scalar doubleScalar
#define ScalarVGREAT doubleScalarVGREAT
#define ScalarVSMALL doubleScalarVSMALL
#define ScalarROOTVGREAT doubleScalarROOTVGREAT
#define ScalarROOTVSMALL doubleScalarROOTVSMALL
#define ScalarVGreat doubleScalarVGreat
#define ScalarVSmall doubleScalarVSmall
#define ScalarRootVGreat doubleScalarRootVGreat
#define ScalarRootVSmall doubleScalarRootVSmall
#define readScalar readDoubleScalar
inline Scalar mag(const Scalar s)
@ -122,10 +127,10 @@ inline Scalar yn(const int n, const Scalar s)
}
#undef Scalar
#undef ScalarVGREAT
#undef ScalarVSMALL
#undef ScalarROOTVGREAT
#undef ScalarROOTVSMALL
#undef ScalarVGreat
#undef ScalarVSmall
#undef ScalarRootVGreat
#undef ScalarRootVSmall
#undef readScalar
#undef transFunc

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -31,17 +31,17 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define Scalar floatScalar
#define ScalarVGREAT floatScalarVGREAT
#define ScalarVSMALL floatScalarVSMALL
#define ScalarROOTVGREAT floatScalarROOTVGREAT
#define ScalarROOTVSMALL floatScalarROOTVSMALL
#define ScalarVGreat floatScalarVGreat
#define ScalarVSmall floatScalarVSmall
#define ScalarRootVGreat floatScalarRootVGreat
#define ScalarRootVSmall floatScalarRootVSmall
#define readScalar readFloatScalar
#include "Scalar.C"
#undef Scalar
#undef ScalarVSMALL
#undef ScalarVSMALL
#undef ScalarROOTVGREAT
#undef ScalarROOTVSMALL
#undef ScalarVSmall
#undef ScalarVSmall
#undef ScalarRootVGreat
#undef ScalarRootVSmall
#undef readScalar
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -39,6 +39,9 @@ SourceFiles
#include "direction.H"
#include "word.H"
#include <limits>
using std::numeric_limits;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -49,15 +52,17 @@ namespace Foam
typedef float floatScalar;
// Largest and smallest scalar values allowed in certain parts of the code
// (6 is the number of significant figures in an
// IEEE single precision number. See limits.h or float.h)
static const floatScalar floatScalarGREAT = 1.0e+6;
static const floatScalar floatScalarVGREAT = 1.0e+37;
static const floatScalar floatScalarROOTVGREAT = 1.0e+18;
static const floatScalar floatScalarSMALL = 1.0e-6;
static const floatScalar floatScalarROOTSMALL = 1.0e-3;
static const floatScalar floatScalarVSMALL = 1.0e-37;
static const floatScalar floatScalarROOTVSMALL = 1.0e-18;
static const floatScalar floatScalarVGreat = numeric_limits<float>::max();
static const floatScalar floatScalarVSmall = numeric_limits<float>::min();
static const floatScalar floatScalarSmall = numeric_limits<float>::epsilon();
static const floatScalar floatScalarGreat = 1.0/floatScalarSmall;
static const floatScalar floatScalarRootVGreat = ::sqrt(floatScalarVGreat);
static const floatScalar floatScalarRootVSmall = ::sqrt(floatScalarVSmall);
static const floatScalar floatScalarRootGreat = ::sqrt(floatScalarGreat);
static const floatScalar floatScalarRootSmall = ::sqrt(floatScalarSmall);
//- Read whole of buf as a scalar. Return true if succesful.
inline bool readScalar(const char* buf, floatScalar& s)
@ -69,10 +74,10 @@ inline bool readScalar(const char* buf, floatScalar& s)
}
#define Scalar floatScalar
#define ScalarVGREAT floatScalarVGREAT
#define ScalarVSMALL floatScalarVSMALL
#define ScalarROOTVGREAT floatScalarROOTVGREAT
#define ScalarROOTVSMALL floatScalarROOTVSMALL
#define ScalarVGreat floatScalarVGreat
#define ScalarVSmall floatScalarVSmall
#define ScalarRootVGreat floatScalarRootVGreat
#define ScalarRootVSmall floatScalarRootVSmall
#define readScalar readFloatScalar
inline Scalar mag(const Scalar s)
@ -122,10 +127,10 @@ inline Scalar yn(const int n, const Scalar s)
}
#undef Scalar
#undef ScalarVGREAT
#undef ScalarVSMALL
#undef ScalarROOTVGREAT
#undef ScalarROOTVSMALL
#undef ScalarVGreat
#undef ScalarVSmall
#undef ScalarRootVGreat
#undef ScalarRootVSmall
#undef readScalar
#undef transFunc

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -49,13 +49,14 @@ namespace Foam
{
typedef floatScalar scalar;
static const scalar GREAT = floatScalarGREAT;
static const scalar VGREAT = floatScalarVGREAT;
static const scalar ROOTVGREAT = floatScalarROOTVGREAT;
static const scalar SMALL = floatScalarSMALL;
static const scalar ROOTSMALL = floatScalarROOTSMALL;
static const scalar VSMALL = floatScalarVSMALL;
static const scalar ROOTVSMALL = floatScalarROOTVSMALL;
static const scalar great = floatScalarGreat;
static const scalar rootGreat = floatScalarRootGreat;
static const scalar vGreat = floatScalarVGreat;
static const scalar rootVGreat = floatScalarRootVGreat;
static const scalar small = floatScalarSmall;
static const scalar rootSmall = floatScalarRootSmall;
static const scalar vSmall = floatScalarVSmall;
static const scalar rootVSmall = floatScalarRootVSmall;
scalar readScalar(Istream& is);
}
@ -68,19 +69,33 @@ namespace Foam
{
typedef doubleScalar scalar;
static const scalar GREAT = doubleScalarGREAT;
static const scalar VGREAT = doubleScalarVGREAT;
static const scalar ROOTVGREAT = doubleScalarROOTVGREAT;
static const scalar SMALL = doubleScalarSMALL;
static const scalar ROOTSMALL = doubleScalarROOTSMALL;
static const scalar VSMALL = doubleScalarVSMALL;
static const scalar ROOTVSMALL = doubleScalarROOTVSMALL;
static const scalar great = doubleScalarGreat;
static const scalar rootGreat = doubleScalarRootGreat;
static const scalar vGreat = doubleScalarVGreat;
static const scalar rootVGreat = doubleScalarRootVGreat;
static const scalar small = doubleScalarSmall;
static const scalar rootSmall = doubleScalarRootSmall;
static const scalar vSmall = doubleScalarVSmall;
static const scalar rootVSmall = doubleScalarRootVSmall;
scalar readScalar(Istream& is);
}
#endif
//- Deprecated limit constant for backward-compatibility
namespace Foam
{
static const scalar GREAT = great;
static const scalar ROOTGREAT = rootGreat;
static const scalar VGREAT = vGreat;
static const scalar ROOTVGREAT = rootVGreat;
static const scalar SMALL = small;
static const scalar ROOTSMALL = rootSmall;
static const scalar VSMALL = vSmall;
static const scalar ROOTVSMALL = rootVSmall;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Additional transcendental functions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,25 +53,25 @@ const Foam::floatTensor Foam::floatTensor::vsType::one
template<>
const Foam::floatTensor Foam::floatTensor::vsType::max
(
floatTensor::uniform(floatScalarVGREAT)
floatTensor::uniform(floatScalarVGreat)
);
template<>
const Foam::floatTensor Foam::floatTensor::vsType::min
(
floatTensor::uniform(-floatScalarVGREAT)
floatTensor::uniform(-floatScalarVGreat)
);
template<>
const Foam::floatTensor Foam::floatTensor::vsType::rootMax
(
floatTensor::uniform(floatScalarROOTVGREAT)
floatTensor::uniform(floatScalarRootVGreat)
);
template<>
const Foam::floatTensor Foam::floatTensor::vsType::rootMin
(
floatTensor::uniform(-floatScalarROOTVGREAT)
floatTensor::uniform(-floatScalarRootVGreat)
);
template<>

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -54,25 +54,25 @@ const Foam::floatVector Foam::floatVector::vsType::one
template<>
const Foam::floatVector Foam::floatVector::vsType::max
(
floatVector::uniform(floatScalarVGREAT)
floatVector::uniform(floatScalarVGreat)
);
template<>
const Foam::floatVector Foam::floatVector::vsType::min
(
floatVector::uniform(-floatScalarVGREAT)
floatVector::uniform(-floatScalarVGreat)
);
template<>
const Foam::floatVector Foam::floatVector::vsType::rootMax
(
floatVector::uniform(floatScalarROOTVGREAT)
floatVector::uniform(floatScalarRootVGreat)
);
template<>
const Foam::floatVector Foam::floatVector::vsType::rootMin
(
floatVector::uniform(-floatScalarROOTVGREAT)
floatVector::uniform(-floatScalarRootVGreat)
);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -132,9 +132,18 @@ void Foam::triad::orthogonalize()
{
for (int i=0; i<2; i++)
{
scalar o01 = mag(operator[](0) & operator[](1));
scalar o02 = mag(operator[](0) & operator[](2));
scalar o12 = mag(operator[](1) & operator[](2));
const scalar o01
(
(set(0) && set(1)) ? mag(operator[](0) & operator[](1)) : VGREAT
);
const scalar o02
(
(set(0) && set(2)) ? mag(operator[](0) & operator[](2)) : VGREAT
);
const scalar o12
(
(set(1) && set(2)) ? mag(operator[](1) & operator[](2)) : VGREAT
);
if (o01 < o02 && o01 < o12)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -30,7 +30,7 @@ License
bool Foam::ensightFile::allowUndef_ = false;
Foam::scalar Foam::ensightFile::undefValue_ = Foam::floatScalarVGREAT;
Foam::scalar Foam::ensightFile::undefValue_ = Foam::floatScalarVGreat;
// default is width 8
Foam::string Foam::ensightFile::mask_ = "********";

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -125,7 +125,7 @@ void Foam::ensightSetWriter<Type>::write
forAll(points, pointi)
{
const scalar comp = points[pointi][cmpt];
if (mag(comp) >= scalar(floatScalarVSMALL))
if (mag(comp) >= scalar(floatScalarVSmall))
{
os << setw(12) << comp << nl;
}
@ -160,7 +160,7 @@ void Foam::ensightSetWriter<Type>::write
const scalarField fld(valueSets[setI]->component(cmpt));
forAll(fld, i)
{
if (mag(fld[i]) >= scalar(floatScalarVSMALL))
if (mag(fld[i]) >= scalar(floatScalarVSmall))
{
os << setw(12) << fld[i] << nl;
}
@ -243,7 +243,7 @@ void Foam::ensightSetWriter<Type>::write
forAll(points, pointi)
{
const scalar comp = points[pointi][cmpt];
if (mag(comp) >= scalar(floatScalarVSMALL))
if (mag(comp) >= scalar(floatScalarVSmall))
{
os << setw(12) << comp << nl;
}
@ -296,7 +296,7 @@ void Foam::ensightSetWriter<Type>::write
const scalarField fld(fieldVals[trackI].component(cmpt));
forAll(fld, i)
{
if (mag(fld[i]) >= scalar(floatScalarVSMALL))
if (mag(fld[i]) >= scalar(floatScalarVSmall))
{
os << setw(12) << fld[i] << nl;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -55,7 +55,7 @@ void Foam::DSMCCloud<ParcelType>::buildConstProps()
const dictionary& molDict(moleculeProperties.subDict(id));
constProps_[i] =
typename ParcelType::constantProperties::constantProperties(molDict);
typename ParcelType::constantProperties(molDict);
}
}
@ -1034,11 +1034,11 @@ Foam::scalar Foam::DSMCCloud<ParcelType>::equipartitionInternalEnergy
{
scalar Ei = 0.0;
if (iDof < SMALL)
if (iDof == 0)
{
return Ei;
}
else if (iDof < 2.0 + SMALL && iDof > 2.0 - SMALL)
else if (iDof == 2)
{
// Special case for iDof = 2, i.e. diatomics;
Ei = -log(rndGen_.scalar01())*physicoChemical::k.value()*temperature;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -475,12 +475,14 @@ Foam::scalar Foam::sweptFaceAreaWeightAMI<SourcePatch, TargetPatch>::interArea
srcNrm[i+1],
tgtTri
);
cutTriList<8> cutTrisTmp;
for (label i = 0; i < cutTris.size(); ++ i)
for (label j = 0; j < cutTris.size(); ++j)
{
triCut
(
cutTris[i],
cutTris[j],
cutPlane,
cut::noOp(),
cut::appendOp<cutTriList<8>>(cutTrisTmp)