20 #ifndef vtk_m_worklet_cellmetrics_CellConditionMetric_h
21 #define vtk_m_worklet_cellmetrics_CellConditionMetric_h
42 #define UNUSED(expr) (void)(expr);
53 template <
typename OutType,
typename Po
intCoordVecType,
typename CellShapeType>
55 const PointCoordVecType& pts,
68 template <
typename OutType,
typename Po
intCoordVecType>
70 const PointCoordVecType& pts,
71 vtkm::CellShapeTagTriangle,
80 using Scalar = OutType;
81 using CollectionOfPoints = PointCoordVecType;
82 using Vector =
typename PointCoordVecType::ComponentType;
84 const Scalar area = GetTriangleArea<Scalar, Vector, CollectionOfPoints>(pts);
86 if (area == Scalar(0.0))
88 return vtkm::Infinity<Scalar>();
90 const Scalar two(2.0);
91 const Scalar rootThree =
vtkm::Sqrt(Scalar(3.0));
92 const Vector L1 = GetTriangleL1<Scalar, Vector, CollectionOfPoints>(pts);
93 const Vector L2 = GetTriangleL2<Scalar, Vector, CollectionOfPoints>(pts);
96 static_cast<Scalar
>((vtkm::Dot(L2, L2) + vtkm::Dot(L1, L1) + vtkm::Dot(L1, L2))) /
97 (two * area * rootThree);
101 template <
typename OutType,
typename Po
intCoordVecType>
103 const PointCoordVecType& pts,
104 vtkm::CellShapeTagQuad,
109 using Scalar = OutType;
110 using CollectionOfPoints = PointCoordVecType;
111 using Vector =
typename PointCoordVecType::ComponentType;
113 const Scalar a0 = GetQuadAlpha0<Scalar, Vector, CollectionOfPoints>(pts);
114 const Scalar a1 = GetQuadAlpha1<Scalar, Vector, CollectionOfPoints>(pts);
115 const Scalar a2 = GetQuadAlpha2<Scalar, Vector, CollectionOfPoints>(pts);
116 const Scalar a3 = GetQuadAlpha3<Scalar, Vector, CollectionOfPoints>(pts);
118 if (a0 < vtkm::NegativeInfinity<Scalar>() || a1 < vtkm::NegativeInfinity<Scalar>() ||
119 a2 < vtkm::NegativeInfinity<Scalar>() || a3 < vtkm::NegativeInfinity<Scalar>())
121 return vtkm::Infinity<Scalar>();
124 const Scalar l0 = GetQuadL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
125 const Scalar l1 = GetQuadL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
126 const Scalar l2 = GetQuadL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
127 const Scalar l3 = GetQuadL3Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
128 const Scalar hhalf(0.5);
130 const Scalar q0 = ((l0 * l0) + (l3 * l3)) / a0;
131 const Scalar q1 = ((l1 * l1) + (l0 * l0)) / a1;
132 const Scalar q2 = ((l2 * l2) + (l1 * l1)) / a2;
133 const Scalar q3 = ((l3 * l3) + (l2 * l2)) / a3;
135 const Scalar q = hhalf * vtkm::Max(q0, vtkm::Max(q1, vtkm::Max(q2, q3)));
141 template <
typename OutType,
typename Po
intCoordVecType>
143 const PointCoordVecType& pts,
144 vtkm::CellShapeTagTetra,
152 using Scalar = OutType;
153 using CollectionOfPoints = PointCoordVecType;
154 using Vector =
typename PointCoordVecType::ComponentType;
156 const Scalar negTwo(-2.0);
157 const Scalar three(3.0);
160 const Vector L0 = GetTetraL0<Scalar, Vector, CollectionOfPoints>(pts);
161 const Vector L2 = GetTetraL2<Scalar, Vector, CollectionOfPoints>(pts);
162 const Vector L3 = GetTetraL3<Scalar, Vector, CollectionOfPoints>(pts);
164 const Vector C1 = L0;
165 const Vector C2 = ((negTwo * L2) - L0) / root3;
166 const Vector C3 = ((three * L3) + L2 - L0) / root6;
168 const Scalar cDet =
static_cast<Scalar
>(vtkm::Dot(C1,
vtkm::Cross(C2, C3)));
170 if (cDet <= Scalar(0.0))
172 return vtkm::Infinity<Scalar>();
179 const Scalar t1 =
static_cast<Scalar
>(vtkm::Dot(C1, C1) + vtkm::Dot(C2, C2) + vtkm::Dot(C3, C3));
180 const Scalar t2 =
static_cast<Scalar
>(vtkm::Dot(C1xC2, C1xC2) + vtkm::Dot(C2xC3, C2xC3) +
181 vtkm::Dot(C1xC3, C1xC3));
183 const Scalar q =
vtkm::Sqrt(t1 * t2) / (three * cDet);
188 template <
typename OutType,
typename Po
intCoordVecType>
190 const PointCoordVecType& pts,
191 vtkm::CellShapeTagHexahedron,
194 return CellMaxAspectFrobeniusMetric<OutType, PointCoordVecType>(
195 numPts, pts, vtkm::CellShapeTagHexahedron(), ec);
200 #endif // vtk_m_worklet_cellmetrics_CellConditionMetric_h