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 +{}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //