1#ifndef DUNE_ALUGRID_DEFAULTINDEXSETS_HH
2#define DUNE_ALUGRID_DEFAULTINDEXSETS_HH
12#include <dune/grid/utility/persistentcontainer.hh>
14#include <dune/alugrid/common/alugrid_assert.hh>
26 template <
class Gr
idImp>
33 template<PartitionIteratorType pitype>
36 typedef typename GridImp::Traits::template
Codim<cd>::template Partition<pitype>::LevelIterator Iterator;
42 template <
class Gr
idImp>
49 template<PartitionIteratorType pitype>
52 typedef typename GridImp::Traits::template
Codim<cd>::
53 template Partition<pitype>::LeafIterator Iterator;
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 ;
88 Index() : index_( -1 ) {}
89 int index()
const {
return index_; }
90 void set(
const int index ) { index_ =
index; }
94 typedef std::vector< std::unique_ptr< PersistentContainerType > > PersistentContainerVectorType;
100 struct InsertEntityLoop
103 static const int nextCodim = codim == dim ? dim : codim + 1;
106 PersistentContainerVectorType &indexContainer,
107 std::vector< int > &sizes )
109 PersistentContainerType &codimContainer = *(indexContainer[ codim ]);
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 )
144 return indexContainer[ e ].index();
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,
158 alugrid_assert ( indexContainer( e, i ).
index() >= 0 );
159 return indexContainer( e, i ).index();
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 )
190 const PersistentContainerType& indexContainer(
const size_t codim )
const
192 alugrid_assert ( codim < indexContainers_.size() );
193 alugrid_assert ( indexContainers_[ codim ] );
194 return *( indexContainers_[ codim ] );
197 PersistentContainerType& indexContainer(
const size_t codim )
199 alugrid_assert ( codim < indexContainers_.size() );
200 alugrid_assert ( 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() ));
214 alugrid_assert ( indexContainer( codim )[ en ].
index() >= 0 );
216 return indexContainer( cd )[ en ].index();
226 const int codim = cd;
229 alugrid_assert ( (codim == dim) ? (
true) : ( level_ < 0 ) || (level_ == en.level() ));
230 alugrid_assert ( indexContainer( cd )[ en ].
index() >= 0 );
232 return indexContainer( cd )[ en ].index();
239 int i,
unsigned int codim )
const
241 alugrid_assert ( (codim != 0) || (level_ < 0) || ( level_ == e.level() ) );
243 return EntitySpec< Entity, cc >::subIndex( indexContainer( codim ), e, i );
247 template<
class EntityType>
250 enum { cd = EntityType::codimension };
251 return (indexContainer( cd )[ en ].
index() >= 0 );
257 alugrid_assert ( codim >= 0 && codim <= GridType::dimension );
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 )
277 indexContainer( cd ).resize( Index() );
278 indexContainer( cd ).fill( Index() );
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 );
321 alugrid_assert ( (
typename PersistentContainerType::Size)idx < indexContainer( cd ).
size() );
322 return ((indexContainer( cd ).begin() + idx)->
index() >= 0);
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_;
339 PersistentContainerVectorType indexContainers_;
342 std::vector< int > size_;
352 template <
class Gr
id>
363 Index() : index_( -1 ) {}
364 int index()
const {
return index_; }
365 void set(
const int index ) { index_ =
index; }
384 alugrid_assert( valid() );
385 alugrid_assert( segmentId <
int(segmentIndex_.size() ) );
386 alugrid_assert( segmentIndex_[ segmentId ].
index() >= 0 );
387 return segmentIndex_[ segmentId ].index();
392 alugrid_assert( valid() );
398 template <
class Gr
idViewType>
399 void update(
const GridViewType& gridView )
402 segmentIndex_.clear();
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();
415 if(
int(segmentIndex_.size()) <=
id )
416 segmentIndex_.resize(
id+1 );
417 if( segmentIndex_[
id ].
index() < 0 )
418 segmentIndex_[ id ].set( numSegments_ ++ );
424 if( numSegments_ ==
int(segmentIndex_.size()) )
426 for(
int i=0; i<numSegments_; ++ i )
428 segmentIndex_[ i ].set( i );
433 bool valid ()
const {
return numSegments_ >= 0; }
434 void invalidate () { numSegments_ = -1; }
interfaces and wrappers needed for the callback adaptation provided by AlbertaGrid and dune-ALUGrid
DefaultBoundarySegmentIndexSet creates an index set for the macro boundary segments.
Definition: defaultindexsets.hh:354
int IndexType
type of index
Definition: defaultindexsets.hh:357
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
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
IndexType index(const typename GridImp::template Codim< cd >::Entity &en) const
return LevelIndex of given entity
Definition: defaultindexsets.hh:221
bool contains(const EntityType &en) const
returns true if this set provides an index for given entity
Definition: defaultindexsets.hh:248
void calcNewIndex(const IteratorType &begin, const IteratorType &end)
Definition: defaultindexsets.hh:271
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition: defaultindexsets.hh:307
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
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
Wrapper class for entities.
Definition: entity.hh:66
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:371
Index Set Interface base class.
Definition: indexidset.hh:78
A class for storing data during an adaptation cycle.
Definition: persistentcontainer.hh:22
Different resources needed by all grid implementations.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
The types of the iterator.
Definition: defaultindexsets.hh:48
LeafIterator tpyes for all codims and partition types.
Definition: defaultindexsets.hh:44
The types.
Definition: defaultindexsets.hh:32
LevelIterator tpyes for all codims and partition types.
Definition: defaultindexsets.hh:28
Various macros to work with Dune module version numbers.