Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFC_Window_transfer.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: RFC_Window_transfer.C,v 1.15 2008/12/06 08:43:29 mtcampbe Exp $
24 
25 //===============================================================
26 // Implementaiton of RFC_Window_transfer and RFC_Pane_transfer.
27 // Author: Xiangmin Jiao
28 // Date: June. 15, 2001
29 //===============================================================
30 
31 #include "RFC_Window_transfer.h"
32 
34 
36  : Base( b, c), _window( NULL), _to_recv( NULL) {}
38 
39 // Constructor and deconstructors
41  MPI_Comm com,
42  const char *pre,
43  const char *format)
44  : Base(b,c,com), _buf_dim(0), _comm( com), _replicated(false),
45  _prefix( pre==NULL?b->name():pre), _IO_format( get_sdv_format(format)) {
46 
47  std::vector< Pane*> pns; panes(pns);
48  std::vector< Pane*>::iterator pit=pns.begin(), piend=pns.end();
49  for ( ; pit != piend; ++pit) {
50  (*pit)->_window = this;
51  }
52 
53  // Initialize pane_map
54  int nprocs = comm_size();
55  _num_panes.resize( nprocs,int(0));
56 
57  const COM::Window::Proc_map &proc_map = _base->proc_map();
58 
59  for ( COM::Window::Proc_map::const_iterator
60  it=proc_map.begin(), iend=proc_map.end(); it!=iend; ++it) {
61  int p=it->second;
62  _pane_map[ it->first] = std::pair<int,int>(p, _num_panes[p]++);
63  }
64 }
65 
67  while ( !_replic_panes.empty()) {
68  delete _replic_panes.begin()->second;
69  _replic_panes.erase( _replic_panes.begin());
70  }
71 }
72 
74 RFC_Window_transfer::pane( const int pid) {
75  Pane_set::iterator pit = _pane_set.find( pid);
76  if ( pit != _pane_set.end()) {
77  return reinterpret_cast<RFC_Pane_transfer&>(*pit->second);
78  }
79  else {
80  return *_replic_panes.find( pid)->second;
81  }
82 }
83 
84 const RFC_Pane_transfer &
85 RFC_Window_transfer::pane( const int pid) const {
86  Pane_set::const_iterator pit = _pane_set.find( pid);
87  if ( pit != _pane_set.end()) {
88  return reinterpret_cast<const RFC_Pane_transfer&>(*pit->second);
89  }
90  else {
91  return *_replic_panes.find( pid)->second;
92  }
93 }
94 
95 // Initialize buffer spaces for data transfer
97 init_nodal_buffers( const Nodal_data &nd, int size, bool init_emm) {
98  _buf_dim = nd.dimension();
99 
100  // Loop through the panes
101  for (Pane_set::iterator pi=_pane_set.begin(); pi != _pane_set.end(); ++pi) {
103 
104  pane._buffer.resize( size);
105 
106  for ( int i=0; i<size; ++i)
107  pane._buffer[i].resize(pane._base->size_of_nodes()*_buf_dim);
108 
109  int n=pane.size_of_faces();
110 
111  if ( !init_emm) continue;
112 
113  pane._emm_offset.resize( n+1);
114  // Initialize space for the mass matrix
115  pane._emm_offset[0] = 0;
116 
117  int k=0;
118  // Loop through the connectivity table to mark their nodes as false.
119  if ( pane._base->is_structured()) {
120  for ( int i=0; i<n; ++i, ++k) {
121  pane._emm_offset[k+1] = pane._emm_offset[k] + 16;
122  }
123  }
124  else {
125  std::vector< const COM::Connectivity*> elems;
126  pane._base->elements( elems);
127 
128  for ( std::vector<const COM::Connectivity*>::const_iterator
129  it = elems.begin(); it != elems.end(); ++it) {
130  const int nn = (*it)->size_of_nodes_pe();
131  for ( int i=1,size=(*it)->size_of_elements(); i<=size; ++i, ++k) {
132  pane._emm_offset[k+1] = pane._emm_offset[k] + nn*nn;
133  }
134  }
135  }
136 
137  pane._emm_buffer.resize( pane._emm_offset[n], 0);
138  }
139 }
140 
142 nodal_buffer( int index) {
143  RFC_assertion( index >= 0);
144  return Nodal_data( -index-1, _buf_dim);
145 }
146 
149  // Loop through the panes to remove the buffer spaces
150  for (Pane_set::iterator pi=_pane_set.begin(); pi != _pane_set.end(); ++pi) {
152 
153  free_vector( pane._buffer);
154  free_vector( pane._emm_offset);
155  free_vector( pane._emm_buffer);
156  }
157 }
158 
160 set_tags( const COM::Attribute *tag) {
161  // Loop through the panes to set the tags
162  for (Pane_set::iterator pi=_pane_set.begin(); pi != _pane_set.end(); ++pi) {
164 
165  pane._to_recv = ( tag == NULL) ? (int *)NULL :
166  (int *)(pane._base->attribute( tag->id())->pointer());
167  }
168 }
169 
170 // Initialize buffer spaces for data transfer
172 init_facial_buffers( const Facial_data &nd, int size) {
173  _buf_dim = nd.dimension();
174 
175  // Loop through the panes
176  for (Pane_set::iterator pi=_pane_set.begin(); pi != _pane_set.end(); ++pi) {
178 
179  pane._buffer.resize( size);
180 
181  for ( int i=0; i<size; ++i)
182  pane._buffer[i].resize(pane.size_of_faces()*_buf_dim);
183  }
184 }
185 
187 facial_buffer( int index) {
188  RFC_assertion( index >= 0);
189  return Facial_data( -index-1, _buf_dim);
190 }
191 
194  // Loop through the panes to remove the buffer spaces
195  for (Pane_set::iterator pi=_pane_set.begin(); pi != _pane_set.end(); ++pi) {
197 
198  free_vector( pane._buffer);
199  }
200 }
201 
202 void
203 RFC_Window_transfer::incident_panes( std::vector<int> &pane_ids) {
204  std::set<int> ids;
205 
206  // Loop through the panes to detect incident panes
207  for (Pane_set::iterator pi=_pane_set.begin(); pi != _pane_set.end(); ++pi) {
209 
210  for ( int i=0, size=pane._subface_counterparts.size(); i<size; ++i) {
211  ids.insert( pane._subface_counterparts[i].pane_id);
212  }
213  for ( int i=0, size=pane._subnode_counterparts.size(); i<size; ++i) {
214  RFC_assertion(ids.find( pane._subnode_counterparts[i].pane_id) != ids.end());
215  }
216  }
217 
218  pane_ids.resize(0); pane_ids.reserve( ids.size());
219  pane_ids.insert( pane_ids.end(), ids.begin(), ids.end());
220 }
221 
223 
224 
225 
226 
227 
228 
RFC_Pane_transfer & pane(const int pid)
void free_vector(std::vector< _TT > &v)
Definition: rfc_basic.h:54
std::vector< int > _num_panes
std::map< int, RFC_Pane_transfer * > _replic_panes
RFC_Window_transfer(COM::Window *b, int color, MPI_Comm com, const char *pre=NULL, const char *format=NULL)
Size dimension() const
j indices k indices k
Definition: Indexing.h:6
void set_tags(const COM::Attribute *tag)
const Attribute * attribute(const char *f) const
Retrieve an attribute object from the base using the attribute name.
Base * _base
Reference to its base object.
RFC_Pane_transfer(COM::Pane *b, int c)
Facial_data facial_buffer(int)
int size_of_faces() const
The total number of faces in the pane.
void panes(std::vector< Pane * > &ps)
Get a vector of local panes contained in the window.
Base * _base
A reference to its base COM::Window object.
#define RFC_END_NAME_SPACE
Definition: rfc_basic.h:29
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE knode iend
RFC_Data< Tag_facial > Facial_data
std::map< int, std::pair< int, int > > _pane_map
blockLoc i
Definition: read.cpp:79
RFC_Data< Tag_nodal > Nodal_data
#define RFC_BEGIN_NAME_SPACE
Definition: rfc_basic.h:28
const NT & n
Nodal_data nodal_buffer(int)
void incident_panes(std::vector< int > &pane_ids)
Determine the remote panes that are incident with local panes.
std::vector< Node_ID > _subnode_counterparts
Ids of counterparts of subnodes.
void init_nodal_buffers(const Nodal_data &nd, int n, bool init_emm)
int size_of_nodes() const
Get the total number of nodes contained the window.
COM::Window Base
Pane_set _pane_set
The set of panes contained in the window.
const double pi
void init_facial_buffers(const Facial_data &nd, int)
std::vector< Real > _emm_buffer
std::vector< std::vector< Real > > _buffer
for(;;)
std::vector< int > _emm_offset
#define RFC_assertion
Definition: rfc_basic.h:65
std::vector< Face_ID > _subface_counterparts
Ids of counterparts of faces.