From d6b8c8f5101cc4eb60e49e294ec45383f80a0857 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Fri, 31 Jul 2015 13:59:37 -0600 Subject: [PATCH] Change TopologyType identifiers from enumeration to tags. Previously, the items used to identify parts of topology like points, cells, faces, etc. were in an enumeration. However, they are only really used in template specialization, and it is easier to use tags in this case. So, change the enumeration to a set of tag structures. Also made the following changes: * Renamed TopologyType to TopologyElement, which is more indicative of what we are referring to. * Moved the structures from the vtkm::cont namespace to the vtkm namespace. There is no reason not to be able to use them from either the control or execution environments. * Added a VTKM_IS_TOPOLOGY_ELEMENT_TAG macro to do type checks on template arguments that are supposed to be topology element tags. --- vtkm/CMakeLists.txt | 1 + vtkm/RegularConnectivity.h | 38 ++++--- vtkm/TopologyElementTag.h | 109 +++++++++++++++++++ vtkm/cont/CMakeLists.txt | 1 - vtkm/cont/CellSet.h | 2 +- vtkm/cont/CellSetExplicit.h | 6 +- vtkm/cont/CellSetStructured.h | 20 ++-- vtkm/cont/TopologyType.h | 37 ------- vtkm/cont/arg/TransportTagTopologyIn.h | 5 +- vtkm/cont/testing/UnitTestDataSetRegular.cxx | 30 +++-- vtkm/worklet/DispatcherMapTopology.h | 9 +- 11 files changed, 175 insertions(+), 83 deletions(-) create mode 100644 vtkm/TopologyElementTag.h delete mode 100644 vtkm/cont/TopologyType.h diff --git a/vtkm/CMakeLists.txt b/vtkm/CMakeLists.txt index 3796750b8..758076c1c 100644 --- a/vtkm/CMakeLists.txt +++ b/vtkm/CMakeLists.txt @@ -29,6 +29,7 @@ set(headers Pair.h RegularConnectivity.h RegularStructure.h + TopologyElementTag.h TypeListTag.h Types.h TypeTraits.h diff --git a/vtkm/RegularConnectivity.h b/vtkm/RegularConnectivity.h index 1db911795..d99ea97b4 100644 --- a/vtkm/RegularConnectivity.h +++ b/vtkm/RegularConnectivity.h @@ -22,9 +22,9 @@ #ifndef vtk_m_RegularConnectivity_h #define vtk_m_RegularConnectivity_h -#include #include -#include +#include +#include #include VTKM_BOOST_PRE_INCLUDE @@ -33,37 +33,38 @@ VTKM_BOOST_POST_INCLUDE namespace vtkm { -template +template struct SchedulingDimension { typedef vtkm::Id ValueType; }; -template -struct SchedulingDimension +template<> +struct SchedulingDimension<2> { typedef vtkm::Id2 ValueType; }; -template -struct SchedulingDimension +template<> +struct SchedulingDimension<3> { typedef vtkm::Id3 ValueType; }; -template +template struct IndexLookupHelper { // We want an unconditional failure if this unspecialized class ever gets // instantiated, because it means someone missed a topology mapping type. // We need to create a test which depends on the templated types so // it doesn't get picked up without a concrete instantiation. - BOOST_STATIC_ASSERT_MSG(From != To && From == To, + BOOST_STATIC_ASSERT_MSG(sizeof(To) == static_cast(-1), "Missing Specialization for Topologies"); }; template -struct IndexLookupHelper +struct IndexLookupHelper< + vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell, Dimension> { template VTKM_EXEC_CONT_EXPORT @@ -75,7 +76,8 @@ struct IndexLookupHelper }; template -struct IndexLookupHelper +struct IndexLookupHelper< + vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint, Dimension> { template VTKM_EXEC_CONT_EXPORT @@ -86,14 +88,16 @@ struct IndexLookupHelper } }; -template class RegularConnectivity { + VTKM_IS_TOPOLOGY_ELEMENT_TAG(FromTopology); + VTKM_IS_TOPOLOGY_ELEMENT_TAG(ToTopology); + public: - typedef typename SchedulingDimension< FromTopology, - ToTopoogy, - Dimension >::ValueType SchedulingDimension; + typedef typename SchedulingDimension::ValueType SchedulingDimension; RegularConnectivity(): rs() { @@ -124,14 +128,14 @@ public: VTKM_EXEC_CONT_EXPORT void GetIndices(vtkm::Id index, vtkm::Vec &ids) { - IndexLookupHelper::GetIndices(rs,index,ids); + IndexLookupHelper::GetIndices(rs,index,ids); } template struct ExecutionTypes { //Using this style so we can template the RegularConnecivity based on the //backend in the future without have to change the Transport logic - typedef vtkm::RegularConnectivity ExecObjectType; + typedef vtkm::RegularConnectivity ExecObjectType; }; template diff --git a/vtkm/TopologyElementTag.h b/vtkm/TopologyElementTag.h new file mode 100644 index 000000000..4fd4221f1 --- /dev/null +++ b/vtkm/TopologyElementTag.h @@ -0,0 +1,109 @@ +//============================================================================ +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +// +// Copyright 2015 Sandia Corporation. +// Copyright 2015 UT-Battelle, LLC. +// Copyright 2015 Los Alamos National Security. +// +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, +// the U.S. Government retains certain rights in this software. +// +// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +// Laboratory (LANL), the U.S. Government retains certain rights in +// this software. +//============================================================================ +#ifndef vtk_m_TopologyElementTag_h +#define vtk_m_TopologyElementTag_h + +#include + +VTKM_BOOST_PRE_INCLUDE +#include +VTKM_BOOST_POST_INCLUDE + +namespace vtkm { + +/// \brief A tag used to identify the cell elements in a topology. +/// +/// A topology element refers to some type of substructure of a topology. For +/// example, a 3D mesh has points, edges, faces, and cells. Each of these is an +/// example of a topology element and has its own tag. +/// +struct TopologyElementTagCell { }; + +/// \brief A tag used to identify the point elements in a topology. +/// +/// A topology element refers to some type of substructure of a topology. For +/// example, a 3D mesh has points, edges, faces, and cells. Each of these is an +/// example of a topology element and has its own tag. +/// +struct TopologyElementTagPoint { }; + +/// \brief A tag used to identify the edge elements in a topology. +/// +/// A topology element refers to some type of substructure of a topology. For +/// example, a 3D mesh has points, edges, faces, and cells. Each of these is an +/// example of a topology element and has its own tag. +/// +struct TopologyElementTagEdge { }; + +/// \brief A tag used to identify the face elements in a topology. +/// +/// A topology element refers to some type of substructure of a topology. For +/// example, a 3D mesh has points, edges, faces, and cells. Each of these is an +/// example of a topology element and has its own tag. +/// +struct TopologyElementTagFace { }; + + +namespace internal { + +/// Checks to see if the given object is a topology element tag. This check is +/// compatible with the Boost meta-template programing library (MPL). It +/// contains a typedef named \c type that is either boost::mpl::true_ or +/// boost::mpl::false_. Both of these have a typedef named value with the +/// respective boolean value. +/// +template +struct TopologyElementTagCheck +{ + typedef boost::mpl::false_ type; +}; + +template<> +struct TopologyElementTagCheck +{ + typedef boost::mpl::true_ type; +}; + +template<> +struct TopologyElementTagCheck +{ + typedef boost::mpl::true_ type; +}; + +template<> +struct TopologyElementTagCheck +{ + typedef boost::mpl::true_ type; +}; + +template<> +struct TopologyElementTagCheck +{ + typedef boost::mpl::true_ type; +}; + +#define VTKM_IS_TOPOLOGY_ELEMENT_TAG(type) \ + BOOST_MPL_ASSERT(( ::vtkm::internal::TopologyElementTagCheck )) + +} // namespace internal + +} // namespace vtkm + +#endif //vtk_m_TopologyElementTag_h diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index 515320692..b0588d1e1 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -64,7 +64,6 @@ set(headers StorageImplicit.h StorageListTag.h Timer.h - TopologyType.h ) #----------------------------------------------------------------------------- diff --git a/vtkm/cont/CellSet.h b/vtkm/cont/CellSet.h index 11c9686ac..920fdaa0b 100644 --- a/vtkm/cont/CellSet.h +++ b/vtkm/cont/CellSet.h @@ -79,7 +79,7 @@ protected: namespace internal { /// Checks to see if the given object is a cell set. This check is compatible -/// with the Boost meta-template programming library(MPL). It contains a +/// with the Boost meta-template programming library (MPL). It contains a /// typedef named \c type that is either boost::mpl::true_ or /// boost::mpl::false_. Both of these have a typedef named value with the /// respective boolean value. diff --git a/vtkm/cont/CellSetExplicit.h b/vtkm/cont/CellSetExplicit.h index 1320d0998..acebd34ab 100644 --- a/vtkm/cont/CellSetExplicit.h +++ b/vtkm/cont/CellSetExplicit.h @@ -20,9 +20,9 @@ #ifndef vtk_m_cont_CellSetExplicit_h #define vtk_m_cont_CellSetExplicit_h +#include #include #include -#include namespace vtkm { namespace cont { @@ -56,8 +56,10 @@ public: return this->NodesOfCellsConnectivity.GetNumberOfElements(); } - template + template struct ConnectivityType { + VTKM_IS_TOPOLOGY_ELEMENT_TAG(FromTopology); + VTKM_IS_TOPOLOGY_ELEMENT_TAG(ToTopology); // This type is really only valid for Point to Cell connectivity. When // other connectivity types are supported, these will need to be added. typedef ExplicitConnectivityType Type; diff --git a/vtkm/cont/CellSetStructured.h b/vtkm/cont/CellSetStructured.h index a5e98ff88..7a69da3bf 100644 --- a/vtkm/cont/CellSetStructured.h +++ b/vtkm/cont/CellSetStructured.h @@ -23,6 +23,7 @@ #include #include #include +#include namespace vtkm { namespace cont { @@ -47,28 +48,31 @@ public: return this->Structure.GetNumberOfCells(); } - template + template struct ConnectivityType { + VTKM_IS_TOPOLOGY_ELEMENT_TAG(FromTopology); + VTKM_IS_TOPOLOGY_ELEMENT_TAG(ToTopology); typedef vtkm::RegularConnectivity Type; }; VTKM_CONT_EXPORT - vtkm::RegularConnectivity + vtkm::RegularConnectivity< + vtkm::TopologyElementTagPoint,vtkm::TopologyElementTagCell,Dimension> GetNodeToCellConnectivity() const { - typedef vtkm::RegularConnectivity NodeToCellConnectivity; return NodeToCellConnectivity(this->Structure); } VTKM_CONT_EXPORT - vtkm::RegularConnectivity + vtkm::RegularConnectivity< + vtkm::TopologyElementTagCell,vtkm::TopologyElementTagPoint,Dimension> GetCellToNodeConnectivity() const { - typedef vtkm::RegularConnectivity CellToNodeConnectivity; return CellToNodeConnectivity(this->Structure); } diff --git a/vtkm/cont/TopologyType.h b/vtkm/cont/TopologyType.h deleted file mode 100644 index 83a86f91b..000000000 --- a/vtkm/cont/TopologyType.h +++ /dev/null @@ -1,37 +0,0 @@ -//============================================================================ -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -// Copyright 2015 Sandia Corporation. -// Copyright 2015 UT-Battelle, LLC. -// Copyright 2015 Los Alamos National Security. -// -// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, -// the U.S. Government retains certain rights in this software. -// -// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National -// Laboratory (LANL), the U.S. Government retains certain rights in -// this software. -//============================================================================ -#ifndef vtk_m_cont_TopologyType_h -#define vtk_m_cont_TopologyType_h - -namespace vtkm { -namespace cont { - -enum TopologyType -{ - NODE, - CELL, - EDGE, - FACE -}; - -} // namespace cont -} // namespace vtkm - -#endif //vtk_m_cont_TopologyType_h diff --git a/vtkm/cont/arg/TransportTagTopologyIn.h b/vtkm/cont/arg/TransportTagTopologyIn.h index cb3071497..8927ab767 100644 --- a/vtkm/cont/arg/TransportTagTopologyIn.h +++ b/vtkm/cont/arg/TransportTagTopologyIn.h @@ -20,10 +20,10 @@ #ifndef vtk_m_cont_arg_TransportTagTopologyIn_h #define vtk_m_cont_arg_TransportTagTopologyIn_h +#include #include #include -#include #include @@ -44,7 +44,8 @@ struct Transport::Type + ::template ConnectivityType< + vtkm::TopologyElementTagPoint,vtkm::TopologyElementTagCell>::Type ::template ExecutionTypes ::ExecObjectType ExecObjectType; diff --git a/vtkm/cont/testing/UnitTestDataSetRegular.cxx b/vtkm/cont/testing/UnitTestDataSetRegular.cxx index df83fb068..cc2d6302a 100644 --- a/vtkm/cont/testing/UnitTestDataSetRegular.cxx +++ b/vtkm/cont/testing/UnitTestDataSetRegular.cxx @@ -18,14 +18,14 @@ // this software. //============================================================================ -#include -#include - #include #include #include #include +#include +#include + static void TwoDimRegularTest(); static void ThreeDimRegularTest(); @@ -67,10 +67,14 @@ TwoDimRegularTest() VTKM_TEST_ASSERT(shape == vtkm::VTKM_PIXEL, "Incorrect element type."); } - vtkm::RegularConnectivity nodeToCell = - cellSet.GetNodeToCellConnectivity(); - vtkm::RegularConnectivity cellToNode = - cellSet.GetCellToNodeConnectivity(); + vtkm::RegularConnectivity< + vtkm::TopologyElementTagPoint, + vtkm::TopologyElementTagCell, + 2> nodeToCell = cellSet.GetNodeToCellConnectivity(); + vtkm::RegularConnectivity< + vtkm::TopologyElementTagCell, + vtkm::TopologyElementTagPoint, + 2> cellToNode = cellSet.GetCellToNodeConnectivity(); vtkm::Id cells[2][4] = {{0,1,3,4}, {1,2,4,5}}; vtkm::Vec nodeIds; @@ -135,8 +139,10 @@ ThreeDimRegularTest() } //Test regular connectivity. - vtkm::RegularConnectivity nodeToCell = - cellSet.GetNodeToCellConnectivity(); + vtkm::RegularConnectivity< + vtkm::TopologyElementTagPoint, + vtkm::TopologyElementTagCell, + 3> nodeToCell = cellSet.GetNodeToCellConnectivity(); vtkm::Id expectedPointIds[8] = {0,1,3,4,6,7,9,10}; vtkm::Vec retrievedPointIds; nodeToCell.GetIndices(0, retrievedPointIds); @@ -147,8 +153,10 @@ ThreeDimRegularTest() "Incorrect node ID for cell"); } - vtkm::RegularConnectivity cellToNode = - cellSet.GetCellToNodeConnectivity(); + vtkm::RegularConnectivity< + vtkm::TopologyElementTagCell, + vtkm::TopologyElementTagPoint, + 3> cellToNode = cellSet.GetCellToNodeConnectivity(); vtkm::Vec expectedCellIds; vtkm::Id retrievedCellIds[8] = {0,-1,-1,-1,-1,-1,-1,-1}; cellToNode.GetIndices(0, expectedCellIds); diff --git a/vtkm/worklet/DispatcherMapTopology.h b/vtkm/worklet/DispatcherMapTopology.h index fbd83e81b..bdd8cb8f7 100644 --- a/vtkm/worklet/DispatcherMapTopology.h +++ b/vtkm/worklet/DispatcherMapTopology.h @@ -114,12 +114,13 @@ public: } template VTKM_CONT_EXPORT - void InvokeBasedOnDomainType(const Invocation &invocation, - const vtkm::RegularConnectivity& domain) const + void InvokeBasedOnDomainType( + const Invocation &invocation, + const vtkm::RegularConnectivity& domain) const { // For a DispatcherMapTopology, the inputDomain is some for of connectivity