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 >
33 class ReferenceElementContainer;
35 template<
class ctype,
int dim >
36 struct ReferenceElements;
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 ]);
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 )
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 >
474 DUNE_UNUSED_PARAMETER(i);
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 )
490 geometries[ codimVariable ].push_back( geometry );
500 template<
class ctype,
int dim >
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 >
570 return container() ( type );
576 return container().simplex();
582 return container().cube();
598 #endif // #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH