Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Pconn_util.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 #include "roccom.h"
24 #include <iostream>
25 #include <sstream>
26 
27 using namespace std;
28 
29 
30 static int abs_val( int a ) {
31  if (a < 0) {return (-a);}
32  else {return a;}
33 }
34 
35 static void add_ghost_nodes2D( COM::Pane *pane, int *pconn) {
36  int ni = pane->size_i();
37  int nj = pane->size_j();
38  int ghost_layers = pane->size_of_ghost_layers();
39  int id = pane->id();
40  int num_com_panes = pconn[0];
41 
42  int indx = 0;
43 
44  indx++;
45 
46  std::vector< std::vector<int> > real2send(num_com_panes);
47  std::vector< std::vector<int> > ghost2recv(num_com_panes);
48  std::vector< std::vector<int> > shared_nodes(num_com_panes);
49  std::vector< int > pane_info(num_com_panes);
50 
51  std::vector< std::vector<int> >::iterator s = shared_nodes.begin();
52  std::vector< std::vector<int> >::iterator s_end = shared_nodes.end();
53 
54  for (int q=0; q< num_com_panes; q++){
55  int id_num = pconn[indx];
56  pane_info[q] = id_num;
57  indx++;
58  int count = pconn[indx];
59  indx++;
60  int val = indx + count;
61  for ( ; indx < val; indx++){
62  (shared_nodes[q]).push_back(pconn[indx]);
63  }
64  }
65 
66  std::vector< std::vector<int> >::iterator p2 = real2send.begin();
67  std::vector< std::vector<int> >::iterator g2 = ghost2recv.begin();
68  std::vector< std::vector<int> >::iterator s2 = shared_nodes.begin();
69 
70  for ( ; s2 != s_end; p2++,g2++,s2++){
71  int node1 = (*s2)[0];
72  int node2 = (*s2)[1];
73  int diff = abs_val(node1-node2);
74  if ( diff == 1) {
75  if ( (node1 - ni*ghost_layers) < ni ) { //top
76  //newnode = node1+ni
77  int size = (*s2).size();
78  for (int k=0; k < size; k++){
79  for (int m=0; m< ghost_layers; m++){
80  (*p2).push_back( (*s2)[k] + (m+1)*ni);
81  (*g2).push_back( (*s2)[k] - (m+1)*ni);
82  }
83  }
84  } else if ( ni*(nj-ghost_layers) - node1 < ni){ //bottom
85  //newnode = node1-ni
86  int size = (*s2).size();
87  for (int k=0; k < size; k++){
88  for (int m=0; m< ghost_layers; m++){
89  (*p2).push_back( (*s2)[k] - (m+1)*ni);
90  (*g2).push_back( (*s2)[k] + (m+1)*ni);
91  }
92  }
93  } else {
94  //error state
95  COM_assertion_msg(false, "Should be top or bottom.");
96  }
97 
98  } else if ( diff == ni ) {
99  if ( (node1 % ni) == (ni - ghost_layers)){ //right
100  //newnode = node1-1
101  int size = (*s2).size();
102  for (int k=0; k < size; k++){
103  for (int m=0; m< ghost_layers; m++){
104  (*p2).push_back( (*s2)[k] - (m+1));
105  (*g2).push_back( (*s2)[k] + (m+1));
106  }
107  }
108 
109  } else if ( (node1 % ni) == (ghost_layers+1) ) { //left
110  //newnode = node1+1
111  int size = (*s2).size();
112  for (int k=0; k < size; k++){
113  for (int m=0; m< ghost_layers; m++){
114  (*p2).push_back( (*s2)[k] + (m+1));
115  (*g2).push_back( (*s2)[k] - (m+1));
116  }
117  }
118 
119  } else {
120  //error state
121  COM_assertion_msg(false, "Should be right or left.");
122  }
123  }
124 
125  }
126 
127  int size = indx;
128 
129  int real_size=0;
130  for (int q=0; q< num_com_panes; q++){
131  real_size += real2send[q].size();
132  }
133 
134  int ghost_size=0;
135  for (int q=0; q< num_com_panes; q++){
136  ghost_size += ghost2recv[q].size();
137  }
138 
139  int big_size = size+ 2*(1 + 2*num_com_panes) +
140  real_size + ghost_size;
141 
142  int new_pconn[big_size];
143 
144  //block 1
145  for (int j=0; j<size; j++){
146  new_pconn[j] = pconn[j];
147  }
148 
149  //block 2
150  new_pconn[indx] = num_com_panes;
151  indx++;
152  for (int k=0; k< num_com_panes; k++){
153  new_pconn[indx] = pane_info[k]; //comm. pane ID
154  indx++;
155  new_pconn[indx] = real2send[k].size(); //num values to follow
156  indx++;
157  for (int m=0; m< real2send[k].size(); m++){
158  new_pconn[indx] = real2send[k][m];
159  indx++;
160  }
161  }
162 
163  //block 3
164  new_pconn[indx] = num_com_panes;
165  indx++;
166  for (int k=0; k< num_com_panes; k++){
167  new_pconn[indx] = pane_info[k]; //comm. pane ID
168  indx++;
169  new_pconn[indx] = ghost2recv[k].size(); //num values to follow
170  indx++;
171  for (int m=0; m< ghost2recv[k].size(); m++){
172  new_pconn[indx] = ghost2recv[k][m];
173  indx++;
174  }
175  }
176 
177  const std::string win_name = (pane->window())->name();
178  const std::string pconn_att = win_name+".pconn";
179  COM_set_array( pconn_att.c_str() , id, new_pconn);
180 
181  return;
182 }
183 
184 
185 
186 
187 
188 
189 
static int abs_val(int a)
Definition: Pconn_util.C:30
j indices k indices k
Definition: Indexing.h:6
#define COM_assertion_msg(EX, msg)
double s
Definition: blastest.C:80
This file contains the prototypes for Roccom API.
static void add_ghost_nodes2D(COM::Pane *pane, int *pconn)
Definition: Pconn_util.C:35
void COM_set_array(const char *wa_str, int pane_id, void *addr, int strd=0, int cap=0)
Associates an array with an attribute for a specific pane.
Definition: roccom_c++.h:156
j indices j
Definition: Indexing.h:6
unsigned long id(const Leda_like_handle &x)
Definition: Handle.h:107
NT q
void int int REAL REAL REAL *z blockDim dim * ni
Definition: read.cpp:77
void int * nj
Definition: read.cpp:74