1 #ifndef DUNE_SPGRID_INDEXSET_HH
2 #define DUNE_SPGRID_INDEXSET_HH
8 #include <dune/grid/common/indexidset.hh>
16 template<
class Gr
id >
18 :
public IndexSet< Grid, SPIndexSet< Grid >, unsigned int, std::array< GeometryType, 1 > >
21 typedef IndexSet< Grid, This, unsigned int, std::array< GeometryType, 1 > > Base;
23 typedef typename std::remove_const< Grid >::type::Traits Traits;
27 typedef typename Base::Types
Types;
29 static const int dimension = Traits::ReferenceCube::dimension;
52 IndexType index (
const MultiIndex &
id,
unsigned int number )
const;
55 IndexType subIndex (
const MultiIndex &
id,
int i,
int codim,
unsigned int number, std::integral_constant< int, cd > )
const;
56 IndexType subIndex (
const MultiIndex &
id,
int i,
int codim,
unsigned int number, std::integral_constant< int, 0 > )
const;
57 IndexType subIndex (
const MultiIndex &
id,
int i,
int codim,
unsigned int number, std::integral_constant< int, dimension > )
const;
60 template<
class Entity >
61 IndexType index (
const Entity &entity )
const;
66 template<
class Entity >
67 IndexType subIndex (
const Entity &entity,
int i,
unsigned int codim )
const;
77 template<
class Entity >
78 bool contains (
const Entity &entity )
const;
90 std::vector< std::array< IndexType, 1 << dimension > > offsets_;
99 template<
class Gr
id >
102 gridLevel_ = &gridLevel;
103 partitions_ = &gridLevel.template partition< All_Partition >();
105 for(
int codim = 0; codim <= dimension; ++codim )
108 offsets_.resize( partitions().maxNumber() - partitions().minNumber() + 1 );
111 for(
unsigned int dir = 0; dir < (1 << dimension); ++dir )
114 unsigned int codim = dimension;
115 for(
int j = 0; j < dimension; ++j )
117 const unsigned int d = (dir >> j) & 1;
118 const int w = pit->bound( 1, j, d ) - pit->bound( 0, j, d );
119 assert( w % 2 == 0 );
120 factor *= (w / 2 + 1);
123 offsets_[ pit->number() - partitions().minNumber() ][ dir ] = size_[ codim ];
124 size_[ codim ] += factor;
130 template<
class Gr
id >
134 const Partition &partition = partitions().partition( number );
137 IndexType factor = 1;
138 unsigned int dir = 0;
139 for(
int j = 0; j < dimension; ++j )
141 const unsigned int d =
id[ j ] & 1;
144 const int begin = partition.bound( 0, j, d );
145 const int end = partition.bound( 1, j, d );
147 const IndexType idLocal = (
id[ j ] - begin) >> 1;
148 const IndexType width = ((end - begin) >> 1) + 1;
149 assert( (idLocal >= 0) && (idLocal < width) );
150 index += idLocal * factor;
154 return offsets_[ number - partitions().minNumber() ][ dir ] + index;
158 template<
class Gr
id >
162 ::subIndex (
const MultiIndex &
id,
int i,
int codim,
unsigned int number, std::integral_constant< int, cd > )
const
164 const int mydim = dimension - cd;
165 const SPMultiIndex< mydim > refId = gridLevel().template referenceCube< cd >().subId( codim - cd, i );
166 MultiIndex subId(
id );
167 for(
int k = 0, l = 0; k < dimension; ++k )
169 if( (
id[ k ] & 1) != 0 )
170 subId[ k ] += refId[ l++ ];
172 return index( subId, number );
175 template<
class Gr
id >
178 ::subIndex (
const MultiIndex &
id,
int i,
int codim,
unsigned int number, std::integral_constant< int, 0 > )
const
180 return index(
id + gridLevel().referenceCube().subId( codim, i ), number );
183 template<
class Gr
id >
186 ::subIndex (
const MultiIndex &
id,
int i,
int codim,
unsigned int number, std::integral_constant< int, dimension > )
const
188 assert( (codim == dimension) && (i == 0) );
189 return index(
id, number );
193 template<
class Gr
id >
194 template<
class Entity >
198 return index< Entity::codimension >( entity );
202 template<
class Gr
id >
203 template<
int codim >
207 assert( contains( entity ) );
209 = entity.impl().entityInfo();
214 template<
class Gr
id >
215 template<
class Entity >
219 return subIndex< Entity::codimension >( entity, i, codim );
223 template<
class Gr
id >
229 assert( contains( entity ) );
231 = entity.impl().entityInfo();
233 return subIndex( entityInfo.
id(), i, codim, entityInfo.
partitionNumber(), std::integral_constant< int, cd >() );
237 template<
class Gr
id >
241 return (type.isCube() ? size( dimension - type.dim() ) : 0);
245 template<
class Gr
id >
249 assert( (codim >= 0) && (codim <= dimension) );
250 return size_[ codim ];
254 template<
class Gr
id >
255 template<
class Entity >
258 return contains< Entity::codimension >( entity );
262 template<
class Gr
id >
263 template<
int codim >
268 = entity.impl().entityInfo();
270 return (&entityInfo.
gridLevel() == &gridLevel());
Definition: iostream.hh:7
Definition: entityinfo.hh:24
const GridLevel & gridLevel() const
Definition: entityinfo.hh:66
const MultiIndex & id() const
Definition: entityinfo.hh:68
unsigned int partitionNumber() const
Definition: entityinfo.hh:73
Definition: gridlevel.hh:35
PartitionPool::PartitionList PartitionList
Definition: gridlevel.hh:64
Definition: indexset.hh:19
Base::Types Types
Definition: indexset.hh:27
static const int dimension
Definition: indexset.hh:29
bool contains(const Entity &entity) const
Definition: indexset.hh:256
Types types(int codim) const
Definition: indexset.hh:72
const PartitionList & partitions() const
Definition: indexset.hh:85
Base::IndexType IndexType
Definition: indexset.hh:26
SPGridLevel< typename std::remove_const< Grid >::type > GridLevel
Definition: indexset.hh:38
GridLevel::PartitionList PartitionList
Definition: indexset.hh:39
IndexType size(const GeometryType &type) const
Definition: indexset.hh:239
const GridLevel & gridLevel() const
Definition: indexset.hh:83
SPIndexSet(const GridLevel &gridLevel)
Definition: indexset.hh:47
void update(const GridLevel &gridLevel)
Definition: indexset.hh:100
Definition: indexset.hh:33
__SPGrid::EntityInfo< Grid, codim > EntityInfo
Definition: indexset.hh:34
Traits::template Codim< codim >::Entity Entity
Definition: indexset.hh:35
Definition: partition.hh:79
Definition: partitionlist.hh:124