Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ex1.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: ex1.C,v 1.20 2008/12/06 08:43:29 mtcampbe Exp $
24 
25 #include "roccom.h"
26 #include <iostream>
27 #include <vector>
28 #include <cstdio>
29 #include <cassert>
30 
31 COM_EXTERN_MODULE( Rocface);
33 
34 using namespace std;
35 
36 // ==== Routines for creating mesh information
37 void init_structured_mesh( double coors[][3], int nrow, int ncol,
38  int rank, int nproc) {
39  // consider the processors as a 2*(nproc/2) grid
40  int proc_col=nproc;
41  if (nproc%2 ==0) {
42  proc_col=nproc/2;
43  }
44  else {
45  proc_col=nproc;
46  }
47  int row=rank/proc_col, col=rank%proc_col;
48 
49  const double width=100., length=100.;
50 
51  for (int i=0; i<nrow; ++i) {
52  for (int j=0; j<ncol; ++j) {
53  coors[i*ncol+j][0]=col*length+length/(ncol-1)*j;
54  coors[i*ncol+j][1]=row*width+width/(nrow-1)*i;
55  coors[i*ncol+j][2]=0.01;
56  }
57  }
58 }
59 
60 void init_unstructure_mesh( double coors[][3], int elmts[][4],
61  int nrow, int ncol, int rank, int nproc) {
62  // consider the processors as a 2*(nproc/2) grid
63  int proc_col=nproc;
64  if (nproc%2 ==0) {
65  proc_col=nproc/2;
66  }
67  else {
68  proc_col=nproc;
69  }
70 
71  int row=rank/proc_col, col=rank%proc_col;
72 
73  const double width=100., length=100.;
74 
75  for (int i=0; i<nrow; ++i) {
76  for (int j=0; j<ncol; ++j) {
77  coors[i*ncol+j][0]=col*length+length/(ncol-1)*j;
78  coors[i*ncol+j][1]=row*width+width/(nrow-1)*i;
79  coors[i*ncol+j][2]=0;
80  }
81  }
82 
83  // computes elmts
84  for (int i=0; i<nrow-1; ++i) {
85  for (int j=0; j<ncol-1; ++j) {
86  elmts[i*(ncol-1)+j][0]=i*ncol+j+1;
87  elmts[i*(ncol-1)+j][1]=i*ncol+j+ncol+1;
88  elmts[i*(ncol-1)+j][2]=i*ncol+j+ncol+2;
89  elmts[i*(ncol-1)+j][3]=i*ncol+j+2;
90  }
91  }
92 }
93 
94 const int total_npanes=4;
95 const int nrow=4, ncol=3;
96 const int num_nodes=nrow*ncol;
97 const int num_elmts=(nrow-1)*(ncol-1);
98 
105 
106 double burnr_f[3][total_npanes][(nrow-1)*(ncol-1)];
107 double burnr_s[3][total_npanes][(nrow-1)*(ncol-1)];
108 
110 
111 
112 int main(int argc, char *argv[]) {
113  const int comm_rank=0;
114  const int comm_size=1;
115  const int npanes=total_npanes, first_pane_id=1;
116 
117  if ( comm_rank == 0)
118  std::cout << "Initializing Roccom and Rocface" << std::endl;
119  COM_init( &argc, &argv);
120  // COM_set_verbose( 1);
121  COM_set_profiling( 1);
122 
123  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
124 
125  if ( comm_rank == 0)
126  std::cout << "Creating window \"unstr\"" << std::endl;
127  COM_new_window("unstr");
128  COM_new_attribute("unstr.velo", 'n', COM_DOUBLE, 3, "m/s");
129  COM_new_attribute("unstr.disp", 'n', COM_DOUBLE, 3, "m");
130  COM_new_attribute("unstr.burnr", 'e', COM_DOUBLE, 3, "m/s");
131 
132  for ( int pid=first_pane_id-1; pid<first_pane_id-1+npanes; ++pid) {
133  init_unstructure_mesh( coors_s[pid], elmts[pid],
134  nrow, ncol, pid, total_npanes);
135 
136  COM_set_size( "unstr.nc", pid+1, num_nodes);
137  COM_set_array( "unstr.nc", pid+1, &coors_s[pid][0][0]);
138  COM_set_size( "unstr.:q4:", pid+1, num_elmts);
139  COM_set_array( "unstr.:q4:", pid+1, &elmts[pid][0][0]);
140 
141  COM_set_array( "unstr.velo", pid+1, &velcts_s[pid][0][0]);
142  COM_set_array( "unstr.disp", pid+1, &disps_s[pid][0][0]);
143 
144  COM_set_array("unstr.burnr", pid+1, &burnr_s[0][pid][0], 1);
145  }
146  COM_window_init_done( "unstr");
147 
148  if ( comm_rank == 0)
149  std::cout << "Creating window \"str\"" << std::endl;
150  COM_new_window("str");
151  COM_new_attribute("str.velo", 'n', COM_DOUBLE, 3, "m/s");
152  COM_new_attribute("str.disp", 'n', COM_DOUBLE, 3, "m");
153  COM_new_attribute("str.burnr", 'e', COM_DOUBLE, 3, "m/s");
154 
155  for ( int pid=first_pane_id-1; pid<first_pane_id-1+npanes; ++pid) {
157 
158  int dims[2] = { ncol, nrow}; // Use Fortran convention
159  COM_set_array("str.:st2:", pid+1, &dims[0]);
160  COM_set_array("str.nc", pid+1, &coors_f[pid][0][0]);
161 
162  COM_set_array("str.velo", pid+1, &velcts_f[pid][0][0]);
163  COM_set_array("str.disp", pid+1, &disps_f[pid][0][0]);
164 
165  COM_set_array("str.burnr", pid+1, &burnr_f[0][pid][0], 1);
166  }
167 
168  COM_window_init_done( "str");
169 
170  for ( int p=first_pane_id-1; p<first_pane_id-1+npanes; ++p) {
171  for (int i=0; i<nrow*ncol; ++i) {
172  disps_s[p][i][0] = disps_f[p][i][0] = coors_f[p][i][0];
173  disps_s[p][i][1] = disps_f[p][i][1] = coors_f[p][i][1];
174  disps_s[p][i][2] = disps_f[p][i][2] = coors_f[p][i][2];
175  velcts_f[p][i][0] = velcts_s[p][i][0] = i;
176  velcts_f[p][i][1] = velcts_s[p][i][1] = i;
177  velcts_f[p][i][2] = velcts_s[p][i][2] = i;
178  }
179  for (int i=0; i<(nrow-1)*(ncol-1); ++i) {
180  burnr_s[0][p][i] = burnr_f[0][p][i] = i;
181  burnr_s[1][p][i] = burnr_f[1][p][i] = i;
182  burnr_s[2][p][i] = burnr_f[2][p][i] = i;
183  }
184  }
185 
186  int str_mesh = COM_get_attribute_handle( "str.mesh");
187  int unstr_mesh = COM_get_attribute_handle( "unstr.mesh");
188  int RFC_clear = COM_get_function_handle( "RFC.clear_overlay");
189 
190  const char *format="HDF";
191 
192  int RFC_write = COM_get_function_handle( "RFC.write_overlay");
193  if ( comm_size == 1) { // Perform mesh overlay.
194  int RFC_overlay = COM_get_function_handle( "RFC.overlay");
195 
196  std::cout << "Overlaying meshes..." << std::endl;
197  COM_call_function( RFC_overlay, &str_mesh, &unstr_mesh);
198  COM_call_function( RFC_write, &str_mesh, &unstr_mesh, "str", "unstr", format);
199  COM_call_function( RFC_clear, "str", "unstr");
200  }
201 
202  int RFC_read = COM_get_function_handle( "RFC.read_overlay");
203  COM_call_function( RFC_read, &str_mesh, &unstr_mesh, NULL,
204  "str", "unstr", format);
205 
206  char prefix1[100], prefix2[100];
207  std::sprintf(prefix1, "str%d", comm_rank);
208  std::sprintf(prefix2, "unstr%d", comm_rank);
209 
210  if ( argc>1) {
211  if ( comm_rank == 0)
212  std::cout << "Perform data transfer..." << std::endl;
213  std::sprintf(prefix1, "str_disp%d", comm_rank);
214  std::sprintf(prefix2, "unstr_disp%d", comm_rank);
215 
217 
218  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
219  int OUT_set = COM_get_function_handle( "OUT.set_option");
220  int str_disp = COM_get_attribute_handle( "str.disp");
221  int unstr_disp = COM_get_attribute_handle( "unstr.disp");
222  COM_call_function( OUT_write, prefix1, &str_disp, "str", "000");
223  COM_call_function( OUT_write, prefix2, &unstr_disp, "unstr", "000");
224 
225  int RFC_transfer = COM_get_function_handle( "RFC.least_squares_transfer");
226  COM_call_function( RFC_transfer, &str_disp, &unstr_disp);
227  COM_call_function( RFC_transfer, &unstr_disp, &str_disp);
228 
229  COM_call_function( OUT_set, "mode", "a");
230  COM_call_function( OUT_write, prefix1, &str_disp, "str", "001");
231  COM_call_function( OUT_write, prefix2, &unstr_disp, "unstr", "001");
232 
233  COM_call_function( RFC_clear, "str", "unstr");
235  }
236 
237  COM_delete_window( "str");
238  COM_delete_window( "unstr");
239 
240  COM_print_profile( "", "");
241 
242  COM_finalize();
243 }
244 
245 
246 
247 
248 
249 
double coors_f[total_npanes][nrow *ncol][3]
Definition: ex1.C:100
const int ncol
Definition: ex1.C:95
double disps_s[total_npanes][num_nodes][3]
Definition: ex1.C:103
void init_structured_mesh(double coors[][3], int nrow, int ncol, int rank, int nproc, int check=1)
Definition: surftest2.C:39
double burnr_s[3][total_npanes][(nrow-1)*(ncol-1)]
Definition: ex1.C:107
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
double disps_f[total_npanes][nrow *ncol][3]
Definition: ex1.C:104
void COM_set_size(const char *wa_str, int pane_id, int size, int ng=0)
Set sizes of for a specific attribute.
Definition: roccom_c++.h:136
This file contains the prototypes for Roccom API.
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
const int total_npanes
Definition: ex1.C:94
double length(Vector3D *const v, int n)
const int num_nodes
Definition: ex1.C:96
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:113
void COM_finalize()
Definition: roccom_c++.h:59
double burnr_f[3][total_npanes][(nrow-1)*(ncol-1)]
Definition: ex1.C:106
void COM_print_profile(const char *fname, const char *header)
Definition: roccom_c++.h:557
Definition: Rocout.h:81
blockLoc i
Definition: read.cpp:79
int elmts[total_npanes][num_elmts][4]
Definition: ex1.C:109
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_set_profiling(int i)
Definition: roccom_c++.h:550
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
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
int main(int argc, char *argv[])
Definition: blastest.C:94
double velcts_f[total_npanes][nrow *ncol][3]
Definition: ex1.C:102
double velcts_s[total_npanes][num_nodes][3]
Definition: ex1.C:101
const int num_elmts
Definition: ex1.C:97
j indices j
Definition: Indexing.h:6
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
const int nrow
Definition: ex1.C:95
void COM_new_attribute(const char *wa_str, const char loc, const int type, int ncomp, const char *unit)
Registering an attribute type.
Definition: roccom_c++.h:118
static int rank
Definition: advectest.C:66
double coors_s[total_npanes][num_nodes][3]
Definition: ex1.C:99
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:111
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116
void init_unstructure_mesh(double coors[18][3], int elmts[4][8])