VTK-m  2.0
TypeOfCellTetrahedral.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_TypeOfCellTetrahedral
21 #define vtk_m_worklet_cellmetrics_TypeOfCellTetrahedral
22 
23 #include <vtkm/Math.h>
24 #include <vtkm/VectorAnalysis.h>
25 
32 template <typename Scalar, typename Vector, typename CollectionOfPoints>
33 VTKM_EXEC Vector GetTetraL0(const CollectionOfPoints& pts)
34 {
35  const Vector L0(pts[1] - pts[0]);
36  return L0;
37 }
38 
45 template <typename Scalar, typename Vector, typename CollectionOfPoints>
46 VTKM_EXEC Vector GetTetraL1(const CollectionOfPoints& pts)
47 {
48  const Vector L1(pts[2] - pts[1]);
49  return L1;
50 }
51 
58 template <typename Scalar, typename Vector, typename CollectionOfPoints>
59 VTKM_EXEC Vector GetTetraL2(const CollectionOfPoints& pts)
60 {
61  const Vector L2(pts[0] - pts[2]);
62  return L2;
63 }
64 
71 template <typename Scalar, typename Vector, typename CollectionOfPoints>
72 VTKM_EXEC Vector GetTetraL3(const CollectionOfPoints& pts)
73 {
74  const Vector L3(pts[3] - pts[0]);
75  return L3;
76 }
77 
84 template <typename Scalar, typename Vector, typename CollectionOfPoints>
85 VTKM_EXEC Vector GetTetraL4(const CollectionOfPoints& pts)
86 {
87  const Vector L4(pts[3] - pts[1]);
88  return L4;
89 }
90 
97 template <typename Scalar, typename Vector, typename CollectionOfPoints>
98 VTKM_EXEC Vector GetTetraL5(const CollectionOfPoints& pts)
99 {
100  const Vector L5(pts[3] - pts[2]);
101  return L5;
102 }
103 
110 template <typename Scalar, typename Vector, typename CollectionOfPoints>
111 VTKM_EXEC Scalar GetTetraL0Magnitude(const CollectionOfPoints& pts)
112 {
113  const Scalar l0 = static_cast<Scalar>(
114  vtkm::Sqrt(vtkm::MagnitudeSquared(GetTetraL0<Scalar, Vector, CollectionOfPoints>(pts))));
115  return l0;
116 }
117 
124 template <typename Scalar, typename Vector, typename CollectionOfPoints>
125 VTKM_EXEC Scalar GetTetraL1Magnitude(const CollectionOfPoints& pts)
126 {
127  const Scalar l1 = static_cast<Scalar>(
128  vtkm::Sqrt(vtkm::MagnitudeSquared(GetTetraL1<Scalar, Vector, CollectionOfPoints>(pts))));
129  return l1;
130 }
131 
138 template <typename Scalar, typename Vector, typename CollectionOfPoints>
139 VTKM_EXEC Scalar GetTetraL2Magnitude(const CollectionOfPoints& pts)
140 {
141  const Scalar l2 = static_cast<Scalar>(
142  vtkm::Sqrt(vtkm::MagnitudeSquared(GetTetraL2<Scalar, Vector, CollectionOfPoints>(pts))));
143  return l2;
144 }
145 
152 template <typename Scalar, typename Vector, typename CollectionOfPoints>
153 VTKM_EXEC Scalar GetTetraL3Magnitude(const CollectionOfPoints& pts)
154 {
155  const Scalar l3 = static_cast<Scalar>(
156  vtkm::Sqrt(vtkm::MagnitudeSquared(GetTetraL3<Scalar, Vector, CollectionOfPoints>(pts))));
157  return l3;
158 }
159 
166 template <typename Scalar, typename Vector, typename CollectionOfPoints>
167 VTKM_EXEC Scalar GetTetraL4Magnitude(const CollectionOfPoints& pts)
168 {
169  const Scalar l4 = static_cast<Scalar>(
170  vtkm::Sqrt(vtkm::MagnitudeSquared(GetTetraL4<Scalar, Vector, CollectionOfPoints>(pts))));
171  return l4;
172 }
173 
180 template <typename Scalar, typename Vector, typename CollectionOfPoints>
181 VTKM_EXEC Scalar GetTetraL5Magnitude(const CollectionOfPoints& pts)
182 {
183  const Scalar l5 = static_cast<Scalar>(
184  vtkm::Sqrt(vtkm::MagnitudeSquared(GetTetraL5<Scalar, Vector, CollectionOfPoints>(pts))));
185  return l5;
186 }
187 
194 template <typename Scalar, typename Vector, typename CollectionOfPoints>
195 VTKM_EXEC Scalar GetTetraLMax(const CollectionOfPoints& pts)
196 {
197  const Scalar l0 = GetTetraL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
198  const Scalar l1 = GetTetraL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
199  const Scalar l2 = GetTetraL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
200  const Scalar l3 = GetTetraL3Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
201  const Scalar l4 = GetTetraL4Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
202  const Scalar l5 = GetTetraL5Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
203  const Scalar lmax = vtkm::Max(l0, vtkm::Max(l1, vtkm::Max(l2, vtkm::Max(l3, vtkm::Max(l4, l5)))));
204  return lmax;
205 }
206 
213 template <typename Scalar, typename Vector, typename CollectionOfPoints>
214 VTKM_EXEC Scalar GetTetraLMin(const CollectionOfPoints& pts)
215 {
216  const Scalar l0 = GetTetraL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
217  const Scalar l1 = GetTetraL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
218  const Scalar l2 = GetTetraL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
219  const Scalar l3 = GetTetraL3Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
220  const Scalar l4 = GetTetraL4Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
221  const Scalar l5 = GetTetraL5Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
222  const Scalar lmin = vtkm::Min(l0, vtkm::Min(l1, vtkm::Min(l2, vtkm::Min(l3, vtkm::Min(l4, l5)))));
223  return lmin;
224 }
225 
232 template <typename Scalar, typename Vector, typename CollectionOfPoints>
233 VTKM_EXEC Scalar GetTetraArea(const CollectionOfPoints& pts)
234 {
235  const Vector L0 = GetTetraL0<Scalar, Vector, CollectionOfPoints>(pts);
236  const Vector L1 = GetTetraL1<Scalar, Vector, CollectionOfPoints>(pts);
237  const Vector L2 = GetTetraL2<Scalar, Vector, CollectionOfPoints>(pts);
238  const Vector L3 = GetTetraL3<Scalar, Vector, CollectionOfPoints>(pts);
239  const Vector L4 = GetTetraL4<Scalar, Vector, CollectionOfPoints>(pts);
240 
241  const Scalar a = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(vtkm::Cross(L2, L0))));
242  const Scalar b = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(vtkm::Cross(L3, L0))));
243  const Scalar c = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(vtkm::Cross(L4, L1))));
244  const Scalar d = static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(vtkm::Cross(L3, L2))));
245  const Scalar hhalf(0.5);
246 
247  const Scalar area = hhalf * (a + b + c + d);
248  return area;
249 }
250 
257 template <typename Scalar, typename Vector, typename CollectionOfPoints>
258 VTKM_EXEC Scalar GetTetraVolume(const CollectionOfPoints& pts)
259 {
260  const Vector L0 = GetTetraL0<Scalar, Vector, CollectionOfPoints>(pts);
261  const Vector L2 = GetTetraL2<Scalar, Vector, CollectionOfPoints>(pts);
262  const Vector L3 = GetTetraL3<Scalar, Vector, CollectionOfPoints>(pts);
263  const Scalar six(6.0);
264 
265  return static_cast<Scalar>(vtkm::Dot(vtkm::Cross(L2, L0), L3)) / six;
266 }
267 
274 template <typename Scalar, typename Vector, typename CollectionOfPoints>
275 VTKM_EXEC Scalar GetTetraInradius(const CollectionOfPoints& pts)
276 {
277  const Scalar three(3.0);
278  const Scalar volume = GetTetraVolume<Scalar, Vector, CollectionOfPoints>(pts);
279  const Scalar area = GetTetraArea<Scalar, Vector, CollectionOfPoints>(pts);
280 
281  return (three * volume) / area;
282 }
283 
284 
291 template <typename Scalar, typename Vector, typename CollectionOfPoints>
292 VTKM_EXEC Scalar GetTetraCircumradius(const CollectionOfPoints& pts)
293 {
294  const Vector L0 = GetTetraL0<Scalar, Vector, CollectionOfPoints>(pts);
295  const Vector L1 = GetTetraL1<Scalar, Vector, CollectionOfPoints>(pts);
296  const Vector L2 = GetTetraL2<Scalar, Vector, CollectionOfPoints>(pts);
297  const Vector L3 = GetTetraL3<Scalar, Vector, CollectionOfPoints>(pts);
298  const Vector L4 = GetTetraL4<Scalar, Vector, CollectionOfPoints>(pts);
299 
300  const Scalar l0l0 = vtkm::MagnitudeSquared(L0);
301  const Scalar l2l2 = vtkm::MagnitudeSquared(L2);
302  const Scalar l3l3 = vtkm::MagnitudeSquared(L3);
303 
304  const Vector A = l3l3 * vtkm::Cross(L2, L0);
305  const Vector B = l2l2 * vtkm::Cross(L3, L0);
306  const Vector C = l0l0 * vtkm::Cross(L3, L2);
307 
308  const Vector D(A + B + C);
309  const Scalar d = vtkm::Sqrt(vtkm::MagnitudeSquared(D));
310 
311  const Scalar twelve(12.0);
312  const Scalar volume = GetTetraVolume<Scalar, Vector, CollectionOfPoints>(pts);
313 
314  const Scalar circumradius = d / (twelve * volume);
315  return circumradius;
316 }
317 
318 #endif
vtkm::Sqrt
VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
Compute the square root of x.
Definition: Math.h:958
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
GetTetraL3
VTKM_EXEC Vector GetTetraL3(const CollectionOfPoints &pts)
Returns the L3 vector, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:72
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
GetTetraL1
VTKM_EXEC Vector GetTetraL1(const CollectionOfPoints &pts)
Returns the L1 vector, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:46
GetTetraL5Magnitude
VTKM_EXEC Scalar GetTetraL5Magnitude(const CollectionOfPoints &pts)
Returns the L5 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:181
GetTetraVolume
VTKM_EXEC Scalar GetTetraVolume(const CollectionOfPoints &pts)
Returns the volume of the Tetra.
Definition: TypeOfCellTetrahedral.h:258
GetTetraL0
VTKM_EXEC Vector GetTetraL0(const CollectionOfPoints &pts)
Returns the L0 vector, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:33
GetTetraL2
VTKM_EXEC Vector GetTetraL2(const CollectionOfPoints &pts)
Returns the L2 vector, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:59
GetTetraLMax
VTKM_EXEC Scalar GetTetraLMax(const CollectionOfPoints &pts)
Returns the Max of the magnitude of each vector which makes up the edges of the Tetra.
Definition: TypeOfCellTetrahedral.h:195
GetTetraInradius
VTKM_EXEC Scalar GetTetraInradius(const CollectionOfPoints &pts)
Returns the inradius of the Tetra.
Definition: TypeOfCellTetrahedral.h:275
GetTetraL4
VTKM_EXEC Vector GetTetraL4(const CollectionOfPoints &pts)
Returns the L4 vector, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:85
VectorAnalysis.h
Math.h
GetTetraL4Magnitude
VTKM_EXEC Scalar GetTetraL4Magnitude(const CollectionOfPoints &pts)
Returns the L4 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:167
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
GetTetraL0Magnitude
VTKM_EXEC Scalar GetTetraL0Magnitude(const CollectionOfPoints &pts)
Returns the L0 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:111
GetTetraL5
VTKM_EXEC Vector GetTetraL5(const CollectionOfPoints &pts)
Returns the L5 vector, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:98
GetTetraArea
VTKM_EXEC Scalar GetTetraArea(const CollectionOfPoints &pts)
Returns the surface area of the Tetra.
Definition: TypeOfCellTetrahedral.h:233
GetTetraL3Magnitude
VTKM_EXEC Scalar GetTetraL3Magnitude(const CollectionOfPoints &pts)
Returns the L3 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:153
GetTetraL1Magnitude
VTKM_EXEC Scalar GetTetraL1Magnitude(const CollectionOfPoints &pts)
Returns the L1 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:125
GetTetraCircumradius
VTKM_EXEC Scalar GetTetraCircumradius(const CollectionOfPoints &pts)
Returns the circumradius of the Tetra.
Definition: TypeOfCellTetrahedral.h:292
GetTetraL2Magnitude
VTKM_EXEC Scalar GetTetraL2Magnitude(const CollectionOfPoints &pts)
Returns the L2 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellTetrahedral.h:139
GetTetraLMin
VTKM_EXEC Scalar GetTetraLMin(const CollectionOfPoints &pts)
Returns the Min of the magnitude of each vector which makes up the sides of the Tetra.
Definition: TypeOfCellTetrahedral.h:214