dune-fem 2.8.0
Loading...
Searching...
No Matches
genericgeometry.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_SPACE_LAGRANGE_GENERICGEOMETRY_HH
2#define DUNE_FEM_SPACE_LAGRANGE_GENERICGEOMETRY_HH
3
4#include <type_traits>
5
6// dune-common includes
7#include <dune/common/fvector.hh>
8
9// dune-geometry includes
10#include <dune/geometry/type.hh>
11
12// dune-fem includes
13#include <dune/fem/misc/metaprogramming.hh>
14
15
16namespace Dune
17{
18
19 namespace Fem
20 {
21
63 {
64 public:
66 static const unsigned int dimension = 0;
67
68 template< unsigned int codim >
69 class Codim
70 {
71 static_assert( (codim <= dimension), "Codimension must be less or equal to dimension." );
72
73 public:
74 static const unsigned int numSubEntities = ((codim == 0) ? 1 : 0);
75 };
76
78 static unsigned int numSubEntities ( unsigned int codim )
79 {
80 return ((codim == 0) ? 1 : 0);
81 }
82 };
83
84
85
90 template< class BaseGeometry >
92 {
93 public:
95 typedef BaseGeometry BaseGeometryType;
96
98 static const unsigned int dimension = BaseGeometryType::dimension + 1;
99
100 template< unsigned int codim >
101 class Codim
102 {
103 static_assert( (codim <= dimension), "Codimension must be less or equal to dimension." );
104
105 public:
106 static const unsigned int numSubEntities
107 = MetaIf< (codim > 0),
108 MetaPlus< MetaInt< Protect< BaseGeometryType::template Codim, codim-1, PointGeometry::template Codim< 0 >, 0 >::numSubEntities >,
109 MetaInt< Protect< BaseGeometryType::template Codim, codim, PointGeometry::template Codim< 0 >, dimension >::numSubEntities > >,
110 MetaInt< 1 > >::value;
111 };
112
114 static unsigned int numSubEntities ( unsigned int codim )
115 {
116 if( codim > 0 )
117 {
118 const unsigned int sameCodimCount = BaseGeometryType::numSubEntities( codim-1 );
119 if( codim < dimension )
120 return sameCodimCount + BaseGeometryType::numSubEntities( codim );
121 else
122 return (codim == dimension ? sameCodimCount+1 : 0);
123 }
124 else
125 return 1;
126 }
127 };
128
129
130
135 template< class FirstGeometry, class SecondGeometry >
137 {
138 public:
140 typedef FirstGeometry FirstGeometryType;
142 typedef SecondGeometry SecondGeometryType;
143
145 static const unsigned int dimension = FirstGeometryType::dimension + SecondGeometryType::dimension;
146
147 template< unsigned int codim >
148 class Codim
149 {
150 static_assert( (codim <= dimension), "Codimension must be less or equal to dimension." );
151
152 template< unsigned int i >
153 struct NumSubEntities
154 : public MetaInt< FirstGeometryType::template Codim< codim-i >::numSubEntities * SecondGeometryType::template Codim< i >::numSubEntities >
155 {};
156
157 public:
158 static const unsigned int numSubEntities = Loop< MetaPlus, NumSubEntities, codim >::value;
159 };
160
162 static unsigned int numSubEntities ( unsigned int codim )
163 {
164 unsigned int cnt = 0;
165 for( unsigned int i = 0; i <= codim; ++i )
166 cnt += FirstGeometryType::numSubEntities( codim - i ) * SecondGeometryType::numSubEntities( i );
167 return cnt;
168 }
169 };
170
171
172
173 template< unsigned int id, unsigned int dim >
175 {
176 static_assert( (id < (1 << dim)), "id too large." );
177
178 static const bool isPrism = ((id >> (dim-1)) != 0);
179
180 typedef GeometryWrapper< (id & ~(1 << (dim-1))), dim-1 > DimensionReductionType;
181
182 template< bool >
183 struct Prism
184 {
185 typedef GeometryWrapper< (id & 1), 1 > LineGeometryType;
187 ImplType;
188 };
189
190 template< bool >
191 struct Pyramid
192 {
194 ImplType;
195 };
196
197 public:
198 static const unsigned int dimension = dim;
199
200 typedef typename std::conditional< isPrism, Prism< true >, Pyramid< false > >::type::ImplType
202 };
203
204 template< unsigned int id >
205 class GeometryWrapper< id, 1 >
206 {
207 static_assert( (id < 2), "id too large." );
208
209 public:
210 static const unsigned int dimension = 1;
211
213 };
214
215 template< unsigned int id >
216 class GeometryWrapper< id, 0 >
217 {
218 static_assert( (id < 1), "id too large." );
219
220 public:
221 static const unsigned int dimension = 0;
222
224 };
225
226
227
228 // Local Coordinates
229 // -----------------
230
231 template< class Geometry, class Field, unsigned int offset = 0 >
233
234
235
236 template< class Field, unsigned int offset >
237 class LocalCoordinate< PointGeometry, Field, offset >
238 {
240
241 public:
243
244 static const unsigned int dimension = GeometryType::dimension;
245
246 typedef Field FieldType;
247
249 {}
250
251 template< int sz >
252 explicit LocalCoordinate ( const FieldVector< FieldType, sz > &x )
253 {
254 static_assert( (sz >= offset + dimension), "Invalid vector size" );
255 }
256
257 ThisType &operator= ( const FieldType s )
258 {
259 return *this;
260 }
261
262 template< int sz >
263 ThisType &operator= ( const FieldVector< FieldType, sz > &x )
264 {
265 static_assert( (sz >= offset + dimension), "Invalid vector size" );
266 return *this;
267 }
268
269 ThisType &operator= ( const ThisType &v )
270 {
271 return *this;
272 }
273
274 ThisType &operator*= ( const FieldType s )
275 {
276 return *this;
277 }
278
279 ThisType &operator+= ( const ThisType &v )
280 {
281 return *this;
282 }
283
284 ThisType &operator-= ( const ThisType &v )
285 {
286 return *this;
287 }
288
289 const FieldType &operator[] ( const unsigned int i ) const
290 {
291 DUNE_THROW( RangeError, "LocalCoordinate: No such index." );
292 }
293
294 FieldType &operator[] ( const unsigned int i )
295 {
296 DUNE_THROW( RangeError, "LocalCoordinate: No such index." );
297 }
298 };
299
300
301
302 template< class BaseGeometry, class Field, unsigned int offset >
303 class LocalCoordinate< PyramidGeometry< BaseGeometry >, Field, offset >
304 {
306
307 public:
308 typedef BaseGeometry BaseGeometryType;
309
311
312 static const unsigned int dimension = GeometryType::dimension;
313
314 typedef Field FieldType;
315
317
318 static const unsigned int index = offset + BaseGeometryType::dimension;
319
321 {}
322
323 template< int sz >
324 explicit LocalCoordinate ( const FieldVector< FieldType, sz > &x )
325 : myCoordinate_( x[ index ] ),
326 baseCoordinate_( x )
327 {
328 static_assert( (sz >= offset + dimension), "Invalid vector size" );
329 }
330
331 ThisType &operator= ( const FieldType s )
332 {
333 myCoordinate_ = s;
334 baseCoordinate_ = s;
335 return *this;
336 }
337
338 template< int sz >
339 ThisType &operator= ( const FieldVector< FieldType, sz > &x )
340 {
341 static_assert( (sz >= offset + dimension), "Invalid vector size" );
342
343 myCoordinate_ = x[ index ];
344 baseCoordinate_ = x;
345 return *this;
346 }
347
348 ThisType &operator= ( const ThisType &v )
349 {
350 myCoordinate_ = v.myCoordinate_;
351 baseCoordinate_ = v.baseCoordinate_;
352 return *this;
353 }
354
355 ThisType &operator*= ( const FieldType s )
356 {
357 myCoordinate_ *= s;
358 baseCoordinate_ *= s;
359 return *this;
360 }
361
362 ThisType &operator+= ( const ThisType &v )
363 {
364 myCoordinate_ += v.myCoordinate_;
365 baseCoordinate_ += v.baseCoordinate_;
366 return *this;
367 }
368
369 ThisType &operator-= ( const ThisType &v )
370 {
371 myCoordinate_ -= v.myCoordinate_;
372 baseCoordinate_ -= v.baseCoordinate_;
373 return *this;
374 }
375
376 const FieldType &operator[] ( const unsigned int i ) const
377 {
378 if( i == index )
379 return myCoordinate_;
380 else
381 return baseCoordinate_[ i ];
382 }
383
384 FieldType &operator[] ( const unsigned int i )
385 {
386 if( i == index )
387 return myCoordinate_;
388 else
389 return baseCoordinate_[ i ];
390 }
391
392 const FieldType &operator* () const
393 {
394 return myCoordinate_;
395 }
396
398 {
399 return myCoordinate_;
400 }
401
402 const BaseCoordinateType &base () const
403 {
404 return baseCoordinate_;
405 }
406
408 {
409 return baseCoordinate_;
410 }
411
412 private:
413 FieldType myCoordinate_;
414 BaseCoordinateType baseCoordinate_;
415 };
416
417
418
419 template< class FirstGeometry, class SecondGeometry, class Field, unsigned int offset >
420 class LocalCoordinate< ProductGeometry< FirstGeometry, SecondGeometry >, Field, offset >
421 {
423
424 public:
425 typedef FirstGeometry FirstGeometryType;
426 typedef SecondGeometry SecondGeometryType;
428
429 static const unsigned int dimension = GeometryType::dimension;
430
431 typedef Field FieldType;
432
433 protected:
434 static const unsigned int firstOffset = offset;
435 static const unsigned int secondOffset = offset + FirstGeometryType::dimension;
436
437 public:
440
442 {}
443
444 template< int sz >
445 explicit LocalCoordinate ( const FieldVector< FieldType, sz > &x )
446 : firstCoordinate_( x ),
447 secondCoordinate_( x )
448 {
449 static_assert( (sz >= offset + dimension), "Invalid vector size" );
450 }
451
452 ThisType &operator= ( const FieldType s )
453 {
454 firstCoordinate_ = s;
455 secondCoordinate_ = s;
456 return *this;
457 }
458
459 template< int sz >
460 ThisType &operator= ( const FieldVector< FieldType, sz > &x )
461 {
462 static_assert( (sz >= offset + dimension), "Invalid vector size" );
463
464 firstCoordinate_ = x;
465 secondCoordinate_ = x;
466 return *this;
467 }
468
469 ThisType &operator= ( const ThisType &v )
470 {
471 firstCoordinate_ = v;
472 secondCoordinate_ = v;
473 return *this;
474 }
475
476 ThisType &operator*= ( const FieldType s )
477 {
478 firstCoordinate_ *= s;
479 secondCoordinate_ *= s;
480 return *this;
481 }
482
483 ThisType &operator+= ( const ThisType &v )
484 {
485 firstCoordinate_ += v;
486 secondCoordinate_ += v;
487 return *this;
488 }
489
490 ThisType &operator-= ( const ThisType &v )
491 {
492 firstCoordinate_ -= v;
493 secondCoordinate_ -= v;
494 return *this;
495 }
496
497 const FieldType &operator[] ( const unsigned int i ) const
498 {
499 if( i < secondOffset )
500 return firstCoordinate_[ i ];
501 else
502 return secondCoordinate_[ i ];
503 }
504
505 FieldType &operator[] ( const unsigned int i )
506 {
507 if( i < secondOffset )
508 return firstCoordinate_[ i ];
509 else
510 return secondCoordinate_[ i ];
511 }
512
514 {
515 return firstCoordinate_;
516 }
517
519 {
520 return firstCoordinate_;
521 }
522
524 {
525 return secondCoordinate_;
526 }
527
529 {
530 return secondCoordinate_;
531 }
532
533 private:
534 FirstCoordinateType firstCoordinate_;
535 SecondCoordinateType secondCoordinate_;
536 };
537
538 } // namespace Fem
539
540} // namespace Dune
541
542#endif // #ifndef DUNE_FEM_SPACE_LAGRANGE_GENERICGEOMETRY_HH
Definition: bindguard.hh:11
Double operator*(const Double &a, const Double &b)
Definition: double.hh:506
generic geometry modelling a single point
Definition: genericgeometry.hh:63
static unsigned int numSubEntities(unsigned int codim)
number of subentites of a given codimension
Definition: genericgeometry.hh:78
static const unsigned int dimension
dimension of the geometry object
Definition: genericgeometry.hh:66
Definition: genericgeometry.hh:70
static const unsigned int numSubEntities
Definition: genericgeometry.hh:74
generic geometry modelling a pyramid over a base geometry
Definition: genericgeometry.hh:92
static unsigned int numSubEntities(unsigned int codim)
number of subentites of a given codimension
Definition: genericgeometry.hh:114
BaseGeometry BaseGeometryType
type of base geometry
Definition: genericgeometry.hh:95
static const unsigned int dimension
dimension of the geometry object
Definition: genericgeometry.hh:98
Definition: genericgeometry.hh:102
static const unsigned int numSubEntities
Definition: genericgeometry.hh:107
generic geometry modelling the product of two base geometries
Definition: genericgeometry.hh:137
static const unsigned int dimension
dimension of the geometry object
Definition: genericgeometry.hh:145
SecondGeometry SecondGeometryType
type of the second base geometry
Definition: genericgeometry.hh:142
static unsigned int numSubEntities(unsigned int codim)
number of subentites of a given codimension
Definition: genericgeometry.hh:162
FirstGeometry FirstGeometryType
type of the first base geometry
Definition: genericgeometry.hh:140
Definition: genericgeometry.hh:149
static const unsigned int numSubEntities
Definition: genericgeometry.hh:158
Definition: genericgeometry.hh:175
std::conditional< isPrism, Prism< true >, Pyramid< false > >::type::ImplType ImplType
Definition: genericgeometry.hh:201
static const unsigned int dimension
Definition: genericgeometry.hh:198
PyramidGeometry< PointGeometry > ImplType
Definition: genericgeometry.hh:212
PointGeometry ImplType
Definition: genericgeometry.hh:223
Definition: genericgeometry.hh:232
LocalCoordinate(const FieldVector< FieldType, sz > &x)
Definition: genericgeometry.hh:252
PointGeometry GeometryType
Definition: genericgeometry.hh:242
LocalCoordinate()
Definition: genericgeometry.hh:248
Field FieldType
Definition: genericgeometry.hh:246
BaseGeometry BaseGeometryType
Definition: genericgeometry.hh:308
BaseCoordinateType & base()
Definition: genericgeometry.hh:407
const BaseCoordinateType & base() const
Definition: genericgeometry.hh:402
LocalCoordinate< BaseGeometry, FieldType, offset > BaseCoordinateType
Definition: genericgeometry.hh:316
LocalCoordinate(const FieldVector< FieldType, sz > &x)
Definition: genericgeometry.hh:324
PyramidGeometry< BaseGeometryType > GeometryType
Definition: genericgeometry.hh:310
const SecondCoordinateType & second() const
Definition: genericgeometry.hh:523
LocalCoordinate< SecondGeometryType, FieldType, secondOffset > SecondCoordinateType
Definition: genericgeometry.hh:439
LocalCoordinate(const FieldVector< FieldType, sz > &x)
Definition: genericgeometry.hh:445
const FirstCoordinateType & first() const
Definition: genericgeometry.hh:513
LocalCoordinate< FirstGeometryType, FieldType, firstOffset > FirstCoordinateType
Definition: genericgeometry.hh:438
ProductGeometry< FirstGeometryType, SecondGeometryType > GeometryType
Definition: genericgeometry.hh:427