From ecaa55295b9be1f81d0cf9657e56439ad44ca3a3 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 13 Jan 2023 20:45:53 +0100 Subject: [PATCH] ENH: add dimensionedLabel typedef GIT: primitives/compat with compatibility includes GIT: primitives/traits with pTraits, contiguous, zero, one etc. COMP: relocate base equal(a,b) definition from scalar.H -> label.H - make more universally available STYLE: replace occasional use of notEqual(a,b) with !equal(a,b) --- .../test/fieldMapping/Test-fieldMapping.C | 15 ++--- .../dimensionedLabel/dimensionedLabel.H | 59 +++++++++++++++++++ .../dimensionedMinMax/dimensionedMinMax.H | 4 +- .../dimensionedScalar/dimensionedScalar.H | 4 +- .../dimensionedScalar/dimensionedScalarFwd.H | 8 +-- .../dimensionedSphericalTensor.H | 6 +- .../dimensionedSymmTensor.H | 4 +- .../dimensionedTensor/dimensionedTensor.H | 4 +- .../dimensionedTypes/dimensionedTypes.H | 6 +- .../dimensionedVector/dimensionedVector.H | 4 +- src/OpenFOAM/primitives/Scalar/Scalar.H | 8 +-- src/OpenFOAM/primitives/Scalar/doubleFloat.H | 12 +--- .../{hashes/Hash => compat}/HashFwd.H | 0 .../primitives/{Swap => compat}/Swap.H | 0 .../{Tensor/floats => compat}/doubleTensor.H | 0 .../{Vector/floats => compat}/doubleVector.H | 0 .../{Tensor/floats => compat}/floatTensor.H | 0 .../{Vector/floats => compat}/floatVector.H | 0 .../primitives/{zero => compat}/nil.H | 0 .../wordRes => compat}/wordReListMatcher.H | 0 src/OpenFOAM/primitives/endian/endian.H | 10 ++-- src/OpenFOAM/primitives/endian/endianI.H | 4 +- src/OpenFOAM/primitives/ints/label/label.H | 10 ++++ .../primitives/nullObject/nullObject.H | 18 +++--- .../{contiguous => traits}/contiguous.H | 0 src/OpenFOAM/primitives/{one => traits}/one.H | 2 +- .../primitives/{one => traits}/oneI.H | 0 .../primitives/{zero => traits}/zero.C | 0 .../primitives/{zero => traits}/zero.H | 21 ++++++- .../primitives/{zero => traits}/zeroI.H | 0 .../specie/thermo/janaf/janafThermoI.H | 6 +- 31 files changed, 140 insertions(+), 65 deletions(-) create mode 100644 src/OpenFOAM/dimensionedTypes/dimensionedLabel/dimensionedLabel.H rename src/OpenFOAM/primitives/{hashes/Hash => compat}/HashFwd.H (100%) rename src/OpenFOAM/primitives/{Swap => compat}/Swap.H (100%) rename src/OpenFOAM/primitives/{Tensor/floats => compat}/doubleTensor.H (100%) rename src/OpenFOAM/primitives/{Vector/floats => compat}/doubleVector.H (100%) rename src/OpenFOAM/primitives/{Tensor/floats => compat}/floatTensor.H (100%) rename src/OpenFOAM/primitives/{Vector/floats => compat}/floatVector.H (100%) rename src/OpenFOAM/primitives/{zero => compat}/nil.H (100%) rename src/OpenFOAM/primitives/{strings/wordRes => compat}/wordReListMatcher.H (100%) rename src/OpenFOAM/primitives/{contiguous => traits}/contiguous.H (100%) rename src/OpenFOAM/primitives/{one => traits}/one.H (99%) rename src/OpenFOAM/primitives/{one => traits}/oneI.H (100%) rename src/OpenFOAM/primitives/{zero => traits}/zero.C (100%) rename src/OpenFOAM/primitives/{zero => traits}/zero.H (88%) rename src/OpenFOAM/primitives/{zero => traits}/zeroI.H (100%) diff --git a/applications/test/fieldMapping/Test-fieldMapping.C b/applications/test/fieldMapping/Test-fieldMapping.C index f65a2d3ae5..2c4b032e15 100644 --- a/applications/test/fieldMapping/Test-fieldMapping.C +++ b/applications/test/fieldMapping/Test-fieldMapping.C @@ -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[]) @@ -154,6 +148,8 @@ int main(int argc, char *argv[]) // Face removal engine. No checking for not merging boundary faces. removeFaces faceRemover(mesh, GREAT); + // Comparison for inequality + const auto isNotEqual = notEqualOp(1e-10); while (runTime.loop()) { @@ -254,7 +250,6 @@ int main(int argc, char *argv[]) } } - // Check constant profile { const scalar max = gMax(one); @@ -263,7 +258,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(max, 1) || isNotEqual(min, 1)) { FatalErrorInFunction << "Uniform volVectorField not preserved." @@ -287,7 +282,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(max, 0) || isNotEqual(min, 0)) { FatalErrorInFunction << "Linear profile not preserved." @@ -310,7 +305,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(max, 1) || isNotEqual(min, 1)) { FatalErrorInFunction << "Uniform surfaceScalarField not preserved." diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedLabel/dimensionedLabel.H b/src/OpenFOAM/dimensionedTypes/dimensionedLabel/dimensionedLabel.H new file mode 100644 index 0000000000..37e6fc4397 --- /dev/null +++ b/src/OpenFOAM/dimensionedTypes/dimensionedLabel/dimensionedLabel.H @@ -0,0 +1,59 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2023 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Typedef + Foam::dimensionedLabel + +Description + Dimensioned label obtained from generic dimensioned type. + +SourceFiles + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_dimensionedLabel_H +#define Foam_dimensionedLabel_H + +#include "dimensionedType.H" +#include "label.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +typedef dimensioned