MeshFields
GPU accelerated mesh-based fields
MeshField_Shape.hpp
Go to the documentation of this file.
1 #ifndef MESHFIELD_SHAPE_H
2 #define MESHFIELD_SHAPE_H
3 #include <MeshField_Defines.hpp>
4 
17 namespace {
26 KOKKOS_INLINE_FUNCTION bool greaterThanOrEqual(MeshField::Real xi, const MeshField::Real val, const MeshField::Real tol) {
27  if ( xi > val ) return true;
28  return (Kokkos::fabs(xi - val) <= tol);
29 }
30 
38 template <typename Array>
39 KOKKOS_INLINE_FUNCTION bool eachGreaterThanOrEqual(Array &xi, const MeshField::Real val, const MeshField::Real tol) {
40  auto gt = true;
41  for (size_t i = 0; i < xi.size(); i++) {
42  gt = gt && greaterThanOrEqual(xi[i],val,tol);
43  }
44  return gt;
45 }
46 
53 KOKKOS_INLINE_FUNCTION bool lessThanOrEqual(MeshField::Real xi, const MeshField::Real val, const MeshField::Real tol) {
54  if ( xi < val ) return true;
55  return (Kokkos::fabs(xi - val) <= tol);
56 }
57 
65 template <typename Array>
66 KOKKOS_INLINE_FUNCTION bool eachLessThanOrEqual(Array &xi, const MeshField::Real val, const MeshField::Real tol) {
67  auto lt = true;
68  for (size_t i = 0; i < xi.size(); i++) {
69  lt = lt && lessThanOrEqual(xi[i],val,tol);
70  }
71  return lt;
72 }
73 
74 } // namespace
75 
76 namespace MeshField {
77 
79 using Vector1 = Kokkos::Array<Real, 1>;
81 using Vector2 = Kokkos::Array<Real, 2>;
83 using Vector3 = Kokkos::Array<Real, 3>;
84 
100  static const size_t numNodes = 2;
101  static const size_t meshEntDim = 1;
102  constexpr static Mesh_Topology DofHolders[1] = {Vertex};
103  constexpr static size_t Order = 1;
104 
109  KOKKOS_INLINE_FUNCTION
110  Kokkos::Array<Real, numNodes * meshEntDim> getNodeParametricCoords() const {
111  // clang-format off
112  return {-1, //node 0
113  1}; //node 1
114  // clang-format on
115  }
116 
122  KOKKOS_INLINE_FUNCTION
123  Kokkos::Array<Real, numNodes> getValues(Vector1 const &xi) const {
124  assert(eachLessThanOrEqual(xi,1.0,ParametricCoordTol));
125  assert(eachGreaterThanOrEqual(xi,-1.0,ParametricCoordTol));
126  // clang-format off
127  return {(1.0 - xi[0]) / 2.0,
128  (1.0 + xi[0]) / 2.0};
129  // clang-format on
130  }
131 
137  KOKKOS_INLINE_FUNCTION
138  Kokkos::Array<Real, numNodes> getLocalGradients(Vector1 const &) const {
139  // clang-format off
140  return {-0.5,
141  0.5};
142  // clang-format on
143  }
144 };
145 
164  static const size_t numNodes = 3;
165  static const size_t numComponentsPerDof = 1;
166  static const size_t meshEntDim = 2;
167  constexpr static Mesh_Topology DofHolders[1] = {Vertex};
168  constexpr static size_t Order = 1;
169 
174  KOKKOS_INLINE_FUNCTION
175  Kokkos::Array<Real, numNodes * meshEntDim> getNodeParametricCoords() const {
176  // clang-format off
177  return {0,0, //node 0
178  1,0, //node 1
179  0,1}; //node 2
180  // clang-format on
181  }
182 
189  KOKKOS_INLINE_FUNCTION
190  Kokkos::Array<Real, numNodes> getValues(Vector2 const &xi) const {
191  assert(eachLessThanOrEqual(xi,1.0,ParametricCoordTol));
192  assert(eachGreaterThanOrEqual(xi,0.0,ParametricCoordTol));
193  const Real L0 = 1 - xi[0] - xi[1];
194  assert(greaterThanOrEqual(L0,0.0,ParametricCoordTol));
195  assert(lessThanOrEqual(L0,1.0,ParametricCoordTol));
196  // clang-format off
197  return {L0,
198  xi[0], //L1
199  xi[1]}; //L2
200  // clang-format on
201  }
202 
209  KOKKOS_INLINE_FUNCTION
210  Kokkos::Array<Real, meshEntDim * numNodes> getLocalGradients(Vector2 const &) const {
211  // clang-format off
212  return { -1,-1, //first vector
213  1, 0,
214  0, 1};
215  // clang-format on
216  }
217 };
218 
231  static const size_t numNodes = 3;
232  static const size_t meshEntDim = 2;
233  constexpr static Mesh_Topology DofHolders[1] = {Vertex};
234  constexpr static size_t Order = 1;
235 
240  KOKKOS_INLINE_FUNCTION
241  Kokkos::Array<Real, numNodes * meshEntDim> getNodeParametricCoords() const {
242  // clang-format off
243  return {0,0, //node 0
244  1,0, //node 1
245  0,1}; //node 2
246  // clang-format on
247  }
248 
254  KOKKOS_INLINE_FUNCTION
255  Kokkos::Array<Real, numNodes> getValues(Vector2 const &xi) const {
256  assert(eachLessThanOrEqual(xi,1.0,ParametricCoordTol));
257  assert(eachGreaterThanOrEqual(xi,0.0,ParametricCoordTol));
258  const Real L0 = 1 - xi[0] - xi[1];
259  assert(greaterThanOrEqual(L0,0.0,ParametricCoordTol));
260  assert(lessThanOrEqual(L0,1.0,ParametricCoordTol));
261  // clang-format off
262  return {L0,
263  xi[0],
264  xi[1]};
265  // clang-format on
266  }
267 };
268 
286  static const size_t numNodes = 6;
287  static const size_t meshEntDim = 2;
288  constexpr static Mesh_Topology DofHolders[2] = {Vertex, Edge};
289  constexpr static size_t NumDofHolders[2] = {3, 3};
290  constexpr static size_t DofsPerHolder[2] = {1, 1};
291  constexpr static size_t Order = 2;
292 
297  KOKKOS_INLINE_FUNCTION
298  Kokkos::Array<Real, numNodes * meshEntDim> getNodeParametricCoords() const {
299  // clang-format off
300  return {
301  //nodes at vertices
302  0 , 0 , //node 0
303  1 , 0 , //node 1
304  0 , 1 , //...
305  //nodes at middle of edges
306  0.5 , 0 ,
307  0.5 , 0.5 ,
308  0 , 0.5 //node 5
309  };
310  // clang-format on
311  }
312 
321  KOKKOS_INLINE_FUNCTION
322  Kokkos::Array<Real, numNodes> getValues(Vector2 const &xi) const {
323  assert(eachLessThanOrEqual(xi,1.0,ParametricCoordTol));
324  assert(eachGreaterThanOrEqual(xi,0.0,ParametricCoordTol));
325  const Real L0 = 1 - xi[0] - xi[1];
326  assert(greaterThanOrEqual(L0,0.0,ParametricCoordTol));
327  assert(lessThanOrEqual(L0,1.0,ParametricCoordTol));
328  const Real L1 = xi[0];
329  const Real L2 = xi[1];
330  // clang-format off
331  return {L0 * (2 * L0 - 1),
332  L1 * (2 * L1 - 1),
333  L2 * (2 * L2 - 1),
334  4 * L1 * L0,
335  4 * L1 * L2,
336  4 * L2 * L0};
337  // clang-format on
338  }
339 
345  KOKKOS_INLINE_FUNCTION
346  Kokkos::Array<Real, meshEntDim * numNodes>
347  getLocalGradients(Vector2 const &xi) const {
348  assert(eachLessThanOrEqual(xi,1.0,ParametricCoordTol));
349  assert(eachGreaterThanOrEqual(xi,0.0,ParametricCoordTol));
350  const Real L0 = 1 - xi[0] - xi[1];
351  assert(greaterThanOrEqual(L0,0.0,ParametricCoordTol));
352  assert(lessThanOrEqual(L0,1.0,ParametricCoordTol));
353  const Real L1 = xi[0];
354  const Real L2 = xi[1];
355  // clang-format off
356  return {
357  -4*L0+1 , -4*L0+1 ,
358  4*L1-1 , 0 ,
359  0 , 4*L2-1 ,
360  4*(L0-L1) , -4*L1 ,
361  4*L2 , 4*L1 ,
362  -4*L2 , 4*(L0-L2)
363  };
364  // clang-format on
365  }
366 };
368 
389  static const size_t numNodes = 4;
390  static const size_t meshEntDim = 3;
391  constexpr static Mesh_Topology DofHolders[1] = {Vertex};
392  constexpr static size_t Order = 1;
393 
398  KOKKOS_INLINE_FUNCTION
399  Kokkos::Array<Real, numNodes * meshEntDim> getNodeParametricCoords() const {
400  // clang-format off
401  return {0,0,0, //node 0
402  1,0,0, //node 1
403  0,1,0, //node 2
404  0,0,1}; //node 3
405  // clang-format on
406  }
407 
414  KOKKOS_INLINE_FUNCTION
415  Kokkos::Array<Real, numNodes> getValues(Vector3 const &xi) const {
416  assert(eachLessThanOrEqual(xi,1.0,ParametricCoordTol));
417  assert(eachGreaterThanOrEqual(xi,0.0,ParametricCoordTol));
418  const Real L0 = 1 - xi[0] - xi[1] - xi[2];
419  assert(greaterThanOrEqual(L0,0.0,ParametricCoordTol));
420  assert(lessThanOrEqual(L0,1.0,ParametricCoordTol));
421  // clang-format off
422  return {L0,
423  xi[0], //L1
424  xi[1], //L2
425  xi[2]}; //L3
426  // clang-format on
427  }
428 
435  KOKKOS_INLINE_FUNCTION
436  Kokkos::Array<Real, meshEntDim * numNodes> getLocalGradients(Vector3 const &) const {
437  // clang-format off
438  return {-1, -1, -1,
439  1, 0, 0,
440  0, 1, 0,
441  0, 0, 1};
442  // clang-format on
443  }
444 };
445 
462  static const size_t numNodes = 10;
463  static const size_t meshEntDim = 3;
464  constexpr static Mesh_Topology DofHolders[2] = {Vertex, Edge};
465  constexpr static size_t NumDofHolders[2] = {4, 6};
466  constexpr static size_t DofsPerHolder[2] = {1, 1};
467  constexpr static size_t Order = 2;
468 
473  KOKKOS_INLINE_FUNCTION
474  Kokkos::Array<Real, numNodes * meshEntDim> getNodeParametricCoords() const {
475  // clang-format off
476  return {
477  //nodes at vertices
478  0,0,0, //node 0
479  1,0,0, //node 1
480  0,1,0, //...
481  0,0,1, //node 3
482  //nodes at middle of edges
483  0.5 , 0 , 0 ,
484  0 , 0.5 , 0 ,
485  0 , 0 , 0.5 ,
486  0.5 , 0.5 , 0 ,
487  0 , 0.5 , 0.5 ,
488  0.5 , 0 , 0.5
489  };
490  // clang-format on
491  }
492 
501  KOKKOS_INLINE_FUNCTION
502  Kokkos::Array<Real, numNodes> getValues(Vector3 const &xi) const {
503  assert(eachLessThanOrEqual(xi,1.0,ParametricCoordTol));
504  assert(eachGreaterThanOrEqual(xi,0.0,ParametricCoordTol));
505  const Real L0 = 1 - xi[0] - xi[1] - xi[2];
506  assert(greaterThanOrEqual(L0,0.0,ParametricCoordTol));
507  assert(lessThanOrEqual(L0,1.0,ParametricCoordTol));
508  const Real L1 = xi[0];
509  const Real L2 = xi[1];
510  const Real L3 = xi[2];
511  // clang-format off
512  return {L0*(2*L0-1),
513  L1*(2*L1-1),
514  L2*(2*L2-1),
515  L3*(2*L3-1),
516  4*L1*L0,
517  4*L2*L0,
518  4*L3*L0,
519  4*L1*L2,
520  4*L2*L3,
521  4*L1*L3};
522  // clang-format on
523  }
524 
530  KOKKOS_INLINE_FUNCTION
531  Kokkos::Array<Real, meshEntDim * numNodes>
532  getLocalGradients(Vector3 const &xi) const {
533  assert(eachLessThanOrEqual(xi,1.0,ParametricCoordTol));
534  assert(eachGreaterThanOrEqual(xi,0.0,ParametricCoordTol));
535  const Real L0 = 1 - xi[0] - xi[1] - xi[2];
536  assert(greaterThanOrEqual(L0,0.0,ParametricCoordTol));
537  assert(lessThanOrEqual(L0,1.0,ParametricCoordTol));
538  const Real L1 = xi[0];
539  const Real L2 = xi[1];
540  const Real L3 = xi[2];
541 
542  const Real d3 = 1 - 4 * L0;
543  // clang-format off
544  return {
545  d3 , d3 , d3 ,
546  4*L1-1 , 0 , 0 ,
547  0 , 4*L2-1 , 0 ,
548  0 , 0 , 4*L3-1 ,
549  4*L0-4*L1 , -4*L1 , -4*L1 ,
550  -4*L2 , 4*L0-4*L2 , -4*L2 ,
551  -4*L3 , -4*L3 , 4*L0-4*L3 ,
552  4*L2 , 4*L1 , 0 ,
553  0 , 4*L3 , 4*L2 ,
554  4*L3 , 0 , 4*L1
555  };
556  // clang-format on
557  }
558 };
559 
560 } // namespace MeshField
561 #endif
Kokkos::Array< Real, 2 > Vector2
2D parametric coordinate vector
Kokkos::Array< Real, 3 > Vector3
3D parametric coordinate vector
Kokkos::Array< Real, 1 > Vector1
1D parametric coordinate vector
Linear (P1) shape functions for 1D edge elements.
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes *meshEntDim > getNodeParametricCoords() const
Get parametric coordinates of element nodes.
static const size_t meshEntDim
Mesh entity dimension (1D)
constexpr static Mesh_Topology DofHolders[1]
DOFs located at vertices.
constexpr static size_t Order
Polynomial order (linear)
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes > getValues(Vector1 const &xi) const
Evaluate shape functions at parametric coordinate.
static const size_t numNodes
Number of nodes (2 for linear edge)
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes > getLocalGradients(Vector1 const &) const
Get gradients of shape functions in parametric coordinates @detail gradients are constant - ignoring ...
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes > getValues(Vector3 const &xi) const
Evaluate shape functions at parametric coordinate.
static const size_t numNodes
Number of nodes (4 for linear tetrahedron)
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes *meshEntDim > getNodeParametricCoords() const
Get parametric coordinates of element nodes.
constexpr static Mesh_Topology DofHolders[1]
DOFs located at vertices.
static const size_t meshEntDim
Mesh entity dimension (3D)
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, meshEntDim *numNodes > getLocalGradients(Vector3 const &) const
Get gradients of shape functions in parametric coordinates @detail gradients are constant - ignoring ...
constexpr static size_t Order
Polynomial order (linear)
Linear triangle shape functions for coordinate fields.
constexpr static Mesh_Topology DofHolders[1]
DOFs located at vertices.
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes > getValues(Vector2 const &xi) const
Evaluate shape functions at parametric coordinate.
static const size_t numNodes
Number of nodes.
constexpr static size_t Order
Polynomial order (linear)
static const size_t meshEntDim
Mesh entity dimension (2D)
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes *meshEntDim > getNodeParametricCoords() const
Get parametric coordinates of element nodes.
Linear (P1) shape functions for 2D triangular elements.
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, meshEntDim *numNodes > getLocalGradients(Vector2 const &) const
Get gradients of shape functions @detail gradients are constant - ignoring parametric coord input.
static const size_t numComponentsPerDof
Components per DOF (scalar field)
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes *meshEntDim > getNodeParametricCoords() const
Get parametric coordinates of element nodes.
constexpr static size_t Order
Polynomial order (linear)
static const size_t meshEntDim
Mesh entity dimension (2D)
static const size_t numNodes
Number of nodes (3 for linear triangle)
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes > getValues(Vector2 const &xi) const
Evaluate shape functions at parametric coordinate.
constexpr static Mesh_Topology DofHolders[1]
DOFs located at vertices.
Quadratic (P2) shape functions for 3D tetrahedral elements.
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes *meshEntDim > getNodeParametricCoords() const
Get parametric coordinates of element nodes.
constexpr static size_t NumDofHolders[2]
4 vertices, 6 edges
constexpr static size_t Order
Polynomial order (quadratic)
static const size_t numNodes
Number of nodes (10 for quadratic tetrahedron)
constexpr static Mesh_Topology DofHolders[2]
DOFs at vertices and edges.
constexpr static size_t DofsPerHolder[2]
1 DOF per vertex/edge
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes > getValues(Vector3 const &xi) const
Evaluate quadratic shape functions at parametric coordinate.
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, meshEntDim *numNodes > getLocalGradients(Vector3 const &xi) const
Get gradients of quadratic shape functions in parametric coordinates.
static const size_t meshEntDim
Mesh entity dimension (3D)
Quadratic (P2) shape functions for 2D triangular elements.
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes > getValues(Vector2 const &xi) const
Evaluate quadratic shape functions at parametric coordinate.
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, meshEntDim *numNodes > getLocalGradients(Vector2 const &xi) const
Get gradients of quadratic shape functions at parametric coordinate.
constexpr static size_t NumDofHolders[2]
3 vertices, 3 edges
KOKKOS_INLINE_FUNCTION Kokkos::Array< Real, numNodes *meshEntDim > getNodeParametricCoords() const
Get parametric coordinates of element nodes.
constexpr static Mesh_Topology DofHolders[2]
DOFs at vertices and edges.
constexpr static size_t DofsPerHolder[2]
1 DOF per vertex/edge
static const size_t numNodes
Number of nodes (6 for quadratic triangle)
constexpr static size_t Order
Polynomial order (quadratic)
static const size_t meshEntDim
Mesh entity dimension (2D)