19 #ifndef EWOMS_PARALLELSERIALOUTPUT_HH
20 #define EWOMS_PARALLELSERIALOUTPUT_HH
23 #include <dune/grid/common/p2pcommunicator.hh>
30 template <
class Gr
idManager >
34 typedef typename GridManager :: Grid
Grid;
47 void setId(
const int globalId ) { globalId_ = globalId; }
51 int id ()
const {
return globalId_; }
59 typedef typename Grid :: LeafGridView
GridView;
83 const std::vector<int>& distributedGlobalIndex,
84 IndexMapType& localIndexMap,
85 IndexMapStorageType& indexMaps )
86 : distributedGlobalIndex_( distributedGlobalIndex ),
87 localIndexMap_( localIndexMap ),
88 indexMaps_( indexMaps ),
91 const size_t size = globalIndex.size();
93 for (
size_t index = 0; index < size; ++index )
95 globalPosition_.insert( std::make_pair( globalIndex[ index ], index ) );
99 if( ! indexMaps_.empty() )
102 IndexMapType& indexMap = indexMaps_.back();
103 const size_t localSize = localIndexMap_.size();
104 indexMap.resize( localSize );
105 for(
size_t i=0; i<localSize; ++i )
107 const int id = distributedGlobalIndex_[ localIndexMap_[ i ] ];
108 indexMap[ i ] = globalPosition_[ id ] ;
110 assert( checkPosition_.find(
id ) == checkPosition_.end() );
111 checkPosition_.insert(
id );
117 void pack(
const int link, MessageBufferType& buffer )
121 OPM_THROW(std::logic_error,
"link in method pack is not 0 as execpted");
125 const int size = localIndexMap_.size();
126 buffer.write( size );
128 for(
int index = 0; index < size; ++index )
130 const int globalIdx = distributedGlobalIndex_[ localIndexMap_[ index ] ];
131 buffer.write( globalIdx );
135 void unpack(
const int link, MessageBufferType& buffer )
138 IndexMapType& indexMap = indexMaps_[ link ];
139 assert( ! globalPosition_.empty() );
143 buffer.read( numCells );
144 indexMap.resize( numCells );
145 for(
int index = 0; index <
numCells; ++index )
148 buffer.read( globalId );
149 assert( globalPosition_.find( globalId ) != globalPosition_.end() );
150 indexMap[ index ] = globalPosition_[ globalId ];
152 assert( checkPosition_.find( globalId ) == checkPosition_.end() );
153 checkPosition_.insert( globalId );
165 const CollectiveCommunication& comm = gridManager.grid().comm();
167 std::set< int > send, recv;
172 const auto& eclGrid = *(gridManager.eclGrid());
173 const size_t cartesianSize = eclGrid.getCartesianSize();
178 for(
size_t cartIndex=0; cartIndex<cartesianSize; ++cartIndex )
180 if( eclGrid.cellActive( cartIndex ) )
186 for(
int i=0; i<comm.size(); ++i)
200 const size_t gridSize = gridManager.grid().size( 0 );
203 unsigned int index = 0;
204 auto localView = gridManager.grid().leafGridView();
205 for(
auto it = localView.template begin< 0 >(),
206 end = localView.template end< 0 >(); it != end; ++it, ++index )
208 const auto element = *it ;
210 if( element.partitionType() == Dune :: InteriorEntity )
227 IndexMapType distributedCartesianIndex;
228 distributedCartesianIndex.reserve( gridSize );
229 for(
size_t cell = 0 ; cell<gridSize; ++cell )
230 distributedCartesianIndex.push_back( gridManager.cartesianIndex( cell ) );
238 template <
class BufferList>
241 BufferList& bufferList_;
243 const IndexMapType& localIndexMap_;
244 const IndexMapStorageType& indexMaps_;
248 const IndexMapType& localIndexMap,
249 const IndexMapStorageType& indexMaps,
250 const size_t globalSize,
252 : bufferList_( bufferList ),
253 localIndexMap_( localIndexMap ),
254 indexMaps_( indexMaps )
258 MessageBufferType buffer;
261 for (
auto it = bufferList_.begin(), end = bufferList_.end(); it != end; ++it )
263 it->second->resize( globalSize );
266 doUnpack( indexMaps.back(), buffer );
272 void pack(
const int link, MessageBufferType& buffer )
276 OPM_THROW(std::logic_error,
"link in method pack is not 0 as execpted");
279 size_t buffers = bufferList_.size();
280 buffer.write( buffers );
281 for (
auto it = bufferList_.begin(), end = bufferList_.end(); it != end; ++it )
283 write( buffer, localIndexMap_, *(it->second) );
287 void doUnpack(
const IndexMapType& indexMap, MessageBufferType& buffer )
290 buffer.read( buffers );
291 assert( buffers == bufferList_.size() );
292 for(
auto it = bufferList_.begin(), end = bufferList_.end(); it != end; ++it )
294 read( buffer, indexMap, *(it->second) );
299 void unpack(
const int link, MessageBufferType& buffer )
301 doUnpack( indexMaps_[ link ], buffer );
305 template <
class Vector>
306 void write( MessageBufferType& buffer,
const IndexMapType& localIndexMap,
const Vector& data )
const
308 const size_t size = localIndexMap.size();
309 assert( size <= data.size() );
310 buffer.write( size );
311 for(
size_t i=0; i<size; ++i )
313 buffer.write( data[ localIndexMap[ i ] ] );
317 template <
class Vector>
318 void read( MessageBufferType& buffer,
const IndexMapType& indexMap, Vector& data )
const
320 size_t size = indexMap.size();
321 assert( size <= data.size() );
323 assert( size == indexMap.size() );
324 for(
size_t i=0; i<size; ++i )
326 buffer.read( data[ indexMap[ i ] ] );
330 void writeString( MessageBufferType& buffer,
const std::string& s)
const
332 const int size = s.size();
333 buffer.write( size );
334 for(
int i=0; i<size; ++i )
336 buffer.write( s[ i ] );
340 void readString( MessageBufferType& buffer, std::string& s)
const
345 for(
int i=0; i<size; ++i )
347 buffer.read( s[ i ] );
353 template <
class BufferList>
357 packUnpack( bufferList,
std::vector< GlobalCellIndex > LocalIndexMapType
Definition: collecttoiorank.hh:65
std::set< int > checkPosition_
Definition: collecttoiorank.hh:78
Dune::PersistentContainer< Grid, GlobalCellIndex > GlobalIndexContainer
Definition: collecttoiorank.hh:55
std::vector< int > IndexMapType
Definition: collecttoiorank.hh:67
void pack(const int link, MessageBufferType &buffer)
Definition: collecttoiorank.hh:272
IndexMapType globalCartesianIndex_
Definition: collecttoiorank.hh:383
Definition: collecttoiorank.hh:38
void doUnpack(const IndexMapType &indexMap, MessageBufferType &buffer)
Definition: collecttoiorank.hh:287
void setIndex(const int localIndex)
Definition: collecttoiorank.hh:48
IndexMapStorageType indexMaps_
Definition: collecttoiorank.hh:385
CollectDataToIORank(const GridManager &gridManager)
Definition: collecttoiorank.hh:161
Definition: collecttoiorank.hh:239
Grid::CollectiveCommunication CollectiveCommunication
Definition: collecttoiorank.hh:35
PackUnPackOutputBuffers(BufferList &bufferList, const IndexMapType &localIndexMap, const IndexMapStorageType &indexMaps, const size_t globalSize, const bool isIORank)
Definition: collecttoiorank.hh:247
GridView AllGridView
Definition: collecttoiorank.hh:60
const bool isIORank_
Definition: collecttoiorank.hh:387
GlobalCellIndex()
Definition: collecttoiorank.hh:44
std::map< const int, const int > globalPosition_
Definition: collecttoiorank.hh:76
IndexMapType localIndexMap_
Definition: collecttoiorank.hh:384
bool isParallel() const
Definition: collecttoiorank.hh:374
bool isInterior() const
Definition: collecttoiorank.hh:52
void readString(MessageBufferType &buffer, std::string &s) const
Definition: collecttoiorank.hh:340
void pack(const int link, MessageBufferType &buffer)
Definition: collecttoiorank.hh:117
void setGhost()
Definition: collecttoiorank.hh:45
P2PCommunicatorType toIORankComm_
Definition: collecttoiorank.hh:382
const std::vector< int > & distributedGlobalIndex_
Definition: collecttoiorank.hh:73
static const int dimension
Definition: collecttoiorank.hh:57
Definition: baseauxiliarymodule.hh:35
void unpack(const int link, MessageBufferType &buffer)
Definition: collecttoiorank.hh:135
IndexMapType & localIndexMap_
Definition: collecttoiorank.hh:74
void unpack(const int link, MessageBufferType &buffer)
Definition: collecttoiorank.hh:299
IndexMapStorageType & indexMaps_
Definition: collecttoiorank.hh:75
bool collect(BufferList &bufferList) const
Definition: collecttoiorank.hh:354
int id() const
Definition: collecttoiorank.hh:51
void read(MessageBufferType &buffer, const IndexMapType &indexMap, Vector &data) const
Definition: collecttoiorank.hh:318
int localIndex() const
Definition: collecttoiorank.hh:50
P2PCommunicatorType::MessageBufferType MessageBufferType
Definition: collecttoiorank.hh:63
Definition: collecttoiorank.hh:70
bool isIORank() const
Definition: collecttoiorank.hh:369
size_t numCells() const
Definition: collecttoiorank.hh:379
void writeString(MessageBufferType &buffer, const std::string &s) const
Definition: collecttoiorank.hh:330
Dune::Point2PointCommunicator< Dune::SimpleMessageBuffer > P2PCommunicatorType
Definition: collecttoiorank.hh:62
DistributeIndexMapping(const std::vector< int > &globalIndex, const std::vector< int > &distributedGlobalIndex, IndexMapType &localIndexMap, IndexMapStorageType &indexMaps)
Definition: collecttoiorank.hh:82
GridManager::Grid Grid
Definition: collecttoiorank.hh:34
void setId(const int globalId)
Definition: collecttoiorank.hh:47
Grid::LeafGridView GridView
Definition: collecttoiorank.hh:59
Definition: collecttoiorank.hh:159
Definition: collecttoiorank.hh:31
void write(MessageBufferType &buffer, const IndexMapType &localIndexMap, const Vector &data) const
Definition: collecttoiorank.hh:306
std::vector< IndexMapType > IndexMapStorageType
Definition: collecttoiorank.hh:68