3 #ifndef DUNE_DEFAULTINDEXSETS_HH 4 #define DUNE_DEFAULTINDEXSETS_HH 11 #include <dune/common/forloop.hh> 27 template <
class Gr
idImp>
34 template<PartitionIteratorType pitype>
43 template <
class Gr
idImp>
50 template<PartitionIteratorType pitype>
53 typedef typename GridImp::Traits::template
Codim<cd>::
65 template <
class Gr
idImp,
class IteratorImp >
67 public IndexSet< GridImp, DefaultIndexSet <GridImp, IteratorImp>, unsigned int >
69 typedef GridImp GridType;
70 enum { dim = GridType :: dimension };
73 enum { ncodim = GridType::dimension + 1 };
80 typedef IteratorImp IteratorType ;
87 int index()
const {
return index_; }
88 void set(
const int index ) { index_ = index; }
100 static void apply (
const typename GridImp::template Codim< 0 >::Entity &entity,
101 PersistentContainerVectorType &indexContainer,
102 std::vector< int > &sizes )
104 PersistentContainerType &codimContainer = *(indexContainer[ codim ]);
107 Index &idx = codimContainer[ entity ];
108 if( idx.
index() < 0 )
109 idx.
set( sizes[ codim ]++ );
113 for(
int i = 0; i < entity.subEntities(codim); ++i )
115 Index &idx = codimContainer( entity, i );
116 if( idx.
index() < 0 )
117 idx.
set( sizes[ codim ]++ );
123 template <
class EntityType,
int codim>
126 static IndexType subIndex(
const PersistentContainerType& indexContainer,
127 const EntityType & e,
131 if( codim == EntityType :: codimension )
132 return indexContainer[ e ].index();
134 DUNE_THROW(NotImplemented,
"subIndex for entities with codimension > 0 is not implemented");
135 return IndexType(-1);
139 template <
class EntityType>
140 struct EntitySpec<EntityType,0>
142 static IndexType subIndex(
const PersistentContainerType& indexContainer,
143 const EntityType & e,
146 assert( indexContainer( e, i ).index() >= 0 );
147 return indexContainer( e, i ).index();
159 const IteratorType& begin,
160 const IteratorType& end,
161 const int level = -1 )
163 indexContainers_( ncodim, (PersistentContainerType *) 0),
167 for(
int codim=0; codim < ncodim; ++codim )
168 indexContainers_[ codim ] =
new PersistentContainerType( grid, codim );
170 calcNewIndex (begin, end);
176 for(
int codim=0; codim < ncodim; ++codim )
177 delete indexContainers_[ codim ];
182 assert( codim < indexContainers_.size() );
183 assert( indexContainers_[ codim ] );
184 return *( indexContainers_[ codim ] );
189 assert( codim < indexContainers_.size() );
190 assert( indexContainers_[ codim ] );
191 return *( indexContainers_[ codim ] );
195 template<
class EntityType>
196 IndexType
index (
const EntityType & en)
const 198 enum { cd = EntityType :: codimension };
202 const int codim = cd;
203 assert( (codim == dim) ? (1) : ( level_ < 0 ) || (level_ == en.level() ));
204 assert( indexContainer( codim )[ en ].index() >= 0 );
206 return indexContainer( cd )[ en ].index();
211 IndexType
index (
const typename GridImp::template Codim<cd>::Entity& en)
const 216 const int codim = cd;
218 assert( (codim == dim) ? (1) : ( level_ < 0 ) || (level_ == en.level() ));
219 assert( indexContainer( cd )[ en ].index() >= 0 );
221 return indexContainer( cd )[ en ].index();
227 IndexType
subIndex (
const typename remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e,
228 int i,
unsigned int codim )
const 230 assert( (codim != 0) || (level_ < 0) || ( level_ == e.level() ) );
231 typedef typename remove_const< GridImp >::type::Traits::template Codim< cc >::Entity
Entity;
232 return EntitySpec< Entity, cc > :: subIndex( indexContainer( codim ), e, i );
236 template<
class EntityType>
239 enum { cd = EntityType :: codimension };
240 return (indexContainer( cd )[ en ].index() >= 0 );
244 IndexType
size (
int codim )
const 246 assert( codim >= 0 && codim <= GridType::dimension );
247 return size_[ codim ];
254 if( typeNotValid(type) )
return 0;
255 return size_[GridType::dimension-type.dim()];
260 void calcNewIndex (
const IteratorType &begin,
const IteratorType &end )
264 for(
int cd = 0; cd < ncodim; ++cd )
266 indexContainer( cd ).resize(
Index() );
267 indexContainer( cd ).shrinkToFit();
268 indexContainer( cd ).fill(
Index() );
273 for( IteratorType it = begin; it != end; ++it )
275 assert( ( level_ < 0 ) ? it->isLeaf() : (it->level() == level_) );
276 ForLoop< InsertEntity, 0, dim >::apply( *it, indexContainers_, size_ );
280 for(
int cd=0; cd<ncodim; ++cd)
283 const int gridSize = ( level_ < 0 ) ? grid_.size( cd ) : grid_.size( level_, cd);
284 const int mySize = size_[cd];
285 if( mySize > gridSize )
287 std::cout <<
"DefaultIndexSet[ " << level_ <<
" ]: " << mySize <<
" s | g " << gridSize << std::endl;
295 std::vector< GeometryType >
types (
int codim )
const {
return grid_.geomTypes( codim ); }
298 const std::vector<GeometryType>&
geomTypes (
int codim)
const 300 return grid_.geomTypes( codim );
307 return ((indexContainer( cd ).begin() + idx)->index() >= 0);
314 int codim = GridType :: dimension - type.dim();
315 const std::vector<GeometryType> & geomT = geomTypes(codim);
316 for(
size_t i=0; i<geomT.size(); ++i)
if(geomT[i] == type)
return false;
321 const GridType& grid_;
324 PersistentContainerVectorType indexContainers_;
327 std::vector< int > size_;
336 #endif // #ifndef DUNE_DEFAULTINDEXSETS_HH IndexType size(GeometryType type) const
Definition: defaultindexsets.hh:252
std::vector< GeometryType > types(int codim) const
Definition: defaultindexsets.hh:295
DefaultIndexSet(const GridType &grid, const IteratorType &begin, const IteratorType &end, const int level=-1)
Definition: defaultindexsets.hh:158
A class for storing data during an adaptation cycle.
Definition: utility/persistentcontainer.hh:18
DefaultIndexSet creates an index set by using the grids persistent container an a given pair of itera...
Definition: defaultindexsets.hh:66
Definition: defaultindexsets.hh:35
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
int index_
Definition: defaultindexsets.hh:85
IndexType index(const EntityType &en) const
return LevelIndex of given entity
Definition: defaultindexsets.hh:196
Wrapper class for entities.
Definition: common/entity.hh:61
GridImp::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator Iterator
Definition: defaultindexsets.hh:54
IndexType subIndex(const typename remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Definition: defaultindexsets.hh:227
LeafIterator tpyes for all codims and partition types.
Definition: defaultindexsets.hh:44
bool contains(const EntityType &en) const
returns true if this set provides an index for given entity
Definition: defaultindexsets.hh:237
const PersistentContainerType & indexContainer(const size_t codim) const
Definition: defaultindexsets.hh:180
LevelIterator tpyes for all codims and partition types.
Definition: defaultindexsets.hh:28
Index()
Definition: defaultindexsets.hh:86
int index() const
Definition: defaultindexsets.hh:87
Index Set Interface base class.
Definition: common/grid.hh:361
PersistentContainerType & indexContainer(const size_t codim)
Definition: defaultindexsets.hh:187
unsigned int IndexType
type of index
Definition: defaultindexsets.hh:76
GridImp::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator Iterator
Definition: defaultindexsets.hh:37
interfaces and wrappers needed for the callback adaptation provided by AlbertaGrid and ALUGrid ...
IndexType index(const typename GridImp::template Codim< cd >::Entity &en) const
return LevelIndex of given entity
Definition: defaultindexsets.hh:211
std::vector< PersistentContainerType * > PersistentContainerVectorType
Definition: defaultindexsets.hh:92
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition: defaultindexsets.hh:298
bool containsIndex(const int cd, const int idx) const
returns true if this set provides an index for given entity
Definition: defaultindexsets.hh:304
~DefaultIndexSet()
desctructor deleting persistent containers
Definition: defaultindexsets.hh:174
std::map< G::LocalIdSet::IdType, T >::size_type Size
Definition: persistentcontainermap.hh:36
void calcNewIndex(const IteratorType &begin, const IteratorType &end)
Definition: defaultindexsets.hh:260
IndexType size(int codim) const
return size of IndexSet for a given level and codim
Definition: defaultindexsets.hh:244
Definition: defaultindexsets.hh:83
The types of the iterator.
Definition: defaultindexsets.hh:48
PersistentContainer< GridType, Index > PersistentContainerType
Definition: defaultindexsets.hh:91
Include standard header files.
Definition: agrid.hh:59
Different resources needed by all grid implementations.
The types.
Definition: defaultindexsets.hh:32
Definition: defaultindexsets.hh:51
void set(const int index)
Definition: defaultindexsets.hh:88