Nektar++
ShapeType.hpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ShapeType.h
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 ////////////////////////////////////////////////////////////////////////////////
32 
33 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHAPE_TYPE_H
34 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHAPE_TYPE_H
35 
36 #include <algorithm>
37 #include <vector>
38 
39 #include <boost/core/ignore_unused.hpp>
40 
42 
43 #ifdef min
44 #undef min
45 #endif
46 
47 namespace Nektar
48 {
49 namespace LibUtilities
50 {
51 
52 // Types of geometry types.
54 {
65 
66  // These are the short names used for MatrixFree operators
75 };
76 
77 const char *const ShapeTypeMap[SIZE_ShapeType] = {
78  "NoGeomShapeType", "Point", "Segment", "Triangle", "Quadrilateral",
79  "Tetrahedron", "Pyramid", "Prism", "Hexahedron",
80 };
81 
82 // Hold the dimension of each of the types of shapes.
83 constexpr unsigned int ShapeTypeDimMap[SIZE_ShapeType] = {
84  0, // Unknown
85  0, // ePoint
86  1, // eSegment
87  2, // eTriangle
88  2, // eQuadrilateral
89  3, // eTetrahedron
90  3, // ePyramid
91  3, // ePrism
92  3, // eHexahedron
93 };
94 
95 namespace StdSegData
96 {
97 inline int getNumberOfCoefficients(int Na)
98 {
99  return Na;
100 }
101 
102 inline int getNumberOfBndCoefficients(int Na)
103 {
104  boost::ignore_unused(Na);
105  return 2;
106 }
107 } // namespace StdSegData
108 
109 // Dimensions of coefficients for each space
110 namespace StdTriData
111 {
112 inline int getNumberOfCoefficients(int Na, int Nb)
113 {
114  // Note these assertions have been set to > 0 because
115  // it can also be used to evaluate face expansion
116  // order
117  ASSERTL2(Na > 0, "Order in 'a' direction must be > 0.");
118  ASSERTL2(Nb > 0, "Order in 'b' direction must be > 0.");
119  ASSERTL1(Na <= Nb, "order in 'a' direction is higher "
120  "than order in 'b' direction");
121  return Na * (Na + 1) / 2 + Na * (Nb - Na);
122 }
123 
124 inline int getNumberOfBndCoefficients(int Na, int Nb)
125 {
126  ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
127  ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
128  ASSERTL1(Na <= Nb, "order in 'a' direction is higher "
129  "than order in 'b' direction");
130  return (Na - 1) + 2 * (Nb - 1);
131 }
132 } // namespace StdTriData
133 
134 namespace StdQuadData
135 {
136 inline int getNumberOfCoefficients(int Na, int Nb)
137 {
138  // Note these assertions have been set to > 0 because
139  // it can also be used to evaluate face expansion
140  // order
141  ASSERTL2(Na > 0, "Order in 'a' direction must be > 0.");
142  ASSERTL2(Nb > 0, "Order in 'b' direction must be > 0.");
143  return Na * Nb;
144 }
145 
146 inline int getNumberOfBndCoefficients(int Na, int Nb)
147 {
148  ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
149  ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
150  return 2 * (Na - 1) + 2 * (Nb - 1);
151 }
152 } // namespace StdQuadData
153 
154 namespace StdHexData
155 {
156 inline int getNumberOfCoefficients(int Na, int Nb, int Nc)
157 {
158  ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
159  ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
160  ASSERTL2(Nc > 1, "Order in 'c' direction must be > 1.");
161  return Na * Nb * Nc;
162 }
163 
164 inline int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
165 {
166  ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
167  ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
168  ASSERTL2(Nc > 1, "Order in 'c' direction must be > 1.");
169  return 2 * Na * Nb + 2 * Na * Nc + 2 * Nb * Nc - 4 * (Na + Nb + Nc) + 8;
170 }
171 } // namespace StdHexData
172 
173 namespace StdTetData
174 {
175 /**
176  * Adds up the number of cells in a truncated Nc by Nc by Nc
177  * pyramid, where the longest Na rows and longest Nb columns are
178  * kept. Example: (Na, Nb, Nc) = (3, 4, 5); The number of
179  * coefficients is the sum of the elements of the following
180  * matrix:
181  *
182  * |5 4 3 2 0|
183  * |4 3 2 0 |
184  * |3 2 0 |
185  * |0 0 |
186  * |0 |
187  *
188  * Sum = 28 = number of tet coefficients.
189  */
190 inline int getNumberOfCoefficients(int Na, int Nb, int Nc)
191 {
192  ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
193  ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
194  ASSERTL2(Nc > 1, "Order in 'c' direction must be > 1.");
195  ASSERTL1(Na <= Nc, "order in 'a' direction is higher "
196  "than order in 'c' direction");
197  ASSERTL1(Nb <= Nc, "order in 'b' direction is higher "
198  "than order in 'c' direction");
199  int nCoef = 0;
200  for (int a = 0; a < Na; ++a)
201  {
202  for (int b = 0; b < Nb - a; ++b)
203  {
204  for (int c = 0; c < Nc - a - b; ++c)
205  {
206  ++nCoef;
207  }
208  }
209  }
210  return nCoef;
211 }
212 
213 inline int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
214 {
215  ASSERTL2(Na > 1, "Order in 'a' direction must be > 1.");
216  ASSERTL2(Nb > 1, "Order in 'b' direction must be > 1.");
217  ASSERTL2(Nc > 1, "Order in 'c' direction must be > 1.");
218  ASSERTL1(Na <= Nc, "order in 'a' direction is higher "
219  "than order in 'c' direction");
220  ASSERTL1(Nb <= Nc, "order in 'b' direction is higher "
221  "than order in 'c' direction");
222 
223  int nCoef = Na * (Na + 1) / 2 + (Nb - Na) * Na // base
224  + Na * (Na + 1) / 2 + (Nc - Na) * Na // front
225  + 2 * (Nb * (Nb + 1) / 2 + (Nc - Nb) * Nb) // 2 other sides
226  - Na - 2 * Nb - 3 * Nc // less edges
227  + 4; // plus vertices
228 
229  return nCoef;
230 }
231 } // namespace StdTetData
232 
233 namespace StdPyrData
234 {
235 inline int getNumberOfCoefficients(int Na, int Nb, int Nc)
236 {
237  ASSERTL1(Na > 1, "Order in 'a' direction must be > 1.");
238  ASSERTL1(Nb > 1, "Order in 'b' direction must be > 1.");
239  ASSERTL1(Nc > 1, "Order in 'c' direction must be > 1.");
240  ASSERTL1(Na <= Nc, "Order in 'a' direction is higher "
241  "than order in 'c' direction.");
242  ASSERTL1(Nb <= Nc, "Order in 'b' direction is higher "
243  "than order in 'c' direction.");
244 
245  // Count number of coefficients explicitly.
246  int nCoeff = 0;
247 
248  // Count number of interior tet modes
249  for (int a = 0; a < Na; ++a)
250  {
251  for (int b = 0; b < Nb; ++b)
252  {
253  for (int c = 0; c < Nc - std::max(a, b); ++c)
254  {
255  ++nCoeff;
256  }
257  }
258  }
259  return nCoeff;
260 }
261 
262 inline int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
263 {
264  ASSERTL1(Na > 1, "Order in 'a' direction must be > 1.");
265  ASSERTL1(Nb > 1, "Order in 'b' direction must be > 1.");
266  ASSERTL1(Nc > 1, "Order in 'c' direction must be > 1.");
267  ASSERTL1(Na <= Nc, "Order in 'a' direction is higher "
268  "than order in 'c' direction.");
269  ASSERTL1(Nb <= Nc, "Order in 'b' direction is higher "
270  "than order in 'c' direction.");
271 
272  return Na * Nb // base
273  + 2 * (Na * (Na + 1) / 2 + (Nc - Na) * Na) // front and back
274  + 2 * (Nb * (Nb + 1) / 2 + (Nc - Nb) * Nb) // sides
275  - 2 * Na - 2 * Nb - 4 * Nc // less edges
276  + 5; // plus vertices
277 }
278 } // namespace StdPyrData
279 
280 namespace StdPrismData
281 {
282 inline int getNumberOfCoefficients(int Na, int Nb, int Nc)
283 {
284  ASSERTL1(Na > 1, "Order in 'a' direction must be > 1.");
285  ASSERTL1(Nb > 1, "Order in 'b' direction must be > 1.");
286  ASSERTL1(Nc > 1, "Order in 'c' direction must be > 1.");
287  ASSERTL1(Na <= Nc, "Order in 'a' direction is higher "
288  "than order in 'c' direction.");
289 
290  return Nb * StdTriData::getNumberOfCoefficients(Na, Nc);
291 }
292 
293 inline int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
294 {
295  ASSERTL1(Na > 1, "Order in 'a' direction must be > 1.");
296  ASSERTL1(Nb > 1, "Order in 'b' direction must be > 1.");
297  ASSERTL1(Nc > 1, "Order in 'c' direction must be > 1.");
298  ASSERTL1(Na <= Nc, "Order in 'a' direction is higher "
299  "than order in 'c' direction.");
300 
301  return Na * Nb + 2 * Nb * Nc // rect faces
302  + 2 * (Na * (Na + 1) / 2 + (Nc - Na) * Na) // tri faces
303  - 2 * Na - 3 * Nb - 4 * Nc // less edges
304  + 6; // plus vertices
305 }
306 } // namespace StdPrismData
307 
309  std::vector<unsigned int> &modes,
310  int offset = 0)
311 {
312  int returnval = 0;
313  switch (shape)
314  {
315  case eSegment:
316  returnval = modes[offset];
317  break;
318  case eTriangle:
319  returnval = StdTriData::getNumberOfCoefficients(modes[offset],
320  modes[offset + 1]);
321  break;
322  case eQuadrilateral:
323  returnval = modes[offset] * modes[offset + 1];
324  break;
325  case eTetrahedron:
327  modes[offset], modes[offset + 1], modes[offset + 2]);
328  break;
329  case ePyramid:
331  modes[offset], modes[offset + 1], modes[offset + 2]);
332  break;
333  case ePrism:
335  modes[offset], modes[offset + 1], modes[offset + 2]);
336  break;
337  case eHexahedron:
338  returnval = modes[offset] * modes[offset + 1] * modes[offset + 2];
339  break;
340  default:
341  NEKERROR(ErrorUtil::efatal, "Unknown Shape Type");
342  break;
343  }
344 
345  return returnval;
346 }
347 
348 inline int GetNumberOfCoefficients(ShapeType shape, int na, int nb = 0,
349  int nc = 0)
350 {
351  int returnval = 0;
352  switch (shape)
353  {
354  case eSegment:
355  returnval = na;
356  break;
357  case eTriangle:
358  returnval = StdTriData::getNumberOfCoefficients(na, nb);
359  break;
360  case eQuadrilateral:
361  returnval = na * nb;
362  break;
363  case eTetrahedron:
364  returnval = StdTetData::getNumberOfCoefficients(na, nb, nc);
365  break;
366  case ePyramid:
367  returnval = StdPyrData::getNumberOfCoefficients(na, nb, nc);
368  break;
369  case ePrism:
370  returnval = StdPrismData::getNumberOfCoefficients(na, nb, nc);
371  break;
372  case eHexahedron:
373  returnval = na * nb * nc;
374  break;
375  default:
376  NEKERROR(ErrorUtil::efatal, "Unknown Shape Type");
377  break;
378  }
379 
380  return returnval;
381 }
382 } // namespace LibUtilities
383 } // namespace Nektar
384 
385 #endif
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
Definition: ErrorUtil.hpp:272
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:156
int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:164
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:282
int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:293
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:235
int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:262
int getNumberOfCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:136
int getNumberOfBndCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:146
int getNumberOfBndCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:213
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:190
int getNumberOfCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:112
int getNumberOfBndCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:124
const char *const ShapeTypeMap[SIZE_ShapeType]
Definition: ShapeType.hpp:77
int GetNumberOfCoefficients(ShapeType shape, std::vector< unsigned int > &modes, int offset=0)
Definition: ShapeType.hpp:308
constexpr unsigned int ShapeTypeDimMap[SIZE_ShapeType]
Definition: ShapeType.hpp:83
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1