Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PaneConnectivity.hpp
Go to the documentation of this file.
1 
8 #ifndef PANECONNECTIVITY_HPP_
9 #define PANECONNECTIVITY_HPP_
10 
11 #include <map>
12 #include <utility>
13 #include <vector>
14 #include <algorithm>
15 #include <cassert>
16 
17 namespace Rocstar { namespace Rocin { namespace Utilities {
18 
20  {
21  private:
22  std::map< int, std::vector< int > > pconn;
23  std::map< int, std::vector< int > > point2remotePaneList;
24  std::map< std::pair< int, int >, int > rmtpanePointPair2Index;
35  inline int getSharedNodeIndex( const int remotePane, const int localPoint )
36  {
37 
38  #ifdef ASSERT_ON
39  assert( this ->hasPane( remotePane ) );
40  assert( this ->hasLocalPoint( localPoint ) );
41  #endif
42 
43  std::pair< int, int > keyPair = std::make_pair( remotePane, localPoint );
44 
45  #ifdef ASSERT_ON
46  assert( this ->rmtpanePointPair2Index.find( keyPair ) != this ->rmtpanePointPair2Index.end( ) );
47  #endif
48 
49  int idx = this ->rmtpanePointPair2Index[ keyPair ];
50 
51  #ifdef ASSERT_ON
52  assert( this ->pconn[ remotePane ][ idx ] == localPoint );
53  #endif
54 
55  return idx;
56  }
57 
70  inline int accesspcon( int &index, const int *p, const int size )
71  {
72 
73  #ifdef ASSERT_ON
74  assert( index >= 0 && index < size );
75  assert( p != NULL );
76  #endif
77 
78  int datum = p[ index ]; ++index;
79  return datum;
80  }
81 
87  inline void buildPaneConnectivity( const int *pconnarray, const int size )
88  {
89  #ifdef ASSERT_ON
90  assert( pconnarray != NULL );
91  assert( size >= 0 );
92  #endif
93 
94  int idx = 0;
95  int numberOfConnections = this ->accesspcon( idx, pconnarray, size );
96 
97  for( int connection=0; connection < numberOfConnections; ++connection )
98  {
99  int rmtpane = this ->accesspcon( idx, pconnarray, size );
100  int numnodes = this ->accesspcon( idx, pconnarray, size );
101 
102  std::vector< int > sharedNodeList;
103  sharedNodeList.resize( numnodes );
104 
105  for( int node = 0; node < numnodes; ++node )
106  {
107  sharedNodeList[ node ] = this ->accesspcon( idx, pconnarray, size )-1; /* Note, pconn is 1-based, not 0-based so 1 is subtracted */
108  std::pair< int, int > keyPair = std::make_pair(rmtpane, sharedNodeList[ node ] );
109  this ->rmtpanePointPair2Index[ keyPair ] = node;
110  this ->point2remotePaneList[ sharedNodeList[ node ] ].push_back( rmtpane );
111  }
112 
113  this ->pconn[ rmtpane ] = sharedNodeList;
114 
115  }
116 
117  #ifdef ASSERT_ON
118  assert( this ->pconn.size( ) == pconnarray[ 0 ] );
119  #endif
120 
121  }
122 
123  public:
124 
130 
139  PaneConnectivity( const int *pconnarray, const int size )
140  {
141  this ->buildPaneConnectivity( pconnarray, size );
142  }
143 
148 
155  void getPointConnectionPairs( const int localPointId, std::vector< std::pair< int, int > > &connections )
156  {
157 
158  std::vector< int > rmtpanes;
159  this ->getRemotePaneIdsSharedWithPoint( localPointId, rmtpanes );
160 
161 
162  for( int i=0; i < rmtpanes.size( ); ++i )
163  {
164 // std::cout << rmtpanes[ i ] << " " << localPointId << std::endl;
165 
166  std::pair< int, int > valuePair = std::make_pair( rmtpanes[ i ], this ->getSharedNodeIndex( rmtpanes[ i ], localPointId ) );
167 
168 // std::cout << valuePair.first << " " << valuePair.second << std::endl;
169  connections.push_back( valuePair );
170  }
171 
172  }
173 
181  void constructPaneConnectivityFromArray( const int *pconnarray, const int size )
182  {
183  this ->buildPaneConnectivity( pconnarray, size );
184  }
185 
191  inline int getNumberOfConnections( ) const { return this ->pconn.size( ); }
192 
198  inline bool hasPane( const int paneId ) const { return( this ->pconn.find( paneId ) != this ->pconn.end( ) ); }
199 
207  int getNumberOfNodesSharedWithRemotePane( const int remotePane )
208  {
209  #ifdef ASSERT_ON
210  assert( this ->hasPane( remotePane ) );
211  #endif
212  return( this ->pconn[ remotePane ].size( ) );
213  }
214 
221  inline bool hasLocalPoint( const int localPointId ) const
222  {
223  #ifdef ASSERT_ON
224  assert( localPointId >= 0 );
225  #endif
226 
227  if( this ->point2remotePaneList.find( localPointId ) != this ->point2remotePaneList.end( ) )
228  return true;
229  else
230  return false;
231  }
232 
239  void getRemotePaneIdsSharedWithPoint( const int localPointId, std::vector< int > &rmtpaneIds )
240  {
241  #ifdef ASSERT_ON
242  assert( this ->hasLocalPoint( localPointId ) );
243  #endif
244 
245  rmtpaneIds.resize( this ->point2remotePaneList[ localPointId ].size( ) );
246  std::copy( this ->point2remotePaneList[ localPointId ].begin( ),
247  this ->point2remotePaneList[ localPointId ].end( ),
248  rmtpaneIds.begin( ) );
249  }
250 
257  void getRemotePaneIds( std::vector< int > &rmtpanes )
258  {
259  if( rmtpanes.size( ) != this ->getNumberOfConnections( ) )
260  rmtpanes.resize( this ->getNumberOfConnections( ) );
261 
262  std::map< int, std::vector< int > >::iterator iter = this ->pconn.begin( );
263  for( int idx=0; iter != this ->pconn.end( ); ++iter, ++idx )
264  rmtpanes[ idx ] = iter ->first;
265  }
266 
276  int getSharedPointIdAt( const int paneId, const int nodeIndex )
277  {
278  #ifdef ASSERT_ON
279  assert( this ->hasPane( paneId ) );
280  assert( nodeIndex >= 0 && nodeIndex < this ->pconn[ paneId ].size( ) );
281  #endif
282  return this ->pconn[ paneId ][ nodeIndex ];
283  }
284 
293  std::vector< int >& getNodesSharedWithRemotePane( const int remotePane )
294  {
295  #ifdef ASSERT_ON
296  assert( this ->hasPane( remotePane ) );
297  #endif
298  return( this ->pconn[ remotePane ] );
299  }
300 
301  }; /* End class Pane Connectivity */
302 
303 } } }
304 #endif /* PANECONNECTIVITY_HPP_ */
void constructPaneConnectivityFromArray(const int *pconnarray, const int size)
Constructs a PaneConnectivity object from the pcon array returned from Rocmap.
std::map< int, std::vector< int > > point2remotePaneList
Holds a mapping of localpoint ids to remote pane ids.
void buildPaneConnectivity(const int *pconnarray, const int size)
Builds the pane connectivity data-structured from a flat integer array returned from RocMap...
PaneConnectivity(const int *pconnarray, const int size)
Custom constructor.
int getNumberOfNodesSharedWithRemotePane(const int remotePane)
Returns the number of nodes shared with a particular remote pane.
int getNumberOfConnections() const
Returns the number of connections for this instance.
Definition: adj.h:150
std::vector< int > & getNodesSharedWithRemotePane(const int remotePane)
Returns a reference to the list of nodes shared with the remotePane.
bool hasPane(const int paneId) const
Checks if the pane exists in this instance.
int getSharedPointIdAt(const int paneId, const int nodeIndex)
This method returns the local shared point Id of the given pane at the given index.
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to ** copy
Definition: roccomf90.h:20
void getRemotePaneIdsSharedWithPoint(const int localPointId, std::vector< int > &rmtpaneIds)
This method returns the list of remote panes that share the point associated with the provided localP...
Definition: Rocin.h:64
blockLoc i
Definition: read.cpp:79
int accesspcon(int &index, const int *p, const int size)
A convenience method which provides safe access to the pconn array by doing bounds checking and memor...
bool hasLocalPoint(const int localPointId) const
This method checks if the local point exists in this instance.
std::map< std::pair< int, int >, int > rmtpanePointPair2Index
Holds a mapping of a (remotePane,localPoint) pair to the index in the shared node list...
int getSharedNodeIndex(const int remotePane, const int localPoint)
Returns the index to the shared node list of the local point that is shared with the given remote pan...
std::map< int, std::vector< int > > pconn
Holds a mapping of remote pane to a list of local ids that are shared.
void getRemotePaneIds(std::vector< int > &rmtpanes)
Returns the remote pane ids that are connected to this instance.
void getPointConnectionPairs(const int localPointId, std::vector< std::pair< int, int > > &connections)
This method returns the point connection pairs for the given local point.