1#ifndef DUNE_ALUGRID_DEFAULTINDEXSETS_HH
2#define DUNE_ALUGRID_DEFAULTINDEXSETS_HH
8#include <dune/common/forloop.hh>
9#include <dune/common/version.hh>
11#include <dune/grid/common/grid.hh>
12#include <dune/grid/common/adaptcallback.hh>
13#include <dune/grid/utility/persistentcontainer.hh>
25 template <
class Gr
idImp>
32 template<PartitionIteratorType pitype>
41 template <
class Gr
idImp>
48 template<PartitionIteratorType pitype>
51 typedef typename GridImp::Traits::template
Codim<cd>::
63 template <
class Gr
idImp,
class IteratorImp >
65 public IndexSet< GridImp, DefaultIndexSet <GridImp, IteratorImp>,
67#if DUNE_VERSION_NEWER(DUNE_GRID,2,4)
68 , std::vector< GeometryType >
72 typedef GridImp GridType;
73 enum { dim = GridType::dimension };
76 enum {
ncodim = GridType::dimension + 1 };
81 typedef std::vector< GeometryType >
Types;
85 typedef IteratorImp IteratorType ;
102 template<
int codim >
105 static void apply (
const typename GridType::template Codim< 0 >::Entity &entity,
107 std::vector< int > &sizes )
112 Index &idx = codimContainer[ entity ];
113 if( idx.
index() < 0 )
114 idx.
set( sizes[ codim ]++ );
118#if DUNE_VERSION_NEWER(DUNE_GRID,2,4)
119 const int subEntities = entity.subEntities( codim );
121 const int subEntities = entity.template count< codim > ();
123 for(
int i = 0; i < subEntities; ++i )
125 Index &idx = codimContainer( entity, i );
126 if( idx.
index() < 0 )
127 idx.
set( sizes[ codim ]++ );
133 template <
class EntityType,
int codim>
137 const EntityType & e,
141 if( codim == EntityType::codimension )
144 DUNE_THROW(NotImplemented,
"subIndex for entities with codimension > 0 is not implemented");
149 template <
class EntityType>
150 struct EntitySpec<EntityType,0>
153 const EntityType & e,
169 const IteratorType& begin,
170 const IteratorType& end,
171 const int level = -1 )
177 for(
int codim=0; codim <
ncodim; ++codim )
186 for(
int codim=0; codim <
ncodim; ++codim )
187 delete indexContainers_[ codim ];
194 return *( indexContainers_[ codim ] );
201 return *( indexContainers_[ codim ] );
205 template<
class EntityType>
208 enum { cd = EntityType::codimension };
212 const int codim = cd;
213 alugrid_assert ( (codim == dim) ? (1) : ( level_ < 0 ) || (level_ == en.level() ));
226 const int codim = cd;
228 alugrid_assert ( (codim == dim) ? (
true) : ( level_ < 0 ) || (level_ == en.level() ));
237 IndexType subIndex (
const typename std::remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e,
238 int i,
unsigned int codim )
const
240 alugrid_assert ( (codim != 0) || (level_ < 0) || ( level_ == e.level() ) );
241 typedef typename std::remove_const< GridImp >::type::Traits::template Codim< cc >::Entity Entity;
242 return EntitySpec< Entity, cc >::subIndex(
indexContainer( codim ), e, i );
246 template<
class EntityType>
249 enum { cd = EntityType::codimension };
257 return size_[ codim ];
264 if( typeNotValid(type) )
return 0;
265 return size_[GridType::dimension-type.dim()];
270 void calcNewIndex (
const IteratorType &begin,
const IteratorType &end )
274 for(
int cd = 0; cd <
ncodim; ++cd )
282 for( IteratorType it = begin; it != end; ++it )
284 alugrid_assert ( ( level_ < 0 ) ? it->isLeaf() : (it->level() == level_) );
285 const typename IteratorType::Entity &entity = *it;
286 ForLoop< InsertEntity, 0, dim >::apply( entity, indexContainers_, size_ );
290 for(
int cd=0; cd<
ncodim; ++cd)
293 const int gridSize = ( level_ < 0 ) ? grid_.size( cd ) : grid_.size( level_, cd);
294 const int mySize = size_[cd];
295 if( mySize > gridSize )
297 std::cout <<
"DefaultIndexSet[ " << level_ <<
" ]: " << mySize <<
" s | g " << gridSize << std::endl;
306 const std::vector<GeometryType>&
geomTypes (
int codim)
const
308 return grid_.geomTypes( codim );
326 bool typeNotValid (
const GeometryType & type)
const
328 int codim = GridType::dimension - type.dim();
329 const std::vector<GeometryType> & geomT =
geomTypes(codim);
330 for(
size_t i=0; i<geomT.size(); ++i)
if(geomT[i] == type)
return false;
335 const GridType& grid_;
341 std::vector< int > size_;
#define alugrid_assert(EX)
Definition alugrid_assert.hh:20
Definition alu3dinclude.hh:80
LevelIterator tpyes for all codims and partition types.
Definition defaultindexsets.hh:27
The types.
Definition defaultindexsets.hh:31
Definition defaultindexsets.hh:34
GridImp::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator Iterator
Definition defaultindexsets.hh:35
LeafIterator tpyes for all codims and partition types.
Definition defaultindexsets.hh:43
The types of the iterator.
Definition defaultindexsets.hh:47
Definition defaultindexsets.hh:50
GridImp::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator Iterator
Definition defaultindexsets.hh:52
DefaultIndexSet creates an index set by using the grids persistent container an a given pair of itera...
Definition defaultindexsets.hh:71
IndexType size(GeometryType type) const
Definition defaultindexsets.hh:262
@ ncodim
Definition defaultindexsets.hh:76
std::vector< PersistentContainerType * > PersistentContainerVectorType
Definition defaultindexsets.hh:97
std::vector< GeometryType > Types
type of geometry types
Definition defaultindexsets.hh:81
Types types(const int codim) const
deliver all geometry types used in this grid
Definition defaultindexsets.hh:312
IndexType size(int codim) const
return size of IndexSet for a given level and codim
Definition defaultindexsets.hh:254
~DefaultIndexSet()
desctructor deleting persistent containers
Definition defaultindexsets.hh:184
IndexType index(const typename GridImp::template Codim< cd >::Entity &en) const
return LevelIndex of given entity
Definition defaultindexsets.hh:221
PersistentContainer< GridType, Index > PersistentContainerType
Definition defaultindexsets.hh:96
const PersistentContainerType & indexContainer(const size_t codim) const
Definition defaultindexsets.hh:190
bool contains(const EntityType &en) const
returns true if this set provides an index for given entity
Definition defaultindexsets.hh:247
void calcNewIndex(const IteratorType &begin, const IteratorType &end)
Definition defaultindexsets.hh:270
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition defaultindexsets.hh:306
unsigned int IndexType
type of index
Definition defaultindexsets.hh:79
bool containsIndex(const int cd, const int idx) const
returns true if this set provides an index for given entity
Definition defaultindexsets.hh:318
IndexType index(const EntityType &en) const
return LevelIndex of given entity
Definition defaultindexsets.hh:206
IndexType subIndex(const typename std::remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Definition defaultindexsets.hh:237
DefaultIndexSet(const GridType &grid, const IteratorType &begin, const IteratorType &end, const int level=-1)
Definition defaultindexsets.hh:168
PersistentContainerType & indexContainer(const size_t codim)
Definition defaultindexsets.hh:197
Definition defaultindexsets.hh:89
void set(const int index)
Definition defaultindexsets.hh:93
int index() const
Definition defaultindexsets.hh:92
int index_
Definition defaultindexsets.hh:90
Index()
Definition defaultindexsets.hh:91