Intrepid2
Intrepid2_Types.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Intrepid2 Package
4 //
5 // Copyright 2007 NTESS and the Intrepid2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
15 #ifndef __INTREPID2_TYPES_HPP__
16 #define __INTREPID2_TYPES_HPP__
17 
18 #include <Kokkos_Core.hpp>
19 #include <Kokkos_DynRankView.hpp>
20 
21 #include <stdexcept>
22 
23 namespace Intrepid2 {
24 
25  // use ordinal_type and size_type everywhere (no index type)
26  typedef int ordinal_type;
27  typedef size_t size_type;
28 
29  template<typename ValueType>
30  KOKKOS_FORCEINLINE_FUNCTION
31  ValueType epsilon() {
32  return 0;
33  }
34 
35  template<>
36  KOKKOS_FORCEINLINE_FUNCTION
37  double epsilon<double>() {
38  typedef union {
39  long long i64;
40  double d64;
41  } dbl_64;
42 
43  dbl_64 s;
44  s.d64 = 1;
45  s.i64++;
46  return (s.i64 < 0 ? 1 - s.d64 : s.d64 - 1);
47  }
48 
49  template<>
50  KOKKOS_FORCEINLINE_FUNCTION
51  float epsilon<float>() {
52  typedef union {
53  int i32;
54  float f32;
55  } flt_32;
56 
57  flt_32 s;
58  s.f32 = 1;
59  s.i32++;
60  return (s.i32 < 0 ? 1 - s.f32 : s.f32 - 1);
61  }
62 
63  KOKKOS_FORCEINLINE_FUNCTION
64  double epsilon() {
65  return epsilon<double>();
66  }
67 
68  template<typename ValueType>
69  KOKKOS_FORCEINLINE_FUNCTION
70  ValueType tolerence() {
71  return 100.0*epsilon<ValueType>();
72  }
73 
74  KOKKOS_FORCEINLINE_FUNCTION
75  double tolerence() {
76  return tolerence<double>();
77  }
78 
79  template<typename ValueType>
80  KOKKOS_FORCEINLINE_FUNCTION
81  ValueType threshold() {
82  return 10.0*epsilon<ValueType>();
83  }
84 
85  KOKKOS_FORCEINLINE_FUNCTION
86  double threshold() {
87  return threshold<double>();
88  }
89 
91  class Parameters {
92  public:
93  // KK: do not chagne max num pts per basis eval bigger than 1.
94  // polylib point and order match needs to be first examined; now if it is set bigger than 1
95  // it creates silent error.
96  //
97  // MP: I tried setting max num pts per basis eval to 2 and everything seems working fine. Leaving it to 1 for now.
98 
100  static constexpr ordinal_type MaxNumPtsPerBasisEval= 1;
102  static constexpr ordinal_type MaxOrder = 20;
104  static constexpr ordinal_type MaxIntegrationPoints = 4893;
106  static constexpr ordinal_type MaxCubatureDegreeEdge= 61;
108  static constexpr ordinal_type MaxCubatureDegreeTri = 50;
110  static constexpr ordinal_type MaxCubatureDegreeTet = 20;
112  static constexpr ordinal_type MaxCubatureDegreePyr = 11;
114  static constexpr ordinal_type MaxDimension = 3;
116  static constexpr ordinal_type MaxNewton = 15;
118  static constexpr ordinal_type MaxDerivative = 10;
120  static constexpr ordinal_type MaxTensorComponents = 7;
122  static constexpr ordinal_type MaxVectorComponents = 7;
123 
124  // we do not want to use hard-wired epsilon, threshold and tolerence.
125  // static constexpr double Epsilon = 1.0e-16;
126  // static constexpr double Threshold = 1.0e-15;
127  // static constexpr double Tolerence = 1.0e-14;
128  };
129  // const double Parameters::Epsilon = epsilon<double>(); // Platform-dependent machine epsilon.
130  // const double Parameters::Threshold = 10.0*epsilon<double>(); // Tolerance for various cell inclusion tests
131  // const double Parameters::Tolerence = 100.0*epsilon<double>(); // General purpose tolerance in, e.g., internal Newton's method to invert ref to phys maps
132 
133  // ===================================================================
134  // Enum classes
135  // - Enum, String (char*) helper, valid
136  // - can be used on device and inside of kernel for debugging purpose
137  // - let's decorate kokkos inline
138 
142  enum EPolyType {
143  POLYTYPE_GAUSS=0,
144  POLYTYPE_GAUSS_RADAU_LEFT,
145  POLYTYPE_GAUSS_RADAU_RIGHT,
146  POLYTYPE_GAUSS_LOBATTO,
147  POLYTYPE_MAX
148  };
149 
150  KOKKOS_INLINE_FUNCTION
151  const char* EPolyTypeToString(const EPolyType polytype) {
152  switch(polytype) {
153  case POLYTYPE_GAUSS: return "Gauss";
154  case POLYTYPE_GAUSS_RADAU_LEFT: return "GaussRadauLeft";
155  case POLYTYPE_GAUSS_RADAU_RIGHT: return "GaussRadauRight";
156  case POLYTYPE_GAUSS_LOBATTO: return "GaussRadauLobatto";
157  case POLYTYPE_MAX: return "Max PolyType";
158  }
159  return "INVALID EPolyType";
160  }
161 
167  KOKKOS_FORCEINLINE_FUNCTION
168  bool isValidPolyType(const EPolyType polytype){
169  return( polytype == POLYTYPE_GAUSS ||
170  polytype == POLYTYPE_GAUSS_RADAU_LEFT ||
171  polytype == POLYTYPE_GAUSS_RADAU_RIGHT ||
172  polytype == POLYTYPE_GAUSS_LOBATTO );
173  }
174 
175 
179  enum ECoordinates{
180  COORDINATES_CARTESIAN=0,
181  COORDINATES_POLAR,
182  COORDINATES_CYLINDRICAL,
183  COORDINATES_SPHERICAL,
184  COORDINATES_MAX
185  };
186 
187  KOKKOS_INLINE_FUNCTION
188  const char* ECoordinatesToString(const ECoordinates coords) {
189  switch(coords) {
190  case COORDINATES_CARTESIAN: return "Cartesian";
191  case COORDINATES_POLAR: return "Polar";
192  case COORDINATES_CYLINDRICAL: return "Cylindrical";
193  case COORDINATES_SPHERICAL: return "Spherical";
194  case COORDINATES_MAX: return "Max. Coordinates";
195  }
196  return "INVALID ECoordinates";
197  }
198 
204  KOKKOS_FORCEINLINE_FUNCTION
205  bool isValidCoordinate(const ECoordinates coordinateType){
206  return( coordinateType == COORDINATES_CARTESIAN ||
207  coordinateType == COORDINATES_POLAR ||
208  coordinateType == COORDINATES_CYLINDRICAL ||
209  coordinateType == COORDINATES_SPHERICAL );
210  }
211 
215  enum ENorm{
216  NORM_ONE = 0,
217  NORM_TWO,
218  NORM_INF,
219  NORM_FRO, // Frobenius matrix norm
220  NORM_MAX
221  };
222 
223  KOKKOS_INLINE_FUNCTION
224  const char* ENormToString(const ENorm norm) {
225  switch(norm) {
226  case NORM_ONE: return "1-Norm";
227  case NORM_TWO: return "2-Norm";
228  case NORM_INF: return "Infinity Norm";
229  case NORM_FRO: return "Frobenius Norm";
230  case NORM_MAX: return "Max. Norm";
231  }
232  return "INVALID ENorm";
233  }
234 
240  KOKKOS_FORCEINLINE_FUNCTION
241  bool isValidNorm(const ENorm normType){
242  return( normType == NORM_ONE ||
243  normType == NORM_TWO ||
244  normType == NORM_INF ||
245  normType == NORM_FRO ||
246  normType == NORM_MAX );
247  }
248 
254  enum EOperator : int {
255  OPERATOR_VALUE = 0,
256  OPERATOR_GRAD, // 1
257  OPERATOR_CURL, // 2
258  OPERATOR_DIV, // 3
259  OPERATOR_D1, // 4
260  OPERATOR_D2, // 5
261  OPERATOR_D3, // 6
262  OPERATOR_D4, // 7
263  OPERATOR_D5, // 8
264  OPERATOR_D6, // 9
265  OPERATOR_D7, // 10
266  OPERATOR_D8, // 11
267  OPERATOR_D9, // 12
268  OPERATOR_D10, // 13
269  OPERATOR_Dn, // 14
270  OPERATOR_MAX = OPERATOR_Dn // 14
271  };
272 
273  KOKKOS_INLINE_FUNCTION
274  const char* EOperatorToString(const EOperator op) {
275  switch(op) {
276  case OPERATOR_VALUE: return "Value";
277  case OPERATOR_GRAD: return "Grad";
278  case OPERATOR_CURL: return "Curl";
279  case OPERATOR_DIV: return "Div";
280  case OPERATOR_D1: return "D1";
281  case OPERATOR_D2: return "D2";
282  case OPERATOR_D3: return "D3";
283  case OPERATOR_D4: return "D4";
284  case OPERATOR_D5: return "D5";
285  case OPERATOR_D6: return "D6";
286  case OPERATOR_D7: return "D7";
287  case OPERATOR_D8: return "D8";
288  case OPERATOR_D9: return "D9";
289  case OPERATOR_D10: return "D10";
290  case OPERATOR_MAX: return "Dn Operator";
291  }
292  return "INVALID EOperator";
293  }
294 
300  KOKKOS_FORCEINLINE_FUNCTION
301  bool isValidOperator(const EOperator operatorType){
302  return ( operatorType == OPERATOR_VALUE ||
303  operatorType == OPERATOR_GRAD ||
304  operatorType == OPERATOR_CURL ||
305  operatorType == OPERATOR_DIV ||
306  operatorType == OPERATOR_D1 ||
307  operatorType == OPERATOR_D2 ||
308  operatorType == OPERATOR_D3 ||
309  operatorType == OPERATOR_D4 ||
310  operatorType == OPERATOR_D5 ||
311  operatorType == OPERATOR_D6 ||
312  operatorType == OPERATOR_D7 ||
313  operatorType == OPERATOR_D8 ||
314  operatorType == OPERATOR_D9 ||
315  operatorType == OPERATOR_D10 );
316  }
317 
318 
322  enum EFunctionSpace {
323  FUNCTION_SPACE_HGRAD = 0,
324  FUNCTION_SPACE_HCURL = 1,
325  FUNCTION_SPACE_HDIV = 2,
326  FUNCTION_SPACE_HVOL = 3,
327  FUNCTION_SPACE_VECTOR_HGRAD = 4,
328  FUNCTION_SPACE_TENSOR_HGRAD = 5,
329  FUNCTION_SPACE_MAX
330  };
331 
332  KOKKOS_INLINE_FUNCTION
333  const char* EFunctionSpaceToString(const EFunctionSpace space) {
334  switch(space) {
335  case FUNCTION_SPACE_HGRAD: return "H(grad)";
336  case FUNCTION_SPACE_HCURL: return "H(curl)";
337  case FUNCTION_SPACE_HDIV: return "H(div)";
338  case FUNCTION_SPACE_HVOL: return "H(vol)";
339  case FUNCTION_SPACE_VECTOR_HGRAD: return "Vector H(grad)";
340  case FUNCTION_SPACE_TENSOR_HGRAD: return "Tensor H(grad)";
341  case FUNCTION_SPACE_MAX: return "Max. Function space";
342  }
343  return "INVALID EFunctionSpace";
344  }
345 
351  KOKKOS_FORCEINLINE_FUNCTION
352  bool isValidFunctionSpace(const EFunctionSpace spaceType){
353  return ( spaceType == FUNCTION_SPACE_HGRAD ||
354  spaceType == FUNCTION_SPACE_HCURL ||
355  spaceType == FUNCTION_SPACE_HDIV ||
356  spaceType == FUNCTION_SPACE_HVOL ||
357  spaceType == FUNCTION_SPACE_VECTOR_HGRAD ||
358  spaceType == FUNCTION_SPACE_TENSOR_HGRAD );
359  }
360 
369  enum EDiscreteSpace {
370  DISCRETE_SPACE_COMPLETE = 0, // value = 0
371  DISCRETE_SPACE_INCOMPLETE, // value = 1
372  DISCRETE_SPACE_BROKEN, // value = 2
373  DISCRETE_SPACE_MAX // value = 3
374  };
375 
376  KOKKOS_INLINE_FUNCTION
377  const char* EDiscreteSpaceToString(const EDiscreteSpace space) {
378  switch(space) {
379  case DISCRETE_SPACE_COMPLETE: return "Complete";
380  case DISCRETE_SPACE_INCOMPLETE: return "Incomplete";
381  case DISCRETE_SPACE_BROKEN: return "Broken";
382  case DISCRETE_SPACE_MAX: return "Max. Rec. Space";
383  }
384  return "INVALID EDiscreteSpace";
385  }
386 
392  KOKKOS_FORCEINLINE_FUNCTION
393  bool isValidDiscreteSpace(const EDiscreteSpace spaceType){
394  return ( spaceType == DISCRETE_SPACE_COMPLETE ||
395  spaceType == DISCRETE_SPACE_INCOMPLETE ||
396  spaceType == DISCRETE_SPACE_BROKEN );
397  }
398 
402  enum EPointType {
403  POINTTYPE_EQUISPACED = 0, // value = 0
404  POINTTYPE_WARPBLEND,
405  POINTTYPE_GAUSS,
406  POINTTYPE_DEFAULT,
407  };
408 
409  KOKKOS_INLINE_FUNCTION
410  const char* EPointTypeToString(const EPointType pointType) {
411  switch (pointType) {
412  case POINTTYPE_EQUISPACED: return "Equispaced Points";
413  case POINTTYPE_WARPBLEND: return "WarpBlend Points";
414  case POINTTYPE_GAUSS: return "Gauss Points";
415  case POINTTYPE_DEFAULT: return "Default Points";
416  }
417  return "INVALID EPointType";
418  }
419 
424  KOKKOS_FORCEINLINE_FUNCTION
425  bool isValidPointType(const EPointType pointType) {
426  return ( pointType == POINTTYPE_EQUISPACED ||
427  pointType == POINTTYPE_WARPBLEND ||
428  pointType == POINTTYPE_GAUSS );
429  }
430 
434  enum EBasis {
435  BASIS_FEM_DEFAULT = 0, // value = 0
436  BASIS_FEM_HIERARCHICAL, // value = 1
437  BASIS_FEM_LAGRANGIAN, // value = 2
438  BASIS_FVD_DEFAULT, // value = 3
439  BASIS_FVD_COVOLUME, // value = 4
440  BASIS_FVD_MIMETIC, // value = 5
441  BASIS_MAX // value = 6
442  };
443 
444  KOKKOS_INLINE_FUNCTION
445  const char* EBasisToString(const EBasis basis) {
446  switch(basis) {
447  case BASIS_FEM_DEFAULT: return "FEM Default";
448  case BASIS_FEM_HIERARCHICAL: return "FEM Hierarchical";
449  case BASIS_FEM_LAGRANGIAN: return "FEM FIAT";
450  case BASIS_FVD_DEFAULT: return "FVD Default";
451  case BASIS_FVD_COVOLUME: return "FVD Covolume";
452  case BASIS_FVD_MIMETIC: return "FVD Mimetic";
453  case BASIS_MAX: return "Max. Basis";
454  }
455  return "INVALID EBasis";
456  }
457 
463  KOKKOS_FORCEINLINE_FUNCTION
464  bool isValidBasis(const EBasis basisType){
465  return ( basisType == BASIS_FEM_DEFAULT ||
466  basisType == BASIS_FEM_HIERARCHICAL ||
467  basisType == BASIS_FEM_LAGRANGIAN ||
468  basisType == BASIS_FVD_DEFAULT ||
469  basisType == BASIS_FVD_COVOLUME ||
470  basisType == BASIS_FVD_MIMETIC );
471  }
472 
473  // /** \enum Intrepid2::ECompEngine
474  // \brief Specifies how operators and functionals are computed internally
475  // (COMP_MANUAL = native C++ implementation, COMP_BLAS = BLAS implementation, etc.).
476  // */
477  // enum ECompEngine {
478  // COMP_CPP = 0,
479  // COMP_BLAS,
480  // COMP_ENGINE_MAX
481  // };
482 
483  // KOKKOS_INLINE_FUNCTION
484  // const char* ECompEngineToString(const ECompEngine cEngine) {
485  // switch(cEngine) {
486  // case COMP_CPP: return "Native C++";
487  // case COMP_BLAS: return "BLAS";
488  // case COMP_ENGINE_MAX: return "Max. Comp. Engine";
489  // default: return "INVALID ECompEngine";
490  // }
491  // return "Error";
492  // }
493 
494 
495  // /** \brief Verifies validity of a computational engine enum
496 
497  // \param compEngType [in] - enum of the computational engine
498  // \return 1 if the argument is valid computational engine; 0 otherwise
499  // */
500  // KOKKOS_FORCEINLINE_FUNCTION
501  // bool isValidCompEngine(const ECompEngine compEngType){
502  // //at the moment COMP_BLAS is not a valid CompEngine.
503  // return (compEngType == COMP_CPP);
504  // }
505 
506 
507 } //namespace Intrepid2
508 
509 #endif
static constexpr ordinal_type MaxDimension
The maximum ambient space dimension.
static constexpr ordinal_type MaxCubatureDegreeTri
The maximum degree of the polynomial that can be integrated exactly by a direct triangle rule...
static constexpr ordinal_type MaxCubatureDegreeTet
The maximum degree of the polynomial that can be integrated exactly by a direct tetrahedron rule...
Define constants.
static constexpr ordinal_type MaxNewton
Maximum number of Newton iterations used internally in methods such as computing the action of the in...
static constexpr ordinal_type MaxNumPtsPerBasisEval
The maximum number of points to eval in serial mode.
static constexpr ordinal_type MaxCubatureDegreePyr
The maximum degree of the polynomial that can be integrated exactly by a direct pyramid rule...
static constexpr ordinal_type MaxVectorComponents
Maximum number of components that a VectorData object will store – 66 corresponds to OPERATOR_D10 on ...
static constexpr ordinal_type MaxIntegrationPoints
The maximum number of integration points for direct cubature rules.
static constexpr ordinal_type MaxCubatureDegreeEdge
The maximum degree of the polynomial that can be integrated exactly by a direct edge rule...
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.
static constexpr ordinal_type MaxDerivative
Maximum order of derivatives allowed in intrepid.
static constexpr ordinal_type MaxTensorComponents
Maximum number of tensor/Cartesian products that can be taken: this allows hypercube basis in 7D to b...