Dune Core Modules (2.4.1)

referenceelements.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
4#define DUNE_GEOMETRY_REFERENCEELEMENTS_HH
5
6#include <algorithm>
7#include <limits>
8
14#include <dune/common/unused.hh>
15
17#include <dune/geometry/genericgeometry/codimtable.hh>
18#include <dune/geometry/genericgeometry/subtopologies.hh>
19#include <dune/geometry/genericgeometry/referencedomain.hh>
20
21namespace Dune
22{
23
24 // Internal Forward Declarations
25 // -----------------------------
26
27 template< class ctype, int dim >
28 class ReferenceElementContainer;
29
30 template< class ctype, int dim >
31 struct ReferenceElements;
32
33
34
53 template< class ctype, int dim >
55 {
57
58 friend class ReferenceElementContainer< ctype, dim >;
59
60 struct SubEntityInfo;
61
62 // make copy constructor private
63 ReferenceElement ( const This & );
64
66
67 template< int codim > struct CreateGeometries;
68
69 public:
71 template< int codim >
72 struct Codim
73 {
75 typedef AffineGeometry< ctype, dim-codim, dim > Geometry;
76 };
77
82 int size ( int c ) const
83 {
84 assert( (c >= 0) && (c <= dim) );
85 return info_[ c ].size();
86 }
87
99 int size ( int i, int c, int cc ) const
100 {
101 assert( (i >= 0) && (i < size( c )) );
102 return info_[ c ][ i ].size( cc );
103 }
104
118 int subEntity ( int i, int c, int ii, int cc ) const
119 {
120 assert( (i >= 0) && (i < size( c )) );
121 return info_[ c ][ i ].number( ii, cc );
122 }
123
132 const GeometryType &type ( int i, int c ) const
133 {
134 assert( (i >= 0) && (i < size( c )) );
135 return info_[ c ][ i ].type();
136 }
137
139 const GeometryType &type () const { return type( 0, 0 ); }
140
150 const FieldVector< ctype, dim > &position( int i, int c ) const
151 {
152 assert( (c >= 0) && (c <= dim) );
153 return baryCenters_[ c ][ i ];
154 }
155
163 bool checkInside ( const FieldVector< ctype, dim > &local ) const
164 {
165 const ctype tolerance = ctype( 64 ) * std::numeric_limits< ctype >::epsilon();
166 return GenericGeometry::template checkInside< ctype, dim >( type().id(), dim, local, tolerance );
167 }
168
182 template< int codim >
183 bool
184 DUNE_DEPRECATED_MSG("Method will be removed after dune-geometry-2.4")
185 checkInside ( const FieldVector< ctype, dim-codim > &local, int i ) const
186 {
187 const ctype tolerance = ctype( 64 ) * std::numeric_limits< ctype >::epsilon();
188 return GenericGeometry::template checkInside< ctype, dim-codim >( type( i, codim ).id(), dim-codim, local, tolerance );
189 }
190
202 template< int codim >
203 typename Codim< codim >::Geometry geometry ( int i ) const
204 {
205 integral_constant< int, codim > codimVariable;
206 return geometries_[ codimVariable ][ i ];
207 }
208
210 ctype volume () const
211 {
212 return volume_;
213 }
214
223 {
224 assert( (face >= 0) && (face < int( integrationNormals_.size() )) );
225 return integrationNormals_[ face ];
226 }
227
228 private:
229 void initialize ( unsigned int topologyId )
230 {
231 assert( topologyId < GenericGeometry::numTopologies( dim ) );
232
233 // set up subentities
234 for( int codim = 0; codim <= dim; ++codim )
235 {
236 const unsigned int size = GenericGeometry::size( topologyId, dim, codim );
237 info_[ codim ].resize( size );
238 for( unsigned int i = 0; i < size; ++i )
239 info_[ codim ][ i ].initialize( topologyId, codim, i );
240 }
241
242 // compute corners
243 const unsigned int numVertices = size( dim );
244 baryCenters_[ dim ].resize( numVertices );
245 GenericGeometry::referenceCorners( topologyId, dim, &(baryCenters_[ dim ][ 0 ]) );
246
247 // compute barycenters
248 for( int codim = 0; codim < dim; ++codim )
249 {
250 baryCenters_[ codim ].resize( size(codim) );
251 for( int i = 0; i < size( codim ); ++i )
252 {
253 baryCenters_[ codim ][ i ] = FieldVector< ctype, dim >( ctype( 0 ) );
254 const unsigned int numCorners = size( i, codim, dim );
255 for( unsigned int j = 0; j < numCorners; ++j )
256 baryCenters_[ codim ][ i ] += baryCenters_[ dim ][ subEntity( i, codim, j, dim ) ];
257 baryCenters_[ codim ][ i ] *= ctype( 1 ) / ctype( numCorners );
258 }
259 }
260
261 // compute reference element volume
262 volume_ = GenericGeometry::template referenceVolume< ctype >( topologyId, dim );
263
264 // compute integration outer normals
265 if( dim > 0 )
266 {
267 integrationNormals_.resize( size( 1 ) );
268 GenericGeometry::referenceIntegrationOuterNormals( topologyId, dim, &(integrationNormals_[ 0 ]) );
269 }
270
271 // set up geometries
273 }
274
276 template< int codim >
277 struct GeometryArray
278 : public std::vector< typename Codim< codim >::Geometry >
279 {};
280
282 typedef GenericGeometry::CodimTable< GeometryArray, dim > GeometryTable;
283
285 ctype volume_;
286
287 std::vector< FieldVector< ctype, dim > > baryCenters_[ dim+1 ];
288 std::vector< FieldVector< ctype, dim > > integrationNormals_;
289
291 GeometryTable geometries_;
292
293 std::vector< SubEntityInfo > info_[ dim+1 ];
294 };
295
297 template< class ctype, int dim >
298 struct ReferenceElement< ctype, dim >::SubEntityInfo
299 {
301 : numbering_( nullptr )
302 {
303 std::fill( offset_.begin(), offset_.end(), 0 );
304 }
305
306 SubEntityInfo ( const SubEntityInfo &other )
307 : offset_( other.offset_ ),
308 type_( other.type_ )
309 {
310 numbering_ = allocate();
311 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
312 }
313
314 ~SubEntityInfo () { deallocate( numbering_ ); }
315
316 const SubEntityInfo &operator= ( const SubEntityInfo &other )
317 {
318 type_ = other.type_;
319 offset_ = other.offset_;
320
321 deallocate( numbering_ );
322 numbering_ = allocate();
323 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
324
325 return *this;
326 }
327
328 int size ( int cc ) const
329 {
330 assert( (cc >= codim()) && (cc <= dim) );
331 return (offset_[ cc+1 ] - offset_[ cc ]);
332 }
333
334 int number ( int ii, int cc ) const
335 {
336 assert( (ii >= 0) && (ii < size( cc )) );
337 return numbering_[ offset_[ cc ] + ii ];
338 }
339
340 const GeometryType &type () const { return type_; }
341
342 void initialize ( unsigned int topologyId, int codim, unsigned int i )
343 {
344 const unsigned int subId = GenericGeometry::subTopologyId( topologyId, dim, codim, i );
345 type_ = GeometryType( subId, dim-codim );
346
347 // compute offsets
348 for( int cc = 0; cc <= codim; ++cc )
349 offset_[ cc ] = 0;
350 for( int cc = codim; cc <= dim; ++cc )
351 offset_[ cc+1 ] = offset_[ cc ] + GenericGeometry::size( subId, dim-codim, cc-codim );
352
353 // compute subnumbering
354 deallocate( numbering_ );
355 numbering_ = allocate();
356 for( int cc = codim; cc <= dim; ++cc )
357 GenericGeometry::subTopologyNumbering( topologyId, dim, codim, i, cc-codim, numbering_+offset_[ cc ], numbering_+offset_[ cc+1 ] );
358 }
359
360 protected:
361 int codim () const { return dim - type().dim(); }
362
363 unsigned int *allocate () { return (capacity() != 0 ? new unsigned int[ capacity() ] : nullptr); }
364 void deallocate ( unsigned int *ptr ) { delete[] ptr; }
365 unsigned int capacity () const { return offset_[ dim+1 ]; }
366
367 private:
368 unsigned int *numbering_;
369 array< unsigned int, dim+2 > offset_;
370 GeometryType type_;
371 };
372
373
374 template< class ctype, int dim >
375 template< int codim >
376 struct ReferenceElement< ctype, dim >::CreateGeometries
377 {
378 template< int cc >
379 static const ReferenceElement< ctype, dim-cc > &
380 subRefElement( const ReferenceElement< ctype, dim > &refElement, int i, integral_constant< int, cc > )
381 {
382 return ReferenceElements< ctype, dim-cc >::general( refElement.type( i, cc ) );
383 }
384
385 static const ReferenceElement< ctype, dim > &
386 subRefElement( const ReferenceElement< ctype, dim > &refElement, int i, integral_constant< int, 0 > )
387 {
389 return refElement;
390 }
391
392 static void apply ( const ReferenceElement< ctype, dim > &refElement, GeometryTable &geometries )
393 {
394 const int size = refElement.size( codim );
395 std::vector< FieldVector< ctype, dim > > origins( size );
396 std::vector< FieldMatrix< ctype, dim - codim, dim > > jacobianTransposeds( size );
397 GenericGeometry::referenceEmbeddings( refElement.type().id(), dim, codim, &(origins[ 0 ]), &(jacobianTransposeds[ 0 ]) );
398
399 integral_constant< int, codim > codimVariable;
400 geometries[ codimVariable ].reserve( size );
401 for( int i = 0; i < size; ++i )
402 {
403 typename Codim< codim >::Geometry geometry( subRefElement( refElement, i, codimVariable ), origins[ i ], jacobianTransposeds[ i ] );
404 geometries[ codimVariable ].push_back( geometry );
405 }
406 }
407 };
408
409
410
411 // ReferenceElementContainer
412 // -------------------------
413
414 template< class ctype, int dim >
415 class ReferenceElementContainer
416 {
417 static const unsigned int numTopologies = (1u << dim);
418
419 public:
420 typedef ReferenceElement< ctype, dim > value_type;
421 typedef const value_type *const_iterator;
422
423 ReferenceElementContainer ()
424 {
425 for( unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
426 values_[ topologyId ].initialize( topologyId );
427 }
428
429 const value_type &operator() ( const GeometryType &type ) const
430 {
431 assert( type.dim() == dim );
432 return values_[ type.id() ];
433 }
434
435 const value_type &simplex () const
436 {
437 return values_[ GenericGeometry::SimplexTopology< dim >::type::id ];
438 }
439
440 const value_type &cube () const
441 {
442 return values_[ GenericGeometry::CubeTopology< dim >::type::id ];
443 }
444
445 const value_type &pyramid () const
446 {
447 return values_[ GenericGeometry::PyramidTopology< dim >::type::id ];
448 }
449
450 const value_type &prism () const
451 {
452 return values_[ GenericGeometry::PrismTopology< dim >::type::id ];
453 }
454
455 const_iterator begin () const { return values_; }
456 const_iterator end () const { return values_ + numTopologies; }
457
458 private:
459 value_type values_[ numTopologies ];
460 };
461
462
463
464 // ReferenceElements
465 // ------------------------
466
477 template< class ctype, int dim >
479 {
481
483 static const ReferenceElement< ctype, dim > &
484 general ( const GeometryType &type )
485 {
486 return container() ( type );
487 }
488
491 {
492 return container().simplex();
493 }
494
497 {
498 return container().cube();
499 }
500
501 static Iterator begin () { return container().begin(); }
502 static Iterator end () { return container().end(); }
503
504 private:
505 DUNE_EXPORT static const ReferenceElementContainer< ctype, dim > &container ()
506 {
507 static ReferenceElementContainer< ctype, dim > container;
508 return container;
509 }
510 };
511
512} // namespace Dune
513
514#endif // #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
An implementation of the Geometry interface for affine geometries.
Fallback implementation of the std::array class (a static array)
Implementation of the Geometry interface for affine geometries.
Definition: affinegeometry.hh:39
A static loop using TMP.
Definition: forloop.hh:110
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
unsigned int dim() const
Return dimension of the type.
Definition: type.hh:321
unsigned int id() const
Return the topology id the type.
Definition: type.hh:326
This class provides access to geometric and topological properties of a reference element.
Definition: referenceelements.hh:55
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:82
int size(int i, int c, int cc) const
number of subentities of codimension cc of subentity (i,c)
Definition: referenceelements.hh:99
const FieldVector< ctype, dim > & position(int i, int c) const
position of the barycenter of entity (i,c)
Definition: referenceelements.hh:150
ctype volume() const
obtain the volume of the reference element
Definition: referenceelements.hh:210
int subEntity(int i, int c, int ii, int cc) const
obtain number of ii-th subentity with codim cc of (i,c)
Definition: referenceelements.hh:118
bool checkInside(const FieldVector< ctype, dim > &local) const
check if a coordinate is in the reference element
Definition: referenceelements.hh:163
const GeometryType & type(int i, int c) const
obtain the type of subentity (i,c)
Definition: referenceelements.hh:132
Codim< codim >::Geometry geometry(int i) const
obtain the embedding of subentity (i,codim) into the reference element
Definition: referenceelements.hh:203
const FieldVector< ctype, dim > & integrationOuterNormal(int face) const
obtain the integration outer normal of the reference element
Definition: referenceelements.hh:222
const GeometryType & type() const
obtain the type of this reference element
Definition: referenceelements.hh:139
A static for loop for template meta-programming.
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
Dune namespace.
Definition: alignment.hh:10
Fallback implementation of the nullptr object in C++0x.
Collection of types depending on the codimension.
Definition: referenceelements.hh:73
AffineGeometry< ctype, dim-codim, dim > Geometry
type of geometry embedding a subentity into the reference element
Definition: referenceelements.hh:75
topological information about the subentities of a reference element
Definition: referenceelements.hh:299
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:479
static const ReferenceElement< ctype, dim > & simplex()
get simplex reference elements
Definition: referenceelements.hh:490
static const ReferenceElement< ctype, dim > & cube()
get hypercube reference elements
Definition: referenceelements.hh:496
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:484
Traits for type conversions and type information.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Definition of macros controlling symbol visibility at the ABI level.
#define DUNE_EXPORT
Export a symbol as part of the public ABI.
Definition: visibility.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)