20 #ifndef vtk_m_worklet_CellShapeMetric_h
21 #define vtk_m_worklet_CellShapeMetric_h
51 template <
typename OutType,
typename Po
intCoordVecType,
typename CellShapeType>
53 const PointCoordVecType& pts,
66 template <
typename OutType,
typename Po
intCoordVecType>
68 const PointCoordVecType& pts,
69 vtkm::CellShapeTagTriangle,
77 using Scalar = OutType;
78 using CollectionOfPoints = PointCoordVecType;
80 const Scalar condition =
81 vtkm::worklet::cellmetrics::CellConditionMetric<Scalar, CollectionOfPoints>(
82 numPts, pts, vtkm::CellShapeTagTriangle(), ec);
83 const Scalar q(1 / condition);
89 template <
typename OutType,
typename Po
intCoordVecType>
91 const PointCoordVecType& pts,
92 vtkm::CellShapeTagQuad,
101 using Scalar = OutType;
102 using CollectionOfPoints = PointCoordVecType;
103 using Vector =
typename PointCoordVecType::ComponentType;
104 const Scalar two(2.0);
105 const Scalar alpha0 = GetQuadAlpha0<Scalar, Vector, CollectionOfPoints>(pts);
106 const Scalar alpha1 = GetQuadAlpha1<Scalar, Vector, CollectionOfPoints>(pts);
107 const Scalar alpha2 = GetQuadAlpha2<Scalar, Vector, CollectionOfPoints>(pts);
108 const Scalar alpha3 = GetQuadAlpha3<Scalar, Vector, CollectionOfPoints>(pts);
109 const Scalar l0Squared =
110 vtkm::Pow(GetQuadL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts), 2);
111 const Scalar l1Squared =
112 vtkm::Pow(GetQuadL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts), 2);
113 const Scalar l2Squared =
114 vtkm::Pow(GetQuadL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts), 2);
115 const Scalar l3Squared =
116 vtkm::Pow(GetQuadL3Magnitude<Scalar, Vector, CollectionOfPoints>(pts), 2);
118 const Scalar min = vtkm::Min(
119 (alpha0 / (l0Squared + l3Squared)),
120 vtkm::Min((alpha1 / (l1Squared + l0Squared)),
121 vtkm::Min((alpha2 / (l2Squared + l1Squared)), (alpha3 / (l3Squared + l2Squared)))));
122 const Scalar q(two * min);
129 template <
typename OutType,
typename Po
intCoordVecType>
131 const PointCoordVecType& pts,
132 vtkm::CellShapeTagTetra,
140 using Scalar = OutType;
141 using CollectionOfPoints = PointCoordVecType;
142 using Vector =
typename PointCoordVecType::ComponentType;
144 const Scalar zero(0.0);
145 const Scalar twoThirds = (Scalar)(2.0 / 3.0);
146 const Scalar threeHalves(1.5);
147 const Scalar rtTwo = (Scalar)(
vtkm::Sqrt(2.0));
148 const Scalar three(3.0);
149 const Scalar jacobian =
150 vtkm::worklet::cellmetrics::CellJacobianMetric<Scalar, CollectionOfPoints>(
151 numPts, pts, vtkm::CellShapeTagTetra(), ec);
153 if (jacobian <= zero)
158 const Vector l0 = GetTetraL0<Scalar, Vector, CollectionOfPoints>(pts);
159 const Vector l2 = GetTetraL2<Scalar, Vector, CollectionOfPoints>(pts);
160 const Vector l3 = GetTetraL3<Scalar, Vector, CollectionOfPoints>(pts);
161 const Vector negl2 = -1 * l2;
163 const Scalar l0l0 =
static_cast<Scalar
>(vtkm::Dot(l0, l0));
164 const Scalar l2l2 =
static_cast<Scalar
>(vtkm::Dot(l2, l2));
165 const Scalar l3l3 =
static_cast<Scalar
>(vtkm::Dot(l3, l3));
166 const Scalar l0negl2 =
static_cast<Scalar
>(vtkm::Dot(l0, negl2));
167 const Scalar l0l3 =
static_cast<Scalar
>(vtkm::Dot(l0, l3));
168 const Scalar negl2l3 =
static_cast<Scalar
>(vtkm::Dot(negl2, l3));
170 const Scalar numerator = three * vtkm::Pow(jacobian * rtTwo, twoThirds);
171 Scalar denominator = (threeHalves * (l0l0 + l2l2 + l3l3)) - (l0negl2 + l0l3 + negl2l3);
172 if (denominator <= zero)
176 Scalar q(numerator / denominator);
181 template <
typename OutType,
typename Po
intCoordVecType>
183 const PointCoordVecType& pts,
184 vtkm::CellShapeTagHexahedron,
192 using Scalar = OutType;
193 using CollectionOfPoints = PointCoordVecType;
194 using Vector =
typename PointCoordVecType::ComponentType;
196 const Scalar zero(0.0);
197 const Scalar twoThirds = (Scalar)(2.0 / 3.0);
199 const Scalar alpha0 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(0));
200 const Scalar alpha1 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(1));
201 const Scalar alpha2 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(2));
202 const Scalar alpha3 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(3));
203 const Scalar alpha4 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(4));
204 const Scalar alpha5 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(5));
205 const Scalar alpha6 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(6));
206 const Scalar alpha7 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(7));
207 const Scalar alpha8 = GetHexAlphai<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(8));
209 const Scalar A0squared =
210 GetHexAiNormSquared<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(0));
211 const Scalar A1squared =
212 GetHexAiNormSquared<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(1));
213 const Scalar A2squared =
214 GetHexAiNormSquared<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(2));
215 const Scalar A3squared =
216 GetHexAiNormSquared<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(3));
217 const Scalar A4squared =
218 GetHexAiNormSquared<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(4));
219 const Scalar A5squared =
220 GetHexAiNormSquared<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(5));
221 const Scalar A6squared =
222 GetHexAiNormSquared<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(6));
223 const Scalar A7squared =
224 GetHexAiNormSquared<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(7));
225 const Scalar A8squared =
226 GetHexAiNormSquared<Scalar, Vector, CollectionOfPoints>(pts,
vtkm::Id(8));
228 if (alpha0 <= zero || alpha1 <= zero || alpha2 <= zero || alpha3 <= zero || alpha4 <= zero ||
229 alpha5 <= zero || alpha6 <= zero || alpha7 <= zero || alpha8 <= zero || A0squared <= zero ||
230 A1squared <= zero || A2squared <= zero || A3squared <= zero || A4squared <= zero ||
231 A5squared <= zero || A6squared <= zero || A7squared <= zero || A8squared <= zero)
236 Scalar min = vtkm::Pow(alpha0, twoThirds) / A0squared;
237 Scalar temp = vtkm::Pow(alpha1, twoThirds) / A1squared;
238 min = temp < min ? temp : min;
240 temp = vtkm::Pow(alpha2, twoThirds) / A2squared;
241 min = temp < min ? temp : min;
243 temp = vtkm::Pow(alpha3, twoThirds) / A3squared;
244 min = temp < min ? temp : min;
246 temp = vtkm::Pow(alpha4, twoThirds) / A4squared;
247 min = temp < min ? temp : min;
249 temp = vtkm::Pow(alpha5, twoThirds) / A5squared;
250 min = temp < min ? temp : min;
252 temp = vtkm::Pow(alpha6, twoThirds) / A6squared;
253 min = temp < min ? temp : min;
255 temp = vtkm::Pow(alpha7, twoThirds) / A7squared;
256 min = temp < min ? temp : min;
258 temp = vtkm::Pow(alpha8, twoThirds) / A8squared;
259 min = temp < min ? temp : min;
267 #endif // vtk_m_worklet_CellShapeMetric_h