From 265e52022560c619dc0115bb88e270e702c95b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz> Date: Sun, 6 Nov 2016 12:27:40 +0100 Subject: [PATCH] Fixed getType methods in MeshConfigBase and MeshEntity --- src/TNL/Meshes/MeshConfigBase.h | 9 ++- src/TNL/Meshes/MeshDetails/MeshEntity_impl.h | 10 +-- src/TNL/Meshes/Topologies/MeshEdgeTopology.h | 9 ++- .../Topologies/MeshHexahedronTopology.h | 13 ++- .../Topologies/MeshQuadrilateralTopology.h | 11 ++- .../Meshes/Topologies/MeshSimplexTopology.h | 81 ++++++++++--------- .../Topologies/MeshTetrahedronTopology.h | 13 ++- .../Meshes/Topologies/MeshTriangleTopology.h | 11 ++- .../Meshes/Topologies/MeshVertexTopology.h | 9 ++- src/TNL/param-types.h | 1 + 10 files changed, 107 insertions(+), 60 deletions(-) diff --git a/src/TNL/Meshes/MeshConfigBase.h b/src/TNL/Meshes/MeshConfigBase.h index 05cd4a8799..0b272fec57 100644 --- a/src/TNL/Meshes/MeshConfigBase.h +++ b/src/TNL/Meshes/MeshConfigBase.h @@ -17,6 +17,7 @@ #pragma once #include <TNL/String.h> +#include <TNL/param-types.h> namespace TNL { namespace Meshes { @@ -49,7 +50,13 @@ struct MeshConfigBase static String getType() { - return String( "MeshConfigBase< >"); + return String( "Meshes::MeshConfigBase< " ) + + Cell::getType() + ", " + + String( WorldDimensions ) + ", " + + TNL::getType< Real >() + ", " + + TNL::getType< GlobalIndex >() + ", " + + TNL::getType< LocalIndex >() + ", " + + TNL::getType< Id >() + " >"; }; /**** diff --git a/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h b/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h index f037a87101..91d28b8c89 100644 --- a/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h +++ b/src/TNL/Meshes/MeshDetails/MeshEntity_impl.h @@ -27,7 +27,9 @@ String MeshEntity< MeshConfig, EntityTopology >:: getType() { - return String( "MeshEntity< ... >" ); + return String( "MeshEntity< " ) + + MeshConfig::getType() + ", " + + EntityTopology::getType() + " >"; } template< typename MeshConfig, @@ -45,8 +47,7 @@ bool MeshEntity< MeshConfig, EntityTopology >:: save( File& file ) const { - if( ! MeshSubentityAccess< MeshConfig, EntityTopology >::save( file ) /*|| - ! MeshSuperentityStorageLayers< MeshConfig, EntityTopology >::save( file )*/ ) + if( ! MeshSubentityAccess< MeshConfig, EntityTopology >::save( file ) ) return false; return true; } @@ -57,8 +58,7 @@ bool MeshEntity< MeshConfig, EntityTopology >:: load( File& file ) { - if( ! MeshSubentityAccess< MeshConfig, EntityTopology >::load( file ) /*|| - ! MeshSuperentityStorageLayers< MeshConfig, EntityTopology >::load( file ) */ ) + if( ! MeshSubentityAccess< MeshConfig, EntityTopology >::load( file ) ) return false; return true; } diff --git a/src/TNL/Meshes/Topologies/MeshEdgeTopology.h b/src/TNL/Meshes/Topologies/MeshEdgeTopology.h index 34e8778baa..8b2a2bc3c6 100644 --- a/src/TNL/Meshes/Topologies/MeshEdgeTopology.h +++ b/src/TNL/Meshes/Topologies/MeshEdgeTopology.h @@ -24,7 +24,12 @@ namespace Meshes { struct MeshEdgeTopology { - static const int dimensions = 1; + static constexpr int dimensions = 1; + + static String getType() + { + return "MeshEdgeTopology"; + } }; @@ -33,7 +38,7 @@ struct MeshSubtopology< MeshEdgeTopology, 0 > { typedef MeshVertexTopology Topology; - static const int count = 2; + static constexpr int count = 2; }; } // namespace Meshes diff --git a/src/TNL/Meshes/Topologies/MeshHexahedronTopology.h b/src/TNL/Meshes/Topologies/MeshHexahedronTopology.h index 4dc1ff3aca..3dd548e0fb 100644 --- a/src/TNL/Meshes/Topologies/MeshHexahedronTopology.h +++ b/src/TNL/Meshes/Topologies/MeshHexahedronTopology.h @@ -23,7 +23,12 @@ namespace Meshes { struct MeshHexahedronTopology { - static const int dimensions = 3; + static constexpr int dimensions = 3; + + static String getType() + { + return "MeshHexahedronTopology"; + } }; template<> @@ -31,7 +36,7 @@ struct MeshSubtopology< MeshHexahedronTopology, 0 > { typedef MeshVertexTopology Topology; - static const int count = 8; + static constexpr int count = 8; }; template<> @@ -39,7 +44,7 @@ struct MeshSubtopology< MeshHexahedronTopology, 1 > { typedef MeshEdgeTopology Topology; - static const int count = 12; + static constexpr int count = 12; }; template<> @@ -47,7 +52,7 @@ struct MeshSubtopology< MeshHexahedronTopology, 2 > { typedef MeshQuadrilateralTopology Topology; - static const int count = 6; + static constexpr int count = 6; }; /**** diff --git a/src/TNL/Meshes/Topologies/MeshQuadrilateralTopology.h b/src/TNL/Meshes/Topologies/MeshQuadrilateralTopology.h index 4dd844e4c9..cd94776454 100644 --- a/src/TNL/Meshes/Topologies/MeshQuadrilateralTopology.h +++ b/src/TNL/Meshes/Topologies/MeshQuadrilateralTopology.h @@ -23,7 +23,12 @@ namespace Meshes { struct MeshQuadrilateralTopology { - static const int dimensions = 2; + static constexpr int dimensions = 2; + + static String getType() + { + return "MeshQuadrilateralTopology"; + } }; @@ -32,7 +37,7 @@ struct MeshSubtopology< MeshQuadrilateralTopology, 0 > { typedef MeshVertexTopology Topology; - static const int count = 4; + static constexpr int count = 4; }; template<> @@ -40,7 +45,7 @@ struct MeshSubtopology< MeshQuadrilateralTopology, 1 > { typedef MeshEdgeTopology Topology; - static const int count = 4; + static constexpr int count = 4; }; diff --git a/src/TNL/Meshes/Topologies/MeshSimplexTopology.h b/src/TNL/Meshes/Topologies/MeshSimplexTopology.h index 2120a71c7a..8bdb3bb01f 100644 --- a/src/TNL/Meshes/Topologies/MeshSimplexTopology.h +++ b/src/TNL/Meshes/Topologies/MeshSimplexTopology.h @@ -17,6 +17,8 @@ #pragma once +#include <TNL/String.h> + namespace TNL { namespace Meshes { @@ -24,7 +26,12 @@ template< int dimensions_ > class MeshSimplexTopology { public: - static const int dimensions = dimensions_; + static constexpr int dimensions = dimensions_; + + static String getType() + { + return String( "MeshSimplexTopology< " ) + String( dimensions ) + " >"; + } }; template< unsigned int n, unsigned int k > @@ -37,26 +44,26 @@ template< int dimensions, int subtopologyDim > class MeshSubtopology< MeshSimplexTopology< dimensions >, subtopologyDim > { - static_assert( 0 < subtopologyDim && subtopologyDim < dim, "invalid subtopology dimension" ); + static_assert( 0 < subtopologyDim && subtopologyDim < dim, "invalid subtopology dimension" ); - static const int topologyVertexCount = MeshSubtopology< MeshSimplexTopology< dimensions >, 0 >::count; - static const int subtopologyVertexCount = MeshSubtopology< MeshSimplexTopology< subtopologyDim >, 0>::count; + static constexpr int topologyVertexCount = MeshSubtopology< MeshSimplexTopology< dimensions >, 0 >::count; + static constexpr int subtopologyVertexCount = MeshSubtopology< MeshSimplexTopology< subtopologyDim >, 0>::count; public: - typedef MeshSimplexTopology< subtopologyDim > Topology; + typedef MeshSimplexTopology< subtopologyDim > Topology; - static const int count = tnlNumCombinations< topologyVertexCount, subtopologyVertexCount >::value; + static constexpr int count = tnlNumCombinations< topologyVertexCount, subtopologyVertexCount >::value; }; template< int dimensions > class MeshSubtopology< MeshSimplexTopology< dimensions >, 0 > { - static_assert(0 < dim, "invalid dimension"); + static_assert(0 < dim, "invalid dimension"); public: - typedef MeshVertexTopology Topology; + typedef MeshVertexTopology Topology; - static const int count = dim + 1; + static constexpr int count = dim + 1; }; @@ -67,44 +74,44 @@ template< int dimensions, struct tnlSubentityVertex< MeshSimplexTopology< dimensions >, Subtopology, subtopologyIndex, vertexIndex > { private: - static const int subtopologyCount = Subtopology< MeshSimplexTopology< dimensions >, Subtopology::dimensions >::count; - static const int topologyVertexCount = Subtopology< MeshSimplex< dimensions >, 0 >::count; - static const int subtopologyVertexCount = Subtopology< Subtopology, 0 >::count; + static constexpr int subtopologyCount = Subtopology< MeshSimplexTopology< dimensions >, Subtopology::dimensions >::count; + static constexpr int topologyVertexCount = Subtopology< MeshSimplex< dimensions >, 0 >::count; + static constexpr int subtopologyVertexCount = Subtopology< Subtopology, 0 >::count; - static_assert(1 < dimensions, "subtopology vertex can be specified for topologies of dimension 2 or higher"); - static_assert(0 <= subtopologyIndex && subtopologyIndex < subtopologyCount, "invalid subtopology index"); - static_assert(0 <= vertexIndex && vertexIndex < subtopologyVertexCount, "invalid subtopology vertex index"); + static_assert(1 < dimensions, "subtopology vertex can be specified for topologies of dimension 2 or higher"); + static_assert(0 <= subtopologyIndex && subtopologyIndex < subtopologyCount, "invalid subtopology index"); + static_assert(0 <= vertexIndex && vertexIndex < subtopologyVertexCount, "invalid subtopology vertex index"); public: - static const int index = CombinationValue< topologyVertexCount, subtopologyVertexCount, subtopologyIndex, vertexIndex>::value; + static constexpr int index = CombinationValue< topologyVertexCount, subtopologyVertexCount, subtopologyIndex, vertexIndex>::value; }; template< unsigned int n, unsigned int k > class tnlStaticNumCombinations { - static_assert(0 < k && k < n, "invalid argument"); + static_assert(0 < k && k < n, "invalid argument"); public: - static const unsigned int value = tnlNumCombinations< n - 1, k - 1 >::value + tnlNumCombinations< n - 1, k >::value; + static const unsigned int value = tnlNumCombinations< n - 1, k - 1 >::value + tnlNumCombinations< n - 1, k >::value; }; // Nummber of combinations (n choose k) template< unsigned int n > class tnlNumCombinations< n, 0 > { - static_assert(0 <= n, "invalid argument"); + static_assert(0 <= n, "invalid argument"); public: - static const unsigned int value = 1; + static const unsigned int value = 1; }; template< unsigned int n > class tnlNumCombinations< n, n > { - static_assert(0 < n, "invalid argument"); + static_assert(0 < n, "invalid argument"); public: - static const unsigned int value = 1; + static const unsigned int value = 1; }; // Compile-time generation of combinations @@ -123,14 +130,14 @@ template< unsigned int n, unsigned int valueIndex > class tnlCombinationValue { - static_assert( combinationIndex < NumCombinations< n, k >::value, "invalid combination index" ); - static_assert( valueIndex < k, "invalid value index" ); + static_assert( combinationIndex < NumCombinations< n, k >::value, "invalid combination index" ); + static_assert( valueIndex < k, "invalid value index" ); - static const unsigned int incrementValueIndex = tnlCombinationIncrement< n, k, combinationIndex - 1>::valueIndex; + static const unsigned int incrementValueIndex = tnlCombinationIncrement< n, k, combinationIndex - 1>::valueIndex; public: - static const unsigned int value = ( valueIndex < incrementValueIndex ? tnlCombinationValue< n, k, combinationIndex - 1, valueIndex >::value : - tnlCombinationValue< n, k, combinationIndex - 1, incrementValueIndex >::value + + static const unsigned int value = ( valueIndex < incrementValueIndex ? tnlCombinationValue< n, k, combinationIndex - 1, valueIndex >::value : + tnlCombinationValue< n, k, combinationIndex - 1, incrementValueIndex >::value + valueIndex - incrementValueIndex + 1); }; @@ -139,12 +146,12 @@ template< unsigned int n, unsigned int valueIndex > class tnlCombinationValue< n, k, 0, valueIndex > { - static_assert( valueIndex < k, "invalid value index" ); + static_assert( valueIndex < k, "invalid value index" ); - static const unsigned int incrementValueIndex = tnlCombinationIncrement< n, k, 0 >::valueIndex; + static const unsigned int incrementValueIndex = tnlCombinationIncrement< n, k, 0 >::valueIndex; public: - static const unsigned int value = valueIndex; + static const unsigned int value = valueIndex; }; // The CombinationIncrement class determines value index of the particular combination which will be incremented when generating the next combination @@ -154,12 +161,12 @@ template< unsigned int n, unsigned int valueIndex > class tnlCombinationIncrementImpl { - static_assert( combinationIndex < tnlNumCombinations< n, k >::value - 1, "nothing to increment" ); + static_assert( combinationIndex < tnlNumCombinations< n, k >::value - 1, "nothing to increment" ); - static const bool incrementPossible = ( tnlCombinationValue< n, k, combinationIndex, valueIndex >::value + k - valueIndex < n ); + static const bool incrementPossible = ( tnlCombinationValue< n, k, combinationIndex, valueIndex >::value + k - valueIndex < n ); public: - static const int valueIndex = ( incrementPossible ? valueIndex : tnlCombinationIncrementImpl< n, k, combinationIndex, valueIndex - 1 >::valueIndex ); + static constexpr int valueIndex = ( incrementPossible ? valueIndex : tnlCombinationIncrementImpl< n, k, combinationIndex, valueIndex - 1 >::valueIndex ); }; template< unsigned int n, @@ -167,10 +174,10 @@ template< unsigned int n, unsigned int combinationIndex > class tnlCombinationIncrementImpl< n, k, combinationIndex, 0 > { - static_assert( combinationIndex < tnlNumCombinations<n, k>::value - 1, "nothing to increment" ); + static_assert( combinationIndex < tnlNumCombinations<n, k>::value - 1, "nothing to increment" ); public: - static const int valueIndex = 0; + static constexpr int valueIndex = 0; }; template< unsigned int n, @@ -178,10 +185,10 @@ template< unsigned int n, unsigned int combinationIndex > class tnlCombinationIncrement { - static_assert( combinationIndex < tnlNumCombinations< n, k >::value - 1, "nothing to increment" ); + static_assert( combinationIndex < tnlNumCombinations< n, k >::value - 1, "nothing to increment" ); public: - static const unsigned int valueIndex = tnlCombinationIncrementImpl< n, k, combinationIndex, k - 1 >::valueIndex; + static const unsigned int valueIndex = tnlCombinationIncrementImpl< n, k, combinationIndex, k - 1 >::valueIndex; }; } // namespace Meshes diff --git a/src/TNL/Meshes/Topologies/MeshTetrahedronTopology.h b/src/TNL/Meshes/Topologies/MeshTetrahedronTopology.h index 4f0067c255..849d528cb7 100644 --- a/src/TNL/Meshes/Topologies/MeshTetrahedronTopology.h +++ b/src/TNL/Meshes/Topologies/MeshTetrahedronTopology.h @@ -23,7 +23,12 @@ namespace Meshes { struct MeshTetrahedronTopology { - static const int dimensions = 3; + static constexpr int dimensions = 3; + + static String getType() + { + return "MeshTetrahedronTopology"; + } }; template<> @@ -31,7 +36,7 @@ struct MeshSubtopology< MeshTetrahedronTopology, 0 > { typedef MeshVertexTopology Topology; - static const int count = 4; + static constexpr int count = 4; }; template<> @@ -39,7 +44,7 @@ struct MeshSubtopology< MeshTetrahedronTopology, 1 > { typedef MeshEdgeTopology Topology; - static const int count = 6; + static constexpr int count = 6; }; template<> @@ -47,7 +52,7 @@ struct MeshSubtopology< MeshTetrahedronTopology, 2 > { typedef MeshTriangleTopology Topology; - static const int count = 4; + static constexpr int count = 4; }; diff --git a/src/TNL/Meshes/Topologies/MeshTriangleTopology.h b/src/TNL/Meshes/Topologies/MeshTriangleTopology.h index 0305c4355c..f49ccf0e10 100644 --- a/src/TNL/Meshes/Topologies/MeshTriangleTopology.h +++ b/src/TNL/Meshes/Topologies/MeshTriangleTopology.h @@ -23,7 +23,12 @@ namespace Meshes { struct MeshTriangleTopology { - static const int dimensions = 2; + static constexpr int dimensions = 2; + + static String getType() + { + return "MeshTriangleTopology"; + } }; @@ -32,7 +37,7 @@ struct MeshSubtopology< MeshTriangleTopology, 0 > { typedef MeshVertexTopology Topology; - static const int count = 3; + static constexpr int count = 3; }; template<> @@ -40,7 +45,7 @@ struct MeshSubtopology< MeshTriangleTopology, 1 > { typedef MeshEdgeTopology Topology; - static const int count = 3; + static constexpr int count = 3; }; diff --git a/src/TNL/Meshes/Topologies/MeshVertexTopology.h b/src/TNL/Meshes/Topologies/MeshVertexTopology.h index 5c70978f74..3040e21a7f 100644 --- a/src/TNL/Meshes/Topologies/MeshVertexTopology.h +++ b/src/TNL/Meshes/Topologies/MeshVertexTopology.h @@ -16,12 +16,19 @@ #pragma once +#include <TNL/String.h> + namespace TNL { namespace Meshes { struct MeshVertexTopology { - static const int dimensions = 0; + static constexpr int dimensions = 0; + + static String getType() + { + return "MeshVertexTopology"; + } }; } // namespace Meshes diff --git a/src/TNL/param-types.h b/src/TNL/param-types.h index 8a13e09565..34d5f68de1 100644 --- a/src/TNL/param-types.h +++ b/src/TNL/param-types.h @@ -18,6 +18,7 @@ namespace TNL { template< typename T > String getType() { return T::getType(); }; +template<> inline String getType< void >() { return String( "void" ); }; template<> inline String getType< bool >() { return String( "bool" ); }; template<> inline String getType< short int >() { return String( "short int" ); }; template<> inline String getType< int >() { return String( "int" ); }; -- GitLab