Nektar++
ShapeType.hpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ShapeType.hpp
4//
5// For more information, please see: http://www.nektar.info/
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHAPE_TYPE_H
36#define NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHAPE_TYPE_H
37
38#include <algorithm>
39#include <vector>
40
42
43#ifdef min
44#undef min
45#endif
46
48{
49
50// Types of geometry types.
52{
63
64 // These are the short names used for MatrixFree operators
73};
74
75const char *const ShapeTypeMap[SIZE_ShapeType] = {
76 "NoGeomShapeType", "Point", "Segment", "Triangle", "Quadrilateral",
77 "Tetrahedron", "Pyramid", "Prism", "Hexahedron",
78};
79
80// Hold the dimension of each of the types of shapes.
81constexpr unsigned int ShapeTypeDimMap[SIZE_ShapeType] = {
82 0, // Unknown
83 0, // ePoint
84 1, // eSegment
85 2, // eTriangle
86 2, // eQuadrilateral
87 3, // eTetrahedron
88 3, // ePyramid
89 3, // ePrism
90 3, // eHexahedron
91};
92
93namespace StdSegData
94{
95inline int getNumberOfCoefficients(int Na)
96{
97 return Na;
98}
99
100inline int getNumberOfBndCoefficients([[maybe_unused]] int Na)
101{
102 return 2;
103}
104} // namespace StdSegData
105
106// Dimensions of coefficients for each space
107namespace StdTriData
108{
109inline int getNumberOfCoefficients(int Na, int Nb)
110{
111 // Note these assertions have been set to > 0 because
112 // it can also be used to evaluate face expansion
113 // order
114 ASSERTL2(Na > 0, "Order in 'a' direction must be > 0.");
115 ASSERTL2(Nb > 0, "Order in 'b' direction must be > 0.");
116 ASSERTL1(Na <= Nb, "order in 'a' direction is higher "
117 "than order in 'b' direction");
118 return Na * (Na + 1) / 2 + Na * (Nb - Na);
119}
120
121inline int getNumberOfBndCoefficients(int Na, int Nb)
122{
123 ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
124 ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
125 ASSERTL1(Na <= Nb, "order in 'a' direction is higher "
126 "than order in 'b' direction");
127 return (Na - 1) + 2 * (Nb - 1);
128}
129} // namespace StdTriData
130
131namespace StdQuadData
132{
133inline int getNumberOfCoefficients(int Na, int Nb)
134{
135 // Note these assertions have been set to > 0 because
136 // it can also be used to evaluate face expansion
137 // order
138 ASSERTL2(Na > 0, "Order in 'a' direction must be > 0.");
139 ASSERTL2(Nb > 0, "Order in 'b' direction must be > 0.");
140 return Na * Nb;
141}
142
143inline int getNumberOfBndCoefficients(int Na, int Nb)
144{
145 ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
146 ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
147 return 2 * (Na - 1) + 2 * (Nb - 1);
148}
149} // namespace StdQuadData
150
151namespace StdHexData
152{
153inline int getNumberOfCoefficients(int Na, int Nb, int Nc)
154{
155 ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
156 ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
157 ASSERTL2(Nc > 1, "Order in 'c' direction must be > 1.");
158 return Na * Nb * Nc;
159}
160
161inline int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
162{
163 ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
164 ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
165 ASSERTL2(Nc > 1, "Order in 'c' direction must be > 1.");
166 return 2 * Na * Nb + 2 * Na * Nc + 2 * Nb * Nc - 4 * (Na + Nb + Nc) + 8;
167}
168} // namespace StdHexData
169
170namespace StdTetData
171{
172/**
173 * Adds up the number of cells in a truncated Nc by Nc by Nc
174 * pyramid, where the longest Na rows and longest Nb columns are
175 * kept. Example: (Na, Nb, Nc) = (3, 4, 5); The number of
176 * coefficients is the sum of the elements of the following
177 * matrix:
178 *
179 * |5 4 3 2 0|
180 * |4 3 2 0 |
181 * |3 2 0 |
182 * |0 0 |
183 * |0 |
184 *
185 * Sum = 28 = number of tet coefficients.
186 */
187inline int getNumberOfCoefficients(int Na, int Nb, int Nc)
188{
189 ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
190 ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
191 ASSERTL2(Nc > 1, "Order in 'c' direction must be > 1.");
192 ASSERTL1(Na <= Nc, "order in 'a' direction is higher "
193 "than order in 'c' direction");
194 ASSERTL1(Nb <= Nc, "order in 'b' direction is higher "
195 "than order in 'c' direction");
196 int nCoef = 0;
197 for (int a = 0; a < Na; ++a)
198 {
199 for (int b = 0; b < Nb - a; ++b)
200 {
201 for (int c = 0; c < Nc - a - b; ++c)
202 {
203 ++nCoef;
204 }
205 }
206 }
207 return nCoef;
208}
209
210inline int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
211{
212 ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
213 ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
214 ASSERTL2(Nc > 1, "Order in 'c' direction must be > 1.");
215 ASSERTL1(Na <= Nc, "order in 'a' direction is higher "
216 "than order in 'c' direction");
217 ASSERTL1(Nb <= Nc, "order in 'b' direction is higher "
218 "than order in 'c' direction");
219
220 int nCoef = Na * (Na + 1) / 2 + (Nb - Na) * Na // base
221 + Na * (Na + 1) / 2 + (Nc - Na) * Na // front
222 + 2 * (Nb * (Nb + 1) / 2 + (Nc - Nb) * Nb) // 2 other sides
223 - Na - 2 * Nb - 3 * Nc // less edges
224 + 4; // plus vertices
225
226 return nCoef;
227}
228} // namespace StdTetData
229
230namespace StdPyrData
231{
232inline int getNumberOfCoefficients(int Na, int Nb, int Nc)
233{
234 ASSERTL1(Na > 1, "Order in 'a' direction must be > 1.");
235 ASSERTL1(Nb > 1, "Order in 'b' direction must be > 1.");
236 ASSERTL1(Nc > 1, "Order in 'c' direction must be > 1.");
237 ASSERTL1(Na <= Nc, "Order in 'a' direction is higher "
238 "than order in 'c' direction.");
239 ASSERTL1(Nb <= Nc, "Order in 'b' direction is higher "
240 "than order in 'c' direction.");
241
242 // Count number of coefficients explicitly.
243 int nCoeff = 0;
244
245 // Count number of interior tet modes
246 for (int a = 0; a < Na; ++a)
247 {
248 for (int b = 0; b < Nb; ++b)
249 {
250 for (int c = 0; c < Nc - std::max(a, b); ++c)
251 {
252 ++nCoeff;
253 }
254 }
255 }
256 return nCoeff;
257}
258
259inline int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
260{
261 ASSERTL1(Na > 1, "Order in 'a' direction must be > 1.");
262 ASSERTL1(Nb > 1, "Order in 'b' direction must be > 1.");
263 ASSERTL1(Nc > 1, "Order in 'c' direction must be > 1.");
264 ASSERTL1(Na <= Nc, "Order in 'a' direction is higher "
265 "than order in 'c' direction.");
266 ASSERTL1(Nb <= Nc, "Order in 'b' direction is higher "
267 "than order in 'c' direction.");
268
269 return Na * Nb // base
270 + 2 * (Na * (Na + 1) / 2 + (Nc - Na) * Na) // front and back
271 + 2 * (Nb * (Nb + 1) / 2 + (Nc - Nb) * Nb) // sides
272 - 2 * Na - 2 * Nb - 4 * Nc // less edges
273 + 5; // plus vertices
274}
275} // namespace StdPyrData
276
277namespace StdPrismData
278{
279inline int getNumberOfCoefficients(int Na, int Nb, int Nc)
280{
281 ASSERTL1(Na > 1, "Order in 'a' direction must be > 1.");
282 ASSERTL1(Nb > 1, "Order in 'b' direction must be > 1.");
283 ASSERTL1(Nc > 1, "Order in 'c' direction must be > 1.");
284 ASSERTL1(Na <= Nc, "Order in 'a' direction is higher "
285 "than order in 'c' direction.");
286
287 return Nb * StdTriData::getNumberOfCoefficients(Na, Nc);
288}
289
290inline int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
291{
292 ASSERTL1(Na > 1, "Order in 'a' direction must be > 1.");
293 ASSERTL1(Nb > 1, "Order in 'b' direction must be > 1.");
294 ASSERTL1(Nc > 1, "Order in 'c' direction must be > 1.");
295 ASSERTL1(Na <= Nc, "Order in 'a' direction is higher "
296 "than order in 'c' direction.");
297
298 return Na * Nb + 2 * Nb * Nc // rect faces
299 + 2 * (Na * (Na + 1) / 2 + (Nc - Na) * Na) // tri faces
300 - 2 * Na - 3 * Nb - 4 * Nc // less edges
301 + 6; // plus vertices
302}
303} // namespace StdPrismData
304
306 std::vector<unsigned int> &modes,
307 int offset = 0)
308{
309 int returnval = 0;
310 switch (shape)
311 {
312 case eSegment:
313 returnval = modes[offset];
314 break;
315 case eTriangle:
316 returnval = StdTriData::getNumberOfCoefficients(modes[offset],
317 modes[offset + 1]);
318 break;
319 case eQuadrilateral:
320 returnval = modes[offset] * modes[offset + 1];
321 break;
322 case eTetrahedron:
324 modes[offset], modes[offset + 1], modes[offset + 2]);
325 break;
326 case ePyramid:
328 modes[offset], modes[offset + 1], modes[offset + 2]);
329 break;
330 case ePrism:
332 modes[offset], modes[offset + 1], modes[offset + 2]);
333 break;
334 case eHexahedron:
335 returnval = modes[offset] * modes[offset + 1] * modes[offset + 2];
336 break;
337 default:
338 NEKERROR(ErrorUtil::efatal, "Unknown Shape Type");
339 break;
340 }
341
342 return returnval;
343}
344
345inline int GetNumberOfCoefficients(ShapeType shape, int na, int nb = 0,
346 int nc = 0)
347{
348 int returnval = 0;
349 switch (shape)
350 {
351 case eSegment:
352 returnval = na;
353 break;
354 case eTriangle:
355 returnval = StdTriData::getNumberOfCoefficients(na, nb);
356 break;
357 case eQuadrilateral:
358 returnval = na * nb;
359 break;
360 case eTetrahedron:
361 returnval = StdTetData::getNumberOfCoefficients(na, nb, nc);
362 break;
363 case ePyramid:
364 returnval = StdPyrData::getNumberOfCoefficients(na, nb, nc);
365 break;
366 case ePrism:
367 returnval = StdPrismData::getNumberOfCoefficients(na, nb, nc);
368 break;
369 case eHexahedron:
370 returnval = na * nb * nc;
371 break;
372 default:
373 NEKERROR(ErrorUtil::efatal, "Unknown Shape Type");
374 break;
375 }
376
377 return returnval;
378}
379} // namespace Nektar::LibUtilities
380
381#endif
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
Definition: ErrorUtil.hpp:265
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:153
int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:161
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:279
int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:290
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:232
int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:259
int getNumberOfCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:133
int getNumberOfBndCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:143
int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:210
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:187
int getNumberOfCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:109
int getNumberOfBndCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:121
const char *const ShapeTypeMap[SIZE_ShapeType]
Definition: ShapeType.hpp:75
int GetNumberOfCoefficients(ShapeType shape, std::vector< unsigned int > &modes, int offset=0)
Definition: ShapeType.hpp:305
constexpr unsigned int ShapeTypeDimMap[SIZE_ShapeType]
Definition: ShapeType.hpp:81