1#ifndef DUNE_SPGRID_INDEXSET_HH
2#define DUNE_SPGRID_INDEXSET_HH
10#include <dune/grid/spgrid/entityinfo.hh>
11#include <dune/grid/spgrid/gridlevel.hh>
16 template<
class Gr
id >
18 :
public IndexSet< Grid, SPIndexSet< Grid >, unsigned int, std::array< GeometryType, 1 > >
20 typedef SPIndexSet< 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;
39 typedef typename GridLevel::PartitionList PartitionList;
42 typedef typename GridLevel::MultiIndex MultiIndex;
43 typedef typename PartitionList::Partition Partition;
46 SPIndexSet () =
default;
47 explicit SPIndexSet (
const GridLevel &gridLevel ) { update( gridLevel ); }
49 void update (
const GridLevel &gridLevel );
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;
64 IndexType
index (
const typename Codim< codim >::Entity &entity )
const;
66 template<
class Entity >
67 IndexType
subIndex (
const Entity &entity,
int i,
unsigned int codim )
const;
70 IndexType
subIndex (
const typename Codim< cd >::Entity &entity,
int i,
unsigned int codim )
const;
74 IndexType
size (
const GeometryType &type )
const;
75 IndexType
size (
const int codim )
const;
77 template<
class Entity >
78 bool contains (
const Entity &entity )
const;
81 bool contains (
const typename Codim< codim >::Entity &entity )
const;
83 const GridLevel &gridLevel ()
const {
return *gridLevel_; }
85 const PartitionList &partitions ()
const { assert( partitions_ );
return *partitions_; }
88 const GridLevel *gridLevel_ =
nullptr;
89 const PartitionList *partitions_ =
nullptr;
90 std::vector< std::array< IndexType, 1 << dimension > > offsets_;
91 IndexType size_[ dimension+1 ];
99 template<
class Gr
id >
100 void SPIndexSet< Grid >::update (
const GridLevel &gridLevel )
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 );
109 for(
typename PartitionList::Iterator pit = partitions().begin(); pit; ++pit )
111 for(
unsigned int dir = 0; dir < (1 << dimension); ++dir )
113 IndexType factor = 1;
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 >
131 inline typename SPIndexSet< Grid >::IndexType
132 SPIndexSet< Grid >::index (
const MultiIndex &
id,
unsigned int number )
const
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 >
160 inline typename SPIndexSet< Grid >::IndexType
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 >
176 inline typename SPIndexSet< Grid >::IndexType
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 >
184 inline typename SPIndexSet< Grid >::IndexType
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 >
195 inline typename SPIndexSet< Grid >::IndexType
196 SPIndexSet< Grid >::index (
const Entity &entity )
const
198 return index< Entity::codimension >( entity );
202 template<
class Gr
id >
203 template<
int codim >
204 inline typename SPIndexSet< Grid >::IndexType
205 SPIndexSet< Grid >::index (
const typename Codim< codim >::Entity &entity )
const
207 assert( contains( entity ) );
208 const typename Codim< codim >::EntityInfo &entityInfo
209 = entity.impl().entityInfo();
210 return index( entityInfo.id(), entityInfo.partitionNumber() );
214 template<
class Gr
id >
215 template<
class Entity >
216 inline typename SPIndexSet< Grid >::IndexType
217 SPIndexSet< Grid >::subIndex (
const Entity &entity,
int i,
unsigned int codim )
const
219 return subIndex< Entity::codimension >( entity, i, codim );
223 template<
class Gr
id >
225 inline typename SPIndexSet< Grid >::IndexType
227 ::subIndex (
const typename Codim< cd >::Entity &entity,
int i,
unsigned int codim )
const
229 assert( contains( entity ) );
230 const typename Codim< cd >::EntityInfo &entityInfo
231 = entity.impl().entityInfo();
233 return subIndex( entityInfo.id(), i, codim, entityInfo.partitionNumber(), std::integral_constant< int, cd >() );
237 template<
class Gr
id >
238 inline typename SPIndexSet< Grid >::IndexType
239 SPIndexSet< Grid >::size (
const GeometryType &type )
const
241 return (type.isCube() ? size( dimension - type.dim() ) : 0);
245 template<
class Gr
id >
246 inline typename SPIndexSet< Grid >::IndexType
247 SPIndexSet< Grid >::size (
const int codim )
const
249 assert( (codim >= 0) && (codim <= dimension) );
250 return size_[ codim ];
254 template<
class Gr
id >
255 template<
class Entity >
256 inline bool SPIndexSet< Grid >::contains (
const Entity &entity )
const
258 return contains< Entity::codimension >( entity );
262 template<
class Gr
id >
263 template<
int codim >
264 inline bool SPIndexSet< Grid >
265 ::contains (
const typename Codim< codim >::Entity &entity )
const
267 const typename Codim< codim >::EntityInfo &entityInfo
268 = entity.impl().entityInfo();
269 assert( partitions().contains( entityInfo.partitionNumber() ) );
270 return (&entityInfo.gridLevel() == &gridLevel());
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
Provides base classes for index and id sets.
Dune namespace.
Definition: alignedallocator.hh:13