1 #ifndef DUNE_FEM_CODIMINDEXSET_HH 2 #define DUNE_FEM_CODIMINDEXSET_HH 10 #include <dune/grid/utility/persistentcontainer.hh> 12 #include <dune/grid/utility/persistentcontainervector.hh> 13 #include <dune/grid/utility/persistentcontainerwrapper.hh> 14 #include <dune/grid/utility/persistentcontainermap.hh> 29 template <
class Gr
idImp>
37 enum INDEXSTATE { UNUSED = 0,
42 const GridType& grid_;
85 const double memoryFactor = 1.1)
127 std::fill( indexState_.
begin(), indexState_.
end(), UNUSED );
132 std::set< int > found ;
134 typedef typename IndexContainerType::Iterator Iterator;
136 const Iterator end = leafIndex_.end();
137 for( Iterator it = leafIndex_.begin(); it != end; ++it )
141 if( found.find( *it ) != found.end() )
143 std::cout <<
"index " << *it <<
" exists twice " << std::endl;
145 assert( found.find( *it ) == found.end() );
162 lastSize_ = indexState_.
size();
169 const int sizeOfVecs = indexState_.
size();
170 holes_.
resize( sizeOfVecs );
173 bool haveToCopy =
false;
180 if( indexState_[
index ] == UNUSED )
181 holes_[ actHole++ ] =
index;
185 const int actSize = sizeOfVecs - actHole;
196 typedef typename IndexContainerType::Iterator Iterator;
197 const Iterator end = leafIndex_.end();
198 for( Iterator it = leafIndex_.begin(); it != end; ++it )
200 IndexType&
index = *it;
205 else if( indexState_[ index ] == UNUSED )
215 if( index >= actSize )
222 assert(actHole >= 0);
223 while ( holes_[actHole] >= actSize )
226 if(actHole < 0)
break;
229 assert(actHole >= 0);
235 if( indexState_[ index ] == USED )
239 oldIdx_[holes] =
index;
240 newIdx_[holes] = holes_[actHole];
244 index = holes_[actHole];
258 for(
int hole = 0; hole < holes; ++hole )
259 indexState_[ newIdx_[ hole ] ] = NEW;
264 numberHoles_ = oldIdx_.
size();
270 indexState_.
resize( actSize );
273 for(
int i=0; i<actSize; ++i )
274 assert( indexState_[ i ] == USED ||
275 indexState_[ i ] == UNUSED ||
276 indexState_[ i ] == NEW );
287 IndexType
size ()
const {
return indexState_.
size(); }
292 return leafIndex_.size();
297 template <
class EntityType>
298 IndexType
index (
const EntityType& entity )
const 300 assert( myCodim_ == EntityType :: codimension );
302 return leafIndex_[ entity ];
306 template <
class EntityType>
308 const int subNumber )
const 310 assert( 0 == EntityType :: codimension );
316 template <
class EntityType>
317 bool exists (
const EntityType& entity )
const 319 assert( myCodim_ == EntityType :: codimension );
320 const IndexType &
index = leafIndex_[ entity ];
324 return (indexState_[ index ] != UNUSED);
327 template <
class EntityType>
329 const int subNumber )
const 331 assert( 0 == EntityType :: codimension );
336 return (indexState_[ index ] != UNUSED);
349 return oldIdx_[elNum];
356 return newIdx_[elNum];
360 template <
class EntityType>
363 assert( myCodim_ == EntityType :: codimension );
368 template <
class EntityType>
372 assert( 0 == EntityType :: codimension );
377 template <
class EntityType>
380 assert( myCodim_ == EntityType :: codimension );
382 IndexType &leafIdx = leafIndex_[ entity ];
387 if( leafIdx >= lastSize_ )
388 indexState_[ leafIdx ] = NEW;
392 template <
class EntityType>
395 assert( myCodim_ == EntityType :: codimension );
396 const IndexType &
index = leafIndex_[ entity ];
398 indexState_[
index ] = UNUSED;
402 template <
class EntityType>
405 assert( myCodim_ == EntityType :: codimension );
406 return (leafIndex_[ entity ] >= 0);
409 void print( std::ostream& out )
const 411 typedef typename IndexContainerType::ConstIterator Iterator;
412 const Iterator end = leafIndex_.end();
413 for( Iterator it = leafIndex_.begin(); it != end; ++it )
415 const IndexType &leafIdx = *it;
416 out <<
"idx: " << leafIdx <<
" stat: " << indexState_[ leafIdx ] << std::endl;
425 assert( idx <
size() );
434 index = indexState_.
size();
435 indexState_.
resize( index+1 );
438 indexState_[
index ] = USED;
443 template <
class StreamTraits>
450 const uint32_t indexSize = indexState_.
size();
454 const uint64_t mysize = leafIndex_.size();
458 typedef typename IndexContainerType::ConstIterator ConstIterator;
459 const ConstIterator end = leafIndex_.end();
460 for( ConstIterator it = leafIndex_.begin(); it != end; ++it )
467 template <
class StreamTraits>
475 indexState_.
resize( size );
476 std::fill( indexState_.
begin(), indexState_.
end(), USED );
479 uint64_t storedSize = 0;
482 uint64_t leafsize = leafIndex_.size();
484 if( storedSize < leafsize )
486 DUNE_THROW(InvalidStateException,
"CodimIndexSet: size consistency check failed during restore!");
490 typedef typename IndexContainerType::Iterator Iterator;
491 const Iterator end = leafIndex_.end();
493 for( Iterator it = leafIndex_.begin(); it != end; ++it, ++count )
497 if( count < storedSize )
500 const uint64_t leftOver = storedSize - count ;
501 for( uint64_t i = 0; i < leftOver; ++i )
514 #endif // #ifndef DUNE_FEM_CODIMINDEXSET_HH IndexArrayType holes_
Definition: codimindexset.hh:64
void prepareCompress()
prepare for setup (nothing to do here)
Definition: codimindexset.hh:112
CodimIndexSet< GridType > ThisType
Definition: codimindexset.hh:34
IndexStateArrayType indexState_
Definition: codimindexset.hh:61
IndexType numberOfHoles() const
return number of holes
Definition: codimindexset.hh:340
void setMemoryFactor(const double memoryFactor)
set memory overestimation factor
Definition: codimindexset.hh:100
size_t size() const
return number of enties of array
Definition: arrays.hh:213
IndexType newIndex(int elNum) const
return new index, for dof manager only returns index
Definition: codimindexset.hh:353
void insertSubEntity(const EntityType &entity, const int subNumber)
Definition: codimindexset.hh:369
IndexType subIndex(const EntityType &entity, const int subNumber) const
return leaf index for given entity
Definition: codimindexset.hh:307
IndexArrayType oldIdx_
Definition: codimindexset.hh:68
bool checkValidIndex(const IndexType &idx) const
Definition: codimindexset.hh:422
static IndexType invalidIndex()
Definition: codimindexset.hh:49
void resize(size_t nsize)
Definition: arrays.hh:491
IndexType numberHoles_
Definition: codimindexset.hh:78
DofIteratorType begin()
iterator pointing to begin of array
Definition: arrays.hh:193
MutableArray< IndexType > IndexArrayType
Definition: codimindexset.hh:53
CodimIndexSet(const GridType &grid, const int codim, const double memoryFactor=1.1)
Constructor taking memory factor (default = 1.1)
Definition: codimindexset.hh:83
void print(std::ostream &out) const
Definition: codimindexset.hh:409
void clear()
clear set
Definition: codimindexset.hh:116
void insertIdx(IndexType &index)
Definition: codimindexset.hh:430
DofIteratorType end()
iterator pointing to end of array
Definition: arrays.hh:203
bool compress()
Definition: codimindexset.hh:167
Definition: coordinate.hh:4
bool read(InStreamInterface< StreamTraits > &in)
Definition: codimindexset.hh:468
GridImp GridType
Definition: codimindexset.hh:33
abstract interface for an input stream
Definition: streams.hh:177
IndexType size() const
return size of grid entities per level and codim
Definition: codimindexset.hh:287
IndexType oldIndex(int elNum) const
return old index, for dof manager only
Definition: codimindexset.hh:346
bool exists(const EntityType &entity) const
return state of index for given hierarchic number
Definition: codimindexset.hh:317
bool validIndex(const EntityType &entity) const
Definition: codimindexset.hh:403
IndexContainerType leafIndex_
Definition: codimindexset.hh:60
void setMemoryFactor(const double memFactor)
set memory factor
Definition: arrays.hh:465
void markForRemoval(const EntityType &entity)
Definition: codimindexset.hh:393
void clearHoles()
clear holes, i.e. set number of holes to zero
Definition: codimindexset.hh:157
void checkConsecutive()
set all entries to unused
Definition: codimindexset.hh:154
const int myCodim_
Definition: codimindexset.hh:75
bool consecutive()
Definition: codimindexset.hh:130
IndexType realSize() const
return size of grid entities per level and codim
Definition: codimindexset.hh:290
IndexType index(const EntityType &entity) const
return leaf index for given entity
Definition: codimindexset.hh:298
IndexType additionalSizeEstimate() const
return how much extra memory is needed for restriction
Definition: codimindexset.hh:284
Definition: codimindexset.hh:30
IndexType lastSize_
Definition: codimindexset.hh:72
int IndexType
Definition: codimindexset.hh:46
IndexArrayType newIdx_
Definition: codimindexset.hh:69
bool write(OutStreamInterface< StreamTraits > &out) const
Definition: codimindexset.hh:444
void insertGhost(const EntityType &entity)
Definition: codimindexset.hh:378
void insert(const EntityType &entity)
Definition: codimindexset.hh:361
MutableArray< INDEXSTATE > IndexStateArrayType
Definition: codimindexset.hh:54
void resize()
reallocate the vectors
Definition: codimindexset.hh:109
PersistentContainer< GridType, IndexType > IndexContainerType
Definition: codimindexset.hh:57
void resetUsed()
set all entries to unused
Definition: codimindexset.hh:125
abstract interface for an output stream
Definition: streams.hh:44
bool exists(const EntityType &entity, const int subNumber) const
Definition: codimindexset.hh:328