From 97a42df7ba6d374884a7937890fd65984a384b62 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 7 Aug 2023 09:01:05 +0200 Subject: [PATCH 1/5] ENH: add VectorSpace trait tests and evaluations - is_vectorspace : test existence and non-zero value of the Type 'rank' static variable - pTraits_rank : value of 'rank' static variable (if it exists), 0 otherwise - pTraits_nComponents : value of 'nComponents' static variable (if it exists), 1 otherwise - pTraits_has_zero : test for pTraits::zero member, which probably means that it also has one, min, max members as well Note that these traits are usable with any classes. For example, - is_vectorspace::value ==> false - pTraits_nComponents::value ==> 1 - pTraits::nComponents ==> fails to compile Thus also allows testing pTraits_rank<...>::value with items for which pTraits<...>::rank fails to compile. Eg, cyclicAMIPolyPatch::interpolate called by FaceCellWave with a wallPoint. pTraits::rank ==> fails to compile is_vectorspace::value ==> false GIT: relocate ListLoopM.H to src/OpenFOAM/fields/Fields (future isolation) --- applications/test/pTraits/Test-pTraits.C | 73 +++++++++++++- src/OpenFOAM/fields/Fields/Field/FieldM.H | 2 +- .../List => fields/Fields/Field}/ListLoopM.H | 0 .../primitives/Vector/bools/boolVector.H | 5 +- src/OpenFOAM/primitives/direction/direction.H | 15 ++- src/OpenFOAM/primitives/traits/pTraits.H | 96 +++++++++++++++++-- 6 files changed, 172 insertions(+), 19 deletions(-) rename src/OpenFOAM/{containers/Lists/List => fields/Fields/Field}/ListLoopM.H (100%) diff --git a/applications/test/pTraits/Test-pTraits.C b/applications/test/pTraits/Test-pTraits.C index d1a4f59bb7..6b4c4a5a54 100644 --- a/applications/test/pTraits/Test-pTraits.C +++ b/applications/test/pTraits/Test-pTraits.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,9 +30,12 @@ Description #include "IOstreams.H" #include "pTraits.H" +#include "contiguous.H" +#include "boolVector.H" // A FixedList pretending to be a vector #include "vector.H" #include "tensor.H" #include "uLabel.H" +#include "Switch.H" #include @@ -40,14 +44,72 @@ using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: +//- Test if Type has typeName member +template +struct has_typeName : std::false_type {}; + +//- Test if Type has typeName member + +template +struct has_typeName::typeName)>> +: + std::true_type +{}; + + +template +typename std::enable_if::value, void>::type +printTypeName() +{ + Info<< pTraits::typeName; +} + +template +typename std::enable_if::value, void>::type +printTypeName() +{ + Info<< typeid(T).name(); +} + + +template +struct has_zero_one : std::false_type {}; + +template +struct has_zero_one +< + T, + stdFoam::void_t::zero), decltype(pTraits::one)> +> : std::true_type {}; + + +template +typename std::enable_if::value, void>::type +printMinMaxRange() +{ + Info<< " zero=" << pTraits::zero + << " one=" << pTraits::one; +} + +template +typename std::enable_if::value, void>::type +printMinMaxRange() +{} + + template void printTraits() { - Info<< pTraits::typeName - << ": zero=" << pTraits::zero - << " one=" << pTraits::one - << " integral=" << std::is_integral::value + printTypeName(); + printMinMaxRange(); + + Info<< " integral=" << std::is_integral::value << " floating=" << std::is_floating_point::value + << " rank=" << pTraits_rank::value + << " nComponents=" << pTraits_nComponents::value + << " vector-space=" << Switch::name(is_vectorspace::value) + << " is_label=" << Switch::name(is_contiguous_label::value) + << " is_scalar=" << Switch::name(is_contiguous_scalar::value) << endl; } @@ -69,6 +131,9 @@ int main() printTraits(); printTraits(); printTraits(); + printTraits(); + printTraits(); + printTraits(); { pTraits b(true); diff --git a/src/OpenFOAM/fields/Fields/Field/FieldM.H b/src/OpenFOAM/fields/Fields/Field/FieldM.H index 0cb9072bfd..142f83fdce 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldM.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldM.H @@ -33,7 +33,7 @@ Description #define Foam_FieldM_H #include "error.H" -#include "ListLoopM.H" +#include "ListLoopM.H" // For list access macros // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/List/ListLoopM.H b/src/OpenFOAM/fields/Fields/Field/ListLoopM.H similarity index 100% rename from src/OpenFOAM/containers/Lists/List/ListLoopM.H rename to src/OpenFOAM/fields/Fields/Field/ListLoopM.H diff --git a/src/OpenFOAM/primitives/Vector/bools/boolVector.H b/src/OpenFOAM/primitives/Vector/bools/boolVector.H index baa2e81bb5..f4905a5e2d 100644 --- a/src/OpenFOAM/primitives/Vector/bools/boolVector.H +++ b/src/OpenFOAM/primitives/Vector/bools/boolVector.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020-2022 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,6 +65,9 @@ public: //- Rank of a vector is 1 static constexpr direction rank = 1; + //- Number of components in this vector space + static constexpr direction nComponents = 3; + //- Component labeling enumeration enum components { X, Y, Z }; diff --git a/src/OpenFOAM/primitives/direction/direction.H b/src/OpenFOAM/primitives/direction/direction.H index b9f67e4370..670a3befd6 100644 --- a/src/OpenFOAM/primitives/direction/direction.H +++ b/src/OpenFOAM/primitives/direction/direction.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,17 +42,20 @@ Note #include #include -#include "pTraits.H" - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Forward Declarations +class Istream; +class Ostream; +// Typedefs typedef uint8_t direction; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + //- Read direction (uint8_t) from stream. direction readDirection(Istream& is); @@ -68,6 +71,10 @@ std::ostream& operator<<(std::ostream& os, const direction val); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#include "pTraits.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/traits/pTraits.H b/src/OpenFOAM/primitives/traits/pTraits.H index d8e219647f..d5576129f7 100644 --- a/src/OpenFOAM/primitives/traits/pTraits.H +++ b/src/OpenFOAM/primitives/traits/pTraits.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,10 +28,10 @@ Class Foam::pTraits Description - A traits class, which is primarily used for primitives. + A traits class, which is primarily used for primitives and vector-space. All primitives need a specialised version of this class. The - specialised version will normally also require a conversion + specialised versions will normally also require a conversion method. \*---------------------------------------------------------------------------*/ @@ -39,14 +39,33 @@ Description #ifndef Foam_pTraits_H #define Foam_pTraits_H +#include "direction.H" +#include // For std::integral_constant, std::void_t (C++17) + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace stdFoam +{ + +//- Map a sequence of any types to \c void as per C++17 \c std::void_t +template +using void_t = void; + +} // End namespace Foam + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -// Forward Declarations -class Istream; -class Ostream; +/*---------------------------------------------------------------------------*\ + Class zero_one Declaration +\*---------------------------------------------------------------------------*/ + +//- Represents 0/1 range or concept. Used for tagged dispatch or clamping +class zero_one {}; + /*---------------------------------------------------------------------------*\ Class pTraits Declaration @@ -78,11 +97,70 @@ public: /*---------------------------------------------------------------------------*\ - Class zero_one Declaration + VectorSpace Traits \*---------------------------------------------------------------------------*/ -//- Represents 0/1 range or concept. Used for tagged dispatch or clamping -class zero_one {}; +//- Test for VectorSpace : default is false +template +struct is_vectorspace : std::false_type {}; + +//- Test for VectorSpace : test for T::rank != 0 static member directly +// Do not need pTraits layer since rank is defined via VectorSpace etc +template +struct is_vectorspace> +: + std::integral_constant +{}; + + +//- The vector-space rank: default is 0. +template +struct pTraits_rank : std::integral_constant {}; + +//- Rank of VectorSpace, +//- using the pTraits \c rank static member. +template +struct pTraits_rank +< + T, + stdFoam::void_t::rank)> +> +: + std::integral_constant::rank> +{}; + + +//- The vector-space number of components: default is 1. +template +struct pTraits_nComponents : std::integral_constant {}; + +//- Number of VectorSpace components, +//- using the pTraits \c nComponents static member. +template +struct pTraits_nComponents +< + T, + stdFoam::void_t::nComponents)> +> +: + std::integral_constant::nComponents> +{}; + + +//- Test for pTraits zero : default is false +template +struct pTraits_has_zero : std::false_type {}; + +//- Test for pTraits zero +template +struct pTraits_has_zero +< + T, + stdFoam::void_t::zero)> +> +: + std::true_type +{}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // From 1340bc50bd0f46e1e99ba99e33dfd8fbc55b52e0 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 9 Aug 2023 18:38:55 +0200 Subject: [PATCH 2/5] STYLE: qualify zero/one dispatch tags with Foam:: prefix - use Foam::zero{} instead of Zero with tagged re-dispatch --- src/OpenFOAM/containers/Buffers/CircularBufferI.H | 4 ++-- .../CompactLists/CompactListList/CompactListListI.H | 2 +- .../containers/Lists/DynamicList/DynamicListI.H | 4 ++-- src/OpenFOAM/containers/Lists/FixedList/FixedListI.H | 4 ++-- src/OpenFOAM/containers/Lists/List/ListI.H | 2 +- src/OpenFOAM/containers/Lists/List/SubListI.H | 2 +- .../containers/Lists/SortableList/SortableList.C | 10 +--------- .../containers/Lists/SortableList/SortableList.H | 2 +- .../fields/Fields/DynamicField/DynamicFieldI.H | 4 ++-- src/OpenFOAM/fields/Fields/Field/FieldI.H | 6 +++--- src/OpenFOAM/fields/Fields/Field/SubFieldI.H | 2 +- .../matrices/DiagonalMatrix/DiagonalMatrix.C | 2 +- src/OpenFOAM/matrices/Matrix/MatrixI.H | 2 +- .../matrices/RectangularMatrix/RectangularMatrixI.H | 8 ++++---- src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.C | 2 +- src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H | 12 ++++++------ .../SymmetricSquareMatrix/SymmetricSquareMatrix.C | 2 +- .../SymmetricSquareMatrix/SymmetricSquareMatrixI.H | 6 +++--- src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H | 4 ++-- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 7 ++++++- src/OpenFOAM/meshes/polyMesh/polyMesh.H | 2 +- src/finiteArea/faMatrices/faMatrix/faMatrix.C | 10 ---------- src/finiteArea/faMatrices/faMatrix/faMatrix.H | 4 ++-- src/finiteVolume/finiteVolume/fvc/fvcDdt.C | 4 ++-- src/finiteVolume/finiteVolume/fvc/fvcDdt.H | 8 ++++---- src/finiteVolume/finiteVolume/fvm/fvmDdt.C | 10 +++++----- src/finiteVolume/finiteVolume/fvm/fvmDdt.H | 10 +++++----- src/finiteVolume/finiteVolume/fvm/fvmLaplacian.C | 8 ++++---- src/finiteVolume/finiteVolume/fvm/fvmLaplacian.H | 8 ++++---- src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C | 10 ---------- src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H | 4 ++-- 31 files changed, 71 insertions(+), 94 deletions(-) diff --git a/src/OpenFOAM/containers/Buffers/CircularBufferI.H b/src/OpenFOAM/containers/Buffers/CircularBufferI.H index d6ffa2ec81..950d6a504b 100644 --- a/src/OpenFOAM/containers/Buffers/CircularBufferI.H +++ b/src/OpenFOAM/containers/Buffers/CircularBufferI.H @@ -530,8 +530,8 @@ inline void Foam::CircularBuffer::operator=(const T& val) template inline void Foam::CircularBuffer::operator=(const Foam::zero) { - this->array_one() = Zero; - this->array_two() = Zero; + this->array_one() = Foam::zero{}; + this->array_two() = Foam::zero{}; } diff --git a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H index 3325fe37b8..03a353cd14 100644 --- a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H @@ -507,7 +507,7 @@ inline void Foam::CompactListList::operator=(const T& val) template inline void Foam::CompactListList::operator=(const Foam::zero) { - values_ = Zero; + values_ = Foam::zero{}; } diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 595ef3b828..c44f9f8697 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -171,7 +171,7 @@ inline Foam::DynamicList::DynamicList const Foam::zero ) : - List(len, Zero), + List(len, Foam::zero{}), capacity_(List::size()) {} @@ -815,7 +815,7 @@ inline void Foam::DynamicList::operator= const Foam::zero ) { - UList::operator=(Zero); + UList::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index 68144b2df5..abc9228b45 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -51,7 +51,7 @@ inline Foam::FixedList::FixedList(const T& val) template inline Foam::FixedList::FixedList(const Foam::zero) { - this->fill(Zero); + this->fill(Foam::zero{}); } @@ -500,7 +500,7 @@ inline void Foam::FixedList::operator=(const T& val) template inline void Foam::FixedList::operator=(const Foam::zero) { - this->fill(Zero); + this->fill(Foam::zero{}); } diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index 6c8aec1f3e..85b20a6424 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -300,7 +300,7 @@ inline void Foam::List::operator=(const T& val) template inline void Foam::List::operator=(const Foam::zero) { - UList::operator=(Zero); + UList::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/containers/Lists/List/SubListI.H b/src/OpenFOAM/containers/Lists/List/SubListI.H index 18718c66f8..29422f1bd4 100644 --- a/src/OpenFOAM/containers/Lists/List/SubListI.H +++ b/src/OpenFOAM/containers/Lists/List/SubListI.H @@ -160,7 +160,7 @@ inline void Foam::SubList::operator=(const T& val) template inline void Foam::SubList::operator=(const Foam::zero) { - UList::operator=(Zero); + UList::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C index ed2aa47fab..6e8ea3f1d6 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C @@ -30,14 +30,6 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -template -inline constexpr Foam::SortableList::SortableList() noexcept -: - List(), - indices_() -{} - - template inline Foam::SortableList::SortableList(const label size) : @@ -48,7 +40,7 @@ inline Foam::SortableList::SortableList(const label size) template inline Foam::SortableList::SortableList(const label size, const Foam::zero) : - List(size, Zero) + List(size, Foam::zero{}) {} diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H index 3009fbeeef..3139408d26 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H @@ -73,7 +73,7 @@ public: // Constructors //- Default construct - inline constexpr SortableList() noexcept; + SortableList() noexcept = default; //- Construct given size, sort later. // The indices remain empty until the list is sorted diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H index a2c15434fb..e5571d4b6e 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H @@ -165,7 +165,7 @@ inline Foam::DynamicField::DynamicField const Foam::zero ) : - Field(len, Zero), + Field(len, Foam::zero{}), capacity_(Field::size()) {} @@ -696,7 +696,7 @@ inline void Foam::DynamicField::operator= const Foam::zero ) { - UList::operator=(Zero); + UList::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/fields/Fields/Field/FieldI.H b/src/OpenFOAM/fields/Fields/Field/FieldI.H index 08eb5de948..f2f4b5d7d4 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldI.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldI.H @@ -60,7 +60,7 @@ inline Foam::Field::Field(const label len, const Type& val) template inline Foam::Field::Field(const label len, const Foam::zero) : - List(len, Zero) + List(len, Foam::zero{}) {} @@ -81,7 +81,7 @@ inline Foam::Field::Field(const Foam::one, Type&& val) template inline Foam::Field::Field(const Foam::one, const Foam::zero) : - List(Foam::one{}, Zero) + List(Foam::one{}, Foam::zero{}) {} @@ -224,7 +224,7 @@ inline void Foam::Field::operator=(const Type& val) template inline void Foam::Field::operator=(const Foam::zero) { - List::operator=(Zero); + List::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H index 6b42e8d91f..184f4b8650 100644 --- a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H +++ b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H @@ -165,7 +165,7 @@ inline void Foam::SubField::operator=(const Type& val) template inline void Foam::SubField::operator=(const Foam::zero) { - SubList::operator=(Zero); + SubList::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C index 681c82c07d..4160fc00d7 100644 --- a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C +++ b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C @@ -40,7 +40,7 @@ Foam::DiagonalMatrix::DiagonalMatrix(const label n) template Foam::DiagonalMatrix::DiagonalMatrix(const label n, const Foam::zero) : - List(n, Zero) + List(n, Foam::zero{}) {} diff --git a/src/OpenFOAM/matrices/Matrix/MatrixI.H b/src/OpenFOAM/matrices/Matrix/MatrixI.H index 707965a4c3..a5ded753c5 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixI.H +++ b/src/OpenFOAM/matrices/Matrix/MatrixI.H @@ -64,7 +64,7 @@ inline Foam::Matrix::Matrix(const labelPair& dims) template inline Foam::Matrix::Matrix(const labelPair& dims, const Foam::zero) : - Matrix(dims.first(), dims.second(), Zero) + Matrix(dims.first(), dims.second(), Foam::zero{}) {} diff --git a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H index e4f67dbbb7..3033c1dc4d 100644 --- a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H +++ b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H @@ -57,7 +57,7 @@ inline Foam::RectangularMatrix::RectangularMatrix const Foam::zero ) : - Matrix, Type>(m, n, Zero) + Matrix, Type>(m, n, Foam::zero{}) {} @@ -81,7 +81,7 @@ inline Foam::RectangularMatrix::RectangularMatrix const Identity ) : - Matrix, Type>(dims.first(), dims.second(), Zero) + RectangularMatrix(dims.first(), dims.second(), Foam::zero{}) { for (label i = 0; i < min(dims.first(), dims.second()); ++i) { @@ -107,7 +107,7 @@ inline Foam::RectangularMatrix::RectangularMatrix const Foam::zero ) : - RectangularMatrix(dims.first(), dims.second(), Zero) + RectangularMatrix(dims.first(), dims.second(), Foam::zero{}) {} @@ -184,7 +184,7 @@ inline void Foam::RectangularMatrix::operator= template inline void Foam::RectangularMatrix::operator=(const Foam::zero) { - Matrix, Type>::operator=(Zero); + Matrix, Type>::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.C b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.C index 1506cb9972..8831ed6f59 100644 --- a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.C +++ b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.C @@ -85,7 +85,7 @@ template template void Foam::SquareMatrix::operator=(const Identity) { - Matrix, Type>::operator=(Zero); + Matrix, Type>::operator=(Foam::zero{}); for (label i = 0; i < this->n(); ++i) { diff --git a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H index 42cd6666ea..d289e9869f 100644 --- a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H +++ b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H @@ -51,7 +51,7 @@ inline Foam::SquareMatrix::SquareMatrix const Foam::zero ) : - Matrix, Type>(n, n, Zero) + Matrix, Type>(n, n, Foam::zero{}) {} @@ -74,7 +74,7 @@ inline Foam::SquareMatrix::SquareMatrix const Identity ) : - Matrix, Type>(n, n, Zero) + SquareMatrix(n, Foam::zero{}) { for (label i = 0; i < n; ++i) { @@ -91,7 +91,7 @@ inline Foam::SquareMatrix::SquareMatrix const Identity ) : - Matrix, Type>(dims, Zero) + Matrix, Type>(dims, Foam::zero{}) { CHECK_MATRIX_IS_SQUARE(dims.first(), dims.second()); @@ -121,7 +121,7 @@ inline Foam::SquareMatrix::SquareMatrix const Foam::zero ) : - Matrix, Type>(dims, Zero) + Matrix, Type>(dims, Foam::zero{}) { CHECK_MATRIX_IS_SQUARE(dims.first(), dims.second()); } @@ -148,7 +148,7 @@ inline Foam::SquareMatrix::SquareMatrix const Foam::zero ) : - Matrix, Type>(m, n, Zero) + Matrix, Type>(m, n, Foam::zero{}) { CHECK_MATRIX_IS_SQUARE(m, n); } @@ -300,7 +300,7 @@ inline void Foam::SquareMatrix::operator=(SquareMatrix&& mat) template inline void Foam::SquareMatrix::operator=(const Foam::zero) { - Matrix, Type>::operator=(Zero); + Matrix, Type>::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.C b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.C index b50a96e7b1..be0457bfbf 100644 --- a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.C +++ b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.C @@ -117,7 +117,7 @@ template template void Foam::SymmetricSquareMatrix::operator=(const Identity) { - Matrix, Type>::operator=(Zero); + Matrix, Type>::operator=(Foam::zero{}); for (label i=0; i < this->n(); ++i) { diff --git a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrixI.H b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrixI.H index f040dbdf19..008db20346 100644 --- a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrixI.H +++ b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrixI.H @@ -51,7 +51,7 @@ inline Foam::SymmetricSquareMatrix::SymmetricSquareMatrix const Foam::zero ) : - Matrix, Type>(n, n, Zero) + Matrix, Type>(n, n, Foam::zero{}) {} @@ -74,7 +74,7 @@ inline Foam::SymmetricSquareMatrix::SymmetricSquareMatrix const Identity ) : - Matrix, Type>(n, n, Zero) + SymmetricSquareMatrix(n, Foam::zero{}) { for (label i=0; i < n; ++i) { @@ -105,7 +105,7 @@ Foam::SymmetricSquareMatrix::clone() const template inline void Foam::SymmetricSquareMatrix::operator=(const Foam::zero) { - Matrix, Type>::operator=(Zero); + Matrix, Type>::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H b/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H index 5cb9e48047..67a6fcc5d4 100644 --- a/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H +++ b/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H @@ -78,7 +78,7 @@ inline Foam::IjkField::IjkField const Foam::zero ) : - Field(cmptProduct(ijk), Zero), + Field(cmptProduct(ijk), Foam::zero{}), ijk_(ijk) {} @@ -247,7 +247,7 @@ inline void Foam::IjkField::operator=(const Type& val) template inline void Foam::IjkField::operator=(const Foam::zero) { - Field::operator=(Zero); + Field::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index b24c973db2..6c7e7cd79f 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -707,7 +707,12 @@ Foam::polyMesh::polyMesh } -Foam::polyMesh::polyMesh(const IOobject& io, const zero, const bool syncPar) +Foam::polyMesh::polyMesh +( + const IOobject& io, + const Foam::zero, + const bool syncPar +) : polyMesh(io, pointField(), faceList(), labelList(), labelList(), syncPar) {} diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H index 1d5a9ed081..1f0a015adb 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H @@ -332,7 +332,7 @@ public: //- Construct from IOobject or as zero-sized mesh // Boundary is added using addPatches() member function - polyMesh(const IOobject& io, const zero, const bool syncPar=true); + polyMesh(const IOobject& io, const Foam::zero, const bool syncPar=true); //- Construct from IOobject and components. // Boundary is added using addPatches() member function diff --git a/src/finiteArea/faMatrices/faMatrix/faMatrix.C b/src/finiteArea/faMatrices/faMatrix/faMatrix.C index d4b8576638..8241455c35 100644 --- a/src/finiteArea/faMatrices/faMatrix/faMatrix.C +++ b/src/finiteArea/faMatrices/faMatrix/faMatrix.C @@ -952,16 +952,6 @@ void Foam::faMatrix::operator-= } -template -void Foam::faMatrix::operator+=(const Foam::zero) -{} - - -template -void Foam::faMatrix::operator-=(const Foam::zero) -{} - - template void Foam::faMatrix::operator*= ( diff --git a/src/finiteArea/faMatrices/faMatrix/faMatrix.H b/src/finiteArea/faMatrices/faMatrix/faMatrix.H index 1d778a964d..d8bc359f13 100644 --- a/src/finiteArea/faMatrices/faMatrix/faMatrix.H +++ b/src/finiteArea/faMatrices/faMatrix/faMatrix.H @@ -499,8 +499,8 @@ public: void operator+=(const dimensioned&); void operator-=(const dimensioned&); - void operator+=(const Foam::zero); - void operator-=(const Foam::zero); + void operator+=(const Foam::zero) {} + void operator-=(const Foam::zero) {} void operator*=(const areaScalarField::Internal&); void operator*=(const tmp&); diff --git a/src/finiteVolume/finiteVolume/fvc/fvcDdt.C b/src/finiteVolume/finiteVolume/fvc/fvcDdt.C index 2b1c28390b..2ae8cc422a 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcDdt.C +++ b/src/finiteVolume/finiteVolume/fvc/fvcDdt.C @@ -146,7 +146,7 @@ template tmp> ddt ( - const one&, + const Foam::one, const GeometricField& vf ) { @@ -159,7 +159,7 @@ tmp> ddt ( const GeometricField& vf, - const one& + const Foam::one ) { return ddt(vf); diff --git a/src/finiteVolume/finiteVolume/fvc/fvcDdt.H b/src/finiteVolume/finiteVolume/fvc/fvcDdt.H index 6d12b192f4..6e658caa30 100644 --- a/src/finiteVolume/finiteVolume/fvc/fvcDdt.H +++ b/src/finiteVolume/finiteVolume/fvc/fvcDdt.H @@ -99,7 +99,7 @@ namespace fvc template tmp> ddt ( - const one&, + const Foam::one, const GeometricField& ); @@ -107,13 +107,13 @@ namespace fvc tmp> ddt ( const GeometricField&, - const one& + const Foam::one ); inline geometricZeroField ddt ( - const one&, - const one& + const Foam::one, + const Foam::one ) { return geometricZeroField(); diff --git a/src/finiteVolume/finiteVolume/fvm/fvmDdt.C b/src/finiteVolume/finiteVolume/fvm/fvmDdt.C index 76923637e1..2c76dca9d0 100644 --- a/src/finiteVolume/finiteVolume/fvm/fvmDdt.C +++ b/src/finiteVolume/finiteVolume/fvm/fvmDdt.C @@ -61,7 +61,7 @@ template tmp> ddt ( - const one&, + const Foam::one, const GeometricField& vf ) { @@ -128,8 +128,8 @@ template tmp> ddt ( - const one&, - const one&, + const Foam::one, + const Foam::one, const GeometricField& vf ) { @@ -141,7 +141,7 @@ template tmp> ddt ( - const one&, + const Foam::one, const volScalarField& rho, const GeometricField& vf ) @@ -155,7 +155,7 @@ tmp> ddt ( const volScalarField& alpha, - const one&, + const Foam::one, const GeometricField& vf ) { diff --git a/src/finiteVolume/finiteVolume/fvm/fvmDdt.H b/src/finiteVolume/finiteVolume/fvm/fvmDdt.H index f0276cd13b..f0eb30219d 100644 --- a/src/finiteVolume/finiteVolume/fvm/fvmDdt.H +++ b/src/finiteVolume/finiteVolume/fvm/fvmDdt.H @@ -61,7 +61,7 @@ namespace fvm template tmp> ddt ( - const one&, + const Foam::one, const GeometricField& ); @@ -90,15 +90,15 @@ namespace fvm template tmp> ddt ( - const one&, - const one&, + const Foam::one, + const Foam::one, const GeometricField& ); template tmp> ddt ( - const one&, + const Foam::one, const volScalarField&, const GeometricField& ); @@ -107,7 +107,7 @@ namespace fvm tmp> ddt ( const volScalarField&, - const one&, + const Foam::one, const GeometricField& ); } diff --git a/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.C b/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.C index 3294d6b10b..d1729c417d 100644 --- a/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.C +++ b/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.C @@ -100,7 +100,7 @@ template tmp> laplacian ( - const zero&, + const Foam::zero, const GeometricField& vf, const word& name ) @@ -116,7 +116,7 @@ template tmp> laplacian ( - const zero&, + const Foam::zero, const GeometricField& vf ) { @@ -131,7 +131,7 @@ template tmp> laplacian ( - const one&, + const Foam::one, const GeometricField& vf, const word& name ) @@ -144,7 +144,7 @@ template tmp> laplacian ( - const one&, + const Foam::one, const GeometricField& vf ) { diff --git a/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.H b/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.H index d50feb2455..de341cc614 100644 --- a/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.H +++ b/src/finiteVolume/finiteVolume/fvm/fvmLaplacian.H @@ -70,7 +70,7 @@ namespace fvm template tmp> laplacian ( - const zero&, + const Foam::zero, const GeometricField&, const word& ); @@ -78,7 +78,7 @@ namespace fvm template tmp> laplacian ( - const zero&, + const Foam::zero, const GeometricField& ); @@ -86,7 +86,7 @@ namespace fvm template tmp> laplacian ( - const one&, + const Foam::one, const GeometricField&, const word& ); @@ -94,7 +94,7 @@ namespace fvm template tmp> laplacian ( - const one&, + const Foam::one, const GeometricField& ); diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C index 14bacc7f0e..d570187911 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C @@ -1763,16 +1763,6 @@ void Foam::fvMatrix::operator-= } -template -void Foam::fvMatrix::operator+=(const Foam::zero) -{} - - -template -void Foam::fvMatrix::operator-=(const Foam::zero) -{} - - template void Foam::fvMatrix::operator*= ( diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H index 9f4b4b3448..b6d2528aef 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H @@ -676,8 +676,8 @@ public: void operator+=(const dimensioned&); void operator-=(const dimensioned&); - void operator+=(const Foam::zero); - void operator-=(const Foam::zero); + void operator+=(const Foam::zero) {} + void operator-=(const Foam::zero) {} void operator*=(const volScalarField::Internal&); void operator*=(const tmp&); From 944840f8d657fdada8bfdd21f08ab715e571e915 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 10 Aug 2023 11:51:18 +0200 Subject: [PATCH 3/5] ENH: polyMesh/faMesh hasGlobalData() query - test for existing globalData() or perhaps use DIY globalIndex instead STYLE: check for non-ASCII instead of BINARY with compression - allows for other non-ASCII formats --- src/OpenFOAM/db/Time/TimeIO.C | 4 ++-- src/OpenFOAM/meshes/pointMesh/pointMesh.H | 8 ++++++- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 22 +++++++------------ src/OpenFOAM/meshes/polyMesh/polyMesh.H | 23 ++++++++++++++------ src/OpenFOAM/meshes/polyMesh/polyMeshClear.C | 2 +- src/finiteArea/faMesh/faMesh.C | 6 +++++ src/finiteArea/faMesh/faMesh.H | 15 ++++++++----- src/finiteArea/faMesh/faMeshI.H | 12 ---------- 8 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/OpenFOAM/db/Time/TimeIO.C b/src/OpenFOAM/db/Time/TimeIO.C index b4126553c5..3084800865 100644 --- a/src/OpenFOAM/db/Time/TimeIO.C +++ b/src/OpenFOAM/db/Time/TimeIO.C @@ -412,10 +412,10 @@ void Foam::Time::readDict() if (writeStreamOption_.compression() == IOstreamOption::COMPRESSED) { - if (writeStreamOption_.format() == IOstreamOption::BINARY) + if (writeStreamOption_.format() != IOstreamOption::ASCII) { IOWarningInFunction(controlDict_) - << "Disabled binary format compression" + << "Disabled output compression for non-ascii format" << " (inefficient/ineffective)" << endl; diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.H b/src/OpenFOAM/meshes/pointMesh/pointMesh.H index ea960a5485..e28905ea80 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.H +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.H @@ -117,7 +117,13 @@ public: return boundary_; } - //- Return parallel info + //- Is demand-driven parallel info available? + bool hasGlobalData() const noexcept + { + return GeoMesh::mesh_.hasGlobalData(); + } + + //- Return parallel info (demand-driven) const globalMeshData& globalData() const { return GeoMesh::mesh_.globalData(); diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index 6c7e7cd79f..21153cf84b 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017, 2020 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -997,7 +997,7 @@ void Foam::polyMesh::addPatches // recalculation. Problem: should really be done in removeBoundary but // there is some info in parallelData which might be interesting inbetween // removeBoundary and addPatches. - globalMeshDataPtr_.clear(); + globalMeshDataPtr_.reset(nullptr); if (validBoundary) { @@ -1309,6 +1309,12 @@ void Foam::polyMesh::resetMotion() const } +bool Foam::polyMesh::hasGlobalData() const noexcept +{ + return bool(globalMeshDataPtr_); +} + + const Foam::globalMeshData& Foam::polyMesh::globalData() const { if (!globalMeshDataPtr_) @@ -1327,18 +1333,6 @@ const Foam::globalMeshData& Foam::polyMesh::globalData() const } -Foam::label Foam::polyMesh::comm() const noexcept -{ - return comm_; -} - - -Foam::label& Foam::polyMesh::comm() noexcept -{ - return comm_; -} - - void Foam::polyMesh::removeFiles(const fileName& instanceDir) const { fileName meshFilesPath = thisDb().time().path()/instanceDir/meshDir(); diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H index 1f0a015adb..513f9413c5 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H @@ -507,14 +507,8 @@ public: return cellZones_; } - //- Return parallel info - const globalMeshData& globalData() const; - //- Return communicator used for parallel communication - label comm() const noexcept; - - //- Return communicator used for parallel communication - label& comm() noexcept; + // Database //- Return the object registry const objectRegistry& thisDb() const noexcept @@ -523,6 +517,21 @@ public: } + // Parallel + + //- The communicator used for parallel communication + label comm() const noexcept { return comm_; } + + //- The communicator used for parallel communication + label& comm() noexcept { return comm_; } + + //- Is demand-driven parallel info available? + bool hasGlobalData() const noexcept; + + //- Return parallel info (demand-driven) + const globalMeshData& globalData() const; + + // Mesh motion //- Is mesh dynamic diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshClear.C b/src/OpenFOAM/meshes/polyMesh/polyMeshClear.C index ca445ea9d4..75703ddaeb 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshClear.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshClear.C @@ -185,7 +185,7 @@ void Foam::polyMesh::clearAddressing(const bool isMeshUpdate) // parallelData depends on the processorPatch ordering so force // recalculation - globalMeshDataPtr_.clear(); + globalMeshDataPtr_.reset(nullptr); // Reset valid directions geometricD_ = Zero; diff --git a/src/finiteArea/faMesh/faMesh.C b/src/finiteArea/faMesh/faMesh.C index 7c9afef0da..9da63cb09c 100644 --- a/src/finiteArea/faMesh/faMesh.C +++ b/src/finiteArea/faMesh/faMesh.C @@ -970,6 +970,12 @@ Foam::faMesh::edgeTransformTensors() const } +bool Foam::faMesh::hasGlobalData() const noexcept +{ + return bool(globalMeshDataPtr_); +} + + const Foam::faGlobalMeshData& Foam::faMesh::globalData() const { if (!globalMeshDataPtr_) diff --git a/src/finiteArea/faMesh/faMesh.H b/src/finiteArea/faMesh/faMesh.H index f3173e6441..8cbd45231e 100644 --- a/src/finiteArea/faMesh/faMesh.H +++ b/src/finiteArea/faMesh/faMesh.H @@ -648,13 +648,19 @@ public: const fileName& facesInstance() const; - // Communication support + // Parallel //- Return communicator used for parallel communication - inline label comm() const noexcept; + label comm() const noexcept { return comm_; } //- Return communicator used for parallel communication - inline label& comm() noexcept; + label& comm() noexcept { return comm_; } + + //- Is demand-driven parallel info available? + bool hasGlobalData() const noexcept; + + //- Return parallel info (demand-driven) + const faGlobalMeshData& globalData() const; // Access: Mesh size parameters @@ -736,9 +742,6 @@ public: //- The polyPatch/local-face for each faceLabels() inline const List& whichPatchFaces() const; - //- Return parallel info - const faGlobalMeshData& globalData() const; - //- Return ldu addressing virtual const lduAddressing& lduAddr() const; diff --git a/src/finiteArea/faMesh/faMeshI.H b/src/finiteArea/faMesh/faMeshI.H index 3d3db7b958..c04646d04c 100644 --- a/src/finiteArea/faMesh/faMeshI.H +++ b/src/finiteArea/faMesh/faMeshI.H @@ -41,18 +41,6 @@ inline const Foam::faBoundaryMesh& Foam::faMesh::boundary() const noexcept } -inline Foam::label Foam::faMesh::comm() const noexcept -{ - return comm_; -} - - -inline Foam::label& Foam::faMesh::comm() noexcept -{ - return comm_; -} - - inline Foam::label Foam::faMesh::nPoints() const noexcept { return nPoints_; From 4daaf6dd2a44979caa091d9150fa5d8a021464bf Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 9 Aug 2023 15:05:11 +0200 Subject: [PATCH 4/5] ENH: support move sematics for get/set putback token --- src/OpenFOAM/db/IOstreams/IOstreams/Istream.C | 54 ++++++++++++++----- src/OpenFOAM/db/IOstreams/IOstreams/Istream.H | 18 +++---- .../db/IOstreams/Pstreams/UIPstreamBase.C | 9 ++-- src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C | 7 +-- src/OpenFOAM/db/IOstreams/token/token.H | 4 ++ 5 files changed, 64 insertions(+), 28 deletions(-) diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C index e3e6875ae1..0c6b4cd824 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.C @@ -51,19 +51,27 @@ const Foam::token& Foam::Istream::peekBack() const noexcept return (putBackAvail_ ? putBackToken_ : token::undefinedToken); } +// Return the putback token if available or fetch a new token +// from the stream. +// +// Foam::token& Foam::Istream::peekToken() +// { +// if (!putBackAvail_) +// { +// putBackToken_.reset(); +// token tok; +// this->read(tok); +// putBackToken_ = std::move(tok); +// } +// +// return putBackToken_; +// } -bool Foam::Istream::peekBack(token& tok) + +void Foam::Istream::putBackClear() { - if (putBackAvail_) - { - tok = putBackToken_; - } - else - { - tok.reset(); - } - - return putBackAvail_; + putBackAvail_ = false; + putBackToken_.reset(); } @@ -89,6 +97,28 @@ void Foam::Istream::putBack(const token& tok) } +void Foam::Istream::putBack(token&& tok) +{ + if (bad()) + { + FatalIOErrorInFunction(*this) + << "Attempt to put back onto bad stream" + << exit(FatalIOError); + } + else if (putBackAvail_) + { + FatalIOErrorInFunction(*this) + << "Attempt to put back another token" + << exit(FatalIOError); + } + else + { + putBackAvail_ = true; + putBackToken_ = std::move(tok); + } +} + + bool Foam::Istream::getBack(token& tok) { if (bad()) @@ -100,7 +130,7 @@ bool Foam::Istream::getBack(token& tok) else if (putBackAvail_) { putBackAvail_ = false; - tok = putBackToken_; + tok = std::move(putBackToken_); return true; } diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H index 6cd20ba048..1710eab7bf 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H @@ -77,10 +77,7 @@ protected: // Protected Member Functions //- True if putback token is in use - bool hasPutback() const noexcept - { - return putBackAvail_; - } + bool hasPutback() const noexcept { return putBackAvail_; } public: @@ -124,15 +121,16 @@ public: // if a putback is unavailable. const token& peekBack() const noexcept; - //- Fetch putback token without removing it. - // \return false sets the token to undefined if no put-back - // was available - bool peekBack(token& tok); + //- Drop the putback token + void putBackClear(); - //- Put back a token. Only a single put back is permitted + //- Put back a token (copy). Only a single put back is permitted void putBack(const token& tok); - //- Get the put-back token if there is one. + //- Put back a token (move). Only a single put back is permitted + void putBack(token&& tok); + + //- Retrieve the put-back token if there is one. // \return false and sets token to undefined if no put-back // was available bool getBack(token& tok); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C index c4d4b8def6..4acde36731 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C @@ -273,6 +273,12 @@ Foam::Istream& Foam::UIPstreamBase::read(token& t) } } + + // Reset token, adjust its line number according to the stream + t.reset(); + t.lineNumber(this->lineNumber()); + + // Read character, return on error // - with additional handling for special stream flags @@ -303,9 +309,6 @@ Foam::Istream& Foam::UIPstreamBase::read(token& t) while (c == token::FLAG); - // Set the line number of this token to the current stream line number - t.lineNumber(this->lineNumber()); - // Analyse input starting with this character. switch (c) { diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C index cfc1deca0f..4385fce1f6 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C @@ -538,6 +538,10 @@ Foam::Istream& Foam::ISstream::read(token& t) return *this; } + // Reset token, adjust its line number according to the stream + t.reset(); + t.lineNumber(this->lineNumber()); + // Assume that the streams supplied are in working order. // Lines are counted by '\n' @@ -546,9 +550,6 @@ Foam::Istream& Foam::ISstream::read(token& t) char c = nextValid(); - // Set the line number of this token to the current stream line number - t.lineNumber(this->lineNumber()); - // Return on error if (!c) { diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index ec2fa135be..be3cb0194c 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -510,6 +510,9 @@ public: //- Token is COMPOUND inline bool isCompound() const noexcept; + //- True if token is not UNDEFINED or ERROR. Same as good(). + explicit operator bool() const noexcept { return good(); } + // Access @@ -690,6 +693,7 @@ public: void operator=(string*) = delete; }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // IOstream Operators From 066a5a997aef7790d87874f78b810444fbe455fa Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 11 Aug 2023 10:50:11 +0200 Subject: [PATCH 5/5] CONFIG: update compiler minimums (gcc-7.5.0) and standard (c++14) --- bin/tools/query-versions | 9 +++-- doc/Requirements.md | 6 ++-- etc/config.csh/compiler | 67 +++++++++++++++++++------------------ etc/config.sh/compiler | 27 ++++++++------- wmake/rules/General/Gcc/c++ | 8 ++--- 5 files changed, 59 insertions(+), 58 deletions(-) diff --git a/bin/tools/query-versions b/bin/tools/query-versions index 3445cf6420..183d004f0d 100755 --- a/bin/tools/query-versions +++ b/bin/tools/query-versions @@ -6,7 +6,7 @@ # \\ / A nd | www.openfoam.com # \\/ M anipulation | #------------------------------------------------------------------------------ -# Copyright (C) 2020 OpenCFD Ltd. +# Copyright (C) 2020-2023 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -116,11 +116,10 @@ export WM_PROJECT_DIR="$projectDir" # # parse this type of content # ---- -# default_clang_version=llvm-3.7.1 -# default_gcc_version=gcc-4.8.5 +# default_clang_version=llvm-[digits].[digits].[digits] +# default_gcc_version=gcc-[digits].[digits].[digits] # -# Gcc48*) gcc_version=gcc-4.8.5 ;; -# Gcc49*) gcc_version=gcc-4.9.4 ;; +# Gcc121*) gcc_version=gcc-[digits].[digits].[digits] ;; # ---- queryCompiler() diff --git a/doc/Requirements.md b/doc/Requirements.md index d4c8e9e1aa..abd3e7f848 100644 --- a/doc/Requirements.md +++ b/doc/Requirements.md @@ -1,10 +1,10 @@ ## OpenFOAM® System Requirements -OpenFOAM requires a functioning C++11 compiler and GNU `make` build toolchain. +OpenFOAM requires a functioning C++14 compiler and GNU `make` build toolchain. ### Minimum recommended versions -- gcc : 4.8.5 (absolute minimum, not really recommended) +- gcc : 7.5.0 (minimum, not necessarily recommended) - cmake: 3.8 (required for ParaView and CGAL build) - boost: 1.48 (required for CGAL build and some functionality) - fftw: 3.3.7 (recommended - required for FFT-related functionality) @@ -217,4 +217,4 @@ at any later stage _without_ recompiling OpenFOAM itself. [wiki-config]: https://develop.openfoam.com/Development/openfoam/-/wikis/configuring --- -Copyright 2019-2022 OpenCFD Ltd +Copyright 2019-2023 OpenCFD Ltd diff --git a/etc/config.csh/compiler b/etc/config.csh/compiler index 73df3611b1..262c792125 100644 --- a/etc/config.csh/compiler +++ b/etc/config.csh/compiler @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2016 OpenFOAM Foundation -# Copyright (C) 2016-2022 OpenCFD Ltd. +# Copyright (C) 2016-2023 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -58,8 +58,8 @@ switch ("$WM_COMPILER_TYPE") case ThirdParty: # Default/minimum versions (compiler, GMP, MPFR, MPC) - override as needed - set default_clang_version=llvm-3.7.1 - set default_gcc_version=gcc-4.8.5 + set default_clang_version=llvm-5.0.2 + set default_gcc_version=gcc-7.5.0 set default_gmp_version=gmp-system set default_mpfr_version=mpfr-system @@ -127,6 +127,7 @@ case ThirdParty: case Gcc75*: set gcc_version=gcc-7.5.0 breaksw + # Older : no assurance that they still work for OpenFOAM case Gcc74*: set gcc_version=gcc-7.4.0 breaksw @@ -159,24 +160,24 @@ case ThirdParty: case Gcc55*: set gcc_version=gcc-5.5.0 breaksw - case Gcc54*: - set gcc_version=gcc-5.4.0 - breaksw - case Gcc53*: - set gcc_version=gcc-5.3.0 - breaksw - case Gcc52*: - set gcc_version=gcc-5.2.0 - breaksw - case Gcc51*: - set gcc_version=gcc-5.1.0 - breaksw - case Gcc49*: - set gcc_version=gcc-4.9.4 - breaksw - case Gcc48*: - set gcc_version=gcc-4.8.5 - breaksw + #ancient# case Gcc54*: + #ancient# set gcc_version=gcc-5.4.0 + #ancient# breaksw + #ancient# case Gcc53*: + #ancient# set gcc_version=gcc-5.3.0 + #ancient# breaksw + #ancient# case Gcc52*: + #ancient# set gcc_version=gcc-5.2.0 + #ancient# breaksw + #ancient# case Gcc51*: + #ancient# set gcc_version=gcc-5.1.0 + #ancient# breaksw + #ancient# case Gcc49*: + #ancient# set gcc_version=gcc-4.9.4 + #ancient# breaksw + #ancient# case Gcc48*: + #ancient# set gcc_version=gcc-4.8.5 + #ancient# breaksw case Clang: set clang_version="$default_clang_version" @@ -217,18 +218,18 @@ case ThirdParty: case Clang50*: set clang_version=llvm-5.0.2 breaksw - case Clang40*: - set clang_version=llvm-4.0.1 - breaksw - case Clang39*: - set clang_version=llvm-3.9.1 - breaksw - case Clang38*: - set clang_version=llvm-3.8.1 - breaksw - case Clang37*: - set clang_version=llvm-3.7.1 - breaksw + #ancient# case Clang40*: + #ancient# set clang_version=llvm-4.0.1 + #ancient# breaksw + #ancient# case Clang39*: + #ancient# set clang_version=llvm-3.9.1 + #ancient# breaksw + #ancient# case Clang38*: + #ancient# set clang_version=llvm-3.8.1 + #ancient# breaksw + #ancient# case Clang37*: + #ancient# set clang_version=llvm-3.7.1 + #ancient# breaksw endsw diff --git a/etc/config.sh/compiler b/etc/config.sh/compiler index 4fa14f93e4..94c03678d1 100644 --- a/etc/config.sh/compiler +++ b/etc/config.sh/compiler @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2016-2022 OpenCFD Ltd. +# Copyright (C) 2016-2023 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -58,8 +58,8 @@ case "$WM_COMPILER_TYPE" in ThirdParty) # Default/minimum versions (compiler, GMP, MPFR, MPC) - override as needed - default_clang_version=llvm-3.7.1 - default_gcc_version=gcc-4.8.5 + default_clang_version=llvm-5.0.2 + default_gcc_version=gcc-7.5.0 default_gmp_version=gmp-system default_mpfr_version=mpfr-system @@ -92,6 +92,7 @@ ThirdParty) Gcc82*) gcc_version=gcc-8.2.0 ;; Gcc81*) gcc_version=gcc-8.1.0 ;; Gcc75*) gcc_version=gcc-7.5.0 ;; + # Older : no assurance that they still work for OpenFOAM Gcc74*) gcc_version=gcc-7.4.0 ;; Gcc73*) gcc_version=gcc-7.3.0 ;; Gcc72*) gcc_version=gcc-7.2.0 ;; @@ -103,12 +104,12 @@ ThirdParty) Gcc62*) gcc_version=gcc-6.2.0 ;; Gcc61*) gcc_version=gcc-6.1.0 ;; Gcc55*) gcc_version=gcc-5.5.0 ;; - Gcc54*) gcc_version=gcc-5.4.0 ;; - Gcc53*) gcc_version=gcc-5.3.0 ;; - Gcc52*) gcc_version=gcc-5.2.0 ;; - Gcc51*) gcc_version=gcc-5.1.0 ;; - Gcc49*) gcc_version=gcc-4.9.4 ;; - Gcc48*) gcc_version=gcc-4.8.5 ;; + #ancient# Gcc54*) gcc_version=gcc-5.4.0 ;; + #ancient# Gcc53*) gcc_version=gcc-5.3.0 ;; + #ancient# Gcc52*) gcc_version=gcc-5.2.0 ;; + #ancient# Gcc51*) gcc_version=gcc-5.1.0 ;; + #ancient# Gcc49*) gcc_version=gcc-4.9.4 ;; + #ancient# Gcc48*) gcc_version=gcc-4.8.5 ;; Clang) clang_version="$default_clang_version" ;; Clang140*) clang_version=llvm-14.0.5 ;; @@ -123,10 +124,10 @@ ThirdParty) Clang70*) clang_version=llvm-7.0.1 ;; Clang60*) clang_version=llvm-6.0.1 ;; Clang50*) clang_version=llvm-5.0.2 ;; - Clang40*) clang_version=llvm-4.0.1 ;; - Clang39*) clang_version=llvm-3.9.1 ;; - Clang38*) clang_version=llvm-3.8.1 ;; - Clang37*) clang_version=llvm-3.7.1 ;; + #ancient# Clang40*) clang_version=llvm-4.0.1 ;; + #ancient# Clang39*) clang_version=llvm-3.9.1 ;; + #ancient# Clang38*) clang_version=llvm-3.8.1 ;; + #ancient# Clang37*) clang_version=llvm-3.7.1 ;; esac diff --git a/wmake/rules/General/Gcc/c++ b/wmake/rules/General/Gcc/c++ index 1ccc6dd61a..d87479014f 100644 --- a/wmake/rules/General/Gcc/c++ +++ b/wmake/rules/General/Gcc/c++ @@ -1,12 +1,12 @@ #------------------------------------------------------------------------------ -# C++14 support with gcc-5 and later, but several systems (as of 2021) -# are still using gcc-4.8.4 (centos7, suse SLES12, ...) +# gcc compiler # -# NOTE if your system gcc is new enough can simply use c++14 too. +# On older systems: may need to upgrade the compiler, use a ThirdParty compiler +# or clang to have sufficient C++ language. #------------------------------------------------------------------------------ SUFFIXES += .C .cc .cpp .cxx -CC := g++$(COMPILER_VERSION) -std=c++11 +CC := g++$(COMPILER_VERSION) -std=c++14 c++ARCH := c++DBUG :=