Skip to content
Snippets Groups Projects
Commit 7b79d628 authored by Christoph Grüninger's avatar Christoph Grüninger
Browse files

Merge branch 'feature/add-subentities-to-all-codims' into 'master'

add method Entity::subEntities to all codimensions

For polyhedral grids, it is not clear how many vertices a face (i.e., a
general polygon) has. For elements, this information is provided by the
(redundant) method Entity::subEntities. This patch add this usually
redundant method to entities of all codimensions.

See merge request !103
parents aafbf29e 1d6da576
No related branches found
No related tags found
1 merge request!103add method Entity::subEntities to all codimensions
Pipeline #
......@@ -98,6 +98,29 @@ namespace Dune
//! obtain entity seed
EntitySeed seed () const { return EntitySeed( AlbertaGridEntitySeed< codim, Grid >( elementInfo(), subEntity() ) ); }
/** \brief Obtain the number of subentities of a given codimension
*
* That number is ((mydimension+1) over (dim-cd+1))
*
* \param cd codimension
*
* \returns the number of subentities of the given codimension
*/
unsigned int subEntities ( unsigned int cd ) const
{
int n = mydimension+1;
int k = dimension-cd+1;
// binomial: n over k
int binomial=1;
for (int i=n-k+1; i<=n; i++)
binomial *= i;
for (long i=2; i<=k; i++)
binomial /= i;
return binomial;
}
//***********************************************
// end of interface methods
//***********************************************
......@@ -233,16 +256,16 @@ namespace Dune
/** \brief Obtain the number of subentities of a given codimension
*
* That number is ((dim+1) over (dim-codim+1))
* That number is ((mydimension+1) over (dim-cd+1))
*
* \param codim codimension
* \param cd codimension
*
* \returns the number of subentities of the given codimension
*/
unsigned int subEntities (unsigned int codim) const
unsigned int subEntities ( unsigned int cd ) const
{
int n = dimension+1;
int k = dimension-codim+1;
int n = mydimension+1;
int k = dimension-cd+1;
// binomial: n over k
int binomial=1;
......
......@@ -3,10 +3,13 @@
#ifndef DUNE_GRID_ENTITY_HH
#define DUNE_GRID_ENTITY_HH
#include <type_traits>
#include <dune/common/iteratorrange.hh>
#include <dune/common/typetraits.hh>
#include <dune/geometry/dimension.hh>
#include <dune/geometry/referenceelements.hh>
#include "grid.hh"
#include "entitypointer.hh"
......@@ -146,6 +149,22 @@ namespace Dune
*/
GeometryType type () const { return realEntity.type(); }
/**
* \brief Number of subentities for a given codimension
*
* \param codim codimension to obtain number of subentities for
*
* \note The codimension is specified with respect to the grid dimension.
*
* \note Unless the geometry type is None, this method is redundant and
* the same information can be obtained from the corresponding
* reference element.
**/
unsigned int subEntities ( unsigned int codim ) const
{
return realEntity.subEntities(codim);
}
/** \brief Return the entity seed which contains sufficient information
* to generate the entity again and uses as little memory as possible
*/
......@@ -318,6 +337,22 @@ namespace Dune
//! @copydoc Dune::Entity::geometry()
Geometry geometry () const { return realEntity.geometry(); }
/**
* \brief Number of subentities for a given codimension
*
* \param codim codimension to obtain number of subentities for
*
* \note The codimension is specified with respect to the grid dimension.
*
* \note Unless the geometry type is None, this method is redundant and
* the same information can be obtained from the corresponding
* reference element.
**/
unsigned int subEntities ( unsigned int codim ) const
{
return realEntity.subEntities(codim);
}
/** \brief Return the name of the reference element. The type can
be used to access the Dune::ReferenceElement.
*/
......@@ -375,16 +410,6 @@ namespace Dune
//@{
//===========================================================
/**\brief Number of subentities with codimension <tt>codim</tt>.
*
* Strictly speaking this method is redundant, because the same information can be obtained
* from the corresponding reference element. It is here for efficiency reasons only.
*/
unsigned int subEntities(unsigned int codim) const
{
return realEntity.subEntities(codim);
}
/** \brief Obtain a subentity
*
* \tparam codim codimension of the desired subentity
......@@ -555,6 +580,23 @@ namespace Dune
//! \brief The corresponding entity seed (for storage of entities)
typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
/**
* \brief Number of subentities for a given codimension
*
* \param codim codimension to obtain number of subentities for
*
* \note The codimension is specified with respect to the grid dimension.
*
* \note Unless the geometry type is None, this method is redundant and
* the same information can be obtained from the corresponding
* reference element.
**/
unsigned int subEntities ( unsigned int codim ) const
{
typedef typename std::remove_const< GridImp >::type::ctype ctype;
return ReferenceElements< ctype, mydimension >::general( asImp().type() ).size( codim - codimension );
}
/** \brief Return the name of the reference element. The type can
be used to access the Dune::ReferenceElement.
*/
......@@ -604,6 +646,23 @@ namespace Dune
*/
bool isRegular() const { return true; }
/**
* \brief Number of subentities for a given codimension
*
* \param codim codimension to obtain number of subentities for
*
* \note The codimension is specified with respect to the grid dimension.
*
* \note Unless the geometry type is None, this method is redundant and
* the same information can be obtained from the corresponding
* reference element.
**/
unsigned int subEntities ( unsigned int codim ) const
{
typedef typename std::remove_const< GridImp >::type::ctype ctype;
return ReferenceElements< ctype, mydimension >::general( asImp().type() ).size( codim - codimension );
}
/** \brief Return the name of the reference element. The type can
be used to access the Dune::ReferenceElement.
*/
......
......@@ -256,6 +256,11 @@ namespace Dune
return Geometry( geo_ );
}
unsigned int subEntities ( unsigned int cc ) const
{
return hostEntity().subEntities( cc );
}
/** \brief return EntitySeed of host grid entity */
EntitySeed seed () const { return typename EntitySeed::Implementation( hostEntity().seed() ); }
/** \} */
......@@ -569,6 +574,13 @@ namespace Dune
return Geometry( geo_ );
}
unsigned int subEntities ( unsigned int cc ) const
{
const ReferenceElement< ctype, dimension > &refElement
= ReferenceElements< ctype, dimension >::general( hostElement().type() );
return refElement.size( subEntity_, codimension, cc );
}
/** \brief return EntitySeed of host grid entity */
EntitySeed seed () const { return typename EntitySeed::Implementation( hostElement().seed(), subEntity_ ); }
/** \} */
......@@ -772,17 +784,6 @@ namespace Dune
assert( i == 0 );
}
template< int codim >
int count () const
{
return hostEntity().template count< codim >();
}
unsigned int subEntities (unsigned int codim) const
{
return hostEntity().subEntities(codim);
}
template< int codim >
typename Grid::template Codim< codim >::Entity
subEntity ( int i ) const
......
......@@ -168,6 +168,12 @@ namespace Dune {
return hostEntity_.template count<cc>();
}
/** \brief Return the number of subEntities of codimension codim.
*/
unsigned int subEntities (unsigned int cc) const
{
return hostEntity_.subEntities(cc);
}
//! geometry of this entity
Geometry geometry () const
......
......@@ -230,6 +230,14 @@ namespace Dune {
//! return the element type identifier (segment)
GeometryType type () const {return GeometryType(0);}
/** \brief Return the number of subentities of codimension codim.
*/
unsigned int subEntities (unsigned int codim) const
{
assert(codim==1);
return 1;
}
//! geometry of this entity
Geometry geometry () const { return Geometry(GeometryImpl(target_->pos_)); }
......
......@@ -9,6 +9,8 @@
#include <memory>
#include <dune/geometry/referenceelements.hh>
#include <dune/grid/common/gridenums.hh>
......@@ -177,6 +179,13 @@ namespace Dune {
/** \brief Get the seed corresponding to this entity */
EntitySeed seed () const { return EntitySeed( *this ); }
/** \brief Return the number of subEntities of codimension codim.
*/
unsigned int subEntities (unsigned int cd) const
{
return ReferenceElements<UGCtype, dim-codim>::general(type()).size(cd-codim);
}
typename UG_NS<dim>::template Entity<codim>::T* getTarget() const
{
return target_;
......@@ -261,6 +270,13 @@ namespace Dune {
return GeometryType(1);
}
/** \brief Return the number of subEntities of codimension codim.
*/
unsigned int subEntities (unsigned int cd) const
{
return ReferenceElements<UGCtype, dim-codim>::general(type()).size(cd-codim);
}
/** \brief The partition type for parallel computing
*/
PartitionType partitionType () const
......@@ -521,6 +537,13 @@ namespace Dune {
return EntitySeed( *this );
}
/** \brief Return the number of subEntities of codimension codim.
*/
unsigned int subEntities (unsigned int cd) const
{
return ReferenceElements<UGCtype, dim-codim>::general(type()).size(cd-codim);
}
/** \brief Set to a UG side vector object
\param target The UG side vector to point to
\param gridImp Dummy argument, only for consistency with codim-0 entities
......
......@@ -270,6 +270,15 @@ namespace Dune {
return Geometry(_geometry);
}
/*! Return number of subentities with codimension cc.
*
* That number is (dim over (dim-codim)) times 2^codim
*/
unsigned int subEntities (unsigned int cc) const
{
return Dune::Yasp::subEnt<dim>(dim-codim,cc-codim);
}
//! return partition type attribute
PartitionType partitionType () const
{
......@@ -821,6 +830,15 @@ namespace Dune {
return EntitySeed(YaspEntitySeed<dim,GridImp>(_g->level(), _it.coord(), _it.which()));
}
/*! Return number of subentities with codimension cc.
*
* That number is (dim over (dim-codim)) times 2^codim
*/
unsigned int subEntities (unsigned int cc) const
{
return Dune::Yasp::subEnt<dim>(dim-dim,cc-dim);
}
//! geometry of this entity
Geometry geometry () const {
GeometryImpl _geometry((_it).lowerleft());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment