VTK-m  2.0
CellJacobianMetric.h
Go to the documentation of this file.
1 
2 //============================================================================
3 // Copyright (c) Kitware, Inc.
4 // All rights reserved.
5 // See LICENSE.txt for details.
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //
10 // Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
11 // Copyright 2018 UT-Battelle, LLC.
12 // Copyright 2018 Los Alamos National Security.
13 //
14 // Under the terms of Contract DE-NA0003525 with NTESS,
15 // the U.S. Government retains certain rights in this software.
16 //
17 // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
18 // Laboratory (LANL), the U.S. Government retains certain rights in
19 // this software.
20 //============================================================================
21 #ifndef vtk_m_worklet_cellmetrics_Jacobian_h
22 #define vtk_m_worklet_cellmetrics_Jacobian_h
23 
24 /*
25  * Mesh quality metric functions that computes the Jacobian of mesh cells.
26  *
27  * These metric computations are adapted from the VTK implementation of the Verdict library,
28  * which provides a set of mesh/cell metrics for evaluating the geometric qualities of regions
29  * of mesh spaces.
30  *
31  * See: The Verdict Library Reference Manual (for per-cell-type metric formulae)
32  * See: vtk/ThirdParty/verdict/vtkverdict (for VTK code implementation of this metric)
33  */
34 
35 #include "TypeOfCellHexahedral.h"
37 #include "TypeOfCellTetrahedral.h"
38 #include "TypeOfCellTriangle.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 namespace vtkm
48 {
49 namespace worklet
50 {
51 namespace cellmetrics
52 {
53 
54 // ========================= Unsupported cells ==================================
55 
56 // By default, cells return the metric 0.0 unless the shape type template is specialized below.
57 template <typename OutType, typename PointCoordVecType, typename CellShapeType>
59  const PointCoordVecType& pts,
60  CellShapeType shape,
62 {
63  UNUSED(numPts);
64  UNUSED(pts);
65  UNUSED(shape);
66  return OutType(0.0);
67 }
68 
69 // ========================= 2D cells ==================================
70 
71 // Compute the Jacobian of a quadrilateral.
72 // Formula: min{Jacobian at each vertex}
73 // Equals 1 for a unit square
74 // Acceptable range: [0,FLOAT_MAX]
75 // Normal range: [0,FLOAT_MAX]
76 // Full range: [FLOAT_MIN,FLOAT_MAX]
77 template <typename OutType, typename PointCoordVecType>
79  const PointCoordVecType& pts,
80  vtkm::CellShapeTagQuad,
81  vtkm::ErrorCode& ec)
82 {
83  if (numPts != 4)
84  {
86  return OutType(0.0);
87  }
88 
89  using Scalar = OutType;
90  using CollectionOfPoints = PointCoordVecType;
91  using Vector = typename PointCoordVecType::ComponentType;
92 
93  const Scalar alpha0 = GetQuadAlpha0<Scalar, Vector, CollectionOfPoints>(pts);
94  const Scalar alpha1 = GetQuadAlpha1<Scalar, Vector, CollectionOfPoints>(pts);
95  const Scalar alpha2 = GetQuadAlpha2<Scalar, Vector, CollectionOfPoints>(pts);
96  const Scalar alpha3 = GetQuadAlpha3<Scalar, Vector, CollectionOfPoints>(pts);
97 
98  const Scalar q = vtkm::Min(alpha0, vtkm::Min(alpha1, vtkm::Min(alpha2, alpha3)));
99 
100  return q;
101 }
102 
103 // ============================= 3D Volume cells ==================================
104 // Compute the Jacobian of a hexahedron.
105 // Formula: min{ {Alpha_i for i in 1..7}, Alpha_8/64}
106 // -Alpha_i -> Jacobian determinant at respective vertex
107 // -Alpha_8 -> Jacobian at center
108 // Equals 1 for a unit cube
109 // Acceptable Range: [0, FLOAT_MAX]
110 // Normal Range: [0, FLOAT_MAX]
111 // Full range: [FLOAT_MIN ,FLOAT_MAX]
112 template <typename OutType, typename PointCoordVecType>
114  const PointCoordVecType& pts,
115  vtkm::CellShapeTagHexahedron,
116  vtkm::ErrorCode& ec)
117 {
118  if (numPts != 8)
119  {
121  return OutType(0.0);
122  }
123 
124  using Scalar = OutType;
125  using CollectionOfPoints = PointCoordVecType;
126  using Vector = typename PointCoordVecType::ComponentType;
127 
128  const Scalar alpha0 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(0));
129  const Scalar alpha1 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(1));
130  const Scalar alpha2 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(2));
131  const Scalar alpha3 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(3));
132  const Scalar alpha4 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(4));
133  const Scalar alpha5 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(5));
134  const Scalar alpha6 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(6));
135  const Scalar alpha7 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(7));
136  const Scalar alpha8 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts, vtkm::Id(8));
137  const Scalar alpha8Div64 = alpha8 / Scalar(64.0);
138 
139  const Scalar q = vtkm::Min(
140  alpha0,
141  vtkm::Min(
142  alpha1,
143  vtkm::Min(
144  alpha2,
145  vtkm::Min(
146  alpha3,
147  vtkm::Min(alpha4,
148  vtkm::Min(alpha5, vtkm::Min(alpha6, vtkm::Min(alpha7, alpha8Div64))))))));
149 
150  return q;
151 }
152 
153 // Compute the Jacobian of a tetrahedron.
154 // Formula: (L2 x L0) * L3
155 // Equals Sqrt(2) / 2 for unit equilateral tetrahedron
156 // Acceptable Range: [0, FLOAT_MAX]
157 // Normal Range: [0, FLOAT_MAX]
158 // Full range: [FLOAT_MIN,FLOAT_MAX]
159 template <typename OutType, typename PointCoordVecType>
161  const PointCoordVecType& pts,
162  vtkm::CellShapeTagTetra,
163  vtkm::ErrorCode& ec)
164 {
165  if (numPts != 4)
166  {
168  return OutType(0.0);
169  }
170 
171  using Scalar = OutType;
172  using CollectionOfPoints = PointCoordVecType;
173  using Vector = typename PointCoordVecType::ComponentType;
174 
175  const Vector L0 = GetTetraL0<Scalar, Vector, CollectionOfPoints>(pts);
176  const Vector L2 = GetTetraL2<Scalar, Vector, CollectionOfPoints>(pts);
177  const Vector L3 = GetTetraL3<Scalar, Vector, CollectionOfPoints>(pts);
178 
179  const Scalar q = static_cast<Scalar>((vtkm::Dot(vtkm::Cross(L2, L0), L3)));
180 
181  return q;
182 }
183 } // namespace cellmetrics
184 } // namespace worklet
185 } // namespace vtkm
186 
187 #endif // vtk_m_worklet_cellmetrics_Jacobian_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
vtkm::worklet::cellmetrics::CellJacobianMetric
VTKM_EXEC OutType CellJacobianMetric(const vtkm::IdComponent &numPts, const PointCoordVecType &pts, CellShapeType shape, vtkm::ErrorCode &)
Definition: CellJacobianMetric.h:58
CellShape.h
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ErrorCode.h
VectorAnalysis.h
vtkm::Cross
VTKM_EXEC_CONT vtkm::Vec< typename detail::FloatingPointReturnType< T >::Type, 3 > Cross(const vtkm::Vec< T, 3 > &x, const vtkm::Vec< T, 3 > &y)
Find the cross product of two vectors.
Definition: VectorAnalysis.h:177
UNUSED
#define UNUSED(expr)
Definition: CellJacobianMetric.h:45
TypeOfCellTetrahedral.h
TypeOfCellTriangle.h
TypeOfCellHexahedral.h
TypeOfCellQuadrilateral.h
CellTraits.h
VecTraits.h
vtkm::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints