1 #ifndef DUNE_DEFAULTINDEXSETS_HH
2 #define DUNE_DEFAULTINDEXSETS_HH
9 #include <dune/common/misc.hh>
24 template <
class Gr
idImp>
31 template<PartitionIteratorType pitype>
40 template <
class Gr
idImp>
47 template<PartitionIteratorType pitype>
50 typedef typename GridImp::Traits::template
Codim<cd>::
57 namespace DefaultIndexSetHelper
60 template<
class Gr
id,
class Index >
67 DUNE_THROW( NotImplemented,
"DefaultIndexSetHelper::ContainsIndex not implemented for this grid." );
79 template <
class Gr
idImp,
class IteratorImp >
81 public IndexSet< GridImp, DefaultIndexSet <GridImp, IteratorImp>, unsigned int >
83 typedef GridImp GridType;
84 enum { dim = GridType :: dimension };
87 enum {
ncodim = GridType::dimension + 1 };
109 template <
class EntityType,
int codim>
112 template <
class SizeVector>
113 static void insert(
const EntityType & en,
118 for(
int i = 0; i < en.template count< codim >(); ++i )
120 Index& idx = codimContainer( en , i );
121 if( idx.
index() < 0 )
123 idx.
set( sizes[codim] );
127 InsertEntity<EntityType,codim-1>::insert(en, indexContainer, sizes);
131 template <
class EntityType>
132 struct InsertEntity<EntityType,0>
134 template <
class SizeVector>
135 static void insert(
const EntityType & en,
141 Index& idx = codimContainer[ en ];
142 if( idx.index() < 0 )
144 idx.set( sizes[codim] );
153 using IndexSet<GridType, DefaultIndexSet>::subIndex;
160 const int level = -1 )
166 for(
int codim=0; codim <
ncodim; ++codim )
175 for(
int codim=0; codim <
ncodim; ++codim )
176 delete indexContainers_[ codim ];
181 assert( codim < indexContainers_.size() );
182 assert( indexContainers_[ codim ] );
183 return *( indexContainers_[ codim ] );
188 assert( codim < indexContainers_.size() );
189 assert( indexContainers_[ codim ] );
190 return *( indexContainers_[ codim ] );
194 template<
class EntityType>
197 enum { cd = EntityType :: codimension };
201 const int codim = cd;
202 assert( (codim == dim) ? (1) : ( level_ < 0 ) || (level_ == en.level() ));
215 const int codim = cd;
217 assert( (codim == dim) ? (1) : ( level_ < 0 ) || (level_ == en.level() ));
226 IndexType subIndex (
const typename remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e,
227 int i,
unsigned int codim )
const
229 assert( (codim != 0) || (level_ < 0) || ( level_ == e.level() ) );
235 template<
class EntityType>
238 enum { cd = EntityType :: codimension };
245 assert( codim >= 0 && codim <= GridType::dimension );
246 return size_[ codim ];
253 if( typeNotValid(type) )
return 0;
254 return size_[GridType::dimension-type.dim()];
263 for(
int cd=0; cd<
ncodim; ++cd)
272 assert( ( level_ < 0 ) ? it->isLeaf() : (it->level() == level_) );
273 insertEntity( *it, size_ );
277 for(
int cd=0; cd<
ncodim; ++cd)
280 const int gridSize = ( level_ < 0 ) ? grid_.size( cd ) : grid_.size( level_, cd);
281 const int mySize = size_[cd];
282 if( mySize > gridSize )
284 std::cout << mySize <<
" s | g " << gridSize << std::endl;
286 assert( mySize <= gridSize );
292 const std::vector<GeometryType>&
geomTypes (
int codim)
const
294 return grid_.geomTypes( codim );
308 int codim = GridType :: dimension - type.dim();
309 const std::vector<GeometryType> & geomT =
geomTypes(codim);
310 for(
size_t i=0; i<geomT.size(); ++i)
if(geomT[i] == type)
return false;
315 template <
class EntityType,
class SizeVector>
316 void insertEntity(EntityType & en, SizeVector& sizes)
318 InsertEntity<EntityType,dim>::insert( en, indexContainers_, sizes);
322 const GridType& grid_;
328 std::vector< int > size_;