1 #ifndef DUNE_ALUGRID_DEFAULTINDEXSETS_HH
2 #define DUNE_ALUGRID_DEFAULTINDEXSETS_HH
8 #include <dune/common/version.hh>
10 #include <dune/grid/common/grid.hh>
11 #include <dune/grid/common/adaptcallback.hh>
12 #include <dune/grid/utility/persistentcontainer.hh>
26 template <
class Gr
idImp>
33 template<PartitionIteratorType pitype>
42 template <
class Gr
idImp>
49 template<PartitionIteratorType pitype>
52 typedef typename GridImp::Traits::template
Codim<cd>::
64 template <
class Gr
idImp,
class IteratorImp >
66 public IndexSet< GridImp, DefaultIndexSet <GridImp, IteratorImp>,
67 unsigned int, std::vector< GeometryType > >
69 typedef GridImp GridType;
70 enum { dim = GridType::dimension };
73 enum {
ncodim = GridType::dimension + 1 };
78 typedef std::vector< GeometryType >
Types;
82 typedef IteratorImp IteratorType ;
100 struct InsertEntityLoop
103 static const int nextCodim = codim == dim ? dim : codim + 1;
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 const int subEntities = entity.subEntities( codim );
119 for(
int i = 0; i < subEntities; ++i )
121 Index &idx = codimContainer( entity, i );
122 if( idx.
index() < 0 )
123 idx.
set( sizes[ codim ]++ );
130 InsertEntityLoop< nextCodim >::apply( entity,
indexContainer, sizes );
135 template <
class EntityType,
int codim>
139 const EntityType & e,
143 if( codim == EntityType::codimension )
146 DUNE_THROW(NotImplemented,
"subIndex for entities with codimension > 0 is not implemented");
151 template <
class EntityType>
152 struct EntitySpec<EntityType,0>
155 const EntityType & e,
164 DefaultIndexSet(
const DefaultIndexSet& org ) =
delete;
169 using IndexSet<GridType, DefaultIndexSet>::subIndex;
174 const IteratorType& begin,
175 const IteratorType& end,
176 const int level = -1 )
178 indexContainers_(
ncodim ),
182 for(
int codim=0; codim <
ncodim; ++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;
229 alugrid_assert ( (codim == dim) ? (
true) : ( level_ < 0 ) || (level_ == en.level() ));
238 IndexType subIndex (
const typename std::remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e,
239 int i,
unsigned int codim )
const
241 alugrid_assert ( (codim != 0) || (level_ < 0) || ( level_ == e.level() ) );
242 typedef typename std::remove_const< GridImp >::type::Traits::template Codim< cc >::Entity Entity;
243 return EntitySpec< Entity, cc >::subIndex(
indexContainer( codim ), e, i );
247 template<
class EntityType>
250 enum { cd = EntityType::codimension };
258 return size_[ codim ];
265 if( typeNotValid(type) )
return 0;
266 return size_[GridType::dimension-type.dim()];
271 void calcNewIndex (
const IteratorType &begin,
const IteratorType &end )
275 for(
int cd = 0; cd <
ncodim; ++cd )
283 for( IteratorType it = begin; it != end; ++it )
285 const typename IteratorType::Entity &entity = *it;
286 alugrid_assert ( ( level_ < 0 ) ? entity.isLeaf() : (entity.level() == level_) );
287 InsertEntityLoop< 0 >::apply( entity, indexContainers_, size_ );
291 for(
int cd=0; cd<
ncodim; ++cd)
294 const int gridSize = ( level_ < 0 ) ? grid_.size( cd ) : grid_.size( level_, cd);
295 const int mySize = size_[cd];
296 if( mySize > gridSize )
298 std::cout <<
"DefaultIndexSet[ " << level_ <<
" ]: " << mySize <<
" s | g " << gridSize << std::endl;
307 const std::vector<GeometryType>&
geomTypes (
int codim)
const
309 return grid_.geomTypes( codim );
327 bool typeNotValid (
const GeometryType & type)
const
329 int codim = GridType::dimension - type.dim();
330 const std::vector<GeometryType> & geomT =
geomTypes(codim);
331 for(
size_t i=0; i<geomT.size(); ++i)
if(geomT[i] == type)
return false;
336 const GridType& grid_;
342 std::vector< int > size_;
352 template <
class Gr
id>
398 template <
class Gr
idViewType>
399 void update(
const GridViewType& gridView )
404 const auto end = gridView.template end<0, Interior_Partition> ();
405 for(
auto it = gridView.template begin<0, Interior_Partition> (); it != end; ++ it )
407 const auto& entity = *it;
408 const auto endi = gridView.iend( entity );
409 for(
auto i = gridView.ibegin( entity ); i != endi; ++i )
411 const auto& intersection = *i;
412 if( intersection.boundary() )
414 const int id = intersection.impl().segmentId();
#define alugrid_assert(EX)
Definition: alugrid_assert.hh:20
Definition: alu3dinclude.hh:63
LevelIterator tpyes for all codims and partition types.
Definition: defaultindexsets.hh:28
The types.
Definition: defaultindexsets.hh:32
Definition: defaultindexsets.hh:35
GridImp::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator Iterator
Definition: defaultindexsets.hh:36
LeafIterator tpyes for all codims and partition types.
Definition: defaultindexsets.hh:44
The types of the iterator.
Definition: defaultindexsets.hh:48
Definition: defaultindexsets.hh:51
GridImp::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator Iterator
Definition: defaultindexsets.hh:53
DefaultIndexSet creates an index set by using the grids persistent container an a given pair of itera...
Definition: defaultindexsets.hh:68
IndexType size(GeometryType type) const
Definition: defaultindexsets.hh:263
std::vector< GeometryType > Types
type of geometry types
Definition: defaultindexsets.hh:78
Types types(const int codim) const
deliver all geometry types used in this grid
Definition: defaultindexsets.hh:313
IndexType size(int codim) const
return size of IndexSet for a given level and codim
Definition: defaultindexsets.hh:255
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition: defaultindexsets.hh:307
std::vector< std::unique_ptr< PersistentContainerType > > PersistentContainerVectorType
Definition: defaultindexsets.hh:94
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:93
bool contains(const EntityType &en) const
returns true if this set provides an index for given entity
Definition: defaultindexsets.hh:248
const PersistentContainerType & indexContainer(const size_t codim) const
Definition: defaultindexsets.hh:190
void calcNewIndex(const IteratorType &begin, const IteratorType &end)
Definition: defaultindexsets.hh:271
unsigned int IndexType
type of index
Definition: defaultindexsets.hh:76
bool containsIndex(const int cd, const int idx) const
returns true if this set provides an index for given entity
Definition: defaultindexsets.hh:319
PersistentContainerType & indexContainer(const size_t codim)
Definition: defaultindexsets.hh:197
@ ncodim
Definition: defaultindexsets.hh:73
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:238
DefaultIndexSet(const GridType &grid, const IteratorType &begin, const IteratorType &end, const int level=-1)
Definition: defaultindexsets.hh:173
Definition: defaultindexsets.hh:86
void set(const int index)
Definition: defaultindexsets.hh:90
int index() const
Definition: defaultindexsets.hh:89
int index_
Definition: defaultindexsets.hh:87
Index()
Definition: defaultindexsets.hh:88
DefaultBoundarySegmentIndexSet creates an index set for the macro boundary segments.
Definition: defaultindexsets.hh:354
int numSegments_
Definition: defaultindexsets.hh:372
IndexType size() const
Definition: defaultindexsets.hh:390
SegmentIndexVectorType segmentIndex_
Definition: defaultindexsets.hh:371
int IndexType
type of index
Definition: defaultindexsets.hh:357
void invalidate()
Definition: defaultindexsets.hh:434
DefaultBoundarySegmentIndexSet()
Definition: defaultindexsets.hh:375
void update(const GridViewType &gridView)
Definition: defaultindexsets.hh:399
std::vector< Index > SegmentIndexVectorType
type of geometry types
Definition: defaultindexsets.hh:369
IndexType index(const int segmentId) const
return LevelIndex of given entity
Definition: defaultindexsets.hh:382
bool valid() const
Definition: defaultindexsets.hh:433
Definition: defaultindexsets.hh:361
void set(const int index)
Definition: defaultindexsets.hh:365
IndexType index_
Definition: defaultindexsets.hh:362
int index() const
Definition: defaultindexsets.hh:364
Index()
Definition: defaultindexsets.hh:363