Merge topic 'cell-face-edge'

eb7ea792 Add VTKM_EXEC_CONT to make_VecC
16970b57 Update ExternalFaces to use common face tables
91f98835 Add CellEdge functions
5ab43f8d Add CellFace functions

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !631
This commit is contained in:
Kenneth Moreland 2016-12-10 10:12:01 -05:00 committed by Kitware Robot
commit 50e0d05c3e
7 changed files with 729 additions and 12 deletions

@ -1204,6 +1204,8 @@ private:
/// Creates a \c VecC from an input array.
///
template<typename T>
VTKM_EXEC_CONT
static inline
vtkm::VecC<T> make_VecC(T *array, vtkm::IdComponent size)
{
return vtkm::VecC<T>(array, size);
@ -1212,6 +1214,8 @@ vtkm::VecC<T> make_VecC(T *array, vtkm::IdComponent size)
/// Creates a \c VecCConst from a constant input array.
///
template<typename T>
VTKM_EXEC_CONT
static inline
vtkm::VecCConst<T> make_VecC(const T *array, vtkm::IdComponent size)
{
return vtkm::VecCConst<T>(array, size);

@ -21,6 +21,8 @@
set(headers
AtomicArray.h
CellDerivative.h
CellEdge.h
CellFace.h
CellInterpolate.h
ConnectivityExplicit.h
ConnectivityPermuted.h

234
vtkm/exec/CellEdge.h Normal file

@ -0,0 +1,234 @@
//============================================================================
// 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 2016 Sandia Corporation.
// Copyright 2016 UT-Battelle, LLC.
// Copyright 2016 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_exec_CellFaces_h
#define vtk_m_exec_CellFaces_h
#include <vtkm/Assert.h>
#include <vtkm/CellShape.h>
#include <vtkm/CellTraits.h>
#include <vtkm/Types.h>
#include <vtkm/internal/Assume.h>
#include <vtkm/exec/FunctorBase.h>
namespace vtkm {
namespace exec {
namespace detail {
static const vtkm::IdComponent MAX_NUM_EDGES = 12;
VTKM_EXEC_CONSTANT
static const vtkm::IdComponent NumEdges[vtkm::NUMBER_OF_CELL_SHAPES] = {
0, // 0: CELL_SHAPE_EMPTY
0, // 1: CELL_SHAPE_VERTEX
0, // 2: Unused
0, // 3: CELL_SHAPE_LINE
0, // 4: Unused
3, // 5: CELL_SHAPE_TRIANGLE
0, // 6: Unused
-1, // 7: CELL_SHAPE_POLYGON ---special case---
0, // 8: Unused
4, // 9: CELL_SHAPE_QUAD
6, // 10: CELL_SHAPE_TETRA
0, // 11: Unused
12, // 12: CELL_SHAPE_HEXAHEDRON
9, // 13: CELL_SHAPE_WEDGE
8 // 14: CELL_SHAPE_PYRAMID
};
VTKM_EXEC_CONSTANT
static const vtkm::IdComponent
PointsInEdge[vtkm::NUMBER_OF_CELL_SHAPES][MAX_NUM_EDGES][2] = {
// 0: CELL_SHAPE_EMPTY
{ { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 1: CELL_SHAPE_VERTEX
{ { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 2: Unused
{ { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 3: CELL_SHAPE_LINE
{ { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 4: Unused
{ { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 5: CELL_SHAPE_TRIANGLE
{ { 0, 1 }, { 1, 2 }, { 2, 0 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 6: Unused
{ { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 7: CELL_SHAPE_POLYGON --- special case ---
{ { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 8: Unused
{ { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 9: CELL_SHAPE_QUAD
{ { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 10: CELL_SHAPE_TETRA
{ { 0, 1 }, { 1, 2 }, { 2, 0 }, { 0, 3 }, { 1, 3 }, { 2, 3 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 11: Unused
{ { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 },
{ -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 12: CELL_SHAPE_HEXAHEDRON
{ { 0, 1 }, { 1, 2 }, { 3, 2 }, { 0, 3 }, { 4, 5 }, { 5, 6 },
{ 7, 6 }, { 4, 7 }, { 0, 4 }, { 1, 5 }, { 3, 7 }, { 2, 6 }
},
// 13: CELL_SHAPE_WEDGE
{ { 0, 1 }, { 1, 2 }, { 2, 0 }, { 3, 4 }, { 4, 5 }, { 5, 3 },
{ 0, 3 }, { 1, 4 }, { 2, 5 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
// 14: CELL_SHAPE_PYRAMID
{ { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }, { 0, 4 }, { 1, 4 },
{ 2, 4 }, { 3, 4 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }
},
};
} // namespace detail
template<typename CellShapeTag>
static inline VTKM_EXEC
vtkm::IdComponent
CellEdgeNumberOfEdges(vtkm::IdComponent numPoints,
CellShapeTag,
const vtkm::exec::FunctorBase &)
{
(void)numPoints; // Silence compiler warnings.
VTKM_ASSERT(numPoints == vtkm::CellTraits<CellShapeTag>::NUM_POINTS);
return detail::NumEdges[CellShapeTag::Id];
}
static inline VTKM_EXEC
vtkm::IdComponent
CellEdgeNumberOfEdges(vtkm::IdComponent numPoints,
vtkm::CellShapeTagPolygon,
const vtkm::exec::FunctorBase &)
{
VTKM_ASSUME(numPoints > 0);
return numPoints;
}
static inline VTKM_EXEC
vtkm::IdComponent
CellEdgeNumberOfEdges(vtkm::IdComponent numPoints,
vtkm::CellShapeTagGeneric shape,
const vtkm::exec::FunctorBase &worklet)
{
if (shape.Id == vtkm::CELL_SHAPE_POLYGON)
{
return CellEdgeNumberOfEdges(
numPoints, vtkm::CellShapeTagPolygon(), worklet);
}
else
{
return detail::NumEdges[shape.Id];
}
}
template<typename CellShapeTag>
static inline VTKM_EXEC
vtkm::Vec<vtkm::IdComponent,2>
CellEdgeLocalIndices(vtkm::IdComponent numPoints,
vtkm::IdComponent edgeIndex,
CellShapeTag shape,
const vtkm::exec::FunctorBase &worklet)
{
VTKM_ASSUME(edgeIndex >= 0);
VTKM_ASSUME(edgeIndex < detail::MAX_NUM_EDGES);
if (edgeIndex >= vtkm::exec::CellEdgeNumberOfEdges(numPoints, shape, worklet))
{
worklet.RaiseError("Invalid edge number.");
return vtkm::Vec<vtkm::IdComponent,2>(0);
}
return vtkm::make_Vec(detail::PointsInEdge[CellShapeTag::Id][edgeIndex][0],
detail::PointsInEdge[CellShapeTag::Id][edgeIndex][1]);
}
static inline VTKM_EXEC
vtkm::Vec<vtkm::IdComponent,2>
CellEdgeLocalIndices(vtkm::IdComponent numPoints,
vtkm::IdComponent edgeIndex,
vtkm::CellShapeTagPolygon,
const vtkm::exec::FunctorBase &)
{
VTKM_ASSUME(numPoints >= 3);
VTKM_ASSUME(edgeIndex >= 0);
VTKM_ASSUME(edgeIndex < numPoints);
if (edgeIndex < numPoints-1)
{
return vtkm::Vec<vtkm::IdComponent,2>(edgeIndex, edgeIndex+1);
}
else
{
return vtkm::Vec<vtkm::IdComponent,2>(edgeIndex, 0);
}
}
static inline VTKM_EXEC
vtkm::Vec<vtkm::IdComponent,2>
CellEdgeLocalIndices(vtkm::IdComponent numPoints,
vtkm::IdComponent edgeIndex,
vtkm::CellShapeTagGeneric shape,
const vtkm::exec::FunctorBase &worklet)
{
VTKM_ASSUME(edgeIndex >= 0);
VTKM_ASSUME(edgeIndex < detail::MAX_NUM_EDGES);
if (shape.Id == vtkm::CELL_SHAPE_POLYGON)
{
return CellEdgeLocalIndices(
numPoints, edgeIndex, vtkm::CellShapeTagPolygon(), worklet);
}
else
{
if (edgeIndex >= detail::NumEdges[shape.Id])
{
worklet.RaiseError("Invalid edge number.");
return vtkm::Vec<vtkm::IdComponent,2>(0);
}
return vtkm::make_Vec(detail::PointsInEdge[shape.Id][edgeIndex][0],
detail::PointsInEdge[shape.Id][edgeIndex][1]);
}
}
}
} // namespace vtkm::exec
#endif //vtk_m_exec_CellFaces_h

238
vtkm/exec/CellFace.h Normal file

@ -0,0 +1,238 @@
//============================================================================
// 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 2016 Sandia Corporation.
// Copyright 2016 UT-Battelle, LLC.
// Copyright 2016 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_exec_CellFace_h
#define vtk_m_exec_CellFace_h
#include <vtkm/Assert.h>
#include <vtkm/CellShape.h>
#include <vtkm/Types.h>
#include <vtkm/internal/Assume.h>
#include <vtkm/exec/FunctorBase.h>
namespace vtkm {
namespace exec {
namespace detail {
static const vtkm::IdComponent MAX_FACE_SIZE = 4;
static const vtkm::IdComponent MAX_NUM_FACES = 6;
VTKM_EXEC_CONSTANT
static const vtkm::IdComponent NumFaces[vtkm::NUMBER_OF_CELL_SHAPES] = {
0, // 0: CELL_SHAPE_EMPTY
0, // 1: CELL_SHAPE_VERTEX
0, // 2: Unused
0, // 3: CELL_SHAPE_LINE
0, // 4: Unused
0, // 5: CELL_SHAPE_TRIANGLE
0, // 6: Unused
0, // 7: CELL_SHAPE_POLYGON
0, // 8: Unused
0, // 9: CELL_SHAPE_QUAD
4, // 10: CELL_SHAPE_TETRA
0, // 11: Unused
6, // 12: CELL_SHAPE_HEXAHEDRON
5, // 13: CELL_SHAPE_WEDGE
5 // 14: CELL_SHAPE_PYRAMID
};
VTKM_EXEC_CONSTANT
static const vtkm::IdComponent
NumPointsInFace[vtkm::NUMBER_OF_CELL_SHAPES][MAX_NUM_FACES] = {
{ -1, -1, -1, -1, -1, -1}, // 0: CELL_SHAPE_EMPTY
{ -1, -1, -1, -1, -1, -1}, // 1: CELL_SHAPE_VERTEX
{ -1, -1, -1, -1, -1, -1}, // 2: Unused
{ -1, -1, -1, -1, -1, -1}, // 3: CELL_SHAPE_LINE
{ -1, -1, -1, -1, -1, -1}, // 4: Unused
{ -1, -1, -1, -1, -1, -1}, // 5: CELL_SHAPE_TRIANGLE
{ -1, -1, -1, -1, -1, -1}, // 6: Unused
{ -1, -1, -1, -1, -1, -1}, // 7: CELL_SHAPE_POLYGON
{ -1, -1, -1, -1, -1, -1}, // 8: Unused
{ -1, -1, -1, -1, -1, -1}, // 9: CELL_SHAPE_QUAD
{ 3, 3, 3, 3, -1, -1}, // 10: CELL_SHAPE_TETRA
{ -1, -1, -1, -1, -1, -1}, // 11: Unused
{ 4, 4, 4, 4, 4, 4}, // 12: CELL_SHAPE_HEXAHEDRON
{ 3, 3, 4, 4, 4, -1}, // 13: CELL_SHAPE_WEDGE
{ 4, 3, 3, 3, 3, -1} // 14: CELL_SHAPE_PYRAMID
};
VTKM_EXEC_CONSTANT
static const vtkm::IdComponent
PointsInFace[vtkm::NUMBER_OF_CELL_SHAPES][MAX_NUM_FACES][MAX_FACE_SIZE] = {
// 0: CELL_SHAPE_EMPTY
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 1: CELL_SHAPE_VERTEX
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 2: Unused
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 3: CELL_SHAPE_LINE
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 4: Unused
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 5: CELL_SHAPE_TRIANGLE
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 6: Unused
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 7: CELL_SHAPE_POLYGON
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 8: Unused
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 9: CELL_SHAPE_QUAD
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 10: CELL_SHAPE_TETRA
{ { 0, 1, 3, -1 },
{ 1, 2, 3, -1 },
{ 2, 0, 3, -1 },
{ 0, 2, 1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 11: Unused
{ { -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 },
{ -1, -1, -1, -1 } },
// 12: CELL_SHAPE_HEXAHEDRON
{ { 0, 4, 7, 3 },
{ 1, 2, 6, 5 },
{ 0, 1, 5, 4 },
{ 3, 7, 6, 2 },
{ 0, 3, 2, 1 },
{ 4, 5, 6, 7 } },
// 13: CELL_SHAPE_WEDGE
{ { 0, 1, 2, -1 },
{ 3, 5, 4, -1 },
{ 0, 3, 4, 1 },
{ 1, 4, 5, 2 },
{ 2, 5, 3, 0 },
{ -1, -1, -1, -1 } },
// 14: CELL_SHAPE_PYRAMID
{ { 0, 3, 2, 1 },
{ 0, 1, 4, -1 },
{ 1, 2, 4, -1 },
{ 2, 3, 4, -1 },
{ 3, 0, 4, -1 },
{ -1, -1, -1, -1 } }
};
} // namespace detail
template<typename CellShapeTag>
static inline VTKM_EXEC
vtkm::IdComponent
CellFaceNumberOfFaces(CellShapeTag shape,
const vtkm::exec::FunctorBase &)
{
return detail::NumFaces[shape.Id];
}
template<typename CellShapeTag>
static inline VTKM_EXEC
vtkm::IdComponent
CellFaceNumberOfPoints(vtkm::IdComponent faceIndex,
CellShapeTag shape,
const vtkm::exec::FunctorBase &worklet)
{
VTKM_ASSUME(faceIndex >= 0);
VTKM_ASSUME(faceIndex < detail::MAX_NUM_FACES);
if (faceIndex >= vtkm::exec::CellFaceNumberOfFaces(shape, worklet))
{
worklet.RaiseError("Invalid face number.");
return 0;
}
return detail::NumPointsInFace[shape.Id][faceIndex];
}
template<typename CellShapeTag>
static inline VTKM_EXEC
vtkm::VecCConst<vtkm::IdComponent>
CellFaceLocalIndices(vtkm::IdComponent faceIndex,
CellShapeTag shape,
const vtkm::exec::FunctorBase &worklet)
{
vtkm::IdComponent numPointsInFace =
vtkm::exec::CellFaceNumberOfPoints(faceIndex, shape, worklet);
if (numPointsInFace < 1)
{
// An invalid face. We should already have gotten an error from
// CellFaceNumberOfPoints.
return vtkm::VecCConst<vtkm::IdComponent>();
}
return vtkm::make_VecC(detail::PointsInFace[shape.Id][faceIndex],
numPointsInFace);
}
}
} // namespace vtkm::exec
#endif //vtk_m_exec_CellFace_h

@ -22,6 +22,7 @@
set(unit_tests
UnitTestCellDerivative.cxx
UnitTestCellEdgeFace.cxx
UnitTestCellInterpolate.cxx
UnitTestParametricCoordinates.cxx
)

@ -0,0 +1,232 @@
//============================================================================
// 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 2016 Sandia Corporation.
// Copyright 2016 UT-Battelle, LLC.
// Copyright 2016 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.
//============================================================================
#include <vtkm/exec/CellEdge.h>
#include <vtkm/exec/CellFace.h>
#include <vtkm/CellShape.h>
#include <vtkm/CellTraits.h>
#include <vtkm/exec/FunctorBase.h>
#include <vtkm/testing/Testing.h>
#include <set>
namespace {
using EdgeType = vtkm::Vec<vtkm::IdComponent,2>;
void MakeEdgeCononical(EdgeType &edge)
{
if (edge[1] < edge[0])
{
std::swap(edge[0], edge[1]);
}
}
struct TestCellFacesFunctor
{
template<typename CellShapeTag>
void DoTest(vtkm::IdComponent numPoints,
CellShapeTag shape,
vtkm::CellTopologicalDimensionsTag<3>) const
{
// Stuff to fake running in the execution environment.
char messageBuffer[256];
messageBuffer[0] = '\0';
vtkm::exec::internal::ErrorMessageBuffer errorMessage(messageBuffer, 256);
vtkm::exec::FunctorBase workletProxy;
workletProxy.SetErrorMessageBuffer(errorMessage);
vtkm::IdComponent numEdges =
vtkm::exec::CellEdgeNumberOfEdges(numPoints, shape, workletProxy);
VTKM_TEST_ASSERT(numEdges > 0, "No edges?");
std::set<EdgeType> edgeSet;
for (vtkm::IdComponent edgeIndex = 0; edgeIndex < numEdges; edgeIndex++)
{
EdgeType edge = vtkm::exec::CellEdgeLocalIndices(
numPoints, edgeIndex, shape, workletProxy);
VTKM_TEST_ASSERT(edge[0] >= 0, "Bad index in edge.");
VTKM_TEST_ASSERT(edge[0] < numPoints, "Bad index in edge.");
VTKM_TEST_ASSERT(edge[1] >= 0, "Bad index in edge.");
VTKM_TEST_ASSERT(edge[1] < numPoints, "Bad index in edge.");
VTKM_TEST_ASSERT(edge[0] != edge[1], "Degenerate edge.");
MakeEdgeCononical(edge);
VTKM_TEST_ASSERT(edge[0] < edge[1],
"Internal test error: MakeEdgeCononical failed");
VTKM_TEST_ASSERT(edgeSet.find(edge) == edgeSet.end(),
"Found duplicate edge");
edgeSet.insert(edge);
}
vtkm::IdComponent numFaces =
vtkm::exec::CellFaceNumberOfFaces(shape, workletProxy);
VTKM_TEST_ASSERT(numFaces > 0, "No faces?");
std::set<EdgeType> edgesFoundInFaces;
for (vtkm::IdComponent faceIndex = 0; faceIndex < numFaces; faceIndex++)
{
vtkm::VecCConst<vtkm::IdComponent> facePoints =
vtkm::exec::CellFaceLocalIndices(faceIndex, shape, workletProxy);
vtkm::IdComponent numPointsInFace = facePoints.GetNumberOfComponents();
VTKM_TEST_ASSERT(numPointsInFace >= 3,
"Face has fewer points than a triangle.");
for (vtkm::IdComponent pointIndex = 0;
pointIndex < numPointsInFace;
pointIndex++)
{
VTKM_TEST_ASSERT(facePoints[pointIndex] >= 0,
"Invalid point index for face.");
VTKM_TEST_ASSERT(facePoints[pointIndex] <= numPoints,
"Invalid point index for face.");
EdgeType edge;
if (pointIndex < numPointsInFace-1)
{
edge = EdgeType(facePoints[pointIndex], facePoints[pointIndex+1]);
}
else
{
edge = EdgeType(facePoints[0], facePoints[pointIndex]);
}
MakeEdgeCononical(edge);
VTKM_TEST_ASSERT(edgeSet.find(edge) != edgeSet.end(),
"Edge in face not in cell's edges");
edgesFoundInFaces.insert(edge);
}
}
VTKM_TEST_ASSERT(edgesFoundInFaces.size() == edgeSet.size(),
"Faces did not contain all edges in cell");
}
// Case of cells that have 2 dimensions (no faces)
template<typename CellShapeTag>
void DoTest(vtkm::IdComponent numPoints,
CellShapeTag shape,
vtkm::CellTopologicalDimensionsTag<2>) const
{
// Stuff to fake running in the execution environment.
char messageBuffer[256];
messageBuffer[0] = '\0';
vtkm::exec::internal::ErrorMessageBuffer errorMessage(messageBuffer, 256);
vtkm::exec::FunctorBase workletProxy;
workletProxy.SetErrorMessageBuffer(errorMessage);
vtkm::IdComponent numEdges =
vtkm::exec::CellEdgeNumberOfEdges(numPoints, shape, workletProxy);
VTKM_TEST_ASSERT(numEdges == numPoints,
"Polygons should have same number of points and edges");
std::set<EdgeType> edgeSet;
for (vtkm::IdComponent edgeIndex = 0; edgeIndex < numEdges; edgeIndex++)
{
EdgeType edge = vtkm::exec::CellEdgeLocalIndices(
numPoints, edgeIndex, shape, workletProxy);
VTKM_TEST_ASSERT(edge[0] >= 0, "Bad index in edge.");
VTKM_TEST_ASSERT(edge[0] < numPoints, "Bad index in edge.");
VTKM_TEST_ASSERT(edge[1] >= 0, "Bad index in edge.");
VTKM_TEST_ASSERT(edge[1] < numPoints, "Bad index in edge.");
VTKM_TEST_ASSERT(edge[0] != edge[1], "Degenerate edge.");
MakeEdgeCononical(edge);
VTKM_TEST_ASSERT(edge[0] < edge[1],
"Internal test error: MakeEdgeCononical failed");
VTKM_TEST_ASSERT(edgeSet.find(edge) == edgeSet.end(),
"Found duplicate edge");
edgeSet.insert(edge);
}
vtkm::IdComponent numFaces =
vtkm::exec::CellFaceNumberOfFaces(shape, workletProxy);
VTKM_TEST_ASSERT(numFaces == 0, "Non 3D shape should have no faces");
}
// Less important case of cells that have less than 2 dimensions
// (no faces or edges)
template<typename CellShapeTag, vtkm::IdComponent NumDimensions>
void DoTest(vtkm::IdComponent numPoints,
CellShapeTag shape,
vtkm::CellTopologicalDimensionsTag<NumDimensions>) const
{
// Stuff to fake running in the execution environment.
char messageBuffer[256];
messageBuffer[0] = '\0';
vtkm::exec::internal::ErrorMessageBuffer errorMessage(messageBuffer, 256);
vtkm::exec::FunctorBase workletProxy;
workletProxy.SetErrorMessageBuffer(errorMessage);
vtkm::IdComponent numEdges =
vtkm::exec::CellEdgeNumberOfEdges(numPoints, shape, workletProxy);
VTKM_TEST_ASSERT(numEdges == 0, "0D or 1D shape should have no edges");
vtkm::IdComponent numFaces =
vtkm::exec::CellFaceNumberOfFaces(shape, workletProxy);
VTKM_TEST_ASSERT(numFaces == 0, "Non 3D shape should have no faces");
}
template<typename CellShapeTag>
void TryShapeWithNumPoints(vtkm::IdComponent numPoints,
CellShapeTag) const
{
std::cout << "--- Test shape tag directly"
<< " (" << numPoints << " points)"
<< std::endl;
this->DoTest(
numPoints,
CellShapeTag(),
typename vtkm::CellTraits<CellShapeTag>::TopologicalDimensionsTag());
std::cout << "--- Test generic shape tag"
<< " (" << numPoints << " points)"
<< std::endl;
this->DoTest(
numPoints,
vtkm::CellShapeTagGeneric(CellShapeTag::Id),
typename vtkm::CellTraits<CellShapeTag>::TopologicalDimensionsTag());
}
template<typename CellShapeTag>
void operator()(CellShapeTag) const
{
this->TryShapeWithNumPoints(vtkm::CellTraits<CellShapeTag>::NUM_POINTS,
CellShapeTag());
}
void operator()(vtkm::CellShapeTagPolygon) const
{
for (vtkm::IdComponent numPoints = 3; numPoints < 7; numPoints++)
{
this->TryShapeWithNumPoints(numPoints,vtkm::CellShapeTagPolygon());
}
}
};
void TestAllShapes()
{
vtkm::testing::Testing::TryAllCellShapes(TestCellFacesFunctor());
}
} // anonymous namespace
int UnitTestCellEdgeFace(int, char *[])
{
return vtkm::testing::Testing::Run(TestAllShapes);
}

@ -23,6 +23,8 @@
#include <vtkm/CellShape.h>
#include <vtkm/Math.h>
#include <vtkm/exec/CellFace.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/ArrayHandleImplicit.h>
@ -152,13 +154,10 @@ struct ExternalFaces
template<typename T>
VTKM_EXEC
T operator()(const T &cellType) const
vtkm::IdComponent operator()(const T &cellType) const
{
if (cellType == vtkm::CELL_SHAPE_TETRA) return 4;
else if (cellType == vtkm::CELL_SHAPE_PYRAMID) return 5;
else if (cellType == vtkm::CELL_SHAPE_WEDGE) return 5;
else if (cellType == vtkm::CELL_SHAPE_HEXAHEDRON) return 6;
else return CELL_SHAPE_EMPTY;
return vtkm::exec::CellFaceNumberOfFaces(
vtkm::CellShapeTagGeneric(cellType), *this);
}
};
@ -187,14 +186,16 @@ struct ExternalFaces
CellShapeTag shape,
const CellNodeVecType &cellNodeIds) const
{
if (shape.Id == vtkm::CELL_SHAPE_TETRA)
{
vtkm::IdComponent faceIdTable[12] = {0,1,2,0,1,3,0,2,3,1,2,3};
vtkm::VecCConst<vtkm::IdComponent> localFaceIndices =
vtkm::exec::CellFaceLocalIndices(
static_cast<vtkm::IdComponent>(cellFaceId), shape, *this);
if (localFaceIndices.GetNumberOfComponents() == 3)
{
//Assign cell points/nodes to this face
vtkm::Id faceP1 = cellNodeIds[faceIdTable[cellFaceId*3]];
vtkm::Id faceP2 = cellNodeIds[faceIdTable[cellFaceId*3 + 1]];
vtkm::Id faceP3 = cellNodeIds[faceIdTable[cellFaceId*3 + 2]];
vtkm::Id faceP1 = cellNodeIds[localFaceIndices[0]];
vtkm::Id faceP2 = cellNodeIds[localFaceIndices[1]];
vtkm::Id faceP3 = cellNodeIds[localFaceIndices[2]];
//Sort the face points/nodes in ascending order
vtkm::Id sorted[3] = {faceP1, faceP2, faceP3};
@ -222,6 +223,11 @@ struct ExternalFaces
faceVertices[1] = static_cast<T>(sorted[1]);
faceVertices[2] = static_cast<T>(sorted[2]);
}
else
{
// TODO: Support all face types.
this->RaiseError("Non-triangular faces not supported.");
}
}
};