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