DUNE-FEM (unstable)

genericgeometry.hh
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
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 >
174 class GeometryWrapper
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;
186 typedef ProductGeometry< typename DimensionReductionType::ImplType, typename LineGeometryType::ImplType >
187 ImplType;
188 };
189
190 template< bool >
191 struct Pyramid
192 {
193 typedef PyramidGeometry< typename DimensionReductionType::ImplType >
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
201 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
212 typedef PyramidGeometry< PointGeometry > ImplType;
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
223 typedef PointGeometry ImplType;
224 };
225
226
227
228 // Local Coordinates
229 // -----------------
230
231 template< class Geometry, class Field, unsigned int offset = 0 >
232 class LocalCoordinate;
233
234
235
236 template< class Field, unsigned int offset >
237 class LocalCoordinate< PointGeometry, Field, offset >
238 {
239 typedef LocalCoordinate< PointGeometry, Field, offset > ThisType;
240
241 public:
242 typedef PointGeometry GeometryType;
243
244 static const unsigned int dimension = GeometryType::dimension;
245
246 typedef Field FieldType;
247
248 inline LocalCoordinate ()
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 {
305 typedef LocalCoordinate< PyramidGeometry< BaseGeometry >, Field, offset > ThisType;
306
307 public:
308 typedef BaseGeometry BaseGeometryType;
309
310 typedef PyramidGeometry< BaseGeometryType > GeometryType;
311
312 static const unsigned int dimension = GeometryType::dimension;
313
314 typedef Field FieldType;
315
316 typedef LocalCoordinate< BaseGeometry, FieldType, offset > BaseCoordinateType;
317
318 static const unsigned int index = offset + BaseGeometryType::dimension;
319
320 LocalCoordinate ()
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
397 FieldType &operator* ()
398 {
399 return myCoordinate_;
400 }
401
402 const BaseCoordinateType &base () const
403 {
404 return baseCoordinate_;
405 }
406
407 BaseCoordinateType &base ()
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 {
422 typedef LocalCoordinate< ProductGeometry< FirstGeometry, SecondGeometry >, Field, offset > ThisType;
423
424 public:
425 typedef FirstGeometry FirstGeometryType;
426 typedef SecondGeometry SecondGeometryType;
427 typedef ProductGeometry< FirstGeometryType, SecondGeometryType > GeometryType;
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:
438 typedef LocalCoordinate< FirstGeometryType, FieldType, firstOffset > FirstCoordinateType;
439 typedef LocalCoordinate< SecondGeometryType, FieldType, secondOffset > SecondCoordinateType;
440
441 LocalCoordinate ()
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
513 const FirstCoordinateType &first () const
514 {
515 return firstCoordinate_;
516 }
517
518 FirstCoordinateType &first ()
519 {
520 return firstCoordinate_;
521 }
522
523 const SecondCoordinateType &second () const
524 {
525 return secondCoordinate_;
526 }
527
528 SecondCoordinateType &second ()
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
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
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
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
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)