VTK-m  2.0
CellSkewMetric.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 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 // Copyright 2014 UT-Battelle, LLC.
11 // Copyright 2014 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_CellSkewMetric_h
21 #define vtk_m_worklet_CellSkewMetric_h
22 /*
23 */
24 
25 #include "CellConditionMetric.h"
26 #include "TypeOfCellHexahedral.h"
28 #include "TypeOfCellTetrahedral.h"
29 #include "TypeOfCellTriangle.h"
30 #include <vtkm/CellShape.h>
31 #include <vtkm/CellTraits.h>
32 #include <vtkm/ErrorCode.h>
33 #include <vtkm/VecTraits.h>
34 #include <vtkm/VectorAnalysis.h>
35 
36 namespace vtkm
37 {
38 namespace worklet
39 {
40 namespace cellmetrics
41 {
42 template <typename OutType, typename PointCoordVecType, typename CellShapeType>
44  const PointCoordVecType& pts,
45  CellShapeType shape,
46  vtkm::ErrorCode& ec)
47 {
48  UNUSED(numPts);
49  UNUSED(pts);
50  UNUSED(shape);
51  UNUSED(ec);
52  return OutType(-1.0);
53 }
54 
55 template <typename OutType, typename PointCoordVecType>
57  const PointCoordVecType& pts,
58  vtkm::CellShapeTagHexahedron,
59  vtkm::ErrorCode& ec)
60 {
61  UNUSED(numPts);
62  UNUSED(ec);
63  using Scalar = OutType;
64  using Vector = typename PointCoordVecType::ComponentType;
65  Vector X1 = (pts[1] - pts[0]) + (pts[2] - pts[3]) + (pts[5] - pts[4]) + (pts[6] - pts[7]);
66  auto X1_mag = vtkm::Magnitude(X1);
67  if (Scalar(X1_mag) <= Scalar(0.0))
68  return vtkm::Infinity<Scalar>();
69  Vector x1 = X1 / X1_mag;
70  Vector X2 = (pts[3] - pts[0]) + (pts[2] - pts[1]) + (pts[7] - pts[4]) + (pts[6] - pts[5]);
71  auto X2_mag = vtkm::Magnitude(X2);
72  if (Scalar(X2_mag) <= Scalar(0.0))
73  return vtkm::Infinity<Scalar>();
74  Vector x2 = X2 / X2_mag;
75  Vector X3 = (pts[4] - pts[0]) + (pts[5] - pts[1]) + (pts[6] - pts[2]) + (pts[7] - pts[3]);
76  auto X3_mag = vtkm::Magnitude(X3);
77  if (Scalar(X3_mag) <= Scalar(0.0))
78  return vtkm::Infinity<Scalar>();
79  Vector x3 = X3 / X3_mag;
80  return static_cast<Scalar>(
81  vtkm::Max(vtkm::Dot(x1, x2), vtkm::Max(vtkm::Dot(x1, x3), vtkm::Dot(x2, x3))));
82 }
83 
84 template <typename OutType, typename PointCoordVecType>
86  const PointCoordVecType& pts,
87  vtkm::CellShapeTagQuad,
88  vtkm::ErrorCode& ec)
89 {
90  UNUSED(numPts);
91  UNUSED(ec);
92  using Scalar = OutType;
93  using CollectionOfPoints = PointCoordVecType;
94  using Vector = typename PointCoordVecType::ComponentType;
95  const Vector X0 = GetQuadX0<Scalar, Vector, CollectionOfPoints>(pts);
96  const Vector X1 = GetQuadX1<Scalar, Vector, CollectionOfPoints>(pts);
97  const auto X0Mag = vtkm::Magnitude(X0);
98  const auto X1Mag = vtkm::Magnitude(X1);
99 
100  if (Scalar(X0Mag) < Scalar(0.0) || Scalar(X1Mag) < Scalar(0.0))
101  return Scalar(0.0);
102  const Vector x0Normalized = X0 / X0Mag;
103  const Vector x1Normalized = X1 / X1Mag;
104  const Scalar dot = static_cast<Scalar>(vtkm::Dot(x0Normalized, x1Normalized));
105  return vtkm::Abs(dot);
106 }
107 }
108 } // worklet
109 } // vtkm
110 #endif
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
UNUSED
#define UNUSED(expr)
Definition: CellAspectFrobeniusMetric.h:42
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::Magnitude
VTKM_EXEC_CONT detail::FloatingPointReturnType< T >::Type Magnitude(const T &x)
Returns the magnitude of a vector.
Definition: VectorAnalysis.h:100
CellShape.h
vtkm::worklet::cellmetrics::CellSkewMetric
VTKM_EXEC OutType CellSkewMetric(const vtkm::IdComponent &numPts, const PointCoordVecType &pts, CellShapeType shape, vtkm::ErrorCode &ec)
Definition: CellSkewMetric.h:43
ErrorCode.h
VectorAnalysis.h
TypeOfCellTetrahedral.h
TypeOfCellTriangle.h
TypeOfCellHexahedral.h
TypeOfCellQuadrilateral.h
CellTraits.h
CellConditionMetric.h
VecTraits.h