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
56namespace 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
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;
141 static constexpr ordinal_type MaxTensorComponents = 7;
142
143 // we do not want to use hard-wired epsilon, threshold and tolerence.
144 // static constexpr double Epsilon = 1.0e-16;
145 // static constexpr double Threshold = 1.0e-15;
146 // static constexpr double Tolerence = 1.0e-14;
147 };
148 // const double Parameters::Epsilon = epsilon<double>(); // Platform-dependent machine epsilon.
149 // const double Parameters::Threshold = 10.0*epsilon<double>(); // Tolerance for various cell inclusion tests
150 // const double Parameters::Tolerence = 100.0*epsilon<double>(); // General purpose tolerance in, e.g., internal Newton's method to invert ref to phys maps
151
152 // ===================================================================
153 // Enum classes
154 // - Enum, String (char*) helper, valid
155 // - can be used on device and inside of kernel for debugging purpose
156 // - let's decorate kokkos inline
157
161 enum EPolyType {
162 POLYTYPE_GAUSS=0,
163 POLYTYPE_GAUSS_RADAU_LEFT,
164 POLYTYPE_GAUSS_RADAU_RIGHT,
165 POLYTYPE_GAUSS_LOBATTO,
166 POLYTYPE_MAX
167 };
168
169 KOKKOS_INLINE_FUNCTION
170 const char* EPolyTypeToString(const EPolyType polytype) {
171 switch(polytype) {
172 case POLYTYPE_GAUSS: return "Gauss";
173 case POLYTYPE_GAUSS_RADAU_LEFT: return "GaussRadauLeft";
174 case POLYTYPE_GAUSS_RADAU_RIGHT: return "GaussRadauRight";
175 case POLYTYPE_GAUSS_LOBATTO: return "GaussRadauLobatto";
176 case POLYTYPE_MAX: return "Max PolyType";
177 }
178 return "INVALID EPolyType";
179 }
180
186 KOKKOS_FORCEINLINE_FUNCTION
187 bool isValidPolyType(const EPolyType polytype){
188 return( polytype == POLYTYPE_GAUSS ||
189 polytype == POLYTYPE_GAUSS_RADAU_LEFT ||
190 polytype == POLYTYPE_GAUSS_RADAU_RIGHT ||
191 polytype == POLYTYPE_GAUSS_LOBATTO );
192 }
193
194
198 enum ECoordinates{
199 COORDINATES_CARTESIAN=0,
200 COORDINATES_POLAR,
201 COORDINATES_CYLINDRICAL,
202 COORDINATES_SPHERICAL,
203 COORDINATES_MAX
204 };
205
206 KOKKOS_INLINE_FUNCTION
207 const char* ECoordinatesToString(const ECoordinates coords) {
208 switch(coords) {
209 case COORDINATES_CARTESIAN: return "Cartesian";
210 case COORDINATES_POLAR: return "Polar";
211 case COORDINATES_CYLINDRICAL: return "Cylindrical";
212 case COORDINATES_SPHERICAL: return "Spherical";
213 case COORDINATES_MAX: return "Max. Coordinates";
214 }
215 return "INVALID ECoordinates";
216 }
217
223 KOKKOS_FORCEINLINE_FUNCTION
224 bool isValidCoordinate(const ECoordinates coordinateType){
225 return( coordinateType == COORDINATES_CARTESIAN ||
226 coordinateType == COORDINATES_POLAR ||
227 coordinateType == COORDINATES_CYLINDRICAL ||
228 coordinateType == COORDINATES_SPHERICAL );
229 }
230
234 enum ENorm{
235 NORM_ONE = 0,
236 NORM_TWO,
237 NORM_INF,
238 NORM_FRO, // Frobenius matrix norm
239 NORM_MAX
240 };
241
242 KOKKOS_INLINE_FUNCTION
243 const char* ENormToString(const ENorm norm) {
244 switch(norm) {
245 case NORM_ONE: return "1-Norm";
246 case NORM_TWO: return "2-Norm";
247 case NORM_INF: return "Infinity Norm";
248 case NORM_FRO: return "Frobenius Norm";
249 case NORM_MAX: return "Max. Norm";
250 }
251 return "INVALID ENorm";
252 }
253
259 KOKKOS_FORCEINLINE_FUNCTION
260 bool isValidNorm(const ENorm normType){
261 return( normType == NORM_ONE ||
262 normType == NORM_TWO ||
263 normType == NORM_INF ||
264 normType == NORM_FRO ||
265 normType == NORM_MAX );
266 }
267
273 enum EOperator{
274 OPERATOR_VALUE = 0,
275 OPERATOR_GRAD, // 1
276 OPERATOR_CURL, // 2
277 OPERATOR_DIV, // 3
278 OPERATOR_D1, // 4
279 OPERATOR_D2, // 5
280 OPERATOR_D3, // 6
281 OPERATOR_D4, // 7
282 OPERATOR_D5, // 8
283 OPERATOR_D6, // 9
284 OPERATOR_D7, // 10
285 OPERATOR_D8, // 11
286 OPERATOR_D9, // 12
287 OPERATOR_D10, // 13
288 OPERATOR_Dn, // 14
289 OPERATOR_MAX = OPERATOR_Dn // 14
290 };
291
292 KOKKOS_INLINE_FUNCTION
293 const char* EOperatorToString(const EOperator op) {
294 switch(op) {
295 case OPERATOR_VALUE: return "Value";
296 case OPERATOR_GRAD: return "Grad";
297 case OPERATOR_CURL: return "Curl";
298 case OPERATOR_DIV: return "Div";
299 case OPERATOR_D1: return "D1";
300 case OPERATOR_D2: return "D2";
301 case OPERATOR_D3: return "D3";
302 case OPERATOR_D4: return "D4";
303 case OPERATOR_D5: return "D5";
304 case OPERATOR_D6: return "D6";
305 case OPERATOR_D7: return "D7";
306 case OPERATOR_D8: return "D8";
307 case OPERATOR_D9: return "D9";
308 case OPERATOR_D10: return "D10";
309 case OPERATOR_MAX: return "Dn Operator";
310 }
311 return "INVALID EOperator";
312 }
313
319 KOKKOS_FORCEINLINE_FUNCTION
320 bool isValidOperator(const EOperator operatorType){
321 return ( operatorType == OPERATOR_VALUE ||
322 operatorType == OPERATOR_GRAD ||
323 operatorType == OPERATOR_CURL ||
324 operatorType == OPERATOR_DIV ||
325 operatorType == OPERATOR_D1 ||
326 operatorType == OPERATOR_D2 ||
327 operatorType == OPERATOR_D3 ||
328 operatorType == OPERATOR_D4 ||
329 operatorType == OPERATOR_D5 ||
330 operatorType == OPERATOR_D6 ||
331 operatorType == OPERATOR_D7 ||
332 operatorType == OPERATOR_D8 ||
333 operatorType == OPERATOR_D9 ||
334 operatorType == OPERATOR_D10 );
335 }
336
337
341 enum EFunctionSpace {
342 FUNCTION_SPACE_HGRAD = 0,
343 FUNCTION_SPACE_HCURL = 1,
344 FUNCTION_SPACE_HDIV = 2,
345 FUNCTION_SPACE_HVOL = 3,
346 FUNCTION_SPACE_VECTOR_HGRAD = 4,
347 FUNCTION_SPACE_TENSOR_HGRAD = 5,
348 FUNCTION_SPACE_MAX
349 };
350
351 KOKKOS_INLINE_FUNCTION
352 const char* EFunctionSpaceToString(const EFunctionSpace space) {
353 switch(space) {
354 case FUNCTION_SPACE_HGRAD: return "H(grad)";
355 case FUNCTION_SPACE_HCURL: return "H(curl)";
356 case FUNCTION_SPACE_HDIV: return "H(div)";
357 case FUNCTION_SPACE_HVOL: return "H(vol)";
358 case FUNCTION_SPACE_VECTOR_HGRAD: return "Vector H(grad)";
359 case FUNCTION_SPACE_TENSOR_HGRAD: return "Tensor H(grad)";
360 case FUNCTION_SPACE_MAX: return "Max. Function space";
361 }
362 return "INVALID EFunctionSpace";
363 }
364
370 KOKKOS_FORCEINLINE_FUNCTION
371 bool isValidFunctionSpace(const EFunctionSpace spaceType){
372 return ( spaceType == FUNCTION_SPACE_HGRAD ||
373 spaceType == FUNCTION_SPACE_HCURL ||
374 spaceType == FUNCTION_SPACE_HDIV ||
375 spaceType == FUNCTION_SPACE_HVOL ||
376 spaceType == FUNCTION_SPACE_VECTOR_HGRAD ||
377 spaceType == FUNCTION_SPACE_TENSOR_HGRAD );
378 }
379
388 enum EDiscreteSpace {
389 DISCRETE_SPACE_COMPLETE = 0, // value = 0
390 DISCRETE_SPACE_INCOMPLETE, // value = 1
391 DISCRETE_SPACE_BROKEN, // value = 2
392 DISCRETE_SPACE_MAX // value = 3
393 };
394
395 KOKKOS_INLINE_FUNCTION
396 const char* EDiscreteSpaceToString(const EDiscreteSpace space) {
397 switch(space) {
398 case DISCRETE_SPACE_COMPLETE: return "Complete";
399 case DISCRETE_SPACE_INCOMPLETE: return "Incomplete";
400 case DISCRETE_SPACE_BROKEN: return "Broken";
401 case DISCRETE_SPACE_MAX: return "Max. Rec. Space";
402 }
403 return "INVALID EDiscreteSpace";
404 }
405
411 KOKKOS_FORCEINLINE_FUNCTION
412 bool isValidDiscreteSpace(const EDiscreteSpace spaceType){
413 return ( spaceType == DISCRETE_SPACE_COMPLETE ||
414 spaceType == DISCRETE_SPACE_INCOMPLETE ||
415 spaceType == DISCRETE_SPACE_BROKEN );
416 }
417
421 enum EPointType {
422 POINTTYPE_EQUISPACED = 0, // value = 0
423 POINTTYPE_WARPBLEND,
424 POINTTYPE_GAUSS,
425 POINTTYPE_DEFAULT,
426 };
427
428 KOKKOS_INLINE_FUNCTION
429 const char* EPointTypeToString(const EPointType pointType) {
430 switch (pointType) {
431 case POINTTYPE_EQUISPACED: return "Equispaced Points";
432 case POINTTYPE_WARPBLEND: return "WarpBlend Points";
433 case POINTTYPE_GAUSS: return "Gauss Points";
434 case POINTTYPE_DEFAULT: return "Default Points";
435 }
436 return "INVALID EPointType";
437 }
438
443 KOKKOS_FORCEINLINE_FUNCTION
444 bool isValidPointType(const EPointType pointType) {
445 return ( pointType == POINTTYPE_EQUISPACED ||
446 pointType == POINTTYPE_WARPBLEND ||
447 pointType == POINTTYPE_GAUSS );
448 }
449
453 enum EBasis {
454 BASIS_FEM_DEFAULT = 0, // value = 0
455 BASIS_FEM_HIERARCHICAL, // value = 1
456 BASIS_FEM_LAGRANGIAN, // value = 2
457 BASIS_FVD_DEFAULT, // value = 3
458 BASIS_FVD_COVOLUME, // value = 4
459 BASIS_FVD_MIMETIC, // value = 5
460 BASIS_MAX // value = 6
461 };
462
463 KOKKOS_INLINE_FUNCTION
464 const char* EBasisToString(const EBasis basis) {
465 switch(basis) {
466 case BASIS_FEM_DEFAULT: return "FEM Default";
467 case BASIS_FEM_HIERARCHICAL: return "FEM Hierarchical";
468 case BASIS_FEM_LAGRANGIAN: return "FEM FIAT";
469 case BASIS_FVD_DEFAULT: return "FVD Default";
470 case BASIS_FVD_COVOLUME: return "FVD Covolume";
471 case BASIS_FVD_MIMETIC: return "FVD Mimetic";
472 case BASIS_MAX: return "Max. Basis";
473 }
474 return "INVALID EBasis";
475 }
476
482 KOKKOS_FORCEINLINE_FUNCTION
483 bool isValidBasis(const EBasis basisType){
484 return ( basisType == BASIS_FEM_DEFAULT ||
485 basisType == BASIS_FEM_HIERARCHICAL ||
486 basisType == BASIS_FEM_LAGRANGIAN ||
487 basisType == BASIS_FVD_DEFAULT ||
488 basisType == BASIS_FVD_COVOLUME ||
489 basisType == BASIS_FVD_MIMETIC );
490 }
491
492 // /** \enum Intrepid2::ECompEngine
493 // \brief Specifies how operators and functionals are computed internally
494 // (COMP_MANUAL = native C++ implementation, COMP_BLAS = BLAS implementation, etc.).
495 // */
496 // enum ECompEngine {
497 // COMP_CPP = 0,
498 // COMP_BLAS,
499 // COMP_ENGINE_MAX
500 // };
501
502 // KOKKOS_INLINE_FUNCTION
503 // const char* ECompEngineToString(const ECompEngine cEngine) {
504 // switch(cEngine) {
505 // case COMP_CPP: return "Native C++";
506 // case COMP_BLAS: return "BLAS";
507 // case COMP_ENGINE_MAX: return "Max. Comp. Engine";
508 // default: return "INVALID ECompEngine";
509 // }
510 // return "Error";
511 // }
512
513
514 // /** \brief Verifies validity of a computational engine enum
515
516 // \param compEngType [in] - enum of the computational engine
517 // \return 1 if the argument is valid computational engine; 0 otherwise
518 // */
519 // KOKKOS_FORCEINLINE_FUNCTION
520 // bool isValidCompEngine(const ECompEngine compEngType){
521 // //at the moment COMP_BLAS is not a valid CompEngine.
522 // return (compEngType == COMP_CPP);
523 // }
524
525
526} //namespace Intrepid2
527
528#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 MaxDimension
The maximum ambient space dimension.
static constexpr ordinal_type MaxDerivative
Maximum order of derivatives allowed in intrepid.