1#ifndef DUNE_SPGRID_LINKAGE_HH
2#define DUNE_SPGRID_LINKAGE_HH
6#include <dune/grid/spgrid/partitionlist.hh>
7#include <dune/grid/spgrid/partitionpool.hh>
18 typedef SPLinkage< dim > This;
21 typedef SPPartitionPool< dim > PartitionPool;
22 typedef SPPartitionList< dim > PartitionList;
24 typedef typename PartitionPool::Mesh Mesh;
25 typedef typename PartitionPool::MultiIndex MultiIndex;
29 SPLinkage (
const int localRank,
30 const PartitionPool &localPool,
31 const std::vector< Mesh > &decomposition );
33 const Interface &interface (
const InterfaceType iftype )
const;
36 template< InterfaceType iftype >
37 bool build (
const int localRank,
const PartitionPool &localPool,
38 const int remoteRank,
const PartitionPool &remotePool );
41 intersect (
const bool order,
const PartitionList &local,
const PartitionList &remote )
const;
44 Interface interface_[ 5 ];
53 class SPLinkage< dim >::Interface
57 typedef std::vector< Node > NodeContainer;
60 typedef typename NodeContainer::const_iterator Iterator;
63 Interface (
const This &other );
67 Iterator begin ()
const {
return nodes_.begin(); }
68 Iterator end ()
const {
return nodes_.end(); }
70 std::size_t size ()
const {
return nodes_.size(); }
72 void add (
int rank,
const PartitionList *sendList,
const PartitionList *receiveList )
74 nodes_.emplace_back( rank, sendList, receiveList );
87 struct SPLinkage< dim >::Interface::Node
90 "enumeration CommunicationDirection has changed." );
92 Node (
const int rank,
const PartitionList *sendList,
const PartitionList *receiveList );
102 const PartitionList *partitionList_[ 2 ];
110 template< InterfaceType iftype >
111 struct SPCommunicationInterface;
154 inline SPLinkage< dim >
155 ::SPLinkage (
const int localRank,
156 const PartitionPool &localPool,
157 const std::vector< Mesh > &decomposition )
159 const int size = decomposition.size();
161 const Mesh &globalMesh = localPool.globalMesh();
162 const MultiIndex &overlap = localPool.overlap();
164 for(
int remoteRank = 0; remoteRank < size; ++remoteRank )
166 if( remoteRank == localRank )
168 PartitionPool remotePool( decomposition[ remoteRank ], globalMesh, overlap, localPool.topology() );
169 if( build< All_All_Interface >( localRank, localPool, remoteRank, remotePool ) )
171 build< InteriorBorder_InteriorBorder_Interface >( localRank, localPool, remoteRank, remotePool );
172 build< InteriorBorder_All_Interface >( localRank, localPool, remoteRank, remotePool );
173 build< Overlap_OverlapFront_Interface >( localRank, localPool, remoteRank, remotePool );
174 build< Overlap_All_Interface >( localRank, localPool, remoteRank, remotePool );
181 inline const typename SPLinkage< dim >::Interface &
182 SPLinkage< dim >::interface (
const InterfaceType iftype )
const
184 assert( (
int( iftype ) >= 0) && (
int( iftype ) < 5) );
185 return interface_[ int( iftype ) ];
190 template< InterfaceType iftype >
191 inline bool SPLinkage< dim >
192 ::build (
const int localRank,
const PartitionPool &localPool,
193 const int remoteRank,
const PartitionPool &remotePool )
198 const bool order = (localRank < remoteRank);
201 const PartitionList *sendList, *receiveList;
202 sendList = intersect( order, localPool.template get< piSend >(), remotePool.template get< piReceive >() );
203 if( piSend != piReceive )
204 receiveList = intersect( order, localPool.template get< piReceive >(), remotePool.template get< piSend >() );
206 receiveList = sendList;
209 if( sendList->empty() && receiveList->empty() )
211 if( sendList != receiveList )
217 assert( (iftype >= 0) && (iftype < 5) );
218 interface_[ iftype ].
add( remoteRank, sendList, receiveList );
224 inline const typename SPLinkage< dim >::PartitionList *
225 SPLinkage< dim >::intersect (
const bool order,
const PartitionList &local,
const PartitionList &remote )
const
227 typedef SPBasicPartition< dim > Intersection;
228 typedef typename PartitionList::Iterator Iterator;
229 typedef typename PartitionList::Partition Partition;
233 PartitionList *link =
new PartitionList;
234 for( Iterator pit = (order ? local.begin() : remote.begin()); pit; ++pit )
236 for( Iterator qit = (order ? remote.begin() : local.begin()); qit; ++qit )
238 const int number = (order ? pit->number() : qit->number());
239 Intersection intersection = pit->intersect( *qit );
240 if( !intersection.empty() )
241 *link += Partition( intersection, number );
253 inline SPLinkage< dim >::Interface::Interface ()
258 inline SPLinkage< dim >::Interface::Interface (
const This &other )
260 nodes_.reserve( other.nodes_.size() );
261 const Iterator end = other.end();
262 for( Iterator it = other.begin(); it != end; ++it )
264 const PartitionList *sendList =
new PartitionList( it->sendList() );
265 const PartitionList *receiveList =
new PartitionList( it->receiveList() );
266 nodes_->push_back( it->rank(), sendList, receiveList );
272 inline SPLinkage< dim >::Interface::~Interface ()
274 typedef typename NodeContainer::iterator Iterator;
275 const Iterator end = nodes_.end();
276 for( Iterator it = nodes_.begin(); it != end; ++it )
286 inline SPLinkage< dim >::Interface::Node
287 ::Node (
const int rank,
const PartitionList *sendList,
const PartitionList *receiveList )
290 partitionList_[ 0 ] = sendList;
291 partitionList_[ 1 ] = receiveList;
296 inline int SPLinkage< dim >::Interface::Node::rank ()
const
298 assert( rank_ >= 0 );
304 inline const typename SPLinkage< dim >::PartitionList &
307 assert( (
int( direction ) >= 0) && (
int( direction ) <= 1) );
308 assert( partitionList_[ direction ] != 0 );
309 return *partitionList_[ direction ];
313 inline const typename SPLinkage< dim >::PartitionList &
316 assert( (
int( direction ) >= 0) && (
int( direction ) <= 1) );
317 assert( partitionList_[ 1 - direction ] != 0 );
318 return *partitionList_[ 1 - direction ];
323 inline void SPLinkage< dim >::Interface::Node::destroy ()
326 if( partitionList_[ 0 ] != partitionList_[ 1 ] )
327 delete partitionList_[ 1 ];
328 delete partitionList_[ 0 ];
329 partitionList_[ 0 ] = partitionList_[ 1 ] = 0;
Dune namespace.
Definition: alignedallocator.hh:13