3 #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
4 #define DUNE_GEOMETRY_REFERENCEELEMENTS_HH
9 #include <dune/common/deprecated.hh>
10 #include <dune/common/array.hh>
11 #include <dune/common/forloop.hh>
12 #include <dune/common/nullptr.hh>
13 #include <dune/common/typetraits.hh>
14 #include <dune/common/visibility.hh>
15 #include <dune/common/unused.hh>
32 template<
class ctype,
int dim >
35 template<
class ctype,
int dim >
56 template<
class ctype,
int dim >
70 template<
int codim >
struct CreateGeometries;
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();
154 const FieldVector< ctype, dim > &
position(
int i,
int c )
const
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 >
188 bool checkInside (
const FieldVector< ctype, dim-codim > &local,
int i )
const
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 >
211 FieldVector< ctype, dim >
212 DUNE_DEPRECATED_MSG(
"Use geometry< codim >( i ).global( local ) instead." )
213 global( const FieldVector< ctype, dim-codim > &local,
int i,
int c )
const
216 DUNE_THROW( Exception,
"Local Coordinate Type does not correspond to codimension c." );
217 assert( c == codim );
218 return geometry< codim >( i ).
global( local );
234 template<
int codim >
235 FieldVector< ctype, dim >
236 DUNE_DEPRECATED_MSG(
"Use geometry< codim >( i ).global( local ) instead." )
237 global( const FieldVector< ctype, dim-codim > &local,
int i )
const
239 return geometry< codim >( i ).
global( local );
253 template<
int codim >
256 integral_constant< int, codim > codimVariable;
257 return geometries_[ codimVariable ][ i ];
271 template<
int codim >
272 DUNE_DEPRECATED_MSG(
"Use geometry(i) instead." )
275 integral_constant< int, codim > codimVariable;
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." )
309 DUNE_DEPRECATED_MSG(
"initializeTopology has never been an official interface method." )
311 initialize( topologyId );
315 void initialize (
unsigned int topologyId )
320 for(
int codim = 0; codim <= 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 );
334 for(
int codim = 0; codim < dim; ++codim )
336 baryCenters_[ codim ].resize(
size(codim) );
337 for(
int i = 0; i <
size( codim ); ++i )
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 );
348 volume_ = GenericGeometry::template referenceVolume< ctype >( topologyId, dim );
353 integrationNormals_.resize(
size( 1 ) );
358 Dune::ForLoop< CreateGeometries, 0, dim >::apply( *
this, geometries_ );
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_ );
416 assert( (cc >= codim()) && (cc <= dim) );
417 return (offset_[ cc+1 ] - offset_[ cc ]);
422 assert( (ii >= 0) && (ii <
size( cc )) );
423 return numbering_[ offset_[ cc ] + ii ];
428 void initialize (
unsigned int topologyId,
int codim,
unsigned int i )
434 for(
int cc = 0; cc <= codim; ++cc )
436 for(
int cc = codim; cc <= dim; ++cc )
440 deallocate( numbering_ );
441 numbering_ = allocate();
442 for(
int cc = codim; cc <= dim; ++cc )
449 unsigned int *
allocate () {
return (capacity() != 0 ?
new unsigned int[ capacity() ] :
nullptr); }
451 unsigned int capacity ()
const {
return offset_[ dim+1 ]; }
454 unsigned int *numbering_;
455 array< unsigned int, dim+2 > offset_;
460 template<
class ctype,
int dim >
461 template<
int codim >
471 static const ReferenceElement< ctype, dim > &
472 subRefElement(
const ReferenceElement< ctype, dim > &refElement,
int i, integral_constant< int, 0 > )
474 DUNE_UNUSED_PARAMETER(i);
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 );
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);
511 for(
unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
512 values_[ topologyId ].initialize( topologyId );
517 assert( type.
dim() == dim );
518 return values_[ type.
id() ];
561 template<
class ctype,
int dim >
562 struct ReferenceElements
570 return container() ( type );
576 return container().simplex();
582 return container().cube();
598 #endif // #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
unsigned int subTopologyId(unsigned int topologyId, int dim, int codim, unsigned int i)
Compute the topology id of a given subentity.
Definition: subtopologies.cc:47
unsigned int referenceEmbeddings(unsigned int topologyId, int dim, int codim, FieldVector< ct, cdim > *origins, FieldMatrix< ct, mydim, cdim > *jacobianTransposeds)
Definition: referencedomain.hh:406
int number(int ii, int cc) const
Definition: referenceelements.hh:420
Collection of types depending on the codimension.
Definition: referenceelements.hh:75
const Codim< codim >::Mapping & mapping(int i) const
obtain the embedding of subentity (i,codim) into the reference element
Definition: referenceelements.hh:273
unsigned int referenceIntegrationOuterNormals(unsigned int topologyId, int dim, const FieldVector< ct, cdim > *origins, FieldVector< ct, cdim > *normals)
Definition: referencedomain.hh:471
void deallocate(unsigned int *ptr)
Definition: referenceelements.hh:450
int codim() const
Definition: referenceelements.hh:447
ReferenceElementContainer()
Definition: referenceelements.hh:509
~SubEntityInfo()
Definition: referenceelements.hh:400
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:86
ctype volume() const
obtain the volume of the reference element
Definition: referenceelements.hh:280
unsigned int capacity() const
Definition: referenceelements.hh:451
Codim< codim >::Geometry geometry(int i) const
obtain the embedding of subentity (i,codim) into the reference element
Definition: referenceelements.hh:254
const_iterator begin() const
Definition: referenceelements.hh:541
unsigned int numTopologies(int dim)
obtain the number of topologies of a given dimension
Definition: topologytypes.hh:135
This class provides access to geometric and topological properties of a reference element...
Definition: affinegeometry.hh:25
FieldVector< ctype, dim > global(const FieldVector< ctype, dim-codim > &local, int i, int c) const
map a local coordinate on subentity (i,codim) into the reference element
Definition: referenceelements.hh:213
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
Definition: topologytypes.hh:215
Definition: topologytypes.hh:249
const FieldVector< ctype, dim > & position(int i, int c) const
position of the barycenter of entity (i,c)
Definition: referenceelements.hh:154
const_iterator end() const
Definition: referenceelements.hh:542
Implementation of the Geometry interface for affine geometries.
Definition: affinegeometry.hh:38
Definition: topologytypes.hh:260
void initialize(unsigned int topologyId, int codim, unsigned int i)
Definition: referenceelements.hh:428
SubEntityInfo()
Definition: referenceelements.hh:386
const GeometryType & type() const
Definition: referenceelements.hh:426
const value_type & pyramid() const
Definition: referenceelements.hh:531
static const ReferenceElement< ctype, dim > & simplex()
get simplex reference elements
Definition: referenceelements.hh:574
const FieldVector< ctype, dim > & volumeOuterNormal(int face) const
Definition: referenceelements.hh:298
unsigned int referenceCorners(unsigned int topologyId, int dim, FieldVector< ct, cdim > *corners)
Definition: referencedomain.hh:308
static Iterator begin()
Definition: referenceelements.hh:585
const GeometryType & type() const
obtain the type of this reference element
Definition: referenceelements.hh:143
unsigned int size(unsigned int topologyId, int dim, int codim)
Compute the number of subentities of a given codimension.
Definition: subtopologies.cc:16
unsigned int id() const
Return the topology id the type.
Definition: type.hh:327
Class providing access to the singletons of the reference elements. Special methods are available for...
Definition: affinegeometry.hh:28
unsigned int * allocate()
Definition: referenceelements.hh:449
const value_type * const_iterator
Definition: referenceelements.hh:507
int size(int cc) const
Definition: referenceelements.hh:414
unsigned int dim() const
Return dimension of the type.
Definition: type.hh:322
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:568
Definition: topologytypes.hh:232
static const ReferenceElement< ctype, dim > & cube()
get hypercube reference elements
Definition: referenceelements.hh:580
An implementation of the Geometry interface for affine geometries.
SubEntityInfo(const SubEntityInfo &other)
Definition: referenceelements.hh:392
Definition: referenceelements.hh:33
const value_type & simplex() const
Definition: referenceelements.hh:521
int size(int i, int c, int cc) const
number of subentities of codimension cc of subentity (i,c)
Definition: referenceelements.hh:103
bool checkInside(const FieldVector< ctype, dim > &local) const
check if a coordinate is in the reference element
Definition: referenceelements.hh:167
AffineGeometry< ctype, dim-codim, dim > Geometry
type of geometry embedding a subentity into the reference element
Definition: referenceelements.hh:78
const FieldVector< ctype, dim > & integrationOuterNormal(int face) const
obtain the integration outer normal of the reference element
Definition: referenceelements.hh:292
static Iterator end()
Definition: referenceelements.hh:586
void subTopologyNumbering(unsigned int topologyId, int dim, int codim, unsigned int i, int subcodim, unsigned int *beginOut, unsigned int *endOut)
Definition: subtopologies.cc:85
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:24
ReferenceElement< ctype, dim > value_type
Definition: referenceelements.hh:506
const value_type & operator()(const GeometryType &type) const
Definition: referenceelements.hh:515
ReferenceElementContainer< ctype, dim >::const_iterator Iterator
Definition: referenceelements.hh:564
void initializeTopology(unsigned int topologyId)
initialize the reference element
Definition: referenceelements.hh:308
const GeometryType & type(int i, int c) const
obtain the type of subentity (i,c)
Definition: referenceelements.hh:136
const value_type & cube() const
Definition: referenceelements.hh:526
const value_type & prism() const
Definition: referenceelements.hh:536
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
topological information about the subentities of a reference element
Definition: referenceelements.hh:384