3 #ifndef DUNE_GEOMETRY_REFERENCEELEMENTS_HH
4 #define DUNE_GEOMETRY_REFERENCEELEMENTS_HH
9 #include <dune/common/forloop.hh>
10 #include <dune/common/typetraits.hh>
11 #include <dune/common/visibility.hh>
12 #include <dune/common/unused.hh>
25 template<
class ctype,
int dim >
26 class ReferenceElementContainer;
28 template<
class ctype,
int dim >
29 struct ReferenceElements;
51 template<
class ctype,
int dim >
52 class ReferenceElement
65 template<
int codim >
struct CreateGeometries;
82 assert( (c >= 0) && (c <= dim) );
83 return info_[ c ].size();
97 int size (
int i,
int c,
int cc )
const
99 assert( (i >= 0) && (i <
size( c )) );
100 return info_[ c ][ i ].size( cc );
118 assert( (i >= 0) && (i <
size( c )) );
119 return info_[ c ][ i ].number( ii, cc );
132 assert( (i >= 0) && (i <
size( c )) );
133 return info_[ c ][ i ].type();
148 const FieldVector< ctype, dim > &
position(
int i,
int c )
const
150 assert( (c >= 0) && (c <= dim) );
151 return baryCenters_[ c ][ i ];
163 const ctype tolerance = ctype( 64 ) * std::numeric_limits< ctype >::epsilon();
164 return GenericGeometry::template checkInside< ctype, dim >(
type().
id(), dim, local, tolerance );
178 template<
int codim >
181 std::integral_constant< int, codim > codimVariable;
182 return geometries_[ codimVariable ][ i ];
200 assert( (face >= 0) && (face <
int( integrationNormals_.size() )) );
201 return integrationNormals_[ face ];
205 void initialize (
unsigned int topologyId )
210 for(
int codim = 0; codim <= dim; ++codim )
213 info_[ codim ].resize(
size );
214 for(
unsigned int i = 0; i <
size; ++i )
215 info_[ codim ][ i ].initialize( topologyId, codim, i );
219 const unsigned int numVertices =
size( dim );
220 baryCenters_[ dim ].resize( numVertices );
224 for(
int codim = 0; codim < dim; ++codim )
226 baryCenters_[ codim ].resize(
size(codim) );
227 for(
int i = 0; i <
size( codim ); ++i )
229 baryCenters_[ codim ][ i ] = FieldVector< ctype, dim >( ctype( 0 ) );
230 const unsigned int numCorners =
size( i, codim, dim );
231 for(
unsigned int j = 0; j < numCorners; ++j )
232 baryCenters_[ codim ][ i ] += baryCenters_[ dim ][
subEntity( i, codim, j, dim ) ];
233 baryCenters_[ codim ][ i ] *= ctype( 1 ) / ctype( numCorners );
238 volume_ = GenericGeometry::template referenceVolume< ctype >( topologyId, dim );
243 integrationNormals_.resize(
size( 1 ) );
248 Dune::ForLoop< CreateGeometries, 0, dim >::apply( *
this, geometries_ );
252 template<
int codim >
254 :
public std::vector< typename Codim< codim >::Geometry >
258 typedef GenericGeometry::CodimTable< GeometryArray, dim > GeometryTable;
263 std::vector< FieldVector< ctype, dim > > baryCenters_[ dim+1 ];
264 std::vector< FieldVector< ctype, dim > > integrationNormals_;
267 GeometryTable geometries_;
269 std::vector< SubEntityInfo > info_[ dim+1 ];
273 template<
class ctype,
int dim >
277 : numbering_( nullptr )
279 std::fill( offset_.begin(), offset_.end(), 0 );
283 : offset_( other.offset_ ),
286 numbering_ = allocate();
287 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
295 offset_ = other.offset_;
297 deallocate( numbering_ );
298 numbering_ = allocate();
299 std::copy( other.numbering_, other.numbering_ + capacity(), numbering_ );
306 assert( (cc >= codim()) && (cc <= dim) );
307 return (offset_[ cc+1 ] - offset_[ cc ]);
312 assert( (ii >= 0) && (ii <
size( cc )) );
313 return numbering_[ offset_[ cc ] + ii ];
318 void initialize (
unsigned int topologyId,
int codim,
unsigned int i )
324 for(
int cc = 0; cc <= codim; ++cc )
326 for(
int cc = codim; cc <= dim; ++cc )
330 deallocate( numbering_ );
331 numbering_ = allocate();
332 for(
int cc = codim; cc <= dim; ++cc )
339 unsigned int *
allocate () {
return (capacity() != 0 ?
new unsigned int[ capacity() ] :
nullptr); }
341 unsigned int capacity ()
const {
return offset_[ dim+1 ]; }
344 unsigned int *numbering_;
345 std::array< unsigned int, dim+2 > offset_;
350 template<
class ctype,
int dim >
351 template<
int codim >
361 static const ReferenceElement< ctype, dim > &
362 subRefElement(
const ReferenceElement< ctype, dim > &refElement,
int i, std::integral_constant< int, 0 > )
364 DUNE_UNUSED_PARAMETER(i);
368 static void apply (
const ReferenceElement< ctype, dim > &refElement, GeometryTable &geometries )
370 const int size = refElement.size( codim );
371 std::vector< FieldVector< ctype, dim > > origins(
size );
372 std::vector< FieldMatrix< ctype, dim - codim, dim > > jacobianTransposeds(
size );
375 std::integral_constant< int, codim > codimVariable;
376 geometries[ codimVariable ].reserve(
size );
377 for(
int i = 0; i <
size; ++i )
380 geometries[ codimVariable ].push_back(
geometry );
390 template<
class ctype,
int dim >
393 static const unsigned int numTopologies = (1u << dim);
401 for(
unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
402 values_[ topologyId ].initialize( topologyId );
407 assert( type.
dim() == dim );
408 return values_[ type.
id() ];
453 template<
class ctype,
int dim >
462 return container() ( type );
468 return container().simplex();
474 return container().cube();
An implementation of the Geometry interface for affine geometries.
Definition: affinegeometry.hh:19
void subTopologyNumbering(unsigned int topologyId, int dim, int codim, unsigned int i, int subcodim, unsigned int *beginOut, unsigned int *endOut)
Definition: subtopologies.cc:85
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 numTopologies(int dim)
obtain the number of topologies of a given dimension
Definition: topologytypes.hh:134
unsigned int referenceCorners(unsigned int topologyId, int dim, FieldVector< ct, cdim > *corners)
Definition: referencedomain.hh:308
unsigned int referenceIntegrationOuterNormals(unsigned int topologyId, int dim, const FieldVector< ct, cdim > *origins, FieldVector< ct, cdim > *normals)
Definition: referencedomain.hh:471
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
This class provides access to geometric and topological properties of a reference element.
Definition: referenceelements.hh:29
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:80
int size(int i, int c, int cc) const
number of subentities of codimension cc of subentity (i,c)
Definition: referenceelements.hh:97
ctype volume() const
obtain the volume of the reference element
Definition: referenceelements.hh:186
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:116
bool checkInside(const FieldVector< ctype, dim > &local) const
check if a coordinate is in the reference element
Definition: referenceelements.hh:161
const FieldVector< ctype, dim > & position(int i, int c) const
position of the barycenter of entity (i,c)
Definition: referenceelements.hh:148
Codim< codim >::Geometry geometry(int i) const
obtain the embedding of subentity (i,codim) into the reference element
Definition: referenceelements.hh:179
const GeometryType & type(int i, int c) const
obtain the type of subentity (i,c)
Definition: referenceelements.hh:130
const GeometryType & type() const
obtain the type of this reference element
Definition: referenceelements.hh:137
const FieldVector< ctype, dim > & integrationOuterNormal(int face) const
obtain the integration outer normal of the reference element
Definition: referenceelements.hh:198
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:455
static const ReferenceElement< ctype, dim > & simplex()
get simplex reference elements
Definition: referenceelements.hh:466
static Iterator end()
Definition: referenceelements.hh:478
static const ReferenceElement< ctype, dim > & cube()
get hypercube reference elements
Definition: referenceelements.hh:472
ReferenceElementContainer< ctype, dim >::const_iterator Iterator
Definition: referenceelements.hh:456
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:460
static Iterator begin()
Definition: referenceelements.hh:477
Implementation of the Geometry interface for affine geometries.
Definition: affinegeometry.hh:39
Definition: topologytypes.hh:215
Definition: topologytypes.hh:232
Definition: topologytypes.hh:249
Definition: topologytypes.hh:260
Definition: referenceelements.hh:392
const value_type & simplex() const
Definition: referenceelements.hh:411
const value_type & pyramid() const
Definition: referenceelements.hh:421
const value_type * const_iterator
Definition: referenceelements.hh:397
const value_type & cube() const
Definition: referenceelements.hh:416
ReferenceElementContainer()
Definition: referenceelements.hh:399
const value_type & prism() const
Definition: referenceelements.hh:426
ReferenceElement< ctype, dim > value_type
Definition: referenceelements.hh:396
const value_type & operator()(const GeometryType &type) const
Definition: referenceelements.hh:405
const_iterator end() const
Definition: referenceelements.hh:432
const_iterator begin() const
Definition: referenceelements.hh:431
Collection of types depending on the codimension.
Definition: referenceelements.hh:71
AffineGeometry< ctype, dim-codim, dim > Geometry
type of geometry embedding a subentity into the reference element
Definition: referenceelements.hh:73
topological information about the subentities of a reference element
Definition: referenceelements.hh:275
int number(int ii, int cc) const
Definition: referenceelements.hh:310
int size(int cc) const
Definition: referenceelements.hh:304
~SubEntityInfo()
Definition: referenceelements.hh:290
unsigned int * allocate()
Definition: referenceelements.hh:339
const GeometryType & type() const
Definition: referenceelements.hh:316
SubEntityInfo()
Definition: referenceelements.hh:276
SubEntityInfo(const SubEntityInfo &other)
Definition: referenceelements.hh:282
unsigned int capacity() const
Definition: referenceelements.hh:341
void deallocate(unsigned int *ptr)
Definition: referenceelements.hh:340
void initialize(unsigned int topologyId, int codim, unsigned int i)
Definition: referenceelements.hh:318
int codim() const
Definition: referenceelements.hh:337
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