dune-fem 2.8.0
Loading...
Searching...
No Matches
commindexmap.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_COMMINDEXMAP_HH
2#define DUNE_FEM_COMMINDEXMAP_HH
3
4#include <set>
5#include <vector>
6
8
9namespace Dune
10{
11
12 namespace Fem
13 {
14
16 {
17 typedef int IndexType ;
18 private:
20
21 public:
24 : indices_( 0 )
25 {
26 indices_.setMemoryFactor( 1.1 );
27 }
28
30
32 const IndexType& operator [] ( const size_t i ) const
33 {
34 assert( i < size() );
35 return indices_[ i ];
36 }
37
39 void clear()
40 {
41 resize( 0 );
42 }
43
46 template <class GlobalKey>
47 void insert( const std :: vector< GlobalKey > &idx )
48 {
49 const size_t size = idx.size();
50 size_t count = indices_.size();
51
52 // reserve memory
53 resize( count + size );
54 assert( indices_.size() == (count + size) );
55
56 // copy indices to index vector
57 for( size_t i = 0; i < size; ++i, ++count )
58 {
59 assert( idx[ i ] >= 0 );
60 indices_[ count ] = idx[ i ];
61 }
62 }
63
65 template <class GlobalKey>
66 void set( const std :: set< GlobalKey > &idxSet )
67 {
68 // resize to given new size
69 resize( idxSet.size() );
70
71 // copy all elements from set to array
72 size_t count = 0;
73 typedef typename std :: set< GlobalKey > :: const_iterator iterator;
74 const iterator end = idxSet.end();
75 for(iterator it = idxSet.begin(); it != end; ++it, ++count)
76 {
77 indices_[count] = *it;
78 }
79 }
80
82 size_t size () const
83 {
84 return indices_.size();
85 }
86
88 void print( std :: ostream &s, int rank ) const
89 {
90 const size_t size = this->size();
91 s << "Start print: size = " << size << std :: endl;
92 for( size_t i = 0; i < size; ++i )
93 s << rank << " idx[ " << i << " ] = " << indices_[ i ] << std :: endl;
94 s << "End of Array" << std :: endl;
95 }
96
98 template <class CommBuffer>
99 void writeToBuffer(CommBuffer& buffer) const
100 {
101 const size_t idxSize = indices_.size();
102 buffer.write( idxSize );
103 //std::cout << "P[" << MPIManager ::rank() << " write Buffer size " << idxSize << std::endl;
104 for(size_t i=0; i<idxSize; ++i)
105 {
106 //std::cout << "P[" << MPIManager ::rank() << " write idx " << indices_[i] << std::endl;
107 buffer.write( indices_[i] );
108 }
109 }
110
112 template <class CommBuffer>
113 void readFromBuffer(CommBuffer& buffer)
114 {
115 size_t idxSize;
116 buffer.read( idxSize );
117 //std::cout << "P[" << MPIManager ::rank() << " read Buffer size " << idxSize << std::endl;
118 indices_.resize( idxSize );
119 for(size_t i=0; i<idxSize; ++i)
120 {
121 buffer.read( indices_[i] );
122 //std::cout << "P[" << MPIManager ::rank() << " read idx " << indices_[i] << std::endl;
123 }
124 }
125
126 protected:
128 inline void resize ( size_t size )
129 {
130 indices_.resize( size );
131 }
132
133 inline void reserve ( size_t size )
134 {
135 indices_.reserve( size );
136 }
137
138 };
139
140 } // namespace Fem
141
142} // namespace Dune
143
144#endif // #ifndef DUNE_FEM_COMMINDEXMAP_HH
Definition: bindguard.hh:11
Definition: commindexmap.hh:16
const IndexType & operator[](const size_t i) const
return index map for entry i
Definition: commindexmap.hh:32
CommunicationIndexMap(const CommunicationIndexMap &)=delete
void clear()
clear index map
Definition: commindexmap.hh:39
void print(std ::ostream &s, int rank) const
print map for debugging only
Definition: commindexmap.hh:88
size_t size() const
return size of map
Definition: commindexmap.hh:82
void set(const std ::set< GlobalKey > &idxSet)
insert sorted set of indices
Definition: commindexmap.hh:66
void resize(size_t size)
resize map with size size
Definition: commindexmap.hh:128
void writeToBuffer(CommBuffer &buffer) const
write all indices to buffer
Definition: commindexmap.hh:99
void readFromBuffer(CommBuffer &buffer)
read all indices from buffer
Definition: commindexmap.hh:113
void reserve(size_t size)
Definition: commindexmap.hh:133
void insert(const std ::vector< GlobalKey > &idx)
Definition: commindexmap.hh:47
CommunicationIndexMap()
constructor creating empty map
Definition: commindexmap.hh:23
size_type size() const
return size of array
Definition: dynamicarray.hh:170
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