VTK-m  2.0
CellAspectGammaMetric.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_CellAspectGammaMetric_h
21 #define vtk_m_worklet_cellmetrics_CellAspectGammaMetric_h
22 
23 /*
24 * Mesh quality metric functions that compute the aspect ratio of mesh cells.
25 ** These metric computations are adapted from the VTK implementation of the Verdict library,
26 * which provides a set of mesh/cell metrics for evaluating the geometric qualities of regions
27 * of mesh spaces.
28 ** See: The Verdict Library Reference Manual (for per-cell-type metric formulae)
29 * See: vtk/ThirdParty/verdict/vtkverdict (for VTK code implementation of this metric)
30 */
31 
32 #include "TypeOfCellHexahedral.h"
34 #include "TypeOfCellTetrahedral.h"
35 #include "TypeOfCellTriangle.h"
36 #include <vtkm/CellShape.h>
37 #include <vtkm/CellTraits.h>
38 #include <vtkm/ErrorCode.h>
39 #include <vtkm/VecTraits.h>
40 #include <vtkm/VectorAnalysis.h>
41 #define UNUSED(expr) (void)(expr);
42 
43 namespace vtkm
44 {
45 namespace worklet
46 {
47 namespace cellmetrics
48 {
49 // ========================= Unsupported cells ==================================
50 
51 // By default, cells have zero shape unless the shape type template is specialized below.
52 template <typename OutType, typename PointCoordVecType, typename CellShapeType>
54  const PointCoordVecType& pts,
55  CellShapeType shape,
57 {
58  UNUSED(numPts);
59  UNUSED(pts);
60  UNUSED(shape);
61  return OutType(0);
62 }
63 
64 // ============================= 3D Volume cells ==================================
65 // Compute the aspect ratio of a tetrahedron.
66 template <typename OutType, typename PointCoordVecType>
68  const PointCoordVecType& pts,
69  vtkm::CellShapeTagTetra,
70  vtkm::ErrorCode& ec)
71 {
72  if (numPts != 4)
73  {
75  return OutType(0.0);
76  }
77 
78  using Scalar = OutType;
79  using CollectionOfPoints = PointCoordVecType;
80  using Vector = typename PointCoordVecType::ComponentType;
81 
82  const Scalar volume = GetTetraVolume<Scalar, Vector, CollectionOfPoints>(pts);
83  const Scalar vAbs = vtkm::Abs(volume);
84 
85  if (vAbs <= Scalar(0.0))
86  {
87  return vtkm::Infinity<Scalar>();
88  }
89  const Scalar six = Scalar(6.0);
90  const Scalar l0 = GetTetraL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
91  const Scalar l1 = GetTetraL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
92  const Scalar l2 = GetTetraL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
93  const Scalar l3 = GetTetraL3Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
94  const Scalar l4 = GetTetraL4Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
95  const Scalar l5 = GetTetraL5Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
96 
97  const Scalar R = vtkm::Sqrt((vtkm::Pow(l0, 2) + vtkm::Pow(l1, 2) + vtkm::Pow(l2, 2) +
98  vtkm::Pow(l3, 2) + vtkm::Pow(l4, 2) + vtkm::Pow(l5, 2)) /
99  six);
100 
101  const Scalar rootTwo(vtkm::Sqrt(Scalar(2.0)));
102  const Scalar twelve(12.0);
103  const Scalar q = (vtkm::Pow(R, 3) * rootTwo) / (twelve * vAbs);
104 
105  return q;
106 }
107 
108 } // namespace cellmetrics
109 } // namespace worklet
110 } // namespace vtkm
111 #endif // vtk_m_worklet_cellmetrics_CellAspectGammaMetric_h
vtkm::Sqrt
VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
Compute the square root of x.
Definition: Math.h:958
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
ErrorCode.h
VectorAnalysis.h
vtkm::worklet::cellmetrics::CellAspectGammaMetric
VTKM_EXEC OutType CellAspectGammaMetric(const vtkm::IdComponent &numPts, const PointCoordVecType &pts, CellShapeType shape, vtkm::ErrorCode &)
Definition: CellAspectGammaMetric.h:53
UNUSED
#define UNUSED(expr)
Definition: CellAspectGammaMetric.h:41
TypeOfCellTetrahedral.h
TypeOfCellTriangle.h
TypeOfCellHexahedral.h
TypeOfCellQuadrilateral.h
CellTraits.h
VecTraits.h
vtkm::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints