1 #ifndef DUNE_ALUGRID_DEFAULTINDEXSETS_HH
2 #define DUNE_ALUGRID_DEFAULTINDEXSETS_HH
7 #include <dune/common/version.hh>
9 #include <dune/grid/common/grid.hh>
10 #include <dune/grid/common/adaptcallback.hh>
11 #include <dune/grid/utility/persistentcontainer.hh>
23 template <
class Gr
idImp>
30 template<PartitionIteratorType pitype>
39 template <
class Gr
idImp>
46 template<PartitionIteratorType pitype>
49 typedef typename GridImp::Traits::template
Codim<cd>::
61 template <
class Gr
idImp,
class IteratorImp >
63 public IndexSet< GridImp, DefaultIndexSet <GridImp, IteratorImp>,
64 unsigned int, std::vector< GeometryType > >
66 typedef GridImp GridType;
67 enum { dim = GridType::dimension };
70 enum {
ncodim = GridType::dimension + 1 };
75 typedef std::vector< GeometryType >
Types;
79 typedef IteratorImp IteratorType ;
97 struct InsertEntityLoop
100 static const int nextCodim = codim == dim ? dim : codim + 1;
102 static void apply (
const typename GridType::template Codim< 0 >::Entity &entity,
104 std::vector< int > &sizes )
109 Index &idx = codimContainer[ entity ];
110 if( idx.
index() < 0 )
111 idx.
set( sizes[ codim ]++ );
115 const int subEntities = entity.subEntities( codim );
116 for(
int i = 0; i < subEntities; ++i )
118 Index &idx = codimContainer( entity, i );
119 if( idx.
index() < 0 )
120 idx.
set( sizes[ codim ]++ );
127 InsertEntityLoop< nextCodim >::apply( entity,
indexContainer, sizes );
132 template <
class EntityType,
int codim>
136 const EntityType & e,
140 if( codim == EntityType::codimension )
143 DUNE_THROW(NotImplemented,
"subIndex for entities with codimension > 0 is not implemented");
148 template <
class EntityType>
149 struct EntitySpec<EntityType,0>
152 const EntityType & e,
163 using IndexSet<GridType, DefaultIndexSet>::subIndex;
168 const IteratorType& begin,
169 const IteratorType& end,
170 const int level = -1 )
176 for(
int codim=0; codim <
ncodim; ++codim )
185 for(
int codim=0; codim <
ncodim; ++codim )
186 delete indexContainers_[ codim ];
193 return *( indexContainers_[ codim ] );
200 return *( indexContainers_[ codim ] );
204 template<
class EntityType>
207 enum { cd = EntityType::codimension };
211 const int codim = cd;
212 alugrid_assert ( (codim == dim) ? (1) : ( level_ < 0 ) || (level_ == en.level() ));
225 const int codim = cd;
227 alugrid_assert ( (codim == dim) ? (
true) : ( level_ < 0 ) || (level_ == en.level() ));
236 IndexType subIndex (
const typename std::remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e,
237 int i,
unsigned int codim )
const
239 alugrid_assert ( (codim != 0) || (level_ < 0) || ( level_ == e.level() ) );
240 typedef typename std::remove_const< GridImp >::type::Traits::template Codim< cc >::Entity Entity;
241 return EntitySpec< Entity, cc >::subIndex(
indexContainer( codim ), e, i );
245 template<
class EntityType>
248 enum { cd = EntityType::codimension };
256 return size_[ codim ];
263 if( typeNotValid(type) )
return 0;
264 return size_[GridType::dimension-type.dim()];
269 void calcNewIndex (
const IteratorType &begin,
const IteratorType &end )
273 for(
int cd = 0; cd <
ncodim; ++cd )
281 for( IteratorType it = begin; it != end; ++it )
283 const typename IteratorType::Entity &entity = *it;
284 alugrid_assert ( ( level_ < 0 ) ? entity.isLeaf() : (entity.level() == level_) );
285 InsertEntityLoop< 0 >::apply( entity, indexContainers_, size_ );
289 for(
int cd=0; cd<
ncodim; ++cd)
292 const int gridSize = ( level_ < 0 ) ? grid_.size( cd ) : grid_.size( level_, cd);
293 const int mySize = size_[cd];
294 if( mySize > gridSize )
296 std::cout <<
"DefaultIndexSet[ " << level_ <<
" ]: " << mySize <<
" s | g " << gridSize << std::endl;
305 const std::vector<GeometryType>&
geomTypes (
int codim)
const
307 return grid_.geomTypes( codim );
325 bool typeNotValid (
const GeometryType & type)
const
327 int codim = GridType::dimension - type.dim();
328 const std::vector<GeometryType> & geomT =
geomTypes(codim);
329 for(
size_t i=0; i<geomT.size(); ++i)
if(geomT[i] == type)
return false;
334 const GridType& grid_;
340 std::vector< int > size_;
350 template <
class Gr
id>
396 template <
class Gr
idViewType>
397 void update(
const GridViewType& gridView )
402 const auto end = gridView.template end<0, Interior_Partition> ();
403 for(
auto it = gridView.template begin<0, Interior_Partition> (); it != end; ++ it )
405 const auto& entity = *it;
406 const auto endi = gridView.iend( entity );
407 for(
auto i = gridView.ibegin( entity ); i != endi; ++i )
409 const auto& intersection = *i;
410 if( intersection.boundary() )
412 const int id = Grid::getRealImplementation( intersection ).segmentId();
#define alugrid_assert(EX)
Definition: alugrid_assert.hh:20
Definition: alu3dinclude.hh:80
LevelIterator tpyes for all codims and partition types.
Definition: defaultindexsets.hh:25
The types.
Definition: defaultindexsets.hh:29
Definition: defaultindexsets.hh:32
GridImp::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator Iterator
Definition: defaultindexsets.hh:33
LeafIterator tpyes for all codims and partition types.
Definition: defaultindexsets.hh:41
The types of the iterator.
Definition: defaultindexsets.hh:45
Definition: defaultindexsets.hh:48
GridImp::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator Iterator
Definition: defaultindexsets.hh:50
DefaultIndexSet creates an index set by using the grids persistent container an a given pair of itera...
Definition: defaultindexsets.hh:65
IndexType size(GeometryType type) const
Definition: defaultindexsets.hh:261
std::vector< PersistentContainerType * > PersistentContainerVectorType
Definition: defaultindexsets.hh:91
std::vector< GeometryType > Types
type of geometry types
Definition: defaultindexsets.hh:75
Types types(const int codim) const
deliver all geometry types used in this grid
Definition: defaultindexsets.hh:311
IndexType size(int codim) const
return size of IndexSet for a given level and codim
Definition: defaultindexsets.hh:253
~DefaultIndexSet()
desctructor deleting persistent containers
Definition: defaultindexsets.hh:183
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition: defaultindexsets.hh:305
IndexType index(const typename GridImp::template Codim< cd >::Entity &en) const
return LevelIndex of given entity
Definition: defaultindexsets.hh:220
PersistentContainer< GridType, Index > PersistentContainerType
Definition: defaultindexsets.hh:90
bool contains(const EntityType &en) const
returns true if this set provides an index for given entity
Definition: defaultindexsets.hh:246
const PersistentContainerType & indexContainer(const size_t codim) const
Definition: defaultindexsets.hh:189
void calcNewIndex(const IteratorType &begin, const IteratorType &end)
Definition: defaultindexsets.hh:269
unsigned int IndexType
type of index
Definition: defaultindexsets.hh:73
bool containsIndex(const int cd, const int idx) const
returns true if this set provides an index for given entity
Definition: defaultindexsets.hh:317
PersistentContainerType & indexContainer(const size_t codim)
Definition: defaultindexsets.hh:196
@ ncodim
Definition: defaultindexsets.hh:70
IndexType index(const EntityType &en) const
return LevelIndex of given entity
Definition: defaultindexsets.hh:205
IndexType subIndex(const typename std::remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Definition: defaultindexsets.hh:236
DefaultIndexSet(const GridType &grid, const IteratorType &begin, const IteratorType &end, const int level=-1)
Definition: defaultindexsets.hh:167
Definition: defaultindexsets.hh:83
void set(const int index)
Definition: defaultindexsets.hh:87
int index() const
Definition: defaultindexsets.hh:86
int index_
Definition: defaultindexsets.hh:84
Index()
Definition: defaultindexsets.hh:85
DefaultBoundarySegmentIndexSet creates an index set for the macro boundary segments.
Definition: defaultindexsets.hh:352
int numSegments_
Definition: defaultindexsets.hh:370
IndexType size() const
Definition: defaultindexsets.hh:388
SegmentIndexVectorType segmentIndex_
Definition: defaultindexsets.hh:369
int IndexType
type of index
Definition: defaultindexsets.hh:355
void invalidate()
Definition: defaultindexsets.hh:432
DefaultBoundarySegmentIndexSet()
Definition: defaultindexsets.hh:373
void update(const GridViewType &gridView)
Definition: defaultindexsets.hh:397
std::vector< Index > SegmentIndexVectorType
type of geometry types
Definition: defaultindexsets.hh:367
IndexType index(const int segmentId) const
return LevelIndex of given entity
Definition: defaultindexsets.hh:380
bool valid() const
Definition: defaultindexsets.hh:431
Definition: defaultindexsets.hh:359
void set(const int index)
Definition: defaultindexsets.hh:363
IndexType index_
Definition: defaultindexsets.hh:360
int index() const
Definition: defaultindexsets.hh:362
Index()
Definition: defaultindexsets.hh:361