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 LocalCoordinate (const LocalCoordinate& ) = default;
324
325 template< int sz >
326 explicit LocalCoordinate ( const FieldVector< FieldType, sz > &x )
327 : myCoordinate_( x[ index ] ),
328 baseCoordinate_( x )
329 {
330 static_assert( (sz >= offset + dimension), "Invalid vector size" );
331 }
332
333 ThisType &operator= ( const FieldType s )
334 {
335 myCoordinate_ = s;
336 baseCoordinate_ = s;
337 return *this;
338 }
339
340 template< int sz >
341 ThisType &operator= ( const FieldVector< FieldType, sz > &x )
342 {
343 static_assert( (sz >= offset + dimension), "Invalid vector size" );
344
345 myCoordinate_ = x[ index ];
346 baseCoordinate_ = x;
347 return *this;
348 }
349
350 ThisType &operator= ( const ThisType &v )
351 {
352 myCoordinate_ = v.myCoordinate_;
353 baseCoordinate_ = v.baseCoordinate_;
354 return *this;
355 }
356
357 ThisType &operator*= ( const FieldType s )
358 {
359 myCoordinate_ *= s;
360 baseCoordinate_ *= s;
361 return *this;
362 }
363
364 ThisType &operator+= ( const ThisType &v )
365 {
366 myCoordinate_ += v.myCoordinate_;
367 baseCoordinate_ += v.baseCoordinate_;
368 return *this;
369 }
370
371 ThisType &operator-= ( const ThisType &v )
372 {
373 myCoordinate_ -= v.myCoordinate_;
374 baseCoordinate_ -= v.baseCoordinate_;
375 return *this;
376 }
377
378 const FieldType &operator[] ( const unsigned int i ) const
379 {
380 if( i == index )
381 return myCoordinate_;
382 else
383 return baseCoordinate_[ i ];
384 }
385
386 FieldType &operator[] ( const unsigned int i )
387 {
388 if( i == index )
389 return myCoordinate_;
390 else
391 return baseCoordinate_[ i ];
392 }
393
394 const FieldType &operator* () const
395 {
396 return myCoordinate_;
397 }
398
399 FieldType &operator* ()
400 {
401 return myCoordinate_;
402 }
403
404 const BaseCoordinateType &base () const
405 {
406 return baseCoordinate_;
407 }
408
409 BaseCoordinateType &base ()
410 {
411 return baseCoordinate_;
412 }
413
414 private:
415 FieldType myCoordinate_;
416 BaseCoordinateType baseCoordinate_;
417 };
418
419
420
421 template< class FirstGeometry, class SecondGeometry, class Field, unsigned int offset >
422 class LocalCoordinate< ProductGeometry< FirstGeometry, SecondGeometry >, Field, offset >
423 {
424 typedef LocalCoordinate< ProductGeometry< FirstGeometry, SecondGeometry >, Field, offset > ThisType;
425
426 public:
427 typedef FirstGeometry FirstGeometryType;
428 typedef SecondGeometry SecondGeometryType;
429 typedef ProductGeometry< FirstGeometryType, SecondGeometryType > GeometryType;
430
431 static const unsigned int dimension = GeometryType::dimension;
432
433 typedef Field FieldType;
434
435 protected:
436 static const unsigned int firstOffset = offset;
437 static const unsigned int secondOffset = offset + FirstGeometryType::dimension;
438
439 public:
440 typedef LocalCoordinate< FirstGeometryType, FieldType, firstOffset > FirstCoordinateType;
441 typedef LocalCoordinate< SecondGeometryType, FieldType, secondOffset > SecondCoordinateType;
442
443 LocalCoordinate ()
444 {}
445
446 LocalCoordinate( const LocalCoordinate& ) = default;
447
448 template< int sz >
449 explicit LocalCoordinate ( const FieldVector< FieldType, sz > &x )
450 : firstCoordinate_( x ),
451 secondCoordinate_( x )
452 {
453 static_assert( (sz >= offset + dimension), "Invalid vector size" );
454 }
455
456 ThisType &operator= ( const FieldType s )
457 {
458 firstCoordinate_ = s;
459 secondCoordinate_ = s;
460 return *this;
461 }
462
463 template< int sz >
464 ThisType &operator= ( const FieldVector< FieldType, sz > &x )
465 {
466 static_assert( (sz >= offset + dimension), "Invalid vector size" );
467
468 firstCoordinate_ = x;
469 secondCoordinate_ = x;
470 return *this;
471 }
472
473 ThisType &operator= ( const ThisType &v )
474 {
475 firstCoordinate_ = v;
476 secondCoordinate_ = v;
477 return *this;
478 }
479
480 ThisType &operator*= ( const FieldType s )
481 {
482 firstCoordinate_ *= s;
483 secondCoordinate_ *= s;
484 return *this;
485 }
486
487 ThisType &operator+= ( const ThisType &v )
488 {
489 firstCoordinate_ += v;
490 secondCoordinate_ += v;
491 return *this;
492 }
493
494 ThisType &operator-= ( const ThisType &v )
495 {
496 firstCoordinate_ -= v;
497 secondCoordinate_ -= v;
498 return *this;
499 }
500
501 const FieldType &operator[] ( const unsigned int i ) const
502 {
503 if( i < secondOffset )
504 return firstCoordinate_[ i ];
505 else
506 return secondCoordinate_[ i ];
507 }
508
509 FieldType &operator[] ( const unsigned int i )
510 {
511 if( i < secondOffset )
512 return firstCoordinate_[ i ];
513 else
514 return secondCoordinate_[ i ];
515 }
516
517 const FirstCoordinateType &first () const
518 {
519 return firstCoordinate_;
520 }
521
522 FirstCoordinateType &first ()
523 {
524 return firstCoordinate_;
525 }
526
527 const SecondCoordinateType &second () const
528 {
529 return secondCoordinate_;
530 }
531
532 SecondCoordinateType &second ()
533 {
534 return secondCoordinate_;
535 }
536
537 private:
538 FirstCoordinateType firstCoordinate_;
539 SecondCoordinateType secondCoordinate_;
540 };
541
542 } // namespace Fem
543
544} // namespace Dune
545
546#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 (Nov 21, 23:30, 2024)