3 #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH 4 #define DUNE_GEOMETRY_REFERENCEELEMENTS_HH 14 #include <dune/common/array.hh> 15 #include <dune/common/forloop.hh> 16 #include <dune/common/fmatrix.hh> 17 #include <dune/common/fvector.hh> 18 #include <dune/common/typetraits.hh> 19 #include <dune/common/visibility.hh> 20 #include <dune/common/unused.hh> 31 template<
class ctype,
int dim >
34 template<
class ctype,
int dim >
43 unsigned int size (
unsigned int topologyId,
int dim,
int codim );
54 unsigned int subTopologyId (
unsigned int topologyId,
int dim,
int codim,
unsigned int i );
61 void subTopologyNumbering (
unsigned int topologyId,
int dim,
int codim,
unsigned int i,
int subcodim,
62 unsigned int *beginOut,
unsigned int *endOut );
70 template<
class ct,
int cdim >
72 checkInside (
unsigned int topologyId,
int dim,
const FieldVector< ct, cdim > &x, ct tolerance, ct factor = ct( 1 ) )
74 assert( (dim >= 0) && (dim <= cdim) );
79 const ct baseFactor = (
isPrism( topologyId, dim ) ? factor : factor - x[ dim-1 ]);
80 if( (x[ dim-1 ] > -tolerance) && (factor - x[ dim-1 ] > -tolerance) )
81 return checkInside< ct, cdim >(
baseTopologyId( topologyId, dim ), dim-1, x, tolerance, baseFactor );
94 template<
class ct,
int cdim >
96 referenceCorners (
unsigned int topologyId,
int dim, FieldVector< ct, cdim > *corners )
98 assert( (dim >= 0) && (dim <= cdim) );
103 const unsigned int nBaseCorners
106 if(
isPrism( topologyId, dim ) )
108 std::copy( corners, corners + nBaseCorners, corners + nBaseCorners );
109 for(
unsigned int i = 0; i < nBaseCorners; ++i )
110 corners[ i+nBaseCorners ][ dim-1 ] = ct( 1 );
111 return 2*nBaseCorners;
115 corners[ nBaseCorners ] = FieldVector< ct, cdim >( ct( 0 ) );
116 corners[ nBaseCorners ][ dim-1 ] = ct( 1 );
117 return nBaseCorners+1;
122 *corners = FieldVector< ct, cdim >( ct( 0 ) );
145 template<
class ct,
int cdim >
147 referenceOrigins (
unsigned int topologyId,
int dim,
int codim, FieldVector< ct, cdim > *origins )
149 assert( (dim >= 0) && (dim <= cdim) );
151 assert( (codim >= 0) && (codim <= dim) );
156 if(
isPrism( topologyId, dim ) )
158 const unsigned int n = (codim < dim ?
referenceOrigins( baseId, dim-1, codim, origins ) : 0);
159 const unsigned int m =
referenceOrigins( baseId, dim-1, codim-1, origins+n );
160 for(
unsigned int i = 0; i < m; ++i )
162 origins[ n+m+i ] = origins[ n+i ];
163 origins[ n+m+i ][ dim-1 ] = ct( 1 );
172 origins[ m ] = FieldVector< ct, cdim >( ct( 0 ) );
173 origins[ m ][ dim-1 ] = ct( 1 );
182 origins[ 0 ] = FieldVector< ct, cdim >( ct( 0 ) );
192 template<
class ct,
int cdim,
int mydim >
195 FieldVector< ct, cdim > *origins,
196 FieldMatrix< ct, mydim, cdim > *jacobianTransposeds )
198 assert( (0 <= codim) && (codim <= dim) && (dim <= cdim) );
199 assert( (dim - codim <= mydim) && (mydim <= cdim) );
205 if(
isPrism( topologyId, dim ) )
207 const unsigned int n = (codim < dim ?
referenceEmbeddings( baseId, dim-1, codim, origins, jacobianTransposeds ) : 0);
208 for(
unsigned int i = 0; i < n; ++i )
209 jacobianTransposeds[ i ][ dim-codim-1 ][ dim-1 ] = ct( 1 );
211 const unsigned int m =
referenceEmbeddings( baseId, dim-1, codim-1, origins+n, jacobianTransposeds+n );
212 std::copy( origins+n, origins+n+m, origins+n+m );
213 std::copy( jacobianTransposeds+n, jacobianTransposeds+n+m, jacobianTransposeds+n+m );
214 for(
unsigned int i = 0; i < m; ++i )
215 origins[ n+m+i ][ dim-1 ] = ct( 1 );
221 const unsigned int m =
referenceEmbeddings( baseId, dim-1, codim-1, origins, jacobianTransposeds );
224 origins[ m ] = FieldVector< ct, cdim >( ct( 0 ) );
225 origins[ m ][ dim-1 ] = ct( 1 );
226 jacobianTransposeds[ m ] = FieldMatrix< ct, mydim, cdim >( ct( 0 ) );
231 const unsigned int n =
referenceEmbeddings( baseId, dim-1, codim, origins+m, jacobianTransposeds+m );
232 for(
unsigned int i = 0; i < n; ++i )
234 for(
int k = 0; k < dim-1; ++k )
235 jacobianTransposeds[ m+i ][ dim-codim-1 ][ k ] = -origins[ m+i ][ k ];
236 jacobianTransposeds[ m+i ][ dim-codim-1 ][ dim-1 ] = ct( 1 );
244 origins[ 0 ] = FieldVector< ct, cdim >( ct( 0 ) );
245 jacobianTransposeds[ 0 ] = FieldMatrix< ct, mydim, cdim >( ct( 0 ) );
246 for(
int k = 0; k < dim; ++k )
247 jacobianTransposeds[ 0 ][ k ][ k ] = ct( 1 );
257 template<
class ct,
int cdim >
260 const FieldVector< ct, cdim > *origins,
261 FieldVector< ct, cdim > *normals )
263 assert( (dim > 0) && (dim <= cdim) );
269 if(
isPrism( topologyId, dim ) )
271 const unsigned int numBaseFaces
274 for(
unsigned int i = 0; i < 2; ++i )
276 normals[ numBaseFaces+i ] = FieldVector< ct, cdim >( ct( 0 ) );
277 normals[ numBaseFaces+i ][ dim-1 ] = ct( 2*
int( i )-1 );
280 return numBaseFaces+2;
284 normals[ 0 ] = FieldVector< ct, cdim >( ct( 0 ) );
285 normals[ 0 ][ dim-1 ] = ct( -1 );
287 const unsigned int numBaseFaces
289 for(
unsigned int i = 1; i <= numBaseFaces; ++i )
290 normals[ i ][ dim-1 ] = normals[ i ]*origins[ i ];
292 return numBaseFaces+1;
297 for(
unsigned int i = 0; i < 2; ++i )
299 normals[ i ] = FieldVector< ct, cdim >( ct( 0 ) );
300 normals[ i ][ 0 ] = ct( 2*
int( i )-1 );
307 template<
class ct,
int cdim >
310 FieldVector< ct, cdim > *normals )
312 assert( (dim > 0) && (dim <= cdim) );
314 FieldVector< ct, cdim > *origins
315 =
new FieldVector< ct, cdim >[
size( topologyId, dim, 1 ) ];
318 const unsigned int numFaces
320 assert( numFaces ==
size( topologyId, dim, 1 ) );
352 template<
class ctype,
int dim >
366 template<
int codim >
struct CreateGeometries;
370 template<
int codim >
383 assert( (c >= 0) && (c <= dim) );
384 return info_[ c ].size();
398 int size (
int i,
int c,
int cc )
const 400 assert( (i >= 0) && (i <
size( c )) );
401 return info_[ c ][ i ].size( cc );
419 assert( (i >= 0) && (i <
size( c )) );
420 return info_[ c ][ i ].number( ii, cc );
433 assert( (i >= 0) && (i <
size( c )) );
434 return info_[ c ][ i ].type();
449 const FieldVector< ctype, dim > &
position(
int i,
int c )
const 451 assert( (c >= 0) && (c <= dim) );
452 return baryCenters_[ c ][ i ];
464 const ctype tolerance = ctype( 64 ) * std::numeric_limits< ctype >::epsilon();
465 return Impl::template checkInside< ctype, dim >( type().id(), dim, local, tolerance );
479 template<
int codim >
482 return std::get< codim >( geometries_ )[ i ];
500 assert( (face >= 0) && (face <
int( integrationNormals_.size() )) );
501 return integrationNormals_[ face ];
505 void initialize (
unsigned int topologyId )
510 for(
int codim = 0; codim <= dim; ++codim )
513 info_[ codim ].resize( size );
514 for(
unsigned int i = 0; i <
size; ++i )
515 info_[ codim ][ i ].initialize( topologyId, codim, i );
519 const unsigned int numVertices =
size( dim );
520 baryCenters_[ dim ].resize( numVertices );
524 for(
int codim = 0; codim < dim; ++codim )
526 baryCenters_[ codim ].resize(
size(codim) );
527 for(
int i = 0; i <
size( codim ); ++i )
529 baryCenters_[ codim ][ i ] = FieldVector< ctype, dim >( ctype( 0 ) );
530 const unsigned int numCorners =
size( i, codim, dim );
531 for(
unsigned int j = 0; j < numCorners; ++j )
532 baryCenters_[ codim ][ i ] += baryCenters_[ dim ][ subEntity( i, codim, j, dim ) ];
533 baryCenters_[ codim ][ i ] *= ctype( 1 ) / ctype( numCorners );
538 volume_ = Impl::template referenceVolume< ctype >( topologyId, dim );
543 integrationNormals_.resize(
size( 1 ) );
548 Dune::ForLoop< CreateGeometries, 0, dim >::apply( *
this, geometries_ );
551 template<
int... codim >
552 static std::tuple< std::vector< typename Codim< codim >::Geometry >... >
553 makeGeometryTable ( std::integer_sequence< int, codim... > );
556 typedef decltype( makeGeometryTable( std::make_integer_sequence< int, dim+1 >() ) ) GeometryTable;
561 std::vector< FieldVector< ctype, dim > > baryCenters_[ dim+1 ];
562 std::vector< FieldVector< ctype, dim > > integrationNormals_;
565 GeometryTable geometries_;
567 std::vector< SubEntityInfo > info_[ dim+1 ];
571 template<
class ctype,
int dim >
575 : numbering_( nullptr )
577 std::fill( offset_.begin(), offset_.end(), 0 );
581 : offset_( other.offset_ ),
584 numbering_ = allocate();
585 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
593 offset_ = other.offset_;
595 deallocate( numbering_ );
596 numbering_ = allocate();
597 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
604 assert( (cc >= codim()) && (cc <= dim) );
605 return (offset_[ cc+1 ] - offset_[ cc ]);
610 assert( (ii >= 0) && (ii <
size( cc )) );
611 return numbering_[ offset_[ cc ] + ii ];
616 void initialize (
unsigned int topologyId,
int codim,
unsigned int i )
622 for(
int cc = 0; cc <= codim; ++cc )
624 for(
int cc = codim; cc <= dim; ++cc )
625 offset_[ cc+1 ] = offset_[ cc ] +
Impl::size( subId, dim-codim, cc-codim );
628 deallocate( numbering_ );
629 numbering_ = allocate();
630 for(
int cc = codim; cc <= dim; ++cc )
635 int codim ()
const {
return dim - type().dim(); }
637 unsigned int *
allocate () {
return (capacity() != 0 ?
new unsigned int[ capacity() ] :
nullptr); }
639 unsigned int capacity ()
const {
return offset_[ dim+1 ]; }
642 unsigned int *numbering_;
643 std::array< unsigned int, dim+2 > offset_;
648 template<
class ctype,
int dim >
649 template<
int codim >
662 DUNE_UNUSED_PARAMETER(i);
668 const int size = refElement.
size( codim );
669 std::vector< FieldVector< ctype, dim > > origins( size );
670 std::vector< FieldMatrix< ctype, dim - codim, dim > > jacobianTransposeds( size );
673 std::get< codim >( geometries ).reserve( size );
674 for(
int i = 0; i <
size; ++i )
676 typename Codim< codim >::Geometry geometry( subRefElement( refElement, i, std::integral_constant< int, codim >() ), origins[ i ], jacobianTransposeds[ i ] );
677 std::get< codim >( geometries ).push_back( geometry );
687 template<
class ctype,
int dim >
698 for(
unsigned int topologyId = 0; topologyId <
numTopologies; ++topologyId )
699 values_[ topologyId ].initialize( topologyId );
704 assert( type.
dim() == dim );
705 return values_[ type.
id() ];
713 const value_type &
cube ()
const 728 const_iterator
begin ()
const {
return values_; }
750 template<
class ctype,
int dim >
759 return container() ( type );
765 return container().simplex();
771 return container().cube();
774 static Iterator
begin () {
return container().begin(); }
775 static Iterator
end () {
return container().end(); }
787 #endif // #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH ReferenceElementContainer< ctype, dim >::const_iterator Iterator
Definition: referenceelements.hh:753
Definition: referenceelements.hh:32
Codim< codim >::Geometry geometry(int i) const
obtain the embedding of subentity (i,codim) into the reference element
Definition: referenceelements.hh:480
unsigned int referenceIntegrationOuterNormals(unsigned int topologyId, int dim, const FieldVector< ct, cdim > *origins, FieldVector< ct, cdim > *normals)
Definition: referenceelements.hh:259
Class providing access to the singletons of the reference elements.
Definition: affinegeometry.hh:28
const FieldVector< ctype, dim > & integrationOuterNormal(int face) const
obtain the integration outer normal of the reference element
Definition: referenceelements.hh:498
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:267
unsigned int dim() const
Return dimension of the type.
Definition: type.hh:565
Collection of types depending on the codimension.
Definition: referenceelements.hh:371
const_iterator end() const
Definition: referenceelements.hh:729
static const ReferenceElement< ctype, dim > & simplex()
get simplex reference elements
Definition: referenceelements.hh:763
const GeometryType & type() const
Definition: referenceelements.hh:614
const value_type & pyramid() const
Definition: referenceelements.hh:718
bool checkInside(unsigned int topologyId, int dim, const FieldVector< ct, cdim > &x, ct tolerance, ct factor=ct(1))
Definition: referenceelements.hh:72
Implementation of the Geometry interface for affine geometries.
Definition: affinegeometry.hh:460
This class provides access to geometric and topological properties of a reference element...
Definition: affinegeometry.hh:25
ReferenceElement< ctype, dim > value_type
Definition: referenceelements.hh:693
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:381
void subTopologyNumbering(unsigned int topologyId, int dim, int codim, unsigned int i, int subcodim, unsigned int *beginOut, unsigned int *endOut)
Definition: referenceelements.cc:85
unsigned int size(unsigned int topologyId, int dim, int codim)
Compute the number of subentities of a given codimension.
Definition: referenceelements.cc:16
Definition: affinegeometry.hh:18
static unsigned int numTopologies(int dim) noexcept
obtain the number of topologies of a given dimension
Definition: type.hh:93
const FieldVector< ctype, dim > & position(int i, int c) const
position of the barycenter of entity (i,c)
Definition: referenceelements.hh:449
A unique label for each type of element that can occur in a grid.
const_iterator begin() const
Definition: referenceelements.hh:728
const value_type & cube() const
Definition: referenceelements.hh:713
int size(int i, int c, int cc) const
number of subentities of codimension cc of subentity (i,c)
Definition: referenceelements.hh:398
void initialize(unsigned int topologyId, int codim, unsigned int i)
Definition: referenceelements.hh:616
const value_type & prism() const
Definition: referenceelements.hh:723
const GeometryType & type() const
obtain the type of this reference element
Definition: referenceelements.hh:438
An implementation of the Geometry interface for affine geometries.
int size(int cc) const
Definition: referenceelements.hh:602
static Iterator begin()
Definition: referenceelements.hh:774
static unsigned int baseTopologyId(unsigned int topologyId, int dim, int codim=1) noexcept
obtain the base topology of a given codimension
Definition: type.hh:160
AffineGeometry< ctype, dim-codim, dim > Geometry
type of geometry embedding a subentity into the reference element
Definition: referenceelements.hh:374
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:757
static const ReferenceElement< ctype, dim > & cube()
get hypercube reference elements
Definition: referenceelements.hh:769
unsigned int referenceCorners(unsigned int topologyId, int dim, FieldVector< ct, cdim > *corners)
Definition: referenceelements.hh:96
unsigned int capacity() const
Definition: referenceelements.hh:639
static bool isPrism(unsigned int topologyId, int dim, int codim=0) noexcept
check whether a prism construction was used to create a given codimension
Definition: type.hh:127
const value_type * const_iterator
Definition: referenceelements.hh:694
unsigned int * allocate()
Definition: referenceelements.hh:637
const value_type & simplex() const
Definition: referenceelements.hh:708
int number(int ii, int cc) const
Definition: referenceelements.hh:608
~SubEntityInfo()
Definition: referenceelements.hh:588
SubEntityInfo()
Definition: referenceelements.hh:574
unsigned int referenceOrigins(unsigned int topologyId, int dim, int codim, FieldVector< ct, cdim > *origins)
Definition: referenceelements.hh:147
unsigned long referenceVolumeInverse(unsigned int topologyId, int dim)
Definition: referenceelements.cc:171
static Iterator end()
Definition: referenceelements.hh:775
unsigned int id() const
Return the topology id the type.
Definition: type.hh:570
bool checkInside(const FieldVector< ctype, dim > &local) const
check if a coordinate is in the reference element
Definition: referenceelements.hh:462
ct referenceVolume(unsigned int topologyId, int dim)
Definition: referenceelements.hh:135
int codim() const
Definition: referenceelements.hh:635
const GeometryType & type(int i, int c) const
obtain the type of subentity (i,c)
Definition: referenceelements.hh:431
ReferenceElementContainer()
Definition: referenceelements.hh:696
unsigned int subTopologyId(unsigned int topologyId, int dim, int codim, unsigned int i)
Compute the topology id of a given subentity.
Definition: referenceelements.cc:47
ctype volume() const
obtain the volume of the reference element
Definition: referenceelements.hh:486
void deallocate(unsigned int *ptr)
Definition: referenceelements.hh:638
unsigned int referenceEmbeddings(unsigned int topologyId, int dim, int codim, FieldVector< ct, cdim > *origins, FieldMatrix< ct, mydim, cdim > *jacobianTransposeds)
Definition: referenceelements.hh:194
SubEntityInfo(const SubEntityInfo &other)
Definition: referenceelements.hh:580
topological information about the subentities of a reference element
Definition: referenceelements.hh:572
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:417