FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
shape.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
10#include <kernel/util/meta_math.hpp>
11#include <kernel/util/string.hpp>
12
13namespace FEAT
14{
18 namespace Shape
19 {
25 struct Vertex
26 {
28 static constexpr int dimension = 0;
29
31 static String name()
32 {
33 return "Vertex";
34 }
35 }; // struct Vertex
36
42 template<int dimension_>
43 struct Simplex
44 {
45 static_assert(dimension_ > 0, "parameter dimension_ must be greater than 0");
46
48 static constexpr int dimension = dimension_;
49
51 static String name()
52 {
53 return "Simplex<" + stringify(dimension_) + ">";
54 }
55 }; // class Simplex
56
62 template<int dimension_>
63 struct Hypercube
64 {
65 static_assert(dimension_ > 0, "parameter dimension_ must be greater than 0");
66
68 static constexpr int dimension = dimension_;
69
71 static String name()
72 {
73 return "Hypercube<" + stringify(dimension_) + ">";
74 }
75 }; // struct Hypercube
76
81
86
99 template<
100 typename Shape_,
101 int face_dim_>
102#ifndef DOXYGEN
103 struct FaceTraits;
104#else
106 {
108 typedef ... ShapeType;
109
111 static constexpr int count = ...
112 };
113#endif // DOXYGEN
114
116
119 template<>
120 struct FaceTraits<Vertex, 0>
121 {
123 typedef Vertex ShapeType;
124
126 static constexpr int count = 1;
127 }; // struct FaceTraits<Vertex,0>
128
134 template<
135 int cell_dim_,
136 int face_dim_>
137 struct FaceTraits<Simplex<cell_dim_>, face_dim_>
138 {
139 static_assert(face_dim_ > 0, "parameter face_dim_ must be greater than 0");
140 static_assert(cell_dim_ >= face_dim_, "face_dim_ must not be greater than cell_dim_");
141
143 typedef Simplex<face_dim_> ShapeType;
144
152 }; // struct FaceTraits<Simplex<...>, ...>
153
159 template<int cell_dim_>
160 struct FaceTraits<Simplex<cell_dim_>, 0>
161 {
162 static_assert(cell_dim_ > 0, "parameter cell_dim_ must be greater than 0");
163
165 typedef Vertex ShapeType;
166
168 static constexpr int count = cell_dim_ + 1;
169 }; // struct FaceTraits<Simplex<...>, 0>
170
176 template<
177 int cell_dim_,
178 int face_dim_>
179 struct FaceTraits<Hypercube<cell_dim_>, face_dim_>
180 {
181 static_assert(face_dim_ > 0, "parameter face_dim_ must be greater than 0");
182 static_assert(cell_dim_ >= face_dim_, "face_dim_ must not be greater than cell_dim_");
183
185 typedef Hypercube<face_dim_> ShapeType;
186
193 static constexpr int count = (1 << (cell_dim_ - face_dim_)) * MetaMath::Binomial<cell_dim_, face_dim_>::value;
194 }; // struct FaceTraits<Hypercube<...>, ...>
195
201 template<int cell_dim_>
202 struct FaceTraits<Hypercube<cell_dim_>, 0>
203 {
204 static_assert(cell_dim_ > 0, "parameter cell_dim_ must be greater than 0");
205
207 typedef Vertex ShapeType;
208
210 static constexpr int count = (1 << cell_dim_);
211 }; // struct FaceTraits<HyperCube<...>, 0>
213
225 template<typename Shape_>
226#ifndef DOXYGEN
227 struct ReferenceCell;
228#else
230 {
246 template<typename T_>
247 static T_ vertex(int vertex_idx, int coord_idx);
248
261 template<typename T_>
262 static T_ centre(int coord_idx);
263
273 template<typename T_>
274 static T_ volume();
275
288 static int facet_orientation(int facet_index);
289 };
290#endif // DOXYGEN
291
293
298 template<>
299 struct ReferenceCell<Shape::Vertex>
300 {
301 template<typename T_>
302 static T_ vertex(int, int)
303 {
304 return T_(0);
305 }
306
307 template<typename T_>
308 static T_ centre(int)
309 {
310 return T_(0);
311 }
312
313 template<typename T_>
314 static T_ volume()
315 {
316 return T_(0);
317 }
318
319 // orientation is not implemented due to being nonsensical
320
321 };
322
328 template<int dim_>
329 struct ReferenceCell< Shape::Simplex<dim_> >
330 {
331 template<typename T_>
332 static T_ vertex(int vertex_idx, int coord_idx)
333 {
334 return (coord_idx + 1) == vertex_idx ? T_(1) : T_(0);
335 }
336
337 template<typename T_>
338 static T_ centre(int)
339 {
340 return T_(1) / T_(dim_+1);
341 }
342
343 template<typename T_>
344 static T_ volume()
345 {
346 return T_(1) / T_(MetaMath::Factorial<dim_>::value);
347 }
348
363 static int facet_orientation(int facet_index)
364 {
365 ASSERTM((facet_index >= 0), "facet index out of range!");
366 ASSERTM((facet_index < FaceTraits<Simplex<dim_>, dim_-1>::count), "facet index out of range!");
367 return 1 - (dim_ == 2 ? 0 : dim_ == 3 ? (facet_index & 1) << 1 : ((facet_index & 1) ^ 1) << 1);
368 }
369 };
370
376 template<int dim_>
377 struct ReferenceCell< Shape::Hypercube<dim_> >
378 {
379 template<typename T_>
380 static T_ vertex(int vertex_idx, int coord_idx)
381 {
382 return T_((((vertex_idx >> coord_idx) & 1) << 1) - 1);
383 }
384
385 template<typename T_>
386 static T_ centre(int)
387 {
388 return T_(0);
389 }
390
391 template<typename T_>
392 static T_ volume()
393 {
394 return T_(1 << dim_); // = 2^dim
395 }
396
412 static int facet_orientation(int facet_index)
413 {
414 ASSERTM((facet_index >= 0), "facet index out of range!");
415 ASSERTM((facet_index < FaceTraits<Hypercube<dim_>,dim_-1>::count), "facet index out of range!");
416
417 return 1 - (( ((facet_index >> 1) ^ facet_index ^ dim_) & 1 ) << 1);
418 }
419 };
420
422 } // namespace Shape
423} // namespace FEAT
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
FEAT Kernel base header.
String class implementation.
Definition: string.hpp:46
Hypercube< 3 > Hexahedron
3-Hypercube: Hexahedron
Definition: shape.hpp:85
Hypercube< 2 > Quadrilateral
2-Hypercube: Quadrilateral
Definition: shape.hpp:83
Simplex< 3 > Tetrahedron
3-Simplex: Tetrahedron
Definition: shape.hpp:80
Simplex< 2 > Triangle
2-Simplex: Triangle
Definition: shape.hpp:78
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944
Binomial template meta-program.
Definition: meta_math.hpp:69
static constexpr int value
value of the factorial
Definition: meta_math.hpp:38
Face traits tag struct template.
Definition: shape.hpp:106
typedef ShapeType
Shape type of the face.
Definition: shape.hpp:108
Hypercube shape tag struct template.
Definition: shape.hpp:64
static String name()
Returns the name of the class as a String.
Definition: shape.hpp:71
static constexpr int dimension
Hypercube dimension.
Definition: shape.hpp:68
Reference cell traits structure.
Definition: shape.hpp:230
static int facet_orientation(int facet_index)
Returns the orientation of a facet.
static T_ centre(int coord_idx)
Returns the coordinate of the reference cell centre.
static T_ vertex(int vertex_idx, int coord_idx)
Returns the coordinate of a reference cell vertex.
static T_ volume()
Returns the volume of the reference cell.
Simplex shape tag struct template.
Definition: shape.hpp:44
static String name()
Returns the name of the class as a String.
Definition: shape.hpp:51
static constexpr int dimension
Simplex dimension.
Definition: shape.hpp:48
Vertex shape tag struct.
Definition: shape.hpp:26
static String name()
Returns the name of the class as a String.
Definition: shape.hpp:31
static constexpr int dimension
Vertex dimension.
Definition: shape.hpp:28