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