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.
This commit is contained in:
Kenneth Moreland 2015-07-31 13:59:37 -06:00
parent 91ce7b12c1
commit d6b8c8f510
11 changed files with 175 additions and 83 deletions

@ -29,6 +29,7 @@ set(headers
Pair.h Pair.h
RegularConnectivity.h RegularConnectivity.h
RegularStructure.h RegularStructure.h
TopologyElementTag.h
TypeListTag.h TypeListTag.h
Types.h Types.h
TypeTraits.h TypeTraits.h

@ -22,9 +22,9 @@
#ifndef vtk_m_RegularConnectivity_h #ifndef vtk_m_RegularConnectivity_h
#define vtk_m_RegularConnectivity_h #define vtk_m_RegularConnectivity_h
#include <vtkm/Types.h>
#include <vtkm/RegularStructure.h> #include <vtkm/RegularStructure.h>
#include <vtkm/cont/TopologyType.h> #include <vtkm/Types.h>
#include <vtkm/TopologyElementTag.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h> #include <vtkm/cont/DeviceAdapterAlgorithm.h>
VTKM_BOOST_PRE_INCLUDE VTKM_BOOST_PRE_INCLUDE
@ -33,37 +33,38 @@ VTKM_BOOST_POST_INCLUDE
namespace vtkm { namespace vtkm {
template<vtkm::cont::TopologyType From, vtkm::cont::TopologyType To, vtkm::IdComponent Dimension> template<vtkm::IdComponent Dimension>
struct SchedulingDimension struct SchedulingDimension
{ {
typedef vtkm::Id ValueType; typedef vtkm::Id ValueType;
}; };
template<vtkm::cont::TopologyType From, vtkm::cont::TopologyType To> template<>
struct SchedulingDimension<From,To, 2> struct SchedulingDimension<2>
{ {
typedef vtkm::Id2 ValueType; typedef vtkm::Id2 ValueType;
}; };
template<vtkm::cont::TopologyType From, vtkm::cont::TopologyType To> template<>
struct SchedulingDimension<From,To, 3> struct SchedulingDimension<3>
{ {
typedef vtkm::Id3 ValueType; typedef vtkm::Id3 ValueType;
}; };
template<vtkm::cont::TopologyType From, vtkm::cont::TopologyType To, vtkm::IdComponent Dimension> template<typename From, typename To, vtkm::IdComponent Dimension>
struct IndexLookupHelper struct IndexLookupHelper
{ {
// We want an unconditional failure if this unspecialized class ever gets // We want an unconditional failure if this unspecialized class ever gets
// instantiated, because it means someone missed a topology mapping type. // instantiated, because it means someone missed a topology mapping type.
// We need to create a test which depends on the templated types so // We need to create a test which depends on the templated types so
// it doesn't get picked up without a concrete instantiation. // 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<size_t>(-1),
"Missing Specialization for Topologies"); "Missing Specialization for Topologies");
}; };
template<vtkm::IdComponent Dimension> template<vtkm::IdComponent Dimension>
struct IndexLookupHelper<vtkm::cont::NODE,vtkm::cont::CELL,Dimension> struct IndexLookupHelper<
vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell, Dimension>
{ {
template <vtkm::IdComponent ItemTupleLength> template <vtkm::IdComponent ItemTupleLength>
VTKM_EXEC_CONT_EXPORT VTKM_EXEC_CONT_EXPORT
@ -75,7 +76,8 @@ struct IndexLookupHelper<vtkm::cont::NODE,vtkm::cont::CELL,Dimension>
}; };
template<vtkm::IdComponent Dimension> template<vtkm::IdComponent Dimension>
struct IndexLookupHelper<vtkm::cont::CELL,vtkm::cont::NODE,Dimension> struct IndexLookupHelper<
vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint, Dimension>
{ {
template <vtkm::IdComponent ItemTupleLength> template <vtkm::IdComponent ItemTupleLength>
VTKM_EXEC_CONT_EXPORT VTKM_EXEC_CONT_EXPORT
@ -86,14 +88,16 @@ struct IndexLookupHelper<vtkm::cont::CELL,vtkm::cont::NODE,Dimension>
} }
}; };
template<vtkm::cont::TopologyType FromTopology, vtkm::cont::TopologyType ToTopoogy, template<typename FromTopology,
typename ToTopology,
vtkm::IdComponent Dimension> vtkm::IdComponent Dimension>
class RegularConnectivity class RegularConnectivity
{ {
VTKM_IS_TOPOLOGY_ELEMENT_TAG(FromTopology);
VTKM_IS_TOPOLOGY_ELEMENT_TAG(ToTopology);
public: public:
typedef typename SchedulingDimension< FromTopology, typedef typename SchedulingDimension<Dimension>::ValueType SchedulingDimension;
ToTopoogy,
Dimension >::ValueType SchedulingDimension;
RegularConnectivity(): RegularConnectivity():
rs() rs()
{ {
@ -124,14 +128,14 @@ public:
VTKM_EXEC_CONT_EXPORT VTKM_EXEC_CONT_EXPORT
void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id,ItemTupleLength> &ids) void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id,ItemTupleLength> &ids)
{ {
IndexLookupHelper<FromTopology,ToTopoogy,Dimension>::GetIndices(rs,index,ids); IndexLookupHelper<FromTopology,ToTopology,Dimension>::GetIndices(rs,index,ids);
} }
template <typename DeviceAdapterTag> template <typename DeviceAdapterTag>
struct ExecutionTypes struct ExecutionTypes
{ //Using this style so we can template the RegularConnecivity based on the { //Using this style so we can template the RegularConnecivity based on the
//backend in the future without have to change the Transport logic //backend in the future without have to change the Transport logic
typedef vtkm::RegularConnectivity<FromTopology,ToTopoogy,Dimension> ExecObjectType; typedef vtkm::RegularConnectivity<FromTopology,ToTopology,Dimension> ExecObjectType;
}; };
template<typename DeviceAdapterTag> template<typename DeviceAdapterTag>

109
vtkm/TopologyElementTag.h Normal file

@ -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/Types.h>
VTKM_BOOST_PRE_INCLUDE
#include <boost/mpl/assert.hpp>
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<typename T>
struct TopologyElementTagCheck
{
typedef boost::mpl::false_ type;
};
template<>
struct TopologyElementTagCheck<vtkm::TopologyElementTagCell>
{
typedef boost::mpl::true_ type;
};
template<>
struct TopologyElementTagCheck<vtkm::TopologyElementTagPoint>
{
typedef boost::mpl::true_ type;
};
template<>
struct TopologyElementTagCheck<vtkm::TopologyElementTagEdge>
{
typedef boost::mpl::true_ type;
};
template<>
struct TopologyElementTagCheck<vtkm::TopologyElementTagFace>
{
typedef boost::mpl::true_ type;
};
#define VTKM_IS_TOPOLOGY_ELEMENT_TAG(type) \
BOOST_MPL_ASSERT(( ::vtkm::internal::TopologyElementTagCheck<type> ))
} // namespace internal
} // namespace vtkm
#endif //vtk_m_TopologyElementTag_h

@ -64,7 +64,6 @@ set(headers
StorageImplicit.h StorageImplicit.h
StorageListTag.h StorageListTag.h
Timer.h Timer.h
TopologyType.h
) )
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------

@ -79,7 +79,7 @@ protected:
namespace internal { namespace internal {
/// Checks to see if the given object is a cell set. This check is compatible /// 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 /// typedef named \c type that is either boost::mpl::true_ or
/// boost::mpl::false_. Both of these have a typedef named value with the /// boost::mpl::false_. Both of these have a typedef named value with the
/// respective boolean value. /// respective boolean value.

@ -20,9 +20,9 @@
#ifndef vtk_m_cont_CellSetExplicit_h #ifndef vtk_m_cont_CellSetExplicit_h
#define vtk_m_cont_CellSetExplicit_h #define vtk_m_cont_CellSetExplicit_h
#include <vtkm/TopologyElementTag.h>
#include <vtkm/cont/CellSet.h> #include <vtkm/cont/CellSet.h>
#include <vtkm/cont/ExplicitConnectivity.h> #include <vtkm/cont/ExplicitConnectivity.h>
#include <vtkm/cont/TopologyType.h>
namespace vtkm { namespace vtkm {
namespace cont { namespace cont {
@ -56,8 +56,10 @@ public:
return this->NodesOfCellsConnectivity.GetNumberOfElements(); return this->NodesOfCellsConnectivity.GetNumberOfElements();
} }
template<vtkm::cont::TopologyType FromTopology, vtkm::cont::TopologyType ToTopoogy> template<typename FromTopology, typename ToTopology>
struct ConnectivityType { 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 // This type is really only valid for Point to Cell connectivity. When
// other connectivity types are supported, these will need to be added. // other connectivity types are supported, these will need to be added.
typedef ExplicitConnectivityType Type; typedef ExplicitConnectivityType Type;

@ -23,6 +23,7 @@
#include <vtkm/cont/CellSet.h> #include <vtkm/cont/CellSet.h>
#include <vtkm/RegularConnectivity.h> #include <vtkm/RegularConnectivity.h>
#include <vtkm/RegularStructure.h> #include <vtkm/RegularStructure.h>
#include <vtkm/TopologyElementTag.h>
namespace vtkm { namespace vtkm {
namespace cont { namespace cont {
@ -47,28 +48,31 @@ public:
return this->Structure.GetNumberOfCells(); return this->Structure.GetNumberOfCells();
} }
template<vtkm::cont::TopologyType FromTopology, template<typename FromTopology, typename ToTopology>
vtkm::cont::TopologyType ToTopology>
struct ConnectivityType { struct ConnectivityType {
VTKM_IS_TOPOLOGY_ELEMENT_TAG(FromTopology);
VTKM_IS_TOPOLOGY_ELEMENT_TAG(ToTopology);
typedef vtkm::RegularConnectivity<FromTopology,ToTopology,Dimension> Type; typedef vtkm::RegularConnectivity<FromTopology,ToTopology,Dimension> Type;
}; };
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
vtkm::RegularConnectivity<vtkm::cont::NODE,vtkm::cont::CELL,Dimension> vtkm::RegularConnectivity<
vtkm::TopologyElementTagPoint,vtkm::TopologyElementTagCell,Dimension>
GetNodeToCellConnectivity() const GetNodeToCellConnectivity() const
{ {
typedef vtkm::RegularConnectivity<vtkm::cont::NODE, typedef vtkm::RegularConnectivity<vtkm::TopologyElementTagPoint,
vtkm::cont::CELL, vtkm::TopologyElementTagCell,
Dimension> NodeToCellConnectivity; Dimension> NodeToCellConnectivity;
return NodeToCellConnectivity(this->Structure); return NodeToCellConnectivity(this->Structure);
} }
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
vtkm::RegularConnectivity<vtkm::cont::CELL,vtkm::cont::NODE,Dimension> vtkm::RegularConnectivity<
vtkm::TopologyElementTagCell,vtkm::TopologyElementTagPoint,Dimension>
GetCellToNodeConnectivity() const GetCellToNodeConnectivity() const
{ {
typedef vtkm::RegularConnectivity<vtkm::cont::CELL, typedef vtkm::RegularConnectivity<vtkm::TopologyElementTagCell,
vtkm::cont::NODE, vtkm::TopologyElementTagPoint,
Dimension> CellToNodeConnectivity; Dimension> CellToNodeConnectivity;
return CellToNodeConnectivity(this->Structure); return CellToNodeConnectivity(this->Structure);
} }

@ -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

@ -20,10 +20,10 @@
#ifndef vtk_m_cont_arg_TransportTagTopologyIn_h #ifndef vtk_m_cont_arg_TransportTagTopologyIn_h
#define vtk_m_cont_arg_TransportTagTopologyIn_h #define vtk_m_cont_arg_TransportTagTopologyIn_h
#include <vtkm/TopologyElementTag.h>
#include <vtkm/Types.h> #include <vtkm/Types.h>
#include <vtkm/cont/CellSet.h> #include <vtkm/cont/CellSet.h>
#include <vtkm/cont/TopologyType.h>
#include <vtkm/cont/arg/Transport.h> #include <vtkm/cont/arg/Transport.h>
@ -44,7 +44,8 @@ struct Transport<vtkm::cont::arg::TransportTagTopologyIn, ContObjectType, Device
VTKM_IS_CELL_SET(ContObjectType); VTKM_IS_CELL_SET(ContObjectType);
typedef typename ContObjectType typedef typename ContObjectType
::template ConnectivityType<vtkm::cont::NODE,vtkm::cont::CELL>::Type ::template ConnectivityType<
vtkm::TopologyElementTagPoint,vtkm::TopologyElementTagCell>::Type
::template ExecutionTypes<Device> ::template ExecutionTypes<Device>
::ExecObjectType ExecObjectType; ::ExecObjectType ExecObjectType;

@ -18,14 +18,14 @@
// this software. // this software.
//============================================================================ //============================================================================
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/DataSet.h> #include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h> #include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/CellType.h> #include <vtkm/CellType.h>
#include <vtkm/RegularConnectivity.h> #include <vtkm/RegularConnectivity.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
static void TwoDimRegularTest(); static void TwoDimRegularTest();
static void ThreeDimRegularTest(); static void ThreeDimRegularTest();
@ -67,10 +67,14 @@ TwoDimRegularTest()
VTKM_TEST_ASSERT(shape == vtkm::VTKM_PIXEL, "Incorrect element type."); VTKM_TEST_ASSERT(shape == vtkm::VTKM_PIXEL, "Incorrect element type.");
} }
vtkm::RegularConnectivity<vtkm::cont::NODE, vtkm::cont::CELL,2> nodeToCell = vtkm::RegularConnectivity<
cellSet.GetNodeToCellConnectivity(); vtkm::TopologyElementTagPoint,
vtkm::RegularConnectivity<vtkm::cont::CELL, vtkm::cont::NODE,2> cellToNode = vtkm::TopologyElementTagCell,
cellSet.GetCellToNodeConnectivity(); 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::Id cells[2][4] = {{0,1,3,4}, {1,2,4,5}};
vtkm::Vec<vtkm::Id,4> nodeIds; vtkm::Vec<vtkm::Id,4> nodeIds;
@ -135,8 +139,10 @@ ThreeDimRegularTest()
} }
//Test regular connectivity. //Test regular connectivity.
vtkm::RegularConnectivity<vtkm::cont::NODE, vtkm::cont::CELL,3> nodeToCell = vtkm::RegularConnectivity<
cellSet.GetNodeToCellConnectivity(); vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
3> nodeToCell = cellSet.GetNodeToCellConnectivity();
vtkm::Id expectedPointIds[8] = {0,1,3,4,6,7,9,10}; vtkm::Id expectedPointIds[8] = {0,1,3,4,6,7,9,10};
vtkm::Vec<vtkm::Id,8> retrievedPointIds; vtkm::Vec<vtkm::Id,8> retrievedPointIds;
nodeToCell.GetIndices(0, retrievedPointIds); nodeToCell.GetIndices(0, retrievedPointIds);
@ -147,8 +153,10 @@ ThreeDimRegularTest()
"Incorrect node ID for cell"); "Incorrect node ID for cell");
} }
vtkm::RegularConnectivity<vtkm::cont::CELL, vtkm::cont::NODE,3> cellToNode = vtkm::RegularConnectivity<
cellSet.GetCellToNodeConnectivity(); vtkm::TopologyElementTagCell,
vtkm::TopologyElementTagPoint,
3> cellToNode = cellSet.GetCellToNodeConnectivity();
vtkm::Vec<vtkm::Id,8> expectedCellIds; vtkm::Vec<vtkm::Id,8> expectedCellIds;
vtkm::Id retrievedCellIds[8] = {0,-1,-1,-1,-1,-1,-1,-1}; vtkm::Id retrievedCellIds[8] = {0,-1,-1,-1,-1,-1,-1,-1};
cellToNode.GetIndices(0, expectedCellIds); cellToNode.GetIndices(0, expectedCellIds);

@ -114,12 +114,13 @@ public:
} }
template<typename Invocation, template<typename Invocation,
vtkm::cont::TopologyType From, typename From,
vtkm::cont::TopologyType To, typename To,
vtkm::IdComponent Domain> vtkm::IdComponent Domain>
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
void InvokeBasedOnDomainType(const Invocation &invocation, void InvokeBasedOnDomainType(
const vtkm::RegularConnectivity<From,To,Domain>& domain) const const Invocation &invocation,
const vtkm::RegularConnectivity<From,To,Domain>& domain) const
{ {
// For a DispatcherMapTopology, the inputDomain is some for of connectivity // For a DispatcherMapTopology, the inputDomain is some for of connectivity