STYLE: logical ops return bool (issue #1043)

- these currently only with bool parameters, but the return value should
  nonetheless always be a bool value:

      andOp(), orOp(), lessOp(), lessEqOp(), greaterOp(), greaterEqOp()

- renamed the unused eqEqOp() to equalOp() for naming consistency with
  the equal() global function.

ENH: equalOp() specialization for scalars

- function object version of the equal() function.
  The default constructor uses the same tolerance (VSMALL),
  but can also supply an alternative tolerance on construction.
This commit is contained in:
Mark Olesen
2018-10-17 07:59:26 +02:00
parent 0a0fee88a0
commit 8b569b16d1
3 changed files with 95 additions and 30 deletions

View File

@ -48,12 +48,6 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool notEqual(const scalar s1, const scalar s2, const scalar tol)
{
return mag(s1-s2) > tol;
}
// Main program:
int main(int argc, char *argv[])
{
@ -180,6 +174,8 @@ int main(int argc, char *argv[])
// Construct refiner. Read initial cell and point levels.
hexRef8 meshCutter(mesh);
// Comparison for inequality
const auto isNotEqual = notEqualOp<scalar>(1e-10);
while (runTime.loop())
{
@ -345,7 +341,7 @@ int main(int argc, char *argv[])
Info<< "Uniform one field min = " << min
<< " max = " << max << endl;
if (notEqual(max, 1.0, 1e-10) || notEqual(min, 1.0, 1e-10))
if (isNotEqual(min, 1) || isNotEqual(max, 1))
{
FatalErrorInFunction
<< "Uniform volVectorField not preserved."
@ -369,7 +365,7 @@ int main(int argc, char *argv[])
Info<< "Linear profile field min = " << min
<< " max = " << max << endl;
if (notEqual(max, 0.0, 1e-10) || notEqual(min, 0.0, 1e-10))
if (isNotEqual(min, 0) || isNotEqual(max, 0))
{
Info<< "Linear profile not preserved."
<< " Min and max should both be 0.0. min:" << min
@ -390,7 +386,7 @@ int main(int argc, char *argv[])
Info<< "Uniform surface field min = " << min
<< " max = " << max << endl;
if (notEqual(max, 1.0, 1e-10) || notEqual(min, 1.0, 1e-10))
if (isNotEqual(min, 1) || isNotEqual(max, 1))
{
FatalErrorInFunction
<< "Uniform surfaceScalarField not preserved."