Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pconn_test1.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( int *pconn , int *new_pconn) {
36  int ni = 8;
37  int nj = 7;
38  int nk = 5;
39  int ghost_layers = 2;
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  //block 1
130  for (int j=0; j<size; j++){
131  new_pconn[j] = pconn[j];
132  }
133 
134  //block 2
135  new_pconn[indx] = num_com_panes;
136  indx++;
137  for (int k=0; k< num_com_panes; k++){
138  new_pconn[indx] = pane_info[k]; //comm. pane ID
139  indx++;
140  new_pconn[indx] = real2send[k].size(); //num values to follow
141  indx++;
142  for (int m=0; m< real2send[k].size(); m++){
143  new_pconn[indx] = real2send[k][m];
144  indx++;
145  }
146  }
147 
148  //block 3
149  new_pconn[indx] = num_com_panes;
150  indx++;
151  for (int k=0; k< num_com_panes; k++){
152  new_pconn[indx] = pane_info[k]; //comm. pane ID
153  indx++;
154  new_pconn[indx] = ghost2recv[k].size(); //num values to follow
155  indx++;
156  for (int m=0; m< ghost2recv[k].size(); m++){
157  new_pconn[indx] = ghost2recv[k][m];
158  indx++;
159  }
160  }
161  //block 3
162  return;
163 }
164 
165 int main(int argc, char *argv[]) {
166 
167  int size = 11;
168 
169  int myPconn[size];
170  myPconn[0] = 2;
171  myPconn[1] = 2;
172  myPconn[2] = 3;
173  myPconn[3] = 36;
174  myPconn[4] = 37;
175  myPconn[5] = 38;
176  myPconn[6] = 3;
177  myPconn[7] = 3;
178  myPconn[8] = 19;
179  myPconn[9] = 27;
180  myPconn[10] = 35;
181 
182  //int *pconn;
183  int new_pconn[45];
184 
185  add_ghost_nodes2D( myPconn, new_pconn);
186  for (int v=0; v < 45; v++){
187  std::cerr << new_pconn[v] << std::endl;
188  }
189 
190  return 0;
191  COM_finalize();
192 }
193 
194 
195 
196 
197 
198 
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.
*********************************************************************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 and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS 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 v
Definition: roccomf90.h:20
static int abs_val(int a)
Definition: pconn_test1.C:30
void COM_finalize()
Definition: roccom_c++.h:59
int main(int argc, char *argv[])
Definition: blastest.C:94
void int int * nk
Definition: read.cpp:74
j indices j
Definition: Indexing.h:6
NT q
void int int REAL REAL REAL *z blockDim dim * ni
Definition: read.cpp:77
void int * nj
Definition: read.cpp:74
static void add_ghost_nodes2D(int *pconn, int *new_pconn)
Definition: pconn_test1.C:35