VTK-m  2.0
CellMaxDiagonalMetric.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_Max_Diagonal_h
21 #define vtk_m_worklet_cellmetrics_Max_Diagonal_h
22 
23 /*
24 * Mesh quality metric functions that compute the Oddy 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 
42 #define UNUSED(expr) (void)(expr);
43 
44 namespace vtkm
45 {
46 namespace worklet
47 {
48 namespace cellmetrics
49 {
50 // ========================= Unsupported cells ==================================
51 
52 // By default, cells have zero shape unless the shape type template is specialized below.
53 template <typename OutType, typename PointCoordVecType, typename CellShapeType>
55  const PointCoordVecType& pts,
56  CellShapeType shape,
58 {
59  UNUSED(numPts);
60  UNUSED(pts);
61  UNUSED(shape);
62  return OutType(-1.0);
63 }
64 // ============================= 3D Volume cells ==================================
65 template <typename OutType, typename PointCoordVecType>
67  const PointCoordVecType& pts,
68  vtkm::CellShapeTagHexahedron,
69  vtkm::ErrorCode& ec)
70 {
71  if (numPts != 8)
72  {
74  return OutType(0.0);
75  }
76 
77  using Scalar = OutType;
78 
79  Scalar temp[3], diag[4];
80  vtkm::IdComponent i(0);
81 
82  //lengths^2 f diag nals
83  for (i = 0; i < 3; i++)
84  {
85  temp[i] = static_cast<Scalar>(pts[6][i] - pts[0][i]);
86  temp[i] = temp[i] * temp[i];
87  }
88  diag[0] = vtkm::Sqrt(temp[0] + temp[1] + temp[2]);
89 
90  for (i = 0; i < 3; i++)
91  {
92  temp[i] = static_cast<Scalar>(pts[4][i] - pts[2][i]);
93  temp[i] = temp[i] * temp[i];
94  }
95  diag[1] = vtkm::Sqrt(temp[0] + temp[1] + temp[2]);
96 
97  for (i = 0; i < 3; i++)
98  {
99  temp[i] = static_cast<Scalar>(pts[7][i] - pts[1][i]);
100  temp[i] = temp[i] * temp[i];
101  }
102  diag[2] = vtkm::Sqrt(temp[0] + temp[1] + temp[2]);
103 
104  for (i = 0; i < 3; i++)
105  {
106  temp[i] = static_cast<Scalar>(pts[5][i] - pts[3][i]);
107  temp[i] = temp[i] * temp[i];
108  }
109  diag[3] = vtkm::Sqrt(temp[0] + temp[1] + temp[2]);
110 
111  Scalar diagonal = diag[0];
112 
113  for (i = 1; i < 4; i++)
114  {
115  diagonal = vtkm::Max(diagonal, diag[i]);
116  }
117  return Scalar(diagonal);
118 }
119 } // namespace cellmetrics
120 } // namespace worklet
121 } // namespace vtkm
122 #endif
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
UNUSED
#define UNUSED(expr)
Definition: CellMaxDiagonalMetric.h:42
vtkm::worklet::cellmetrics::CellMaxDiagonalMetric
VTKM_EXEC OutType CellMaxDiagonalMetric(const vtkm::IdComponent &numPts, const PointCoordVecType &pts, CellShapeType shape, vtkm::ErrorCode &)
Definition: CellMaxDiagonalMetric.h:54
TypeOfCellTetrahedral.h
TypeOfCellTriangle.h
TypeOfCellHexahedral.h
TypeOfCellQuadrilateral.h
CellTraits.h
VecTraits.h
vtkm::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints