1 //  Copyright (c) Kitware, Inc.
2 //  All rights reserved.
3 //  See LICENSE.txt for details.
4 //  This software is distributed WITHOUT ANY WARRANTY; without even
5 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
6 //  PURPOSE.  See the above copyright notice for more information.
7 //
8 //  Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
9 //  Copyright 2014 UT-Battelle, LLC.
10 //  Copyright 2014 Los Alamos National Security.
11 //
12 //  Under the terms of Contract DE-NA0003525 with NTESS,
13 //  the U.S. Government retains certain rights in this software.
14 //
15 //  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
16 //  Laboratory (LANL), the U.S. Government retains certain rights in
17 //  this software.
18 //============================================================================
19 #ifndef vtk_m_worklet_cellmetrics_CellShapeAndSizeMetric_h
20 #define vtk_m_worklet_cellmetrics_CellShapeAndSizeMetric_h
21 /*
22  * Mesh quality metric functions that compute the shape and size of a cell. This
23  * takes the shape metric and multiplies it by the relative size squared metric.
24  *
25  * These metric computations are adapted from the VTK implementation of the
26  * Verdict library, which provides a set of mesh/cell metrics for evaluating the
27  * geometric qualities of regions of mesh spaces.
28  *
29  * See: The Verdict Library Reference Manual (for per-cell-type metric formulae)
30  * See: vtk/ThirdParty/verdict/vtkverdict (for VTK code implementation of this
31  * metric)
32  */
33 
34 #include "vtkm/CellShape.h"
35 #include "vtkm/CellTraits.h"
36 #include "vtkm/VecTraits.h"
37 #include "vtkm/VectorAnalysis.h"
38 #include "vtkm/exec/FunctorBase.h"
39 #include "vtkm/worklet/cellmetrics/CellShapeMetric.h"
40 
41 #define UNUSED(expr) (void)(expr);
42 
43 namespace vtkm
44 {
45 namespace worklet
46 {
47 namespace cellmetrics
48 {
49 
50 using FloatType = vtkm::FloatDefault;
51 
52 // ========================= Unsupported cells ==================================
53 
54 // By default, cells have zero shape unless the shape type template is specialized below.
55 template <typename OutType, typename PointCoordVecType, typename CellShapeType>
CellShapeAndSizeMetric(const vtkm::IdComponent & numPts,const PointCoordVecType & pts,const OutType & avgArea,CellShapeType shape,vtkm::ErrorCode &)56 VTKM_EXEC OutType CellShapeAndSizeMetric(const vtkm::IdComponent& numPts,
57                                          const PointCoordVecType& pts,
58                                          const OutType& avgArea,
59                                          CellShapeType shape,
60                                          vtkm::ErrorCode&)
61 {
62   UNUSED(numPts);
63   UNUSED(pts);
64   UNUSED(avgArea);
65   UNUSED(shape);
66   return OutType(-1.);
67 }
68 
69 // ========================= 2D cells ==================================
70 
71 template <typename OutType, typename PointCoordVecType>
CellShapeAndSizeMetric(const vtkm::IdComponent & numPts,const PointCoordVecType & pts,const OutType & avgArea,vtkm::CellShapeTagTriangle tag,vtkm::ErrorCode & ec)72 VTKM_EXEC OutType CellShapeAndSizeMetric(const vtkm::IdComponent& numPts,
73                                          const PointCoordVecType& pts,
74                                          const OutType& avgArea,
75                                          vtkm::CellShapeTagTriangle tag,
76                                          vtkm::ErrorCode& ec)
77 {
78   OutType rss = vtkm::worklet::cellmetrics::CellRelativeSizeSquaredMetric<OutType>(
79     numPts, pts, avgArea, tag, ec);
80   OutType shape = vtkm::worklet::cellmetrics::CellShapeMetric<OutType>(numPts, pts, tag, ec);
81   OutType q = rss * shape;
82   return OutType(q);
83 }
84 
85 template <typename OutType, typename PointCoordVecType>
CellShapeAndSizeMetric(const vtkm::IdComponent & numPts,const PointCoordVecType & pts,const OutType & avgArea,vtkm::CellShapeTagQuad tag,vtkm::ErrorCode & ec)86 VTKM_EXEC OutType CellShapeAndSizeMetric(const vtkm::IdComponent& numPts,
87                                          const PointCoordVecType& pts,
88                                          const OutType& avgArea,
89                                          vtkm::CellShapeTagQuad tag,
90                                          vtkm::ErrorCode& ec)
91 {
92   OutType rss = vtkm::worklet::cellmetrics::CellRelativeSizeSquaredMetric<OutType>(
93     numPts, pts, avgArea, tag, ec);
94   OutType shape = vtkm::worklet::cellmetrics::CellShapeMetric<OutType>(numPts, pts, tag, ec);
95   OutType q = rss * shape;
96   return OutType(q);
97 }
98 
99 // ========================= 3D cells ==================================
100 
101 template <typename OutType, typename PointCoordVecType>
CellShapeAndSizeMetric(const vtkm::IdComponent & numPts,const PointCoordVecType & pts,const OutType & avgVolume,vtkm::CellShapeTagTetra tag,vtkm::ErrorCode & ec)102 VTKM_EXEC OutType CellShapeAndSizeMetric(const vtkm::IdComponent& numPts,
103                                          const PointCoordVecType& pts,
104                                          const OutType& avgVolume,
105                                          vtkm::CellShapeTagTetra tag,
106                                          vtkm::ErrorCode& ec)
107 {
108   OutType rss = vtkm::worklet::cellmetrics::CellRelativeSizeSquaredMetric<OutType>(
109     numPts, pts, avgVolume, tag, ec);
110   OutType shape = vtkm::worklet::cellmetrics::CellShapeMetric<OutType>(numPts, pts, tag, ec);
111   OutType q = rss * shape;
112   return OutType(q);
113 }
114 
115 template <typename OutType, typename PointCoordVecType>
CellShapeAndSizeMetric(const vtkm::IdComponent & numPts,const PointCoordVecType & pts,const OutType & avgVolume,vtkm::CellShapeTagHexahedron tag,vtkm::ErrorCode & ec)116 VTKM_EXEC OutType CellShapeAndSizeMetric(const vtkm::IdComponent& numPts,
117                                          const PointCoordVecType& pts,
118                                          const OutType& avgVolume,
119                                          vtkm::CellShapeTagHexahedron tag,
120                                          vtkm::ErrorCode& ec)
121 {
122   OutType rss = vtkm::worklet::cellmetrics::CellRelativeSizeSquaredMetric<OutType>(
123     numPts, pts, avgVolume, tag, ec);
124   OutType shape = vtkm::worklet::cellmetrics::CellShapeMetric<OutType>(numPts, pts, tag, ec);
125   OutType q = rss * shape;
126   return OutType(q);
127 }
128 
129 } // namespace cellmetrics
130 } // namespace worklet
131 } // namespace vtkm
132 
133 #endif // vtk_m_exec_cellmetrics_CellShapeAndSizeMetric.h
134