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)
This commit is contained in:
parent
a50d32b587
commit
ecaa55295b
@ -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<scalar>(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."
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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<label> dimensionedLabel;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
@ -40,8 +40,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dimensionedMinMax_H
|
||||
#define dimensionedMinMax_H
|
||||
#ifndef Foam_dimensionedMinMax_H
|
||||
#define Foam_dimensionedMinMax_H
|
||||
|
||||
#include "dimensionedType.H"
|
||||
#include "MinMax.H"
|
||||
|
@ -35,8 +35,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dimensionedScalar_H
|
||||
#define dimensionedScalar_H
|
||||
#ifndef Foam_dimensionedScalar_H
|
||||
#define Foam_dimensionedScalar_H
|
||||
|
||||
#include "dimensionedType.H"
|
||||
#include "scalar.H"
|
||||
|
@ -23,14 +23,12 @@ License
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dimensionedScalarFwd_H
|
||||
#define dimensionedScalarFwd_H
|
||||
#ifndef Foam_dimensionedScalarFwd_H
|
||||
#define Foam_dimensionedScalarFwd_H
|
||||
|
||||
#include "scalar.H"
|
||||
#include "scalarFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
@ -34,8 +34,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dimensionedSphericalTensor_H
|
||||
#define dimensionedSphericalTensor_H
|
||||
#ifndef Foam_dimensionedSphericalTensor_H
|
||||
#define Foam_dimensionedSphericalTensor_H
|
||||
|
||||
#include "dimensionedType.H"
|
||||
#include "sphericalTensor.H"
|
||||
@ -50,7 +50,7 @@ namespace Foam
|
||||
typedef dimensioned<sphericalTensor> dimensionedSphericalTensor;
|
||||
|
||||
|
||||
// global functions
|
||||
// Global Functions
|
||||
|
||||
dimensionedScalar tr(const dimensionedSphericalTensor&);
|
||||
dimensionedScalar det(const dimensionedSphericalTensor&);
|
||||
|
@ -34,8 +34,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dimensionedSymmTensor_H
|
||||
#define dimensionedSymmTensor_H
|
||||
#ifndef Foam_dimensionedSymmTensor_H
|
||||
#define Foam_dimensionedSymmTensor_H
|
||||
|
||||
#include "dimensionedVector.H"
|
||||
#include "symmTensor.H"
|
||||
|
@ -35,8 +35,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dimensionedTensor_H
|
||||
#define dimensionedTensor_H
|
||||
#ifndef Foam_dimensionedTensor_H
|
||||
#define Foam_dimensionedTensor_H
|
||||
|
||||
#include "dimensionedVector.H"
|
||||
#include "dimensionedSymmTensor.H"
|
||||
|
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,11 +26,12 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dimensionedTypes_H
|
||||
#define dimensionedTypes_H
|
||||
#ifndef Foam_dimensionedTypes_H
|
||||
#define Foam_dimensionedTypes_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "dimensionedLabel.H"
|
||||
#include "dimensionedScalar.H"
|
||||
#include "dimensionedVector.H"
|
||||
#include "dimensionedSphericalTensor.H"
|
||||
|
@ -34,8 +34,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef dimensionedVector_H
|
||||
#define dimensionedVector_H
|
||||
#ifndef Foam_dimensionedVector_H
|
||||
#define Foam_dimensionedVector_H
|
||||
|
||||
#include "dimensionedScalar.H"
|
||||
#include "vector.H"
|
||||
|
@ -282,15 +282,15 @@ inline Scalar negPart(const Scalar s) noexcept
|
||||
}
|
||||
|
||||
|
||||
inline bool equal(const Scalar& s1, const Scalar& s2)
|
||||
inline bool equal(const Scalar& a, const Scalar& b)
|
||||
{
|
||||
return mag(s1 - s2) <= ScalarVSMALL;
|
||||
return mag(a - b) <= ScalarVSMALL;
|
||||
}
|
||||
|
||||
|
||||
inline bool notEqual(const Scalar s1, const Scalar s2)
|
||||
inline bool notEqual(const Scalar a, const Scalar b)
|
||||
{
|
||||
return mag(s1 - s2) > ScalarVSMALL;
|
||||
return mag(a - b) > ScalarVSMALL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,8 +26,8 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef doubleFloat_H
|
||||
#define doubleFloat_H
|
||||
#ifndef Foam_doubleFloat_H
|
||||
#define Foam_doubleFloat_H
|
||||
|
||||
#include "label.H"
|
||||
#include "products.H"
|
||||
@ -41,14 +41,6 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
//- Compare two values for equality
|
||||
template<class T>
|
||||
inline bool equal(const T& s1, const T& s2)
|
||||
{
|
||||
return s1 == s2;
|
||||
}
|
||||
|
||||
|
||||
#define MAXMINPOW(retType, type1, type2) \
|
||||
\
|
||||
MAXMIN(retType, type1, type2) \
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -35,8 +35,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamEndian_H // Prefixed with 'foam' to avoid any name clashes
|
||||
#define foamEndian_H
|
||||
#ifndef Foam_endian_H
|
||||
#define Foam_endian_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@ -75,10 +75,10 @@ public:
|
||||
// Public Methods
|
||||
|
||||
//- Runtime check for big endian.
|
||||
inline static bool isBig();
|
||||
inline static bool isBig() noexcept;
|
||||
|
||||
//- Runtime check for little endian.
|
||||
inline static bool isLittle();
|
||||
inline static bool isLittle() noexcept;
|
||||
|
||||
//- Byte endian swapping for 32-bits
|
||||
inline static uint32_t swap32(uint32_t);
|
||||
|
@ -40,7 +40,7 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::endian::isBig()
|
||||
inline bool Foam::endian::isBig() noexcept
|
||||
{
|
||||
const short testBig = 0x0100;
|
||||
|
||||
@ -49,7 +49,7 @@ inline bool Foam::endian::isBig()
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::endian::isLittle()
|
||||
inline bool Foam::endian::isLittle() noexcept
|
||||
{
|
||||
const short testLittle = 0x0001;
|
||||
|
||||
|
@ -132,6 +132,16 @@ inline constexpr label component(const label val, const direction) noexcept
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * General Functions * * * * * * * * * * * * * //
|
||||
|
||||
//- Compare two values for equality
|
||||
template<class T>
|
||||
inline bool equal(const T& a, const T& b)
|
||||
{
|
||||
return (a == b);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Struct labelOp Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
@ -39,8 +39,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef nullObject_H
|
||||
#define nullObject_H
|
||||
#ifndef Foam_nullObject_H
|
||||
#define Foam_nullObject_H
|
||||
|
||||
#include "labelFwd.H"
|
||||
|
||||
@ -101,37 +101,37 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- A nullptr pointer content
|
||||
inline const void* pointer() const
|
||||
const void* pointer() const noexcept
|
||||
{
|
||||
return data_[0].ptr;
|
||||
}
|
||||
|
||||
//- Zero valued integer content
|
||||
inline unsigned long value() const
|
||||
unsigned long value() const noexcept
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- No elements
|
||||
inline bool empty() const
|
||||
bool empty() const noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//- Zero elements
|
||||
inline label size() const
|
||||
label size() const noexcept
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//- No-op method (for HashTable replacement)
|
||||
inline const NullObject& toc() const
|
||||
const NullObject& toc() const noexcept
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
//- No-op method (for HashTable replacement)
|
||||
inline const NullObject& sortedToc() const
|
||||
const NullObject& sortedToc() const noexcept
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
@ -141,7 +141,7 @@ public:
|
||||
|
||||
//- Swallow assignment (cf, std::ignore)
|
||||
template<class T>
|
||||
inline const NullObject& operator=(const T&) const
|
||||
const NullObject& operator=(const T&) const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ SeeAlso
|
||||
#ifndef Foam_one_H
|
||||
#define Foam_one_H
|
||||
|
||||
#include "label.H"
|
||||
#include "labelFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
@ -53,6 +53,7 @@ namespace Foam
|
||||
|
||||
// Forward Declarations
|
||||
class zero;
|
||||
class zero_one;
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
@ -124,7 +125,7 @@ public:
|
||||
//- A static zero::null for dereferencing as a dummy element
|
||||
static null dummy;
|
||||
|
||||
//- Null constructible
|
||||
//- Default construct
|
||||
constexpr null() noexcept {}
|
||||
|
||||
//- Construct from Istream consumes no content.
|
||||
@ -132,6 +133,24 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class zero_one Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- Represents 0/1 concept, eg for tagged dispatch
|
||||
class zero_one
|
||||
{
|
||||
public:
|
||||
typedef zero_one value_type;
|
||||
|
||||
//- Default construct
|
||||
constexpr zero_one() noexcept {}
|
||||
|
||||
//- Construct from Istream consumes no content.
|
||||
explicit constexpr zero_one(Istream&) noexcept {}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
//- Global zero (0)
|
@ -294,7 +294,7 @@ inline void Foam::janafThermo<EquationOfState>::operator+=
|
||||
if
|
||||
(
|
||||
janafThermo<EquationOfState>::debug
|
||||
&& notEqual(Tcommon_, jt.Tcommon_)
|
||||
&& !equal(Tcommon_, jt.Tcommon_)
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
@ -375,7 +375,7 @@ inline Foam::janafThermo<EquationOfState> Foam::operator+
|
||||
if
|
||||
(
|
||||
janafThermo<EquationOfState>::debug
|
||||
&& notEqual(jt1.Tcommon_, jt2.Tcommon_)
|
||||
&& !equal(jt1.Tcommon_, jt2.Tcommon_)
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
@ -456,7 +456,7 @@ inline Foam::janafThermo<EquationOfState> Foam::operator==
|
||||
if
|
||||
(
|
||||
janafThermo<EquationOfState>::debug
|
||||
&& notEqual(jt2.Tcommon_, jt1.Tcommon_)
|
||||
&& !equal(jt2.Tcommon_, jt1.Tcommon_)
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
|
Loading…
Reference in New Issue
Block a user