VTK-m  2.0
CellShearMetric.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 // This software is distributed WITHOUT ANY WARRANTY; without even
6 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 // PURPOSE. See the above copyright notice for more information.
8 //
9 // Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 // Copyright 2018 UT-Battelle, LLC.
11 // Copyright 2018 Los Alamos National Security.
12 //
13 // Under the terms of Contract DE-NA0003525 with NTESS,
14 // the U.S. Government retains certain rights in this software.
15 //
16 // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 // Laboratory (LANL), the U.S. Government retains certain rights in
18 // this software.
19 //============================================================================
20 #ifndef vtk_m_worklet_cellmetrics_CellShearMetric_h
21 #define vtk_m_worklet_cellmetrics_CellShearMetric_h
22 
23 /*
24  * Mesh quality metric function that computes the shear of a cell. The shear is
25  * defined as the minimum of areas of the faces divided by the length of the
26  * indexed face multiplied by the index - 1 mod num_faces.
27  *
28  * These metric computations are adapted from the VTK implementation of the
29  * Verdict library, which provides a set of mesh/cell metrics for evaluating the
30  * geometric qualities of regions of mesh spaces.
31  *
32  * See: The Verdict Library Reference Manual (for per-cell-type metric formulae)
33  * See: vtk/ThirdParty/verdict/vtkverdict (for VTK code implementation of this
34  * metric)
35  */
36 
37 #include "TypeOfCellHexahedral.h"
39 #include <vtkm/CellShape.h>
40 #include <vtkm/CellTraits.h>
41 #include <vtkm/ErrorCode.h>
42 #include <vtkm/VecTraits.h>
43 #include <vtkm/VectorAnalysis.h>
44 
45 #define UNUSED(expr) (void)(expr);
46 
47 
48 namespace vtkm
49 {
50 namespace worklet
51 {
52 namespace cellmetrics
53 {
54 
55 // ========================= Unsupported cells ==================================
56 
57 // By default, cells have zero shape unless the shape type template is specialized below.
58 template <typename OutType, typename PointCoordVecType, typename CellShapeType>
60  const PointCoordVecType& pts,
61  CellShapeType shape,
63 {
64  UNUSED(numPts);
65  UNUSED(pts);
66  UNUSED(shape);
67  return OutType(-1.0);
68 }
69 
70 // ========================= 2D cells ==================================
71 
72 template <typename OutType, typename PointCoordVecType>
74  const PointCoordVecType& pts,
75  vtkm::CellShapeTagQuad,
76  vtkm::ErrorCode& ec)
77 {
78  if (numPts != 4)
79  {
81  return OutType(0.0);
82  }
83  using Scalar = OutType;
84  using CollectionOfPoints = PointCoordVecType;
85  using Vector = typename PointCoordVecType::ComponentType;
86 
87  const Scalar alpha0 = GetQuadAlpha0<Scalar, Vector, CollectionOfPoints>(pts);
88  const Scalar alpha1 = GetQuadAlpha1<Scalar, Vector, CollectionOfPoints>(pts);
89  const Scalar alpha2 = GetQuadAlpha2<Scalar, Vector, CollectionOfPoints>(pts);
90  const Scalar alpha3 = GetQuadAlpha3<Scalar, Vector, CollectionOfPoints>(pts);
91 
92  const Scalar L0 = GetQuadL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
93  const Scalar L1 = GetQuadL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
94  const Scalar L2 = GetQuadL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
95  const Scalar L3 = GetQuadL3Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
96 
97  const Scalar x0 = alpha0 / (L0 * L3);
98  const Scalar x1 = alpha1 / (L1 * L0);
99  const Scalar x2 = alpha2 / (L2 * L1);
100  const Scalar x3 = alpha3 / (L3 * L2);
101 
102  const Scalar q = vtkm::Min(x0, vtkm::Min(x1, vtkm::Min(x2, x3)));
103 
104  return q;
105 }
106 
107 // ========================= 3D cells ==================================
108 
109 template <typename OutType, typename PointCoordVecType>
111  const PointCoordVecType& pts,
112  vtkm::CellShapeTagHexahedron,
113  vtkm::ErrorCode& ec)
114 {
115  if (numPts != 8)
116  {
118  return OutType(-1.0);
119  }
120  using Scalar = OutType;
121  using CollectionOfPoints = PointCoordVecType;
122  using Vector = typename PointCoordVecType::ComponentType;
123 
124  const Scalar a0 = GetHexAlphaiHat<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(0));
125  const Scalar a1 = GetHexAlphaiHat<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(1));
126  const Scalar a2 = GetHexAlphaiHat<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(2));
127  const Scalar a3 = GetHexAlphaiHat<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(3));
128  const Scalar a4 = GetHexAlphaiHat<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(4));
129  const Scalar a5 = GetHexAlphaiHat<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(5));
130  const Scalar a6 = GetHexAlphaiHat<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(6));
131  const Scalar a7 = GetHexAlphaiHat<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(7));
132 
133  const Scalar q = vtkm::Min(
134  a0,
135  vtkm::Min(a1, vtkm::Min(a2, vtkm::Min(a3, vtkm::Min(a4, vtkm::Min(a5, vtkm::Min(a6, a7)))))));
136 
137  return q;
138 }
139 
140 
141 } // namespace cellmetrics
142 } // namespace worklet
143 } // namespace vtkm
144 
145 #endif // vtk_m_worklet_cellmetrics_CellShearMetric_h
vtkm::ErrorCode
ErrorCode
Definition: ErrorCode.h:19
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
CellShape.h
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ErrorCode.h
VectorAnalysis.h
UNUSED
#define UNUSED(expr)
Definition: CellShearMetric.h:45
vtkm::worklet::cellmetrics::CellShearMetric
VTKM_EXEC OutType CellShearMetric(const vtkm::IdComponent &numPts, const PointCoordVecType &pts, CellShapeType shape, vtkm::ErrorCode &)
Definition: CellShearMetric.h:59
TypeOfCellHexahedral.h
TypeOfCellQuadrilateral.h
CellTraits.h
VecTraits.h
vtkm::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints