3#ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
4#define DUNE_GEOMETRY_REFERENCEELEMENTS_HH
17#include <dune/geometry/genericgeometry/codimtable.hh>
18#include <dune/geometry/genericgeometry/subtopologies.hh>
19#include <dune/geometry/genericgeometry/referencedomain.hh>
27 template<
class ctype,
int dim >
28 class ReferenceElementContainer;
30 template<
class ctype,
int dim >
31 struct ReferenceElements;
53 template<
class ctype,
int dim >
58 friend class ReferenceElementContainer< ctype, dim >;
67 template<
int codim >
struct CreateGeometries;
84 assert( (c >= 0) && (c <= dim) );
85 return info_[ c ].size();
99 int size (
int i,
int c,
int cc )
const
101 assert( (i >= 0) && (i <
size( c )) );
102 return info_[ c ][ i ].size( cc );
120 assert( (i >= 0) && (i <
size( c )) );
121 return info_[ c ][ i ].number( ii, cc );
134 assert( (i >= 0) && (i <
size( c )) );
135 return info_[ c ][ i ].type();
152 assert( (c >= 0) && (c <= dim) );
153 return baryCenters_[ c ][ i ];
165 const ctype tolerance = ctype( 64 ) * std::numeric_limits< ctype >::epsilon();
166 return GenericGeometry::template checkInside< ctype, dim >(
type().
id(), dim, local, tolerance );
182 template<
int codim >
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 );
202 template<
int codim >
205 integral_constant< int, codim > codimVariable;
206 return geometries_[ codimVariable ][ i ];
224 assert( (face >= 0) && (face <
int( integrationNormals_.size() )) );
225 return integrationNormals_[ face ];
229 void initialize (
unsigned int topologyId )
231 assert( topologyId < GenericGeometry::numTopologies( dim ) );
234 for(
int codim = 0; codim <= dim; ++codim )
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 );
243 const unsigned int numVertices =
size( dim );
244 baryCenters_[ dim ].resize( numVertices );
245 GenericGeometry::referenceCorners( topologyId, dim, &(baryCenters_[ dim ][ 0 ]) );
248 for(
int codim = 0; codim < dim; ++codim )
250 baryCenters_[ codim ].resize(
size(codim) );
251 for(
int i = 0; i <
size( codim ); ++i )
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 );
262 volume_ = GenericGeometry::template referenceVolume< ctype >( topologyId, dim );
267 integrationNormals_.resize(
size( 1 ) );
268 GenericGeometry::referenceIntegrationOuterNormals( topologyId, dim, &(integrationNormals_[ 0 ]) );
276 template<
int codim >
278 :
public std::vector< typename Codim< codim >::Geometry >
282 typedef GenericGeometry::CodimTable< GeometryArray, dim > GeometryTable;
287 std::vector< FieldVector< ctype, dim > > baryCenters_[ dim+1 ];
288 std::vector< FieldVector< ctype, dim > > integrationNormals_;
291 GeometryTable geometries_;
293 std::vector< SubEntityInfo > info_[ dim+1 ];
297 template<
class ctype,
int dim >
301 : numbering_(
nullptr )
303 std::fill( offset_.begin(), offset_.end(), 0 );
307 : offset_( other.offset_ ),
310 numbering_ = allocate();
311 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
319 offset_ = other.offset_;
321 deallocate( numbering_ );
322 numbering_ = allocate();
323 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
328 int size (
int cc )
const
330 assert( (cc >= codim()) && (cc <= dim) );
331 return (offset_[ cc+1 ] - offset_[ cc ]);
334 int number (
int ii,
int cc )
const
336 assert( (ii >= 0) && (ii <
size( cc )) );
337 return numbering_[ offset_[ cc ] + ii ];
342 void initialize (
unsigned int topologyId,
int codim,
unsigned int i )
344 const unsigned int subId = GenericGeometry::subTopologyId( topologyId, dim, codim, i );
348 for(
int cc = 0; cc <= codim; ++cc )
350 for(
int cc = codim; cc <= dim; ++cc )
351 offset_[ cc+1 ] = offset_[ cc ] + GenericGeometry::size( subId, dim-codim, cc-codim );
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 ] );
361 int codim ()
const {
return dim -
type().
dim(); }
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 ]; }
368 unsigned int *numbering_;
369 array< unsigned int, dim+2 > offset_;
374 template<
class ctype,
int dim >
375 template<
int codim >
392 static void apply (
const ReferenceElement< ctype, dim > &refElement, GeometryTable &geometries )
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 ]) );
399 integral_constant< int, codim > codimVariable;
400 geometries[ codimVariable ].reserve(
size );
401 for(
int i = 0; i <
size; ++i )
404 geometries[ codimVariable ].push_back(
geometry );
414 template<
class ctype,
int dim >
415 class ReferenceElementContainer
417 static const unsigned int numTopologies = (1u << dim);
420 typedef ReferenceElement< ctype, dim > value_type;
421 typedef const value_type *const_iterator;
423 ReferenceElementContainer ()
425 for(
unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
426 values_[ topologyId ].initialize( topologyId );
429 const value_type &operator() (
const GeometryType &type )
const
431 assert( type.dim() == dim );
432 return values_[ type.id() ];
435 const value_type &simplex ()
const
437 return values_[ GenericGeometry::SimplexTopology< dim >::type::id ];
440 const value_type &cube ()
const
442 return values_[ GenericGeometry::CubeTopology< dim >::type::id ];
445 const value_type &pyramid ()
const
447 return values_[ GenericGeometry::PyramidTopology< dim >::type::id ];
450 const value_type &prism ()
const
452 return values_[ GenericGeometry::PrismTopology< dim >::type::id ];
455 const_iterator begin ()
const {
return values_; }
456 const_iterator end ()
const {
return values_ + numTopologies; }
459 value_type values_[ numTopologies ];
477 template<
class ctype,
int dim >
486 return container() ( type );
492 return container().simplex();
498 return container().cube();
501 static Iterator begin () {
return container().begin(); }
502 static Iterator end () {
return container().end(); }
505 DUNE_EXPORT static const ReferenceElementContainer< ctype, dim > &container ()
507 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
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