Dune Core Modules (2.3.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 
10 #include <dune/common/array.hh>
11 #include <dune/common/forloop.hh>
12 #include <dune/common/nullptr.hh>
15 #include <dune/common/unused.hh>
16 
18 #include <dune/geometry/genericgeometry/codimtable.hh>
19 #include <dune/geometry/genericgeometry/subtopologies.hh>
20 #include <dune/geometry/genericgeometry/referencedomain.hh>
21 
22 // for backward compatibility include header
23 // with deprecated classes. Remove after Dune 2.3
24 #include "genericreferenceelements.hh"
25 
26 namespace Dune
27 {
28 
29  // Internal Forward Declarations
30  // -----------------------------
31 
32  template< class ctype, int dim >
33  class ReferenceElementContainer;
34 
35  template< class ctype, int dim >
36  struct ReferenceElements;
37 
38 
39 
56  template< class ctype, int dim >
57  class ReferenceElement
58  {
59  typedef ReferenceElement< ctype, dim > This;
60 
61  friend class ReferenceElementContainer< ctype, dim >;
62 
63  struct SubEntityInfo;
64 
65  // make copy constructor private
66  ReferenceElement ( const This & );
67 
68  ReferenceElement () {}
69 
70  template< int codim > struct CreateGeometries;
71 
72  public:
74  template< int codim >
75  struct Codim
76  {
78  typedef AffineGeometry< ctype, dim-codim, dim > Geometry;
79  typedef Geometry Mapping DUNE_DEPRECATED_MSG ( "Use Geometry instead." );
80  };
81 
86  int size ( int c ) const
87  {
88  assert( (c >= 0) && (c <= dim) );
89  return info_[ c ].size();
90  }
91 
103  int size ( int i, int c, int cc ) const
104  {
105  assert( (i >= 0) && (i < size( c )) );
106  return info_[ c ][ i ].size( cc );
107  }
108 
122  int subEntity ( int i, int c, int ii, int cc ) const
123  {
124  assert( (i >= 0) && (i < size( c )) );
125  return info_[ c ][ i ].number( ii, cc );
126  }
127 
136  const GeometryType &type ( int i, int c ) const
137  {
138  assert( (i >= 0) && (i < size( c )) );
139  return info_[ c ][ i ].type();
140  }
141 
143  const GeometryType &type () const { return type( 0, 0 ); }
144 
154  const FieldVector< ctype, dim > &position( int i, int c ) const
155  {
156  assert( (c >= 0) && (c <= dim) );
157  return baryCenters_[ c ][ i ];
158  }
159 
167  bool checkInside ( const FieldVector< ctype, dim > &local ) const
168  {
169  const ctype tolerance = ctype( 64 ) * std::numeric_limits< ctype >::epsilon();
170  return GenericGeometry::template checkInside< ctype, dim >( type().id(), dim, local, tolerance );
171  }
172 
187  template< int codim >
188  bool checkInside ( const FieldVector< ctype, dim-codim > &local, int i ) const
189  {
190  const ctype tolerance = ctype( 64 ) * std::numeric_limits< ctype >::epsilon();
191  return GenericGeometry::template checkInside< ctype, dim >( type( i, codim ).id(), dim-codim, local, tolerance );
192  }
193 
210  template< int codim >
212  DUNE_DEPRECATED_MSG( "Use geometry< codim >( i ).global( local ) instead." )
213  global( const FieldVector< ctype, dim-codim > &local, int i, int c ) const
214  {
215  if( c != codim )
216  DUNE_THROW( Exception, "Local Coordinate Type does not correspond to codimension c." );
217  assert( c == codim );
218  return geometry< codim >( i ).global( local );
219  }
220 
234  template< int codim >
236  DUNE_DEPRECATED_MSG( "Use geometry< codim >( i ).global( local ) instead." )
237  global( const FieldVector< ctype, dim-codim > &local, int i ) const
238  {
239  return geometry< codim >( i ).global( local );
240  }
241 
253  template< int codim >
254  typename Codim< codim >::Geometry geometry ( int i ) const
255  {
256  integral_constant< int, codim > codimVariable;
257  return geometries_[ codimVariable ][ i ];
258  }
259 
271  template< int codim >
272  DUNE_DEPRECATED_MSG( "Use geometry(i) instead." )
273  const typename Codim< codim >::Mapping &mapping( int i ) const
274  {
275  integral_constant< int, codim > codimVariable;
276  return geometries_[ codimVariable ][ i ];
277  }
278 
280  ctype volume () const
281  {
282  return volume_;
283  }
284 
293  {
294  assert( (face >= 0) && (face < int( integrationNormals_.size() )) );
295  return integrationNormals_[ face ];
296  }
297 
298  const FieldVector< ctype, dim > &volumeOuterNormal ( int face ) const
299  DUNE_DEPRECATED_MSG( "This method has always returned the integration outer normal; use integrationOuterNormal instead." )
300  {
301  return integrationOuterNormal( face );
302  }
303 
308  void initializeTopology ( unsigned int topologyId )
309  DUNE_DEPRECATED_MSG( "initializeTopology has never been an official interface method." )
310  {
311  initialize( topologyId );
312  }
313 
314  private:
315  void initialize ( unsigned int topologyId )
316  {
317  assert( topologyId < GenericGeometry::numTopologies( dim ) );
318 
319  // set up subentities
320  for( int codim = 0; codim <= dim; ++codim )
321  {
322  const unsigned int size = GenericGeometry::size( topologyId, dim, codim );
323  info_[ codim ].resize( size );
324  for( unsigned int i = 0; i < size; ++i )
325  info_[ codim ][ i ].initialize( topologyId, codim, i );
326  }
327 
328  // compute corners
329  const unsigned int numVertices = size( dim );
330  baryCenters_[ dim ].resize( numVertices );
331  GenericGeometry::referenceCorners( topologyId, dim, &(baryCenters_[ dim ][ 0 ]) );
332 
333  // compute barycenters
334  for( int codim = 0; codim < dim; ++codim )
335  {
336  baryCenters_[ codim ].resize( size(codim) );
337  for( int i = 0; i < size( codim ); ++i )
338  {
339  baryCenters_[ codim ][ i ] = FieldVector< ctype, dim >( ctype( 0 ) );
340  const unsigned int numCorners = size( i, codim, dim );
341  for( unsigned int j = 0; j < numCorners; ++j )
342  baryCenters_[ codim ][ i ] += baryCenters_[ dim ][ subEntity( i, codim, j, dim ) ];
343  baryCenters_[ codim ][ i ] *= ctype( 1 ) / ctype( numCorners );
344  }
345  }
346 
347  // compute reference element volume
348  volume_ = GenericGeometry::template referenceVolume< ctype >( topologyId, dim );
349 
350  // compute integration outer normals
351  if( dim > 0 )
352  {
353  integrationNormals_.resize( size( 1 ) );
354  GenericGeometry::referenceIntegrationOuterNormals( topologyId, dim, &(integrationNormals_[ 0 ]) );
355  }
356 
357  // set up geometries
359  }
360 
362  template< int codim >
363  struct GeometryArray
364  : public std::vector< typename Codim< codim >::Geometry >
365  {};
366 
368  typedef GenericGeometry::CodimTable< GeometryArray, dim > GeometryTable;
369 
371  ctype volume_;
372 
373  std::vector< FieldVector< ctype, dim > > baryCenters_[ dim+1 ];
374  std::vector< FieldVector< ctype, dim > > integrationNormals_;
375 
377  GeometryTable geometries_;
378 
379  std::vector< SubEntityInfo > info_[ dim+1 ];
380  };
381 
383  template< class ctype, int dim >
384  struct ReferenceElement< ctype, dim >::SubEntityInfo
385  {
386  SubEntityInfo ()
387  : numbering_( nullptr )
388  {
389  std::fill( offset_.begin(), offset_.end(), 0 );
390  }
391 
392  SubEntityInfo ( const SubEntityInfo &other )
393  : offset_( other.offset_ ),
394  type_( other.type_ )
395  {
396  numbering_ = allocate();
397  std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
398  }
399 
400  ~SubEntityInfo () { deallocate( numbering_ ); }
401 
402  const SubEntityInfo &operator= ( const SubEntityInfo &other )
403  {
404  type_ = other.type_;
405  offset_ = other.offset_;
406 
407  deallocate( numbering_ );
408  numbering_ = allocate();
409  std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
410 
411  return *this;
412  }
413 
414  int size ( int cc ) const
415  {
416  assert( (cc >= codim()) && (cc <= dim) );
417  return (offset_[ cc+1 ] - offset_[ cc ]);
418  }
419 
420  int number ( int ii, int cc ) const
421  {
422  assert( (ii >= 0) && (ii < size( cc )) );
423  return numbering_[ offset_[ cc ] + ii ];
424  }
425 
426  const GeometryType &type () const { return type_; }
427 
428  void initialize ( unsigned int topologyId, int codim, unsigned int i )
429  {
430  const unsigned int subId = GenericGeometry::subTopologyId( topologyId, dim, codim, i );
431  type_ = GeometryType( subId, dim-codim );
432 
433  // compute offsets
434  for( int cc = 0; cc <= codim; ++cc )
435  offset_[ cc ] = 0;
436  for( int cc = codim; cc <= dim; ++cc )
437  offset_[ cc+1 ] = offset_[ cc ] + GenericGeometry::size( subId, dim-codim, cc-codim );
438 
439  // compute subnumbering
440  deallocate( numbering_ );
441  numbering_ = allocate();
442  for( int cc = codim; cc <= dim; ++cc )
443  GenericGeometry::subTopologyNumbering( topologyId, dim, codim, i, cc-codim, numbering_+offset_[ cc ], numbering_+offset_[ cc+1 ] );
444  }
445 
446  protected:
447  int codim () const { return dim - type().dim(); }
448 
449  unsigned int *allocate () { return (capacity() != 0 ? new unsigned int[ capacity() ] : nullptr); }
450  void deallocate ( unsigned int *ptr ) { delete[] ptr; }
451  unsigned int capacity () const { return offset_[ dim+1 ]; }
452 
453  private:
454  unsigned int *numbering_;
456  GeometryType type_;
457  };
458 
459 
460  template< class ctype, int dim >
461  template< int codim >
462  struct ReferenceElement< ctype, dim >::CreateGeometries
463  {
464  template< int cc >
465  static const ReferenceElement< ctype, dim-cc > &
466  subRefElement( const ReferenceElement< ctype, dim > &refElement, int i, integral_constant< int, cc > )
467  {
468  return ReferenceElements< ctype, dim-cc >::general( refElement.type( i, cc ) );
469  }
470 
471  static const ReferenceElement< ctype, dim > &
472  subRefElement( const ReferenceElement< ctype, dim > &refElement, int i, integral_constant< int, 0 > )
473  {
475  return refElement;
476  }
477 
478  static void apply ( const ReferenceElement< ctype, dim > &refElement, GeometryTable &geometries )
479  {
480  const int size = refElement.size( codim );
481  std::vector< FieldVector< ctype, dim > > origins( size );
482  std::vector< FieldMatrix< ctype, dim - codim, dim > > jacobianTransposeds( size );
483  GenericGeometry::referenceEmbeddings( refElement.type().id(), dim, codim, &(origins[ 0 ]), &(jacobianTransposeds[ 0 ]) );
484 
485  integral_constant< int, codim > codimVariable;
486  geometries[ codimVariable ].reserve( size );
487  for( int i = 0; i < size; ++i )
488  {
489  typename Codim< codim >::Geometry geometry( subRefElement( refElement, i, codimVariable ), origins[ i ], jacobianTransposeds[ i ] );
490  geometries[ codimVariable ].push_back( geometry );
491  }
492  }
493  };
494 
495 
496 
497  // ReferenceElementContainer
498  // -------------------------
499 
500  template< class ctype, int dim >
501  class ReferenceElementContainer
502  {
503  static const unsigned int numTopologies = (1u << dim);
504 
505  public:
506  typedef ReferenceElement< ctype, dim > value_type;
507  typedef const value_type *const_iterator;
508 
509  ReferenceElementContainer ()
510  {
511  for( unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
512  values_[ topologyId ].initialize( topologyId );
513  }
514 
515  const value_type &operator() ( const GeometryType &type ) const
516  {
517  assert( type.dim() == dim );
518  return values_[ type.id() ];
519  }
520 
521  const value_type &simplex () const
522  {
523  return values_[ GenericGeometry::SimplexTopology< dim >::type::id ];
524  }
525 
526  const value_type &cube () const
527  {
528  return values_[ GenericGeometry::CubeTopology< dim >::type::id ];
529  }
530 
531  const value_type &pyramid () const
532  {
533  return values_[ GenericGeometry::PyramidTopology< dim >::type::id ];
534  }
535 
536  const value_type &prism () const
537  {
538  return values_[ GenericGeometry::PrismTopology< dim >::type::id ];
539  }
540 
541  const_iterator begin () const { return values_; }
542  const_iterator end () const { return values_ + numTopologies; }
543 
544  private:
545  value_type values_[ numTopologies ];
546  };
547 
548 
549 
550  // ReferenceElements
551  // ------------------------
552 
561  template< class ctype, int dim >
563  {
565 
567  static const ReferenceElement< ctype, dim > &
568  general ( const GeometryType &type )
569  {
570  return container() ( type );
571  }
572 
575  {
576  return container().simplex();
577  }
578 
581  {
582  return container().cube();
583  }
584 
585  static Iterator begin () { return container().begin(); }
586  static Iterator end () { return container().end(); }
587 
588  private:
589  DUNE_EXPORT static const ReferenceElementContainer< ctype, dim > &container ()
590  {
591  static ReferenceElementContainer< ctype, dim > container;
592  return container;
593  }
594  };
595 
596 } // namespace Dune
597 
598 #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
Base class for Dune-Exceptions.
Definition: exceptions.hh:92
A static loop using TMP.
Definition: forloop.hh:223
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:322
This class provides access to geometric and topological properties of a reference element....
Definition: referenceelements.hh:36
void initializeTopology(unsigned int topologyId) DUNE_DEPRECATED_MSG("initializeTopology has never been an official interface method.")
initialize the reference element
Definition: referenceelements.hh:308
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:86
FieldVector< ctype, dim > DUNE_DEPRECATED_MSG("Use geometry< codim >( i ).global( local ) instead.") global(const FieldVector< ctype
map a local coordinate on subentity (i,codim) into the reference element
bool checkInside(const FieldVector< ctype, dim-codim > &local, int i) const
check if a local coordinate is in the reference element of the i-th subentity E with codimension c of...
Definition: referenceelements.hh:188
int size(int i, int c, int cc) const
number of subentities of codimension cc of subentity (i,c)
Definition: referenceelements.hh:103
ctype volume() const
obtain the volume of the reference element
Definition: referenceelements.hh:280
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:122
bool checkInside(const FieldVector< ctype, dim > &local) const
check if a coordinate is in the reference element
Definition: referenceelements.hh:167
const FieldVector< ctype, dim > & position(int i, int c) const
position of the barycenter of entity (i,c)
Definition: referenceelements.hh:154
Codim< codim >::Geometry geometry(int i) const
obtain the embedding of subentity (i,codim) into the reference element
Definition: referenceelements.hh:254
const GeometryType & type(int i, int c) const
obtain the type of subentity (i,c)
Definition: referenceelements.hh:136
const Codim< codim >::Mapping & mapping(int i) const
obtain the embedding of subentity (i,codim) into the reference element
Definition: referenceelements.hh:273
const GeometryType & type() const
obtain the type of this reference element
Definition: referenceelements.hh:143
const FieldVector< ctype, dim > & integrationOuterNormal(int face) const
obtain the integration outer normal of the reference element
Definition: referenceelements.hh:292
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
A static for loop for template meta-programming.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
Fallback implementation of the nullptr object in C++0x.
Collection of types depending on the codimension.
Definition: referenceelements.hh:76
AffineGeometry< ctype, dim-codim, dim > Geometry
type of geometry embedding a subentity into the reference element
Definition: referenceelements.hh:78
topological information about the subentities of a reference element
Definition: referenceelements.hh:385
Class providing access to the singletons of the reference elements. Special methods are available for...
Definition: referenceelements.hh:563
static const ReferenceElement< ctype, dim > & simplex()
get simplex reference elements
Definition: referenceelements.hh:574
static const ReferenceElement< ctype, dim > & cube()
get hypercube reference elements
Definition: referenceelements.hh:580
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:568
Generate a type for a given integral constant.
Definition: typetraits.hh:457
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.80.0 (May 16, 22:29, 2024)