From 3be01b9e86a3d2b444387505bfb73bd2600dfc25 Mon Sep 17 00:00:00 2001 From: henry <Henry Weller h.weller@opencfd.co.uk> Date: Fri, 23 Jan 2009 08:35:29 +0000 Subject: [PATCH] Added "max" and "min" constants to the primitive types which represent the largest and smallest representable values. Accessible directly and via pTraits. --- .../FieldFields/FieldField/FieldFieldFunctions.C | 10 ++-------- .../fields/Fields/Field/FieldFunctions.C | 10 ++-------- src/OpenFOAM/primitives/DiagTensor/DiagTensor.H | 2 ++ src/OpenFOAM/primitives/Scalar/Scalar.C | 3 ++- src/OpenFOAM/primitives/Scalar/Scalar.H | 2 ++ .../Scalar/doubleScalar/doubleScalar.C | 2 ++ .../Scalar/doubleScalar/doubleScalar.H | 2 ++ .../primitives/Scalar/floatScalar/floatScalar.C | 2 ++ .../primitives/Scalar/floatScalar/floatScalar.H | 2 ++ .../primitives/SphericalTensor/SphericalTensor.H | 2 ++ .../SphericalTensor2D/SphericalTensor2D.H | 2 ++ src/OpenFOAM/primitives/SymmTensor/SymmTensor.H | 2 ++ src/OpenFOAM/primitives/Tensor/Tensor.H | 2 ++ src/OpenFOAM/primitives/Tensor2D/Tensor2D.H | 3 +++ src/OpenFOAM/primitives/Vector/Vector.H | 2 ++ src/OpenFOAM/primitives/Vector2D/Vector2D.H | 2 ++ src/OpenFOAM/primitives/diagTensor/diagTensor.C | 6 ++++++ src/OpenFOAM/primitives/label/label.C | 5 ++--- src/OpenFOAM/primitives/label/label.H | 2 ++ .../primitives/sphericalTensor/sphericalTensor.C | 6 ++++++ .../sphericalTensor2D/sphericalTensor2D.C | 6 ++++++ src/OpenFOAM/primitives/symmTensor/symmTensor.C | 16 ++++++++++++++++ src/OpenFOAM/primitives/tensor/tensor.C | 16 ++++++++++++++++ src/OpenFOAM/primitives/tensor2D/tensor2D.C | 14 ++++++++++++++ src/OpenFOAM/primitives/uLabel/uLabel.C | 5 ++--- src/OpenFOAM/primitives/uLabel/uLabel.H | 6 +++++- src/OpenFOAM/primitives/vector/vector.C | 6 ++++++ src/OpenFOAM/primitives/vector2D/vector2D.C | 6 ++++++ 28 files changed, 120 insertions(+), 24 deletions(-) diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C index fd5f0968981..c0600bd97c4 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C @@ -430,10 +430,7 @@ Type max(const FieldField<Field, Type>& f) } else { - WarningIn("max(const FieldField<Field, Type>&) const") - << "empty fieldField, returning zero" << endl; - - return pTraits<Type>::zero; + return pTraits<Type>::min; } } @@ -464,10 +461,7 @@ Type min(const FieldField<Field, Type>& f) } else { - WarningIn("min(const FieldField<Field, Type>&) const") - << "empty fieldField, returning zero" << endl; - - return pTraits<Type>::zero; + return pTraits<Type>::max; } } diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C index ea1debc2359..b000421d76a 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C @@ -319,10 +319,7 @@ Type max(const UList<Type>& f) } else { - WarningIn("max(const UList<Type>&)") - << "empty field, returning zero" << endl; - - return pTraits<Type>::zero; + return pTraits<Type>::min; } } @@ -339,10 +336,7 @@ Type min(const UList<Type>& f) } else { - WarningIn("min(const UList<Type>&)") - << "empty field, returning zero" << endl; - - return pTraits<Type>::zero; + return pTraits<Type>::max; } } diff --git a/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H b/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H index a425ab1b106..035551a240f 100644 --- a/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H +++ b/src/OpenFOAM/primitives/DiagTensor/DiagTensor.H @@ -71,6 +71,8 @@ public: static const char* componentNames[]; static const DiagTensor zero; static const DiagTensor one; + static const DiagTensor max; + static const DiagTensor min; //- Component labeling enumeration diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.C b/src/OpenFOAM/primitives/Scalar/Scalar.C index 4593405cd5c..86087309cb0 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.C +++ b/src/OpenFOAM/primitives/Scalar/Scalar.C @@ -34,6 +34,8 @@ 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>::max = ScalarVGREAT; +const Scalar pTraits<Scalar>::min = -ScalarVGREAT; const char* pTraits<Scalar>::componentNames[] = { "x" }; @@ -45,7 +47,6 @@ pTraits<Scalar>::pTraits(Istream& is) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -//- return a string representation of a Scalar word name(const Scalar s) { std::ostringstream osBuffer; diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.H b/src/OpenFOAM/primitives/Scalar/Scalar.H index 5e2fbc0a26d..365a7f017eb 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.H +++ b/src/OpenFOAM/primitives/Scalar/Scalar.H @@ -61,6 +61,8 @@ public: static const char* componentNames[]; static const Scalar zero; static const Scalar one; + static const Scalar max; + static const Scalar min; // Constructors diff --git a/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.C b/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.C index a3bcf71c999..6fb4d373207 100644 --- a/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.C +++ b/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.C @@ -32,10 +32,12 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define Scalar doubleScalar +#define ScalarVGREAT doubleScalarVGREAT #define ScalarVSMALL doubleScalarVSMALL #define readScalar readDoubleScalar #include "Scalar.C" #undef Scalar +#undef ScalarVGREAT #undef ScalarVSMALL #undef readScalar diff --git a/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H b/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H index 640918c8134..ff4db3393b4 100644 --- a/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H +++ b/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H @@ -61,6 +61,7 @@ static const doubleScalar doubleScalarROOTVSMALL = 1.0e-150; #define Scalar doubleScalar +#define ScalarVGREAT doubleScalarVGREAT #define ScalarVSMALL doubleScalarVSMALL #define readScalar readDoubleScalar @@ -98,6 +99,7 @@ inline Scalar yn(const int n, const Scalar s) } #undef Scalar +#undef ScalarVGREAT #undef ScalarVSMALL #undef readScalar #undef transFunc diff --git a/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.C b/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.C index 5355dc9d897..d5488cebd3f 100644 --- a/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.C +++ b/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.C @@ -32,11 +32,13 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define Scalar floatScalar +#define ScalarVGREAT floatScalarVGREAT #define ScalarVSMALL floatScalarVSMALL #define readScalar readFloatScalar #include "Scalar.C" #undef Scalar #undef ScalarVSMALL +#undef ScalarVSMALL #undef readScalar // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H b/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H index 7ae47138a7d..99537311ce2 100644 --- a/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H +++ b/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H @@ -61,6 +61,7 @@ static const floatScalar floatScalarROOTVSMALL = 1.0e-18; #define Scalar floatScalar +#define ScalarVGREAT floatScalarVGREAT #define ScalarVSMALL floatScalarVSMALL #define readScalar readFloatScalar @@ -98,6 +99,7 @@ inline Scalar yn(const int n, const Scalar s) } #undef Scalar +#undef ScalarVGREAT #undef ScalarVSMALL #undef readScalar #undef transFunc diff --git a/src/OpenFOAM/primitives/SphericalTensor/SphericalTensor.H b/src/OpenFOAM/primitives/SphericalTensor/SphericalTensor.H index e0698ba7f0f..56c51a48d8b 100644 --- a/src/OpenFOAM/primitives/SphericalTensor/SphericalTensor.H +++ b/src/OpenFOAM/primitives/SphericalTensor/SphericalTensor.H @@ -75,6 +75,8 @@ public: static const char* componentNames[]; static const SphericalTensor zero; static const SphericalTensor one; + static const SphericalTensor max; + static const SphericalTensor min; static const SphericalTensor I; static const SphericalTensor oneThirdI; static const SphericalTensor twoThirdsI; diff --git a/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2D.H b/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2D.H index 8e5adcabf47..03ba8598012 100644 --- a/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2D.H +++ b/src/OpenFOAM/primitives/SphericalTensor2D/SphericalTensor2D.H @@ -71,6 +71,8 @@ public: static const char* componentNames[]; static const SphericalTensor2D zero; static const SphericalTensor2D one; + static const SphericalTensor2D max; + static const SphericalTensor2D min; static const SphericalTensor2D I; static const SphericalTensor2D oneThirdI; static const SphericalTensor2D twoThirdsI; diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H index efb76e2f872..e43a0d741d7 100644 --- a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H +++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H @@ -78,6 +78,8 @@ public: static const SymmTensor zero; static const SymmTensor one; + static const SymmTensor max; + static const SymmTensor min; //- Component labeling enumeration diff --git a/src/OpenFOAM/primitives/Tensor/Tensor.H b/src/OpenFOAM/primitives/Tensor/Tensor.H index ea4e5d72b19..305829c16de 100644 --- a/src/OpenFOAM/primitives/Tensor/Tensor.H +++ b/src/OpenFOAM/primitives/Tensor/Tensor.H @@ -79,6 +79,8 @@ public: static const Tensor zero; static const Tensor one; + static const Tensor max; + static const Tensor min; //- Component labeling enumeration diff --git a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H index 1f2e629761b..f3c5d30e644 100644 --- a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H +++ b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H @@ -74,6 +74,9 @@ public: static const Tensor2D zero; static const Tensor2D one; + static const Tensor2D max; + static const Tensor2D min; + //- Component labeling enumeration enum components { XX, XY, YX, YY }; diff --git a/src/OpenFOAM/primitives/Vector/Vector.H b/src/OpenFOAM/primitives/Vector/Vector.H index bc1af5db057..c9d7de52868 100644 --- a/src/OpenFOAM/primitives/Vector/Vector.H +++ b/src/OpenFOAM/primitives/Vector/Vector.H @@ -81,6 +81,8 @@ public: static const char* componentNames[]; static const Vector zero; static const Vector one; + static const Vector max; + static const Vector min; //- Component labeling enumeration diff --git a/src/OpenFOAM/primitives/Vector2D/Vector2D.H b/src/OpenFOAM/primitives/Vector2D/Vector2D.H index 496c4433929..392c5ba70bd 100644 --- a/src/OpenFOAM/primitives/Vector2D/Vector2D.H +++ b/src/OpenFOAM/primitives/Vector2D/Vector2D.H @@ -71,6 +71,8 @@ public: static const char* componentNames[]; static const Vector2D zero; static const Vector2D one; + static const Vector2D max; + static const Vector2D min; //- Component labeling enumeration diff --git a/src/OpenFOAM/primitives/diagTensor/diagTensor.C b/src/OpenFOAM/primitives/diagTensor/diagTensor.C index 3e95d759701..7cc498b12c2 100644 --- a/src/OpenFOAM/primitives/diagTensor/diagTensor.C +++ b/src/OpenFOAM/primitives/diagTensor/diagTensor.C @@ -48,6 +48,12 @@ const diagTensor diagTensor::zero(0, 0, 0); template<> const diagTensor diagTensor::one(1, 1, 1); +template<> +const diagTensor diagTensor::max(VGREAT, VGREAT, VGREAT); + +template<> +const diagTensor diagTensor::min(-VGREAT, -VGREAT, -VGREAT); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/label/label.C b/src/OpenFOAM/primitives/label/label.C index 5d4d7dd2bb6..38217bd6b2e 100644 --- a/src/OpenFOAM/primitives/label/label.C +++ b/src/OpenFOAM/primitives/label/label.C @@ -22,9 +22,6 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -Description - - \*---------------------------------------------------------------------------*/ #include "error.H" @@ -40,6 +37,8 @@ namespace Foam const char* const pTraits<label>::typeName = "label"; const label pTraits<label>::zero = 0; const label pTraits<label>::one = 1; +const label pTraits<label>::max = labelMax; +const label pTraits<label>::min = labelMin; const char* pTraits<label>::componentNames[] = { "x" }; diff --git a/src/OpenFOAM/primitives/label/label.H b/src/OpenFOAM/primitives/label/label.H index d83cd7b08e9..f9c523be3df 100644 --- a/src/OpenFOAM/primitives/label/label.H +++ b/src/OpenFOAM/primitives/label/label.H @@ -150,6 +150,8 @@ public: static const char* componentNames[]; static const label zero; static const label one; + static const label max; + static const label min; // Constructors diff --git a/src/OpenFOAM/primitives/sphericalTensor/sphericalTensor.C b/src/OpenFOAM/primitives/sphericalTensor/sphericalTensor.C index 7943dea5ccf..2e74cb70ce7 100644 --- a/src/OpenFOAM/primitives/sphericalTensor/sphericalTensor.C +++ b/src/OpenFOAM/primitives/sphericalTensor/sphericalTensor.C @@ -45,6 +45,12 @@ const sphericalTensor sphericalTensor::zero(0); template<> const sphericalTensor sphericalTensor::one(1); +template<> +const sphericalTensor sphericalTensor::max(VGREAT); + +template<> +const sphericalTensor sphericalTensor::min(-VGREAT); + template<> const sphericalTensor sphericalTensor::I(1); diff --git a/src/OpenFOAM/primitives/sphericalTensor2D/sphericalTensor2D.C b/src/OpenFOAM/primitives/sphericalTensor2D/sphericalTensor2D.C index 974aa6278be..f5fa54eb2f1 100644 --- a/src/OpenFOAM/primitives/sphericalTensor2D/sphericalTensor2D.C +++ b/src/OpenFOAM/primitives/sphericalTensor2D/sphericalTensor2D.C @@ -45,6 +45,12 @@ const sphericalTensor2D sphericalTensor2D::zero(0); template<> const sphericalTensor2D sphericalTensor2D::one(1); +template<> +const sphericalTensor2D sphericalTensor2D::max(VGREAT); + +template<> +const sphericalTensor2D sphericalTensor2D::min(-VGREAT); + template<> const sphericalTensor2D sphericalTensor2D::I(1); diff --git a/src/OpenFOAM/primitives/symmTensor/symmTensor.C b/src/OpenFOAM/primitives/symmTensor/symmTensor.C index c9faf9aa1ef..f5a56a3d86e 100644 --- a/src/OpenFOAM/primitives/symmTensor/symmTensor.C +++ b/src/OpenFOAM/primitives/symmTensor/symmTensor.C @@ -61,6 +61,22 @@ const symmTensor symmTensor::one 1 ); +template<> +const symmTensor symmTensor::max +( + VGREAT, VGREAT, VGREAT, + VGREAT, VGREAT, + VGREAT +); + +template<> +const symmTensor symmTensor::min +( + -VGREAT, -VGREAT, -VGREAT, + -VGREAT, -VGREAT, + -VGREAT +); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/tensor/tensor.C b/src/OpenFOAM/primitives/tensor/tensor.C index d8236547b61..f3658931256 100644 --- a/src/OpenFOAM/primitives/tensor/tensor.C +++ b/src/OpenFOAM/primitives/tensor/tensor.C @@ -61,6 +61,22 @@ const tensor tensor::one 1, 1, 1 ); +template<> +const tensor tensor::max +( + VGREAT, VGREAT, VGREAT, + VGREAT, VGREAT, VGREAT, + VGREAT, VGREAT, VGREAT +); + +template<> +const tensor tensor::min +( + -VGREAT, -VGREAT, -VGREAT, + -VGREAT, -VGREAT, -VGREAT, + -VGREAT, -VGREAT, -VGREAT +); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/tensor2D/tensor2D.C b/src/OpenFOAM/primitives/tensor2D/tensor2D.C index 25f361f6958..e782cd0fea8 100644 --- a/src/OpenFOAM/primitives/tensor2D/tensor2D.C +++ b/src/OpenFOAM/primitives/tensor2D/tensor2D.C @@ -58,6 +58,20 @@ const tensor2D tensor2D::one 1, 1 ); +template<> +const tensor2D tensor2D::max +( + VGREAT, VGREAT, + VGREAT, VGREAT +); + +template<> +const tensor2D tensor2D::min +( + -VGREAT, -VGREAT, + -VGREAT, -VGREAT +); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/uLabel/uLabel.C b/src/OpenFOAM/primitives/uLabel/uLabel.C index b4e72c18a60..b005ed9fbaf 100644 --- a/src/OpenFOAM/primitives/uLabel/uLabel.C +++ b/src/OpenFOAM/primitives/uLabel/uLabel.C @@ -37,6 +37,8 @@ namespace Foam const char* const pTraits<uLabel>::typeName = "uLabel"; const uLabel pTraits<uLabel>::zero = 0; const uLabel pTraits<uLabel>::one = 1; +const uLabel pTraits<uLabel>::max = uLabelMax; +const uLabel pTraits<uLabel>::min = uLabelMin; const char* pTraits<uLabel>::componentNames[] = { "x" }; @@ -46,9 +48,6 @@ pTraits<uLabel>::pTraits(Istream& is) } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/primitives/uLabel/uLabel.H b/src/OpenFOAM/primitives/uLabel/uLabel.H index 7b99b79eb1f..97bb3e5fa2a 100644 --- a/src/OpenFOAM/primitives/uLabel/uLabel.H +++ b/src/OpenFOAM/primitives/uLabel/uLabel.H @@ -57,6 +57,7 @@ namespace Foam typedef unsigned int uLabel; static const uLabel uLabelMax = UINT_MAX; + static const uLabel uLabelMin = 0; inline uLabel readULabel(Istream& is) { @@ -77,7 +78,8 @@ namespace Foam { typedef unsigned long uLabel; - static const uLabel uLabelMax = LONG_MAX; + static const uLabel uLabelMax = ULONG_MAX; + static const uLabel uLabelMin = 0; inline uLabel readULabel(Istream& is) { @@ -130,6 +132,8 @@ public: static const char* componentNames[]; static const uLabel zero; static const uLabel one; + static const uLabel max; + static const uLabel min; // Constructors diff --git a/src/OpenFOAM/primitives/vector/vector.C b/src/OpenFOAM/primitives/vector/vector.C index 1864a7d8af6..7c2c84ae9a0 100644 --- a/src/OpenFOAM/primitives/vector/vector.C +++ b/src/OpenFOAM/primitives/vector/vector.C @@ -48,6 +48,12 @@ const vector vector::zero(0, 0, 0); template<> const vector vector::one(1, 1, 1); +template<> +const vector vector::max(VGREAT, VGREAT, VGREAT); + +template<> +const vector vector::min(-VGREAT, -VGREAT, -VGREAT); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/primitives/vector2D/vector2D.C b/src/OpenFOAM/primitives/vector2D/vector2D.C index da5a2ec5320..cbe0d89d1e1 100644 --- a/src/OpenFOAM/primitives/vector2D/vector2D.C +++ b/src/OpenFOAM/primitives/vector2D/vector2D.C @@ -48,6 +48,12 @@ const vector2D vector2D::zero(0, 0); template<> const vector2D vector2D::one(1, 1); +template<> +const vector2D vector2D::max(VGREAT, VGREAT); + +template<> +const vector2D vector2D::min(-VGREAT, -VGREAT); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam -- GitLab