1#ifndef DUNE_FEM_COMMINDEXMAP_HH
2#define DUNE_FEM_COMMINDEXMAP_HH
7#include <dune/fem/storage/dynamicarray.hh>
15 class CommunicationIndexMap
21 typedef int IndexType ;
25 static const IndexType invalidIndex = IndexType(-1);
29 CommunicationIndexMap()
35 CommunicationIndexMap(
const CommunicationIndexMap& ) =
delete;
38 const IndexType& operator [] (
const size_t i )
const
45 void erase(
const size_t i )
47 indices_[ i ] = invalidIndex;
58 template <
class GlobalKey>
59 void insert(
const std :: vector< GlobalKey > &idx )
61 const size_t size = idx.size();
62 size_t count = indices_.
size();
65 resize( count +
size );
66 assert( indices_.
size() == (count +
size) );
69 for(
size_t i = 0; i <
size; ++i, ++count )
71 assert( idx[ i ] >= 0 );
72 indices_[ count ] = idx[ i ];
77 template <
class GlobalKey>
78 void set(
const std :: set< GlobalKey > &idxSet )
81 resize( idxSet.size() );
85 typedef typename std :: set< GlobalKey > :: const_iterator iterator;
86 const iterator end = idxSet.end();
87 for(iterator it = idxSet.begin(); it != end; ++it, ++count)
89 indices_[count] = *it;
96 return indices_.
size();
100 void print( std :: ostream &s,
int rank )
const
103 s <<
"Start print: size = " <<
size << std :: endl;
104 for(
size_t i = 0; i <
size; ++i )
105 s << rank <<
" idx[ " << i <<
" ] = " << indices_[ i ] << std :: endl;
106 s <<
"End of Array" << std :: endl;
110 template <
class CommBuffer>
111 void writeToBuffer(CommBuffer& buffer)
const
113 const size_t idxSize = indices_.
size();
114 buffer.write( idxSize );
116 for(
size_t i=0; i<idxSize; ++i)
119 buffer.write( indices_[i] );
124 template <
class CommBuffer>
125 void readFromBuffer(CommBuffer& buffer)
128 buffer.read( idxSize );
130 indices_.
resize( idxSize );
131 for(
size_t i=0; i<idxSize; ++i)
133 buffer.read( indices_[i] );
142 const size_t idxSize = indices_.
size();
143 for(
size_t i=0; i<idxSize; ++i)
145 if( indices_[ i ] != invalidIndex )
148 indices_[ writePos ] = indices_[ i ];
152 indices_.
resize( writePos );
157 inline void resize (
size_t size )
162 inline void reserve (
size_t size )
void setMemoryFactor(double memFactor)
set memory factor
Definition: dynamicarray.hh:296
void reserve(size_type mSize)
Definition: dynamicarray.hh:371
void resize(size_type nsize)
Definition: dynamicarray.hh:334
size_type size() const
return size of array
Definition: dynamicarray.hh:170
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75