VTK-m  2.0
CellTaperMetric.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_CellTaperMetric_h
21 #define vtk_m_worklet_CellTaperMetric_h
22 /*
23 * Mesh quality metric functions that compute the shape, or weighted Jacobian, of mesh cells.
24 * The Jacobian of a cell is weighted by the condition metric value of the cell.
25 ** These metric computations are adapted from the VTK implementation of the Verdict library,
26 * which provides a set of cell metrics for evaluating the geometric qualities of regions of mesh spaces.
27 ** See: The Verdict Library Reference Manual (for per-cell-type metric formulae)
28 * See: vtk/ThirdParty/verdict/vtkverdict (for VTK code implementation of this metric)
29 */
30 
31 #include "TypeOfCellHexahedral.h"
33 #include "TypeOfCellTetrahedral.h"
34 #include "TypeOfCellTriangle.h"
35 #include <vtkm/CellShape.h>
36 #include <vtkm/CellTraits.h>
37 #include <vtkm/ErrorCode.h>
38 #include <vtkm/VecTraits.h>
39 #include <vtkm/VectorAnalysis.h>
40 
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,
56  vtkm::ErrorCode& ec)
57 {
58  UNUSED(numPts);
59  UNUSED(pts);
60  UNUSED(shape);
61  UNUSED(ec);
62  return OutType(-1.0);
63 }
64 // ========================= 2D cells ==================================
65 template <typename OutType, typename PointCoordVecType>
67  const PointCoordVecType& pts,
68  vtkm::CellShapeTagQuad,
69  vtkm::ErrorCode& ec)
70 {
71  UNUSED(numPts);
72  UNUSED(ec);
73  using Scalar = OutType;
74  using CollectionOfPoints = PointCoordVecType;
75  using Vector = typename PointCoordVecType::ComponentType;
76 
77  const Vector X12 = Vector((pts[0] - pts[1]) + (pts[2] - pts[3]));
78  const Vector X1 = GetQuadX0<Scalar, Vector, CollectionOfPoints>(pts);
79  const Vector X2 = GetQuadX1<Scalar, Vector, CollectionOfPoints>(pts);
80 
81  const Scalar x12 = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(X12)));
82  const Scalar x1 = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(X1)));
83  const Scalar x2 = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(X2)));
84  const Scalar minLength = vtkm::Min(x1, x2);
85 
86  if (minLength <= Scalar(0.0))
87  {
88  return vtkm::Infinity<Scalar>();
89  }
90 
91  const Scalar q = x12 / minLength;
92  return q;
93 }
94 
95 // ========================= 3D cells ==================================
96 
97 template <typename OutType, typename PointCoordVecType>
99  const PointCoordVecType& pts,
100  vtkm::CellShapeTagHexahedron,
101  vtkm::ErrorCode& ec)
102 {
103  UNUSED(numPts);
104  UNUSED(ec);
105  using Scalar = OutType;
106 
107  Scalar X1 = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(
108  (pts[1] - pts[0]) + (pts[2] - pts[3]) + (pts[5] - pts[4]) + (pts[6] - pts[7]))));
109  Scalar X2 = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(
110  (pts[3] - pts[0]) + (pts[2] - pts[1]) + (pts[7] - pts[4]) + (pts[6] - pts[5]))));
111  Scalar X3 = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(
112  (pts[4] - pts[0]) + (pts[5] - pts[1]) + (pts[6] - pts[2]) + (pts[7] - pts[3]))));
113  if ((X1 <= Scalar(0.0)) || (X2 <= Scalar(0.0)) || (X3 <= Scalar(0.0)))
114  {
115  return vtkm::Infinity<Scalar>();
116  }
117  Scalar X12 = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(
118  ((pts[2] - pts[3]) - (pts[1] - pts[0])) + ((pts[6] - pts[7]) - (pts[5] - pts[4])))));
119  Scalar X13 = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(
120  ((pts[5] - pts[1]) - (pts[4] - pts[0])) + ((pts[6] - pts[2]) - (pts[7] - pts[3])))));
121  Scalar X23 = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(
122  ((pts[7] - pts[4]) - (pts[3] - pts[0])) + ((pts[6] - pts[5]) - (pts[2] - pts[1])))));
123  Scalar T12 = X12 / vtkm::Min(X1, X2);
124  Scalar T13 = X13 / vtkm::Min(X1, X3);
125  Scalar T23 = X23 / vtkm::Min(X2, X3);
126  return vtkm::Max(T12, vtkm::Max(T13, T23));
127 }
128 }
129 } // worklet
130 } // vtkm
131 #endif // vtk_m_worklet_CellTaperMetric_h
UNUSED
#define UNUSED(expr)
Definition: CellTaperMetric.h:41
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::MagnitudeSquared
VTKM_EXEC_CONT detail::FloatingPointReturnType< T >::Type MagnitudeSquared(const T &x)
Returns the square of the magnitude of a vector.
Definition: VectorAnalysis.h:64
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::CellTaperMetric
VTKM_EXEC OutType CellTaperMetric(const vtkm::IdComponent &numPts, const PointCoordVecType &pts, CellShapeType shape, vtkm::ErrorCode &ec)
Definition: CellTaperMetric.h:53
CellShape.h
ErrorCode.h
VectorAnalysis.h
TypeOfCellTetrahedral.h
TypeOfCellTriangle.h
TypeOfCellHexahedral.h
TypeOfCellQuadrilateral.h
CellTraits.h
VecTraits.h