1#ifndef DUNE_SPGRID_HINDEXSET_HH
2#define DUNE_SPGRID_HINDEXSET_HH
8#include <dune/grid/spgrid/indexset.hh>
16 template<
class Gr
id >
17 class SPHierarchyIndexSet
18 :
public IndexSet< Grid, SPHierarchyIndexSet< Grid >, unsigned int, std::array< GeometryType, 1 > >
20 typedef SPHierarchyIndexSet< Grid > This;
21 typedef IndexSet< Grid, This, unsigned int, std::array< GeometryType, 1 > > Base;
23 typedef typename std::remove_const< Grid >::type::Traits Traits;
29 static const int dimension = Traits::ReferenceCube::dimension;
34 typedef __SPGrid::EntityInfo< Grid, codim > EntityInfo;
35 typedef typename Traits::template Codim< codim >::Entity Entity;
38 typedef SPGridLevel< typename std::remove_const< Grid >::type > GridLevel;
41 typedef SPIndexSet< Grid > LevelIndexSet;
43 typedef std::array< IndexType, dimension+1 > CodimIndexArray;
46 explicit SPHierarchyIndexSet (
const Grid &grid )
49 for(
int codim = 0; codim <= dimension; ++codim )
55 for(
int codim = 0; codim <= dimension; ++codim )
58 const int maxLevel = grid().maxLevel();
59 levelIndexSets_.resize( maxLevel+1 );
60 offsets_.resize( maxLevel+1 );
61 for(
int level = 0; level <= maxLevel; ++level )
63 const LevelIndexSet &levelIndexSet = grid().levelIndexSet( level );
64 levelIndexSets_[ level ] = &levelIndexSet;
65 for(
int codim = 0; codim <= dimension; ++codim )
67 offsets_[ level ][ codim ] = size_[ codim ];
68 size_[ codim ] += levelIndexSet.size( codim );
73 template<
class Entity >
74 IndexType
index (
const Entity &entity )
const
76 return index< Entity::codimension >( entity );
80 IndexType
index (
const typename Codim< codim >::Entity &entity )
const
82 const int level = entity.level();
83 const IndexType offset = offsets_[ level ][ codim ];
84 return offset + levelIndexSet( level ).index( entity );
87 template<
class Entity >
88 IndexType
subIndex (
const Entity &entity,
89 const int i,
const unsigned int codim )
const
91 return subIndex< Entity::codimension >( entity, i, codim );
95 IndexType
subIndex (
const typename Codim< cd >::Entity &entity,
96 const int i,
const unsigned int codim )
const
98 const int level = entity.level();
99 const IndexType offset = offsets_[ level ][ codim ];
100 return offset + levelIndexSet( level ).subIndex( entity, i, codim );
105 const std::vector< GeometryType > &geomTypes (
const int codim )
const
107 return levelIndexSet( 0 ).geomTypes( codim );
110 IndexType
size (
const GeometryType &type )
const
112 return (type.isCube() ?
size( dimension - type.dim() ) : 0);
115 IndexType
size (
const int codim )
const
117 assert( (codim >= 0) && (codim <= dimension) );
118 return size_[ codim ];
121 template<
class Entity >
122 bool contains (
const Entity &entity )
const
124 return contains< Entity::codimension >( entity );
127 template<
int codim >
128 bool contains (
const typename Codim< codim >::Entity &entity )
const
133 const Grid &grid ()
const
138 const LevelIndexSet &levelIndexSet (
const int level )
const
140 assert( (level >= 0) && (level <= (
int)levelIndexSets_.size()) );
141 assert( (
int)levelIndexSets_.size() == grid().maxLevel()+1 );
142 return *levelIndexSets_[ level ];
147 std::vector< const LevelIndexSet * > levelIndexSets_;
148 std::vector< CodimIndexArray > offsets_;
149 CodimIndexArray size_;
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:223
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:153
TypesImp Types
iterator range for geometry types in domain
Definition: indexidset.hh:95
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:113
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:92
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:472
Dune namespace.
Definition: alignedallocator.hh:13