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
23namespace 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;
124 static constexpr ordinal_type MaxBasisFamilies = 3;
125
126 // we do not want to use hard-wired epsilon, threshold and tolerence.
127 // static constexpr double Epsilon = 1.0e-16;
128 // static constexpr double Threshold = 1.0e-15;
129 // static constexpr double Tolerence = 1.0e-14;
130 };
131 // const double Parameters::Epsilon = epsilon<double>(); // Platform-dependent machine epsilon.
132 // const double Parameters::Threshold = 10.0*epsilon<double>(); // Tolerance for various cell inclusion tests
133 // const double Parameters::Tolerence = 100.0*epsilon<double>(); // General purpose tolerance in, e.g., internal Newton's method to invert ref to phys maps
134
135 // ===================================================================
136 // Enum classes
137 // - Enum, String (char*) helper, valid
138 // - can be used on device and inside of kernel for debugging purpose
139 // - let's decorate kokkos inline
140
144 enum EPolyType {
145 POLYTYPE_GAUSS=0,
146 POLYTYPE_GAUSS_RADAU_LEFT,
147 POLYTYPE_GAUSS_RADAU_RIGHT,
148 POLYTYPE_GAUSS_LOBATTO,
149 POLYTYPE_MAX
150 };
151
152 KOKKOS_INLINE_FUNCTION
153 const char* EPolyTypeToString(const EPolyType polytype) {
154 switch(polytype) {
155 case POLYTYPE_GAUSS: return "Gauss";
156 case POLYTYPE_GAUSS_RADAU_LEFT: return "GaussRadauLeft";
157 case POLYTYPE_GAUSS_RADAU_RIGHT: return "GaussRadauRight";
158 case POLYTYPE_GAUSS_LOBATTO: return "GaussRadauLobatto";
159 case POLYTYPE_MAX: return "Max PolyType";
160 }
161 return "INVALID EPolyType";
162 }
163
169 KOKKOS_FORCEINLINE_FUNCTION
170 bool isValidPolyType(const EPolyType polytype){
171 return( polytype == POLYTYPE_GAUSS ||
172 polytype == POLYTYPE_GAUSS_RADAU_LEFT ||
173 polytype == POLYTYPE_GAUSS_RADAU_RIGHT ||
174 polytype == POLYTYPE_GAUSS_LOBATTO );
175 }
176
177
181 enum ECoordinates{
182 COORDINATES_CARTESIAN=0,
183 COORDINATES_POLAR,
184 COORDINATES_CYLINDRICAL,
185 COORDINATES_SPHERICAL,
186 COORDINATES_MAX
187 };
188
189 KOKKOS_INLINE_FUNCTION
190 const char* ECoordinatesToString(const ECoordinates coords) {
191 switch(coords) {
192 case COORDINATES_CARTESIAN: return "Cartesian";
193 case COORDINATES_POLAR: return "Polar";
194 case COORDINATES_CYLINDRICAL: return "Cylindrical";
195 case COORDINATES_SPHERICAL: return "Spherical";
196 case COORDINATES_MAX: return "Max. Coordinates";
197 }
198 return "INVALID ECoordinates";
199 }
200
206 KOKKOS_FORCEINLINE_FUNCTION
207 bool isValidCoordinate(const ECoordinates coordinateType){
208 return( coordinateType == COORDINATES_CARTESIAN ||
209 coordinateType == COORDINATES_POLAR ||
210 coordinateType == COORDINATES_CYLINDRICAL ||
211 coordinateType == COORDINATES_SPHERICAL );
212 }
213
217 enum ENorm{
218 NORM_ONE = 0,
219 NORM_TWO,
220 NORM_INF,
221 NORM_FRO, // Frobenius matrix norm
222 NORM_MAX
223 };
224
225 KOKKOS_INLINE_FUNCTION
226 const char* ENormToString(const ENorm norm) {
227 switch(norm) {
228 case NORM_ONE: return "1-Norm";
229 case NORM_TWO: return "2-Norm";
230 case NORM_INF: return "Infinity Norm";
231 case NORM_FRO: return "Frobenius Norm";
232 case NORM_MAX: return "Max. Norm";
233 }
234 return "INVALID ENorm";
235 }
236
242 KOKKOS_FORCEINLINE_FUNCTION
243 bool isValidNorm(const ENorm normType){
244 return( normType == NORM_ONE ||
245 normType == NORM_TWO ||
246 normType == NORM_INF ||
247 normType == NORM_FRO ||
248 normType == NORM_MAX );
249 }
250
256 enum EOperator : int {
257 OPERATOR_VALUE = 0,
258 OPERATOR_GRAD, // 1
259 OPERATOR_CURL, // 2
260 OPERATOR_DIV, // 3
261 OPERATOR_D1, // 4
262 OPERATOR_D2, // 5
263 OPERATOR_D3, // 6
264 OPERATOR_D4, // 7
265 OPERATOR_D5, // 8
266 OPERATOR_D6, // 9
267 OPERATOR_D7, // 10
268 OPERATOR_D8, // 11
269 OPERATOR_D9, // 12
270 OPERATOR_D10, // 13
271 OPERATOR_Dn, // 14
272 OPERATOR_MAX = OPERATOR_Dn // 14
273 };
274
275 KOKKOS_INLINE_FUNCTION
276 const char* EOperatorToString(const EOperator op) {
277 switch(op) {
278 case OPERATOR_VALUE: return "Value";
279 case OPERATOR_GRAD: return "Grad";
280 case OPERATOR_CURL: return "Curl";
281 case OPERATOR_DIV: return "Div";
282 case OPERATOR_D1: return "D1";
283 case OPERATOR_D2: return "D2";
284 case OPERATOR_D3: return "D3";
285 case OPERATOR_D4: return "D4";
286 case OPERATOR_D5: return "D5";
287 case OPERATOR_D6: return "D6";
288 case OPERATOR_D7: return "D7";
289 case OPERATOR_D8: return "D8";
290 case OPERATOR_D9: return "D9";
291 case OPERATOR_D10: return "D10";
292 case OPERATOR_MAX: return "Dn Operator";
293 }
294 return "INVALID EOperator";
295 }
296
302 KOKKOS_FORCEINLINE_FUNCTION
303 bool isValidOperator(const EOperator operatorType){
304 return ( operatorType == OPERATOR_VALUE ||
305 operatorType == OPERATOR_GRAD ||
306 operatorType == OPERATOR_CURL ||
307 operatorType == OPERATOR_DIV ||
308 operatorType == OPERATOR_D1 ||
309 operatorType == OPERATOR_D2 ||
310 operatorType == OPERATOR_D3 ||
311 operatorType == OPERATOR_D4 ||
312 operatorType == OPERATOR_D5 ||
313 operatorType == OPERATOR_D6 ||
314 operatorType == OPERATOR_D7 ||
315 operatorType == OPERATOR_D8 ||
316 operatorType == OPERATOR_D9 ||
317 operatorType == OPERATOR_D10 );
318 }
319
320
324 enum EFunctionSpace {
325 FUNCTION_SPACE_HGRAD = 0,
326 FUNCTION_SPACE_HCURL = 1,
327 FUNCTION_SPACE_HDIV = 2,
328 FUNCTION_SPACE_HVOL = 3,
329 FUNCTION_SPACE_VECTOR_HGRAD = 4,
330 FUNCTION_SPACE_TENSOR_HGRAD = 5,
331 FUNCTION_SPACE_MAX
332 };
333
334 KOKKOS_INLINE_FUNCTION
335 const char* EFunctionSpaceToString(const EFunctionSpace space) {
336 switch(space) {
337 case FUNCTION_SPACE_HGRAD: return "H(grad)";
338 case FUNCTION_SPACE_HCURL: return "H(curl)";
339 case FUNCTION_SPACE_HDIV: return "H(div)";
340 case FUNCTION_SPACE_HVOL: return "H(vol)";
341 case FUNCTION_SPACE_VECTOR_HGRAD: return "Vector H(grad)";
342 case FUNCTION_SPACE_TENSOR_HGRAD: return "Tensor H(grad)";
343 case FUNCTION_SPACE_MAX: return "Max. Function space";
344 }
345 return "INVALID EFunctionSpace";
346 }
347
353 KOKKOS_FORCEINLINE_FUNCTION
354 bool isValidFunctionSpace(const EFunctionSpace spaceType){
355 return ( spaceType == FUNCTION_SPACE_HGRAD ||
356 spaceType == FUNCTION_SPACE_HCURL ||
357 spaceType == FUNCTION_SPACE_HDIV ||
358 spaceType == FUNCTION_SPACE_HVOL ||
359 spaceType == FUNCTION_SPACE_VECTOR_HGRAD ||
360 spaceType == FUNCTION_SPACE_TENSOR_HGRAD );
361 }
362
371 enum EDiscreteSpace {
372 DISCRETE_SPACE_COMPLETE = 0, // value = 0
373 DISCRETE_SPACE_INCOMPLETE, // value = 1
374 DISCRETE_SPACE_BROKEN, // value = 2
375 DISCRETE_SPACE_MAX // value = 3
376 };
377
378 KOKKOS_INLINE_FUNCTION
379 const char* EDiscreteSpaceToString(const EDiscreteSpace space) {
380 switch(space) {
381 case DISCRETE_SPACE_COMPLETE: return "Complete";
382 case DISCRETE_SPACE_INCOMPLETE: return "Incomplete";
383 case DISCRETE_SPACE_BROKEN: return "Broken";
384 case DISCRETE_SPACE_MAX: return "Max. Rec. Space";
385 }
386 return "INVALID EDiscreteSpace";
387 }
388
394 KOKKOS_FORCEINLINE_FUNCTION
395 bool isValidDiscreteSpace(const EDiscreteSpace spaceType){
396 return ( spaceType == DISCRETE_SPACE_COMPLETE ||
397 spaceType == DISCRETE_SPACE_INCOMPLETE ||
398 spaceType == DISCRETE_SPACE_BROKEN );
399 }
400
404 enum EPointType {
405 POINTTYPE_EQUISPACED = 0, // value = 0
406 POINTTYPE_WARPBLEND,
407 POINTTYPE_GAUSS,
408 POINTTYPE_DEFAULT,
409 };
410
411 KOKKOS_INLINE_FUNCTION
412 const char* EPointTypeToString(const EPointType pointType) {
413 switch (pointType) {
414 case POINTTYPE_EQUISPACED: return "Equispaced Points";
415 case POINTTYPE_WARPBLEND: return "WarpBlend Points";
416 case POINTTYPE_GAUSS: return "Gauss Points";
417 case POINTTYPE_DEFAULT: return "Default Points";
418 }
419 return "INVALID EPointType";
420 }
421
426 KOKKOS_FORCEINLINE_FUNCTION
427 bool isValidPointType(const EPointType pointType) {
428 return ( pointType == POINTTYPE_EQUISPACED ||
429 pointType == POINTTYPE_WARPBLEND ||
430 pointType == POINTTYPE_GAUSS );
431 }
432
436 enum EBasis {
437 BASIS_FEM_DEFAULT = 0, // value = 0
438 BASIS_FEM_HIERARCHICAL, // value = 1
439 BASIS_FEM_LAGRANGIAN, // value = 2
440 BASIS_FVD_DEFAULT, // value = 3
441 BASIS_FVD_COVOLUME, // value = 4
442 BASIS_FVD_MIMETIC, // value = 5
443 BASIS_MAX // value = 6
444 };
445
446 KOKKOS_INLINE_FUNCTION
447 const char* EBasisToString(const EBasis basis) {
448 switch(basis) {
449 case BASIS_FEM_DEFAULT: return "FEM Default";
450 case BASIS_FEM_HIERARCHICAL: return "FEM Hierarchical";
451 case BASIS_FEM_LAGRANGIAN: return "FEM FIAT";
452 case BASIS_FVD_DEFAULT: return "FVD Default";
453 case BASIS_FVD_COVOLUME: return "FVD Covolume";
454 case BASIS_FVD_MIMETIC: return "FVD Mimetic";
455 case BASIS_MAX: return "Max. Basis";
456 }
457 return "INVALID EBasis";
458 }
459
465 KOKKOS_FORCEINLINE_FUNCTION
466 bool isValidBasis(const EBasis basisType){
467 return ( basisType == BASIS_FEM_DEFAULT ||
468 basisType == BASIS_FEM_HIERARCHICAL ||
469 basisType == BASIS_FEM_LAGRANGIAN ||
470 basisType == BASIS_FVD_DEFAULT ||
471 basisType == BASIS_FVD_COVOLUME ||
472 basisType == BASIS_FVD_MIMETIC );
473 }
474
475 // /** \enum Intrepid2::ECompEngine
476 // \brief Specifies how operators and functionals are computed internally
477 // (COMP_MANUAL = native C++ implementation, COMP_BLAS = BLAS implementation, etc.).
478 // */
479 // enum ECompEngine {
480 // COMP_CPP = 0,
481 // COMP_BLAS,
482 // COMP_ENGINE_MAX
483 // };
484
485 // KOKKOS_INLINE_FUNCTION
486 // const char* ECompEngineToString(const ECompEngine cEngine) {
487 // switch(cEngine) {
488 // case COMP_CPP: return "Native C++";
489 // case COMP_BLAS: return "BLAS";
490 // case COMP_ENGINE_MAX: return "Max. Comp. Engine";
491 // default: return "INVALID ECompEngine";
492 // }
493 // return "Error";
494 // }
495
496
497 // /** \brief Verifies validity of a computational engine enum
498
499 // \param compEngType [in] - enum of the computational engine
500 // \return 1 if the argument is valid computational engine; 0 otherwise
501 // */
502 // KOKKOS_FORCEINLINE_FUNCTION
503 // bool isValidCompEngine(const ECompEngine compEngType){
504 // //at the moment COMP_BLAS is not a valid CompEngine.
505 // return (compEngType == COMP_CPP);
506 // }
507
508
509} //namespace Intrepid2
510
511#endif
KOKKOS_FORCEINLINE_FUNCTION bool isValidFunctionSpace(const EFunctionSpace spaceType)
Verifies validity of a function space enum.
KOKKOS_FORCEINLINE_FUNCTION bool isValidPointType(const EPointType pointType)
Verifies validity of a point type enum.
KOKKOS_FORCEINLINE_FUNCTION bool isValidPolyType(const EPolyType polytype)
Verifies validity of a PolyType enum.
KOKKOS_FORCEINLINE_FUNCTION bool isValidNorm(const ENorm normType)
Verifies validity of a Norm enum.
KOKKOS_FORCEINLINE_FUNCTION bool isValidBasis(const EBasis basisType)
Verifies validity of a basis enum.
KOKKOS_FORCEINLINE_FUNCTION bool isValidCoordinate(const ECoordinates coordinateType)
Verifies validity of a Coordinate enum.
KOKKOS_FORCEINLINE_FUNCTION bool isValidDiscreteSpace(const EDiscreteSpace spaceType)
Verifies validity of a discrete space enum.
KOKKOS_FORCEINLINE_FUNCTION bool isValidOperator(const EOperator operatorType)
Verifies validity of an operator 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 MaxCubatureDegreePyr
The maximum degree of the polynomial that can be integrated exactly by a direct pyramid rule.
static constexpr ordinal_type MaxCubatureDegreeTet
The maximum degree of the polynomial that can be integrated exactly by a direct tetrahedron rule.
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 MaxIntegrationPoints
The maximum number of integration points for direct cubature rules.
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 MaxTensorComponents
Maximum number of tensor/Cartesian products that can be taken: this allows hypercube basis in 7D to b...
static constexpr ordinal_type MaxNumPtsPerBasisEval
The maximum number of points to eval in serial mode.
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 MaxDimension
The maximum ambient space dimension.
static constexpr ordinal_type MaxDerivative
Maximum order of derivatives allowed in intrepid.
static constexpr ordinal_type MaxBasisFamilies
Maximum number of families that a VectorData object will store – 3 corresponds to H(div) and H(curl) ...