VTK-m  2.0
TypeOfCellQuadrilateral.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_TypeOfCellQuadrilateral
21 #define vtk_m_worklet_cellmetrics_TypeOfCellQuadrilateral
22 
35 #include <vtkm/Math.h>
36 #include <vtkm/VectorAnalysis.h>
37 
44 template <typename Scalar, typename Vector, typename CollectionOfPoints>
45 VTKM_EXEC Vector GetQuadL0(const CollectionOfPoints& pts)
46 {
47  const Vector L0(pts[1] - pts[0]);
48  return L0;
49 }
50 
57 template <typename Scalar, typename Vector, typename CollectionOfPoints>
58 VTKM_EXEC Vector GetQuadL1(const CollectionOfPoints& pts)
59 {
60  const Vector L1(pts[2] - pts[1]);
61  return L1;
62 }
63 
70 template <typename Scalar, typename Vector, typename CollectionOfPoints>
71 VTKM_EXEC Vector GetQuadL2(const CollectionOfPoints& pts)
72 {
73  const Vector L2(pts[3] - pts[2]);
74  return L2;
75 }
76 
83 template <typename Scalar, typename Vector, typename CollectionOfPoints>
84 VTKM_EXEC Vector GetQuadL3(const CollectionOfPoints& pts)
85 {
86  const Vector L3(pts[0] - pts[3]);
87  return L3;
88 }
89 
96 template <typename Scalar, typename Vector, typename CollectionOfPoints>
97 VTKM_EXEC Scalar GetQuadL0Magnitude(const CollectionOfPoints& pts)
98 {
99  const Scalar l0 = static_cast<Scalar>(
100  vtkm::Sqrt(vtkm::MagnitudeSquared(GetQuadL0<Scalar, Vector, CollectionOfPoints>(pts))));
101  return l0;
102 }
103 
110 template <typename Scalar, typename Vector, typename CollectionOfPoints>
111 VTKM_EXEC Scalar GetQuadL1Magnitude(const CollectionOfPoints& pts)
112 {
113  const Scalar l1 = static_cast<Scalar>(
114  vtkm::Sqrt(vtkm::MagnitudeSquared(GetQuadL1<Scalar, Vector, CollectionOfPoints>(pts))));
115  return l1;
116 }
117 
124 template <typename Scalar, typename Vector, typename CollectionOfPoints>
125 VTKM_EXEC Scalar GetQuadL2Magnitude(const CollectionOfPoints& pts)
126 {
127  const Scalar l2 = static_cast<Scalar>(
128  vtkm::Sqrt(vtkm::MagnitudeSquared(GetQuadL2<Scalar, Vector, CollectionOfPoints>(pts))));
129  return l2;
130 }
131 
138 template <typename Scalar, typename Vector, typename CollectionOfPoints>
139 VTKM_EXEC Scalar GetQuadL3Magnitude(const CollectionOfPoints& pts)
140 {
141  const Scalar l3 = static_cast<Scalar>(
142  vtkm::Sqrt(vtkm::MagnitudeSquared(GetQuadL3<Scalar, Vector, CollectionOfPoints>(pts))));
143  return l3;
144 }
145 
152 template <typename Scalar, typename Vector, typename CollectionOfPoints>
153 VTKM_EXEC Scalar GetQuadLMax(const CollectionOfPoints& pts)
154 {
155  const Scalar l0 = GetQuadL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
156  const Scalar l1 = GetQuadL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
157  const Scalar l2 = GetQuadL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
158  const Scalar l3 = GetQuadL3Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
159  const Scalar lmax = vtkm::Max(l0, vtkm::Max(l1, vtkm::Max(l2, l3)));
160  return lmax;
161 }
162 
169 template <typename Scalar, typename Vector, typename CollectionOfPoints>
170 VTKM_EXEC Scalar GetQuadLMin(const CollectionOfPoints& pts)
171 {
172  const Scalar l0 = GetQuadL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
173  const Scalar l1 = GetQuadL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
174  const Scalar l2 = GetQuadL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
175  const Scalar l3 = GetQuadL3Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
176  const Scalar lmin = vtkm::Min(l0, vtkm::Min(l1, vtkm::Min(l2, l3)));
177  return lmin;
178 }
179 
186 template <typename Scalar, typename Vector, typename CollectionOfPoints>
187 VTKM_EXEC Vector GetQuadD0(const CollectionOfPoints& pts)
188 {
189  const Vector D0(pts[2] - pts[0]);
190  return D0;
191 }
192 
199 template <typename Scalar, typename Vector, typename CollectionOfPoints>
200 VTKM_EXEC Vector GetQuadD1(const CollectionOfPoints& pts)
201 {
202  const Vector D1(pts[3] - pts[1]);
203  return D1;
204 }
205 
212 template <typename Scalar, typename Vector, typename CollectionOfPoints>
213 VTKM_EXEC Scalar GetQuadD0Magnitude(const CollectionOfPoints& pts)
214 {
215  const Scalar d0 = static_cast<Scalar>(
216  vtkm::Sqrt(vtkm::MagnitudeSquared(GetQuadD0<Scalar, Vector, CollectionOfPoints>(pts))));
217  return d0;
218 }
219 
226 template <typename Scalar, typename Vector, typename CollectionOfPoints>
227 VTKM_EXEC Scalar GetQuadD1Magnitude(const CollectionOfPoints& pts)
228 {
229  const Scalar d1 = static_cast<Scalar>(
230  vtkm::Sqrt(vtkm::MagnitudeSquared(GetQuadD1<Scalar, Vector, CollectionOfPoints>(pts))));
231  return d1;
232 }
233 
240 template <typename Scalar, typename Vector, typename CollectionOfPoints>
241 VTKM_EXEC Scalar GetQuadDMax(const CollectionOfPoints& pts)
242 {
243  const Scalar d0 = GetQuadD0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
244  const Scalar d1 = GetQuadD1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
245 
246  const Scalar dmax = vtkm::Max(d0, d1);
247  return dmax;
248 }
249 
256 template <typename Scalar, typename Vector, typename CollectionOfPoints>
257 VTKM_EXEC Vector GetQuadX0(const CollectionOfPoints& pts)
258 {
259  const Vector X0((pts[1] - pts[0]) + (pts[2] - pts[3]));
260  return X0;
261 }
262 
269 template <typename Scalar, typename Vector, typename CollectionOfPoints>
270 VTKM_EXEC Vector GetQuadX1(const CollectionOfPoints& pts)
271 {
272  const Vector X1((pts[2] - pts[1]) + (pts[3] - pts[0]));
273  return X1;
274 }
275 
282 template <typename Scalar, typename Vector, typename CollectionOfPoints>
283 VTKM_EXEC Vector GetQuadN0(const CollectionOfPoints& pts)
284 {
285  const Vector A = GetQuadL3<Scalar, Vector, CollectionOfPoints>(pts);
286  const Vector B = GetQuadL0<Scalar, Vector, CollectionOfPoints>(pts);
287  const Vector N0 = vtkm::Cross(A, B);
288  return N0;
289 }
290 
297 template <typename Scalar, typename Vector, typename CollectionOfPoints>
298 VTKM_EXEC Vector GetQuadN1(const CollectionOfPoints& pts)
299 {
300  const Vector A = GetQuadL0<Scalar, Vector, CollectionOfPoints>(pts);
301  const Vector B = GetQuadL1<Scalar, Vector, CollectionOfPoints>(pts);
302  const Vector N1 = vtkm::Cross(A, B);
303  return N1;
304 }
305 
312 template <typename Scalar, typename Vector, typename CollectionOfPoints>
313 VTKM_EXEC Vector GetQuadN2(const CollectionOfPoints& pts)
314 {
315  const Vector A = GetQuadL1<Scalar, Vector, CollectionOfPoints>(pts);
316  const Vector B = GetQuadL2<Scalar, Vector, CollectionOfPoints>(pts);
317  const Vector N2 = vtkm::Cross(A, B);
318  return N2;
319 }
320 
327 template <typename Scalar, typename Vector, typename CollectionOfPoints>
328 VTKM_EXEC Vector GetQuadN3(const CollectionOfPoints& pts)
329 {
330  const Vector A = GetQuadL2<Scalar, Vector, CollectionOfPoints>(pts);
331  const Vector B = GetQuadL3<Scalar, Vector, CollectionOfPoints>(pts);
332  const Vector N3 = vtkm::Cross(A, B);
333  return N3;
334 }
335 
342 template <typename Scalar, typename Vector, typename CollectionOfPoints>
343 VTKM_EXEC Vector GetQuadNc(const CollectionOfPoints& pts)
344 {
345  const Vector A = GetQuadX0<Scalar, Vector, CollectionOfPoints>(pts);
346  const Vector B = GetQuadX1<Scalar, Vector, CollectionOfPoints>(pts);
347  const Vector Nc = vtkm::Cross(A, B);
348  return Nc;
349 }
350 
357 template <typename Scalar, typename Vector, typename CollectionOfPoints>
358 VTKM_EXEC Vector GetQuadN0Normalized(const CollectionOfPoints& pts)
359 {
360  return vtkm::Normal(GetQuadN0<Scalar, Vector, CollectionOfPoints>(pts));
361 }
362 
369 template <typename Scalar, typename Vector, typename CollectionOfPoints>
370 VTKM_EXEC Vector GetQuadN1Normalized(const CollectionOfPoints& pts)
371 {
372  return vtkm::Normal(GetQuadN1<Scalar, Vector, CollectionOfPoints>(pts));
373 }
374 
381 template <typename Scalar, typename Vector, typename CollectionOfPoints>
382 VTKM_EXEC Vector GetQuadN2Normalized(const CollectionOfPoints& pts)
383 {
384  return vtkm::Normal(GetQuadN2<Scalar, Vector, CollectionOfPoints>(pts));
385 }
386 
393 template <typename Scalar, typename Vector, typename CollectionOfPoints>
394 VTKM_EXEC Vector GetQuadN3Normalized(const CollectionOfPoints& pts)
395 {
396  return vtkm::Normal(GetQuadN3<Scalar, Vector, CollectionOfPoints>(pts));
397 }
398 
405 template <typename Scalar, typename Vector, typename CollectionOfPoints>
406 VTKM_EXEC Vector GetQuadNcNormalized(const CollectionOfPoints& pts)
407 {
408  return vtkm::Normal(GetQuadNc<Scalar, Vector, CollectionOfPoints>(pts));
409 }
410 
417 template <typename Scalar, typename Vector, typename CollectionOfPoints>
418 VTKM_EXEC Scalar GetQuadAlpha0(const CollectionOfPoints& pts)
419 {
420  const Vector normalizedCenterNormal =
421  GetQuadNcNormalized<Scalar, Vector, CollectionOfPoints>(pts);
422  const Vector N0 = GetQuadN0<Scalar, Vector, CollectionOfPoints>(pts);
423  return static_cast<Scalar>(vtkm::Dot(normalizedCenterNormal, N0));
424 }
425 
432 template <typename Scalar, typename Vector, typename CollectionOfPoints>
433 VTKM_EXEC Scalar GetQuadAlpha1(const CollectionOfPoints& pts)
434 {
435  const Vector normalizedCenterNormal =
436  GetQuadNcNormalized<Scalar, Vector, CollectionOfPoints>(pts);
437  const Vector N1 = GetQuadN1<Scalar, Vector, CollectionOfPoints>(pts);
438  return static_cast<Scalar>(vtkm::Dot(normalizedCenterNormal, N1));
439 }
440 
447 template <typename Scalar, typename Vector, typename CollectionOfPoints>
448 VTKM_EXEC Scalar GetQuadAlpha2(const CollectionOfPoints& pts)
449 {
450  const Vector normalizedCenterNormal =
451  GetQuadNcNormalized<Scalar, Vector, CollectionOfPoints>(pts);
452  const Vector N2 = GetQuadN2<Scalar, Vector, CollectionOfPoints>(pts);
453  return static_cast<Scalar>(vtkm::Dot(normalizedCenterNormal, N2));
454 }
455 
456 
463 template <typename Scalar, typename Vector, typename CollectionOfPoints>
464 VTKM_EXEC Scalar GetQuadAlpha3(const CollectionOfPoints& pts)
465 {
466  const Vector normalizedCenterNormal =
467  GetQuadNcNormalized<Scalar, Vector, CollectionOfPoints>(pts);
468  const Vector N3 = GetQuadN3<Scalar, Vector, CollectionOfPoints>(pts);
469  return static_cast<Scalar>(vtkm::Dot(normalizedCenterNormal, N3));
470 }
471 
472 
479 template <typename Scalar, typename Vector, typename CollectionOfPoints>
480 VTKM_EXEC Scalar GetQuadArea(const CollectionOfPoints& pts)
481 {
482  const Scalar quarter(0.25);
483  const Scalar a0 = GetQuadAlpha0<Scalar, Vector, CollectionOfPoints>(pts);
484  const Scalar a1 = GetQuadAlpha1<Scalar, Vector, CollectionOfPoints>(pts);
485  const Scalar a2 = GetQuadAlpha2<Scalar, Vector, CollectionOfPoints>(pts);
486  const Scalar a3 = GetQuadAlpha3<Scalar, Vector, CollectionOfPoints>(pts);
487  return quarter * (a0 + a1 + a2 + a3);
488 }
489 
490 #endif
GetQuadAlpha3
VTKM_EXEC Scalar GetQuadAlpha3(const CollectionOfPoints &pts)
Returns the alpha3 scalar, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:464
GetQuadL1
VTKM_EXEC Vector GetQuadL1(const CollectionOfPoints &pts)
Returns the L1 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:58
GetQuadN3
VTKM_EXEC Vector GetQuadN3(const CollectionOfPoints &pts)
Returns the N3 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:328
GetQuadL3
VTKM_EXEC Vector GetQuadL3(const CollectionOfPoints &pts)
Returns the L3 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:84
vtkm::Sqrt
VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
Compute the square root of x.
Definition: Math.h:958
GetQuadNc
VTKM_EXEC Vector GetQuadNc(const CollectionOfPoints &pts)
Returns the normal center vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:343
GetQuadN0Normalized
VTKM_EXEC Vector GetQuadN0Normalized(const CollectionOfPoints &pts)
Returns the normalized N0 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:358
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
GetQuadLMin
VTKM_EXEC Scalar GetQuadLMin(const CollectionOfPoints &pts)
Returns the Min of the magnitude of each vector which makes up the sides of the Quad.
Definition: TypeOfCellQuadrilateral.h:170
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
GetQuadNcNormalized
VTKM_EXEC Vector GetQuadNcNormalized(const CollectionOfPoints &pts)
Returns the normalized Nc vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:406
GetQuadN1Normalized
VTKM_EXEC Vector GetQuadN1Normalized(const CollectionOfPoints &pts)
Returns the normalized N1 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:370
GetQuadD0Magnitude
VTKM_EXEC Scalar GetQuadD0Magnitude(const CollectionOfPoints &pts)
Returns the D0 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:213
GetQuadX1
VTKM_EXEC Vector GetQuadX1(const CollectionOfPoints &pts)
Returns the X1 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:270
GetQuadD1
VTKM_EXEC Vector GetQuadD1(const CollectionOfPoints &pts)
Returns the D1 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:200
GetQuadL1Magnitude
VTKM_EXEC Scalar GetQuadL1Magnitude(const CollectionOfPoints &pts)
Returns the L1 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:111
GetQuadL0Magnitude
VTKM_EXEC Scalar GetQuadL0Magnitude(const CollectionOfPoints &pts)
Returns the L0 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:97
GetQuadArea
VTKM_EXEC Scalar GetQuadArea(const CollectionOfPoints &pts)
Returns the area of the quad, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:480
GetQuadL2Magnitude
VTKM_EXEC Scalar GetQuadL2Magnitude(const CollectionOfPoints &pts)
Returns the L2 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:125
vtkm::Normal
VTKM_EXEC_CONT T Normal(const T &x)
Returns a normalized version of the given vector.
Definition: VectorAnalysis.h:157
VectorAnalysis.h
GetQuadX0
VTKM_EXEC Vector GetQuadX0(const CollectionOfPoints &pts)
Returns the X0 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:257
Math.h
GetQuadAlpha1
VTKM_EXEC Scalar GetQuadAlpha1(const CollectionOfPoints &pts)
Returns the alpha1 scalar, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:433
GetQuadLMax
VTKM_EXEC Scalar GetQuadLMax(const CollectionOfPoints &pts)
Returns the Max of the magnitude of each vector which makes up the sides of the Quad.
Definition: TypeOfCellQuadrilateral.h:153
vtkm::Cross
VTKM_EXEC_CONT vtkm::Vec< typename detail::FloatingPointReturnType< T >::Type, 3 > Cross(const vtkm::Vec< T, 3 > &x, const vtkm::Vec< T, 3 > &y)
Find the cross product of two vectors.
Definition: VectorAnalysis.h:177
GetQuadN2
VTKM_EXEC Vector GetQuadN2(const CollectionOfPoints &pts)
Returns the N2 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:313
GetQuadN3Normalized
VTKM_EXEC Vector GetQuadN3Normalized(const CollectionOfPoints &pts)
Returns the normalized N3 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:394
GetQuadL0
VTKM_EXEC Vector GetQuadL0(const CollectionOfPoints &pts)
The Verdict manual defines a set of commonly used components of a quadrilateral (quad).
Definition: TypeOfCellQuadrilateral.h:45
GetQuadN0
VTKM_EXEC Vector GetQuadN0(const CollectionOfPoints &pts)
Returns the N0 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:283
GetQuadAlpha2
VTKM_EXEC Scalar GetQuadAlpha2(const CollectionOfPoints &pts)
Returns the alpha2 scalar, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:448
GetQuadN1
VTKM_EXEC Vector GetQuadN1(const CollectionOfPoints &pts)
Returns the N1 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:298
GetQuadN2Normalized
VTKM_EXEC Vector GetQuadN2Normalized(const CollectionOfPoints &pts)
Returns the normalized N2 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:382
GetQuadL3Magnitude
VTKM_EXEC Scalar GetQuadL3Magnitude(const CollectionOfPoints &pts)
Returns the L3 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:139
GetQuadD0
VTKM_EXEC Vector GetQuadD0(const CollectionOfPoints &pts)
Returns the D0 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:187
GetQuadAlpha0
VTKM_EXEC Scalar GetQuadAlpha0(const CollectionOfPoints &pts)
Returns the alpha0 scalar, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:418
GetQuadD1Magnitude
VTKM_EXEC Scalar GetQuadD1Magnitude(const CollectionOfPoints &pts)
Returns the D0 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:227
GetQuadL2
VTKM_EXEC Vector GetQuadL2(const CollectionOfPoints &pts)
Returns the L2 vector, as defined by the verdict manual.
Definition: TypeOfCellQuadrilateral.h:71
GetQuadDMax
VTKM_EXEC Scalar GetQuadDMax(const CollectionOfPoints &pts)
Returns the Max of the magnitude of each vector which makes up the diagonals of the Quad.
Definition: TypeOfCellQuadrilateral.h:241