Intrepid2
Intrepid2_Types.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid2 Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kyungjoo Kim (kyukim@sandia.gov), or
38 // Mauro Perego (mperego@sandia.gov)
39 //
40 // ************************************************************************
41 // @HEADER
42 
48 #ifndef __INTREPID2_TYPES_HPP__
49 #define __INTREPID2_TYPES_HPP__
50 
51 #include <Kokkos_Core.hpp>
52 #include <Kokkos_DynRankView.hpp>
53 
54 #include <stdexcept>
55 
56 namespace Intrepid2 {
57 
58  // use ordinal_type and size_type everywhere (no index type)
59  typedef int ordinal_type;
60  typedef size_t size_type;
61 
62  template<typename ValueType>
63  KOKKOS_FORCEINLINE_FUNCTION
64  ValueType epsilon() {
65  return 0;
66  }
67 
68  template<>
69  KOKKOS_FORCEINLINE_FUNCTION
70  double epsilon<double>() {
71  typedef union {
72  long long i64;
73  double d64;
74  } dbl_64;
75 
76  dbl_64 s;
77  s.d64 = 1;
78  s.i64++;
79  return (s.i64 < 0 ? 1 - s.d64 : s.d64 - 1);
80  }
81 
82  template<>
83  KOKKOS_FORCEINLINE_FUNCTION
84  float epsilon<float>() {
85  typedef union {
86  int i32;
87  float f32;
88  } flt_32;
89 
90  flt_32 s;
91  s.f32 = 1;
92  s.f32++;
93  return (s.i32 < 0 ? 1 - s.f32 : s.f32 - 1);
94  }
95 
96  KOKKOS_FORCEINLINE_FUNCTION
97  double epsilon() {
98  return epsilon<double>();
99  }
100 
101  KOKKOS_FORCEINLINE_FUNCTION
102  double tolerence() {
103  return 100.0*epsilon();
104  }
105 
106  KOKKOS_FORCEINLINE_FUNCTION
107  double threshold() {
108  return 10.0*epsilon();
109  }
110 
112  class Parameters {
113  public:
114  // KK: do not chagne max num pts per basis eval bigger than 1.
115  // polylib point and order match needs to be first examined; now if it is set bigger than 1
116  // it creates silent error.
117  //
118  // MP: I tried setting max num pts per basis eval to 2 and everything seems working fine. Leaving it to 1 for now.
119 
121  static constexpr ordinal_type MaxNumPtsPerBasisEval= 1;
123  static constexpr ordinal_type MaxOrder = 8;
125  static constexpr ordinal_type MaxIntegrationPoints = 1001;
127  static constexpr ordinal_type MaxCubatureDegreeEdge= 20;
129  static constexpr ordinal_type MaxCubatureDegreeTri = 20;
131  static constexpr ordinal_type MaxCubatureDegreeTet = 20;
133  static constexpr ordinal_type MaxCubatureDegreePyr = 11;
135  static constexpr ordinal_type MaxDimension = 3;
137  static constexpr ordinal_type MaxNewton = 15;
139  static constexpr ordinal_type MaxDerivative = 10;
140 
141  // we do not want to use hard-wired epsilon, threshold and tolerence.
142  // static constexpr double Epsilon = 1.0e-16;
143  // static constexpr double Threshold = 1.0e-15;
144  // static constexpr double Tolerence = 1.0e-14;
145  };
146  // const double Parameters::Epsilon = epsilon<double>(); // Platform-dependent machine epsilon.
147  // const double Parameters::Threshold = 10.0*epsilon<double>(); // Tolerance for various cell inclusion tests
148  // const double Parameters::Tolerence = 100.0*epsilon<double>(); // General purpose tolerance in, e.g., internal Newton's method to invert ref to phys maps
149 
150  // ===================================================================
151  // Enum classes
152  // - Enum, String (char*) helper, valid
153  // - can be used on device and inside of kernel for debugging purpose
154  // - let's decorate kokkos inline
155 
159  enum EPolyType {
160  POLYTYPE_GAUSS=0,
161  POLYTYPE_GAUSS_RADAU_LEFT,
162  POLYTYPE_GAUSS_RADAU_RIGHT,
163  POLYTYPE_GAUSS_LOBATTO,
164  POLYTYPE_MAX
165  };
166 
167  KOKKOS_INLINE_FUNCTION
168  const char* EPolyTypeToString(const EPolyType polytype) {
169  switch(polytype) {
170  case POLYTYPE_GAUSS: return "Gauss";
171  case POLYTYPE_GAUSS_RADAU_LEFT: return "GaussRadauLeft";
172  case POLYTYPE_GAUSS_RADAU_RIGHT: return "GaussRadauRight";
173  case POLYTYPE_GAUSS_LOBATTO: return "GaussRadauLobatto";
174  case POLYTYPE_MAX: return "Max PolyType";
175  }
176  return "INVALID EPolyType";
177  }
178 
184  KOKKOS_FORCEINLINE_FUNCTION
185  bool isValidPolyType(const EPolyType polytype){
186  return( polytype == POLYTYPE_GAUSS ||
187  polytype == POLYTYPE_GAUSS_RADAU_LEFT ||
188  polytype == POLYTYPE_GAUSS_RADAU_RIGHT ||
189  polytype == POLYTYPE_GAUSS_LOBATTO );
190  }
191 
192 
197  COORDINATES_CARTESIAN=0,
198  COORDINATES_POLAR,
199  COORDINATES_CYLINDRICAL,
200  COORDINATES_SPHERICAL,
201  COORDINATES_MAX
202  };
203 
204  KOKKOS_INLINE_FUNCTION
205  const char* ECoordinatesToString(const ECoordinates coords) {
206  switch(coords) {
207  case COORDINATES_CARTESIAN: return "Cartesian";
208  case COORDINATES_POLAR: return "Polar";
209  case COORDINATES_CYLINDRICAL: return "Cylindrical";
210  case COORDINATES_SPHERICAL: return "Spherical";
211  case COORDINATES_MAX: return "Max. Coordinates";
212  }
213  return "INVALID ECoordinates";
214  }
215 
221  KOKKOS_FORCEINLINE_FUNCTION
222  bool isValidCoordinate(const ECoordinates coordinateType){
223  return( coordinateType == COORDINATES_CARTESIAN ||
224  coordinateType == COORDINATES_POLAR ||
225  coordinateType == COORDINATES_CYLINDRICAL ||
226  coordinateType == COORDINATES_SPHERICAL );
227  }
228 
232  enum ENorm{
233  NORM_ONE = 0,
234  NORM_TWO,
235  NORM_INF,
236  NORM_FRO, // Frobenius matrix norm
237  NORM_MAX
238  };
239 
240  KOKKOS_INLINE_FUNCTION
241  const char* ENormToString(const ENorm norm) {
242  switch(norm) {
243  case NORM_ONE: return "1-Norm";
244  case NORM_TWO: return "2-Norm";
245  case NORM_INF: return "Infinity Norm";
246  case NORM_FRO: return "Frobenius Norm";
247  case NORM_MAX: return "Max. Norm";
248  }
249  return "INVALID ENorm";
250  }
251 
257  KOKKOS_FORCEINLINE_FUNCTION
258  bool isValidNorm(const ENorm normType){
259  return( normType == NORM_ONE ||
260  normType == NORM_TWO ||
261  normType == NORM_INF ||
262  normType == NORM_FRO ||
263  normType == NORM_MAX );
264  }
265 
271  enum EOperator{
272  OPERATOR_VALUE = 0,
273  OPERATOR_GRAD, // 1
274  OPERATOR_CURL, // 2
275  OPERATOR_DIV, // 3
276  OPERATOR_D1, // 4
277  OPERATOR_D2, // 5
278  OPERATOR_D3, // 6
279  OPERATOR_D4, // 7
280  OPERATOR_D5, // 8
281  OPERATOR_D6, // 9
282  OPERATOR_D7, // 10
283  OPERATOR_D8, // 11
284  OPERATOR_D9, // 12
285  OPERATOR_D10, // 13
286  OPERATOR_Dn, // 14
287  OPERATOR_MAX = OPERATOR_Dn // 14
288  };
289 
290  KOKKOS_INLINE_FUNCTION
291  const char* EOperatorToString(const EOperator op) {
292  switch(op) {
293  case OPERATOR_VALUE: return "Value";
294  case OPERATOR_GRAD: return "Grad";
295  case OPERATOR_CURL: return "Curl";
296  case OPERATOR_DIV: return "Div";
297  case OPERATOR_D1: return "D1";
298  case OPERATOR_D2: return "D2";
299  case OPERATOR_D3: return "D3";
300  case OPERATOR_D4: return "D4";
301  case OPERATOR_D5: return "D5";
302  case OPERATOR_D6: return "D6";
303  case OPERATOR_D7: return "D7";
304  case OPERATOR_D8: return "D8";
305  case OPERATOR_D9: return "D9";
306  case OPERATOR_D10: return "D10";
307  case OPERATOR_MAX: return "Dn Operator";
308  }
309  return "INVALID EOperator";
310  }
311 
317  KOKKOS_FORCEINLINE_FUNCTION
318  bool isValidOperator(const EOperator operatorType){
319  return ( operatorType == OPERATOR_VALUE ||
320  operatorType == OPERATOR_GRAD ||
321  operatorType == OPERATOR_CURL ||
322  operatorType == OPERATOR_DIV ||
323  operatorType == OPERATOR_D1 ||
324  operatorType == OPERATOR_D2 ||
325  operatorType == OPERATOR_D3 ||
326  operatorType == OPERATOR_D4 ||
327  operatorType == OPERATOR_D5 ||
328  operatorType == OPERATOR_D6 ||
329  operatorType == OPERATOR_D7 ||
330  operatorType == OPERATOR_D8 ||
331  operatorType == OPERATOR_D9 ||
332  operatorType == OPERATOR_D10 );
333  }
334 
335 
339  enum EFunctionSpace {
340  FUNCTION_SPACE_HGRAD = 0,
341  FUNCTION_SPACE_HCURL = 1,
342  FUNCTION_SPACE_HDIV = 2,
343  FUNCTION_SPACE_HVOL = 3,
344  FUNCTION_SPACE_VECTOR_HGRAD = 4,
345  FUNCTION_SPACE_TENSOR_HGRAD = 5,
346  FUNCTION_SPACE_MAX
347  };
348 
349  KOKKOS_INLINE_FUNCTION
350  const char* EFunctionSpaceToString(const EFunctionSpace space) {
351  switch(space) {
352  case FUNCTION_SPACE_HGRAD: return "H(grad)";
353  case FUNCTION_SPACE_HCURL: return "H(curl)";
354  case FUNCTION_SPACE_HDIV: return "H(div)";
355  case FUNCTION_SPACE_HVOL: return "H(vol)";
356  case FUNCTION_SPACE_VECTOR_HGRAD: return "Vector H(grad)";
357  case FUNCTION_SPACE_TENSOR_HGRAD: return "Tensor H(grad)";
358  case FUNCTION_SPACE_MAX: return "Max. Function space";
359  }
360  return "INVALID EFunctionSpace";
361  }
362 
368  KOKKOS_FORCEINLINE_FUNCTION
369  bool isValidFunctionSpace(const EFunctionSpace spaceType){
370  return ( spaceType == FUNCTION_SPACE_HGRAD ||
371  spaceType == FUNCTION_SPACE_HCURL ||
372  spaceType == FUNCTION_SPACE_HDIV ||
373  spaceType == FUNCTION_SPACE_HVOL ||
374  spaceType == FUNCTION_SPACE_VECTOR_HGRAD ||
375  spaceType == FUNCTION_SPACE_TENSOR_HGRAD );
376  }
377 
387  DISCRETE_SPACE_COMPLETE = 0, // value = 0
388  DISCRETE_SPACE_INCOMPLETE, // value = 1
389  DISCRETE_SPACE_BROKEN, // value = 2
390  DISCRETE_SPACE_MAX // value = 3
391  };
392 
393  KOKKOS_INLINE_FUNCTION
394  const char* EDiscreteSpaceToString(const EDiscreteSpace space) {
395  switch(space) {
396  case DISCRETE_SPACE_COMPLETE: return "Complete";
397  case DISCRETE_SPACE_INCOMPLETE: return "Incomplete";
398  case DISCRETE_SPACE_BROKEN: return "Broken";
399  case DISCRETE_SPACE_MAX: return "Max. Rec. Space";
400  }
401  return "INVALID EDiscreteSpace";
402  }
403 
409  KOKKOS_FORCEINLINE_FUNCTION
410  bool isValidDiscreteSpace(const EDiscreteSpace spaceType){
411  return ( spaceType == DISCRETE_SPACE_COMPLETE ||
412  spaceType == DISCRETE_SPACE_INCOMPLETE ||
413  spaceType == DISCRETE_SPACE_BROKEN );
414  }
415 
419  enum EPointType {
420  POINTTYPE_EQUISPACED = 0, // value = 0
421  POINTTYPE_WARPBLEND,
422  POINTTYPE_GAUSS
423  };
424 
425  KOKKOS_INLINE_FUNCTION
426  const char* EPointTypeToString(const EPointType pointType) {
427  switch (pointType) {
428  case POINTTYPE_EQUISPACED: return "Equispaced Points";
429  case POINTTYPE_WARPBLEND: return "WarpBlend Points";
430  case POINTTYPE_GAUSS: return "Gauss Points";
431  }
432  return "INVALID EPointType";
433  }
434 
439  KOKKOS_FORCEINLINE_FUNCTION
440  bool isValidPointType(const EPointType pointType) {
441  return ( pointType == POINTTYPE_EQUISPACED ||
442  pointType == POINTTYPE_WARPBLEND ||
443  pointType == POINTTYPE_GAUSS );
444  }
445 
449  enum EBasis {
450  BASIS_FEM_DEFAULT = 0, // value = 0
451  BASIS_FEM_HIERARCHICAL, // value = 1
452  BASIS_FEM_FIAT, // value = 2
453  BASIS_FVD_DEFAULT, // value = 3
454  BASIS_FVD_COVOLUME, // value = 4
455  BASIS_FVD_MIMETIC, // value = 5
456  BASIS_MAX // value = 6
457  };
458 
459  KOKKOS_INLINE_FUNCTION
460  const char* EBasisToString(const EBasis basis) {
461  switch(basis) {
462  case BASIS_FEM_DEFAULT: return "FEM Default";
463  case BASIS_FEM_HIERARCHICAL: return "FEM Hierarchical";
464  case BASIS_FEM_FIAT: return "FEM FIAT";
465  case BASIS_FVD_DEFAULT: return "FVD Default";
466  case BASIS_FVD_COVOLUME: return "FVD Covolume";
467  case BASIS_FVD_MIMETIC: return "FVD Mimetic";
468  case BASIS_MAX: return "Max. Basis";
469  }
470  return "INVALID EBasis";
471  }
472 
478  KOKKOS_FORCEINLINE_FUNCTION
479  bool isValidBasis(const EBasis basisType){
480  return ( basisType == BASIS_FEM_DEFAULT ||
481  basisType == BASIS_FEM_HIERARCHICAL ||
482  basisType == BASIS_FEM_FIAT ||
483  basisType == BASIS_FVD_DEFAULT ||
484  basisType == BASIS_FVD_COVOLUME ||
485  basisType == BASIS_FVD_MIMETIC );
486  }
487 
488  // /** \enum Intrepid2::ECompEngine
489  // \brief Specifies how operators and functionals are computed internally
490  // (COMP_MANUAL = native C++ implementation, COMP_BLAS = BLAS implementation, etc.).
491  // */
492  // enum ECompEngine {
493  // COMP_CPP = 0,
494  // COMP_BLAS,
495  // COMP_ENGINE_MAX
496  // };
497 
498  // KOKKOS_INLINE_FUNCTION
499  // const char* ECompEngineToString(const ECompEngine cEngine) {
500  // switch(cEngine) {
501  // case COMP_CPP: return "Native C++";
502  // case COMP_BLAS: return "BLAS";
503  // case COMP_ENGINE_MAX: return "Max. Comp. Engine";
504  // default: return "INVALID ECompEngine";
505  // }
506  // return "Error";
507  // }
508 
509 
510  // /** \brief Verifies validity of a computational engine enum
511 
512  // \param compEngType [in] - enum of the computational engine
513  // \return 1 if the argument is valid computational engine; 0 otherwise
514  // */
515  // KOKKOS_FORCEINLINE_FUNCTION
516  // bool isValidCompEngine(const ECompEngine compEngType){
517  // //at the moment COMP_BLAS is not a valid CompEngine.
518  // return (compEngType == COMP_CPP);
519  // }
520 
521 
522 } //namespace Intrepid2
523 
524 #endif
KOKKOS_FORCEINLINE_FUNCTION bool isValidFunctionSpace(const EFunctionSpace spaceType)
Verifies validity of a function space enum.
static constexpr ordinal_type MaxDimension
The maximum ambient space dimension.
KOKKOS_FORCEINLINE_FUNCTION bool isValidCoordinate(const ECoordinates coordinateType)
Verifies validity of a Coordinate enum.
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...
KOKKOS_FORCEINLINE_FUNCTION bool isValidPointType(const EPointType pointType)
Verifies validity of a point type enum.
ECoordinates
Enumeration of coordinate systems for geometrical entities (cells, points).
Define constants.
KOKKOS_FORCEINLINE_FUNCTION bool isValidNorm(const ENorm normType)
Verifies validity of a Norm enum.
static constexpr ordinal_type MaxNewton
Maximum number of Newton iterations used internally in methods such as computing the action of the in...
ENorm
Enumeration of norm types for vectors and functions.
static constexpr ordinal_type MaxNumPtsPerBasisEval
The maximum number of points to eval in serial mode.
EBasis
Enumeration of basis types for discrete spaces in Intrepid.
EOperator
Enumeration of primitive operators available in Intrepid. Primitive operators act on reconstructed fu...
KOKKOS_FORCEINLINE_FUNCTION bool isValidBasis(const EBasis basisType)
Verifies validity of a basis enum.
static constexpr ordinal_type MaxCubatureDegreePyr
The maximum degree of the polynomial that can be integrated exactly by a direct pyramid rule...
EDiscreteSpace
Enumeration of the discrete spaces used to define bases for function spaces. Intrepid allows up to th...
EPointType
Enumeration of types of point distributions in Intrepid.
static constexpr ordinal_type MaxIntegrationPoints
The maximum number of integration points for direct cubature rules.
KOKKOS_FORCEINLINE_FUNCTION bool isValidPolyType(const EPolyType polytype)
Verifies validity of a PolyType enum.
KOKKOS_FORCEINLINE_FUNCTION bool isValidOperator(const EOperator operatorType)
Verifies validity of an operator enum.
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.
KOKKOS_FORCEINLINE_FUNCTION bool isValidDiscreteSpace(const EDiscreteSpace spaceType)
Verifies validity of a discrete space enum.
static constexpr ordinal_type MaxDerivative
Maximum order of derivatives allowed in intrepid.