3#ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
4#define DUNE_GEOMETRY_REFERENCEELEMENTS_HH
18#include <dune/geometry/genericgeometry/codimtable.hh>
19#include <dune/geometry/genericgeometry/subtopologies.hh>
20#include <dune/geometry/genericgeometry/referencedomain.hh>
24#include "genericreferenceelements.hh"
32 template<
class ctype,
int dim >
33 class ReferenceElementContainer;
35 template<
class ctype,
int dim >
36 struct ReferenceElements;
56 template<
class ctype,
int dim >
61 friend class ReferenceElementContainer< ctype, dim >;
70 template<
int codim >
struct CreateGeometries;
79 typedef Geometry Mapping DUNE_DEPRECATED_MSG (
"Use Geometry instead." );
88 assert( (c >= 0) && (c <= dim) );
89 return info_[ c ].size();
103 int size (
int i,
int c,
int cc )
const
105 assert( (i >= 0) && (i <
size( c )) );
106 return info_[ c ][ i ].size( cc );
124 assert( (i >= 0) && (i <
size( c )) );
125 return info_[ c ][ i ].number( ii, cc );
138 assert( (i >= 0) && (i <
size( c )) );
139 return info_[ c ][ i ].type();
156 assert( (c >= 0) && (c <= dim) );
157 return baryCenters_[ c ][ i ];
169 const ctype tolerance = ctype( 64 ) * std::numeric_limits< ctype >::epsilon();
170 return GenericGeometry::template checkInside< ctype, dim >(
type().
id(), dim, local, tolerance );
187 template<
int codim >
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 );
210 template<
int codim >
213 global( const
FieldVector< ctype, dim-codim > &local,
int i,
int c )
const
217 assert( c == codim );
218 return geometry< codim >( i ).global( local );
234 template<
int codim >
237 global( const
FieldVector< ctype, dim-codim > &local,
int i )
const
239 return geometry< codim >( i ).global( local );
253 template<
int codim >
257 return geometries_[ codimVariable ][ i ];
271 template<
int codim >
276 return geometries_[ codimVariable ][ i ];
294 assert( (face >= 0) && (face <
int( integrationNormals_.size() )) );
295 return integrationNormals_[ face ];
299 DUNE_DEPRECATED_MSG(
"This method has always returned the integration outer normal; use integrationOuterNormal instead." )
311 initialize( topologyId );
315 void initialize (
unsigned int topologyId )
317 assert( topologyId < GenericGeometry::numTopologies( dim ) );
320 for(
int codim = 0; codim <= dim; ++codim )
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 );
329 const unsigned int numVertices =
size( dim );
330 baryCenters_[ dim ].resize( numVertices );
331 GenericGeometry::referenceCorners( topologyId, dim, &(baryCenters_[ dim ][ 0 ]) );
334 for(
int codim = 0; codim < dim; ++codim )
336 baryCenters_[ codim ].resize(
size(codim) );
337 for(
int i = 0; i <
size( codim ); ++i )
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 );
348 volume_ = GenericGeometry::template referenceVolume< ctype >( topologyId, dim );
353 integrationNormals_.resize(
size( 1 ) );
354 GenericGeometry::referenceIntegrationOuterNormals( topologyId, dim, &(integrationNormals_[ 0 ]) );
362 template<
int codim >
364 :
public std::vector< typename Codim< codim >::Geometry >
368 typedef GenericGeometry::CodimTable< GeometryArray, dim > GeometryTable;
373 std::vector< FieldVector< ctype, dim > > baryCenters_[ dim+1 ];
374 std::vector< FieldVector< ctype, dim > > integrationNormals_;
377 GeometryTable geometries_;
379 std::vector< SubEntityInfo > info_[ dim+1 ];
383 template<
class ctype,
int dim >
387 : numbering_(
nullptr )
389 std::fill( offset_.begin(), offset_.end(), 0 );
393 : offset_( other.offset_ ),
396 numbering_ = allocate();
397 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
405 offset_ = other.offset_;
407 deallocate( numbering_ );
408 numbering_ = allocate();
409 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
414 int size (
int cc )
const
416 assert( (cc >= codim()) && (cc <= dim) );
417 return (offset_[ cc+1 ] - offset_[ cc ]);
420 int number (
int ii,
int cc )
const
422 assert( (ii >= 0) && (ii <
size( cc )) );
423 return numbering_[ offset_[ cc ] + ii ];
428 void initialize (
unsigned int topologyId,
int codim,
unsigned int i )
430 const unsigned int subId = GenericGeometry::subTopologyId( topologyId, dim, codim, i );
434 for(
int cc = 0; cc <= codim; ++cc )
436 for(
int cc = codim; cc <= dim; ++cc )
437 offset_[ cc+1 ] = offset_[ cc ] + GenericGeometry::size( subId, dim-codim, cc-codim );
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 ] );
447 int codim ()
const {
return dim -
type().
dim(); }
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 ]; }
454 unsigned int *numbering_;
460 template<
class ctype,
int dim >
461 template<
int codim >
478 static void apply (
const ReferenceElement< ctype, dim > &refElement, GeometryTable &geometries )
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 ]) );
485 integral_constant< int, codim > codimVariable;
486 geometries[ codimVariable ].reserve(
size );
487 for(
int i = 0; i <
size; ++i )
489 typename Codim< codim >::Geometry geometry( subRefElement( refElement, i, codimVariable ), origins[ i ], jacobianTransposeds[ i ] );
490 geometries[ codimVariable ].push_back( geometry );
500 template<
class ctype,
int dim >
501 class ReferenceElementContainer
503 static const unsigned int numTopologies = (1u << dim);
506 typedef ReferenceElement< ctype, dim > value_type;
507 typedef const value_type *const_iterator;
509 ReferenceElementContainer ()
511 for(
unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
512 values_[ topologyId ].initialize( topologyId );
515 const value_type &operator() (
const GeometryType &type )
const
517 assert( type.dim() == dim );
518 return values_[ type.id() ];
521 const value_type &simplex ()
const
523 return values_[ GenericGeometry::SimplexTopology< dim >::type::id ];
526 const value_type &cube ()
const
528 return values_[ GenericGeometry::CubeTopology< dim >::type::id ];
531 const value_type &pyramid ()
const
533 return values_[ GenericGeometry::PyramidTopology< dim >::type::id ];
536 const value_type &prism ()
const
538 return values_[ GenericGeometry::PrismTopology< dim >::type::id ];
541 const_iterator begin ()
const {
return values_; }
542 const_iterator end ()
const {
return values_ + numTopologies; }
545 value_type values_[ numTopologies ];
561 template<
class ctype,
int dim >
570 return container() ( type );
576 return container().simplex();
582 return container().cube();
585 static Iterator begin () {
return container().begin(); }
586 static Iterator end () {
return container().end(); }
589 DUNE_EXPORT static const ReferenceElementContainer< ctype, dim > &container ()
591 static ReferenceElementContainer< ctype, dim > container;
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:58
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
const Codim< codim >::Mapping & mapping(int i) const
obtain the embedding of subentity (i,codim) into the reference element
Definition: referenceelements.hh:273
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
const FieldVector< ctype, dim > & position(int i, int c) const
position of the barycenter of entity (i,c)
Definition: referenceelements.hh:154
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 GeometryType & type(int i, int c) const
obtain the type of subentity (i,c)
Definition: referenceelements.hh:136
Codim< codim >::Geometry geometry(int i) const
obtain the embedding of subentity (i,codim) into the reference element
Definition: referenceelements.hh:254
const FieldVector< ctype, dim > & integrationOuterNormal(int face) const
obtain the integration outer normal of the reference element
Definition: referenceelements.hh:292
const GeometryType & type() const
obtain the type of this reference element
Definition: referenceelements.hh:143
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