mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: additional contiguous traits (#1378)
- change contiguous from a series of global functions to separate
templated traits classes:
- is_contiguous
- is_contiguous_label
- is_contiguous_scalar
The static constexpr 'value' and a constexpr conversion operator
allow use in template expressions. The change also makes it much
easier to define general traits and to inherit from them.
The is_contiguous_label and is_contiguous_scalar are special traits
for handling data of homogeneous components of the respective types.
This commit is contained in:
committed by
Andrew Heather
parent
3c07a1bb6f
commit
1d79c0452c
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -78,7 +78,7 @@ void infoHashString
|
||||
|
||||
void reportHashList(const UList<string>& list)
|
||||
{
|
||||
Info<< "contiguous = " << contiguous<string>() << nl << nl;
|
||||
Info<< "contiguous = " << is_contiguous<string>::value << nl << nl;
|
||||
|
||||
for (const string& val : list)
|
||||
{
|
||||
@ -91,7 +91,7 @@ void reportHashList(const UList<string>& list)
|
||||
|
||||
void reportHashList(const UList<label>& list)
|
||||
{
|
||||
Info<<"contiguous = " << contiguous<label>() << nl << nl;
|
||||
Info<<"contiguous = " << is_contiguous<label>::value << nl << nl;
|
||||
|
||||
for (const label val : list)
|
||||
{
|
||||
@ -110,7 +110,7 @@ void reportHashList(const UList<label>& list)
|
||||
|
||||
void reportHashList(const UList<face>& list)
|
||||
{
|
||||
Info<<"contiguous = " << contiguous<label>() << nl << nl;
|
||||
Info<<"contiguous = " << is_contiguous<label>::value << nl << nl;
|
||||
|
||||
for (const face& f : list)
|
||||
{
|
||||
@ -157,7 +157,7 @@ typedef Pair<word> wordPair;
|
||||
|
||||
void reportHashList(const UList<wordPair>& list)
|
||||
{
|
||||
Info<<"contiguous = " << contiguous<wordPair>() << nl << nl;
|
||||
Info<<"contiguous = " << is_contiguous<wordPair>::value << nl << nl;
|
||||
|
||||
for (const wordPair& pr : list)
|
||||
{
|
||||
@ -182,7 +182,7 @@ void reportHashList(const UList<wordPair>& list)
|
||||
|
||||
void reportHashList(const UList<labelPair>& list)
|
||||
{
|
||||
Info<<"contiguous = " << contiguous<labelPair>() << nl << nl;
|
||||
Info<<"contiguous = " << is_contiguous<labelPair>::value << nl << nl;
|
||||
|
||||
for (const labelPair& pr : list)
|
||||
{
|
||||
@ -203,7 +203,7 @@ void reportHashList(const UList<labelPair>& list)
|
||||
|
||||
void reportHashList(const UList<labelPairPair>& list)
|
||||
{
|
||||
Info<<"contiguous = " << contiguous<labelPairPair>() << nl << nl;
|
||||
Info<<"contiguous = " << is_contiguous<labelPairPair>::value << nl << nl;
|
||||
|
||||
for (const labelPairPair& pr : list)
|
||||
{
|
||||
@ -224,7 +224,7 @@ void reportHashList(const UList<labelPairPair>& list)
|
||||
|
||||
void reportHashList(const UList<edge>& list)
|
||||
{
|
||||
Info<<"contiguous = " << contiguous<edge>() << nl << nl;
|
||||
Info<<"contiguous = " << is_contiguous<edge>::value << nl << nl;
|
||||
|
||||
for (const edge& e : list)
|
||||
{
|
||||
@ -245,7 +245,7 @@ void reportHashList(const UList<edge>& list)
|
||||
|
||||
void reportHashList(const UList<triFace>& list)
|
||||
{
|
||||
Info<<"contiguous = " << contiguous<triFace>() << nl << nl;
|
||||
Info<<"contiguous = " << is_contiguous<triFace>::value << nl << nl;
|
||||
|
||||
for (const triFace& f : list)
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -112,7 +112,7 @@ Ostream& printListOutputType(const char* what)
|
||||
{
|
||||
Info<< what
|
||||
<< " (contiguous="
|
||||
<< contiguous<T>() << " no_linebreak="
|
||||
<< is_contiguous<T>::value << " no_linebreak="
|
||||
<< Detail::ListPolicy::no_linebreak<T>::value
|
||||
<< " short_length="
|
||||
<< Detail::ListPolicy::short_length<T>::value << ')';
|
||||
|
||||
@ -1,2 +1,7 @@
|
||||
/* EXE_INC = */
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/fileFormats/lnInclude \
|
||||
-I$(LIB_SRC)/surfMesh/lnInclude \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude \
|
||||
-I$(LIB_SRC)/parallel/distributed/lnInclude
|
||||
|
||||
/* EXE_LIBS = */
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -37,6 +37,7 @@ Description
|
||||
#include "IOstreams.H"
|
||||
#include "scalar.H"
|
||||
#include "vector.H"
|
||||
#include "Switch.H"
|
||||
|
||||
#include "labelRange.H"
|
||||
#include "scalarList.H"
|
||||
@ -44,24 +45,43 @@ Description
|
||||
#include "FixedList.H"
|
||||
#include "Pair.H"
|
||||
|
||||
#include "distributedTriSurfaceMesh.H"
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Wrong, but interesting to test
|
||||
// template<> struct contiguous<Pair<word>> : std::true_type {};
|
||||
template<> struct is_contiguous<Pair<word>> : std::true_type {};
|
||||
|
||||
} // End namespace Foam
|
||||
} // end namespace Foam
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
|
||||
template<class T>
|
||||
void printContiguous()
|
||||
void printInfo(const char* const name = nullptr)
|
||||
{
|
||||
Info<<"contiguous " << typeid(T).name() << " () = "
|
||||
<< contiguous<T>()
|
||||
// << " value = " << contiguous<T>::value
|
||||
<< nl;
|
||||
if (name == nullptr)
|
||||
{
|
||||
Info<< typeid(T).name();
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< name;
|
||||
}
|
||||
|
||||
Info<< " contiguous=" << Switch(is_contiguous<T>::value);
|
||||
|
||||
if (is_contiguous_label<T>::value)
|
||||
{
|
||||
Info<< " label";
|
||||
}
|
||||
if (is_contiguous_scalar<T>::value)
|
||||
{
|
||||
Info<< " scalar";
|
||||
}
|
||||
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
|
||||
@ -74,18 +94,16 @@ int main(int argc, char *argv[])
|
||||
argList::noParallel();
|
||||
argList::noFunctionObjects();
|
||||
|
||||
#include "setRootCase.H"
|
||||
printInfo<label>();
|
||||
printInfo<double>();
|
||||
printInfo<FixedList<double, 4>>();
|
||||
printInfo<Pair<long>>();
|
||||
|
||||
printContiguous<label>();
|
||||
printContiguous<double>();
|
||||
printContiguous<FixedList<int, 2>>();
|
||||
printContiguous<FixedList<int, 3>>();
|
||||
printContiguous<Pair<long>>();
|
||||
printInfo<FixedList<word, 2>>();
|
||||
printInfo<Pair<word>>();
|
||||
|
||||
printContiguous<FixedList<word, 2>>();
|
||||
printContiguous<Pair<word>>();
|
||||
|
||||
printContiguous<FixedList<FixedList<int, 2>, 2>>();
|
||||
printInfo<FixedList<FixedList<int, 2>, 2>>();
|
||||
printInfo<segment>();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2012-2015 OpenFOAM Foundation
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2012-2015 OpenFOAM Foundation
|
||||
@ -36,6 +36,7 @@ SourceFiles
|
||||
#ifndef indexedCellEnum_H
|
||||
#define indexedCellEnum_H
|
||||
|
||||
#include "contiguous.H"
|
||||
#include "Enum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -63,11 +64,10 @@ public:
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
inline bool contiguous<indexedCellEnum>()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
|
||||
|
||||
//- Contiguous data for indexedCellEnum
|
||||
template<> struct is_contiguous<indexedCellEnum> : std::true_type {};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
@ -323,32 +323,26 @@ public:
|
||||
|
||||
} // End namespace CGAL
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef CGAL_INEXACT
|
||||
namespace Foam
|
||||
{
|
||||
// For inexact representations where the storage type is a double, the data
|
||||
// is contiguous. This may not be true for exact number types.
|
||||
|
||||
template<>
|
||||
inline bool contiguous
|
||||
struct is_contiguous
|
||||
<
|
||||
CGAL::indexedVertex
|
||||
<
|
||||
K,
|
||||
CGAL::Triangulation_vertex_base_3<K>
|
||||
>
|
||||
>()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
CGAL::indexedVertex<K, CGAL::Triangulation_vertex_base_3<K>>
|
||||
> : std::true_type {};
|
||||
|
||||
template<>
|
||||
inline bool contiguous<CGAL::Triangulation_vertex_base_3<K>::Point>()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
struct is_contiguous
|
||||
<
|
||||
CGAL::Triangulation_vertex_base_3<K>::Point
|
||||
> : std::true_type {};
|
||||
|
||||
} // End namespace Foam
|
||||
#endif
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
@ -84,15 +84,17 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
|
||||
|
||||
//- Contiguous data for indexedVertexEnum
|
||||
template<> struct is_contiguous<indexedVertexEnum> : std::true_type {};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
||||
|
||||
Istream& operator>>(Istream&, indexedVertexEnum::vertexType&);
|
||||
Ostream& operator<<(Ostream&, const indexedVertexEnum::vertexType&);
|
||||
|
||||
template<>
|
||||
inline bool contiguous<indexedVertexEnum>()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
Reference in New Issue
Block a user