Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ex3.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: ex3.C,v 1.26 2008/12/06 08:43:29 mtcampbe Exp $
24 
25 #include "roccom.h"
26 #include <cstdio>
27 #include <iostream>
28 #include <fstream>
29 #include <vector>
30 #include <algorithm>
31 #include <cstring>
32 #include <string>
33 #include "commpi.h"
34 
35 COM_EXTERN_MODULE( Rocface);
37 
38 using namespace std;
39 
40 extern int read_obj( std::istream &is, vector<double> &coors,
41  vector<int> &elems);
42 extern void read_ij( std::istream &is, vector<double> &coors, int dims[2]);
43 
44 int main(int argc, char *argv[]) {
45  COM_init( &argc, &argv);
46 
47  if ( argc < 7) {
48  std::cout << "Usage: " << argv[0]
49  << " <str_prefix> <str_num_blocks> <str_suffix> "
50  << " <tri_prefix> <tri_num_blocks> <tri_suffix>" << std::endl;
51  exit(-1);
52  }
53 
54  COM_set_verbose( 1);
56 
57  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
58 
59  MPI_Comm comm = MPI_COMM_WORLD;
60  const int comm_rank=0;
61  const int comm_size=1;
62 
63  const char *str_prefix = argv[1];
64  const int str_num_blocks=atoi(argv[2]);
65  const char *str_suffix = argv[3];
66  assert( str_num_blocks <= 5);
67 
68  const char *tri_prefix = argv[4];
69  const int tri_num_blocks=atoi(argv[5]);
70  const char *tri_suffix = argv[6];
71  assert( tri_num_blocks <= 5);
72 
73  std::vector<double> str_mesh_coors[5];
74  std::vector<double> str_mesh_nd[5];
75  std::vector<double> str_mesh_npress[5];
76  std::vector<double> str_mesh_fpress[5];
77  int dims[5][2];
78 
79  for ( int i=0; i<str_num_blocks; ++i) {
80  if ( i%comm_size==comm_rank) {
81  char fname[100];
82  std::sprintf( fname, "%s%d%s", str_prefix, i+1, str_suffix);
83  std::ifstream is( fname);
84  assert( is != NULL);
85  read_ij( is, str_mesh_coors[i], dims[i]);
86 
87  str_mesh_nd[i] = str_mesh_coors[i];
88  str_mesh_npress[i].resize( dims[i][0]*dims[i][1]*3,3);
89  str_mesh_fpress[i].resize( (dims[i][0]-1)*(dims[i][1]-1)*3,3);
90  }
91  }
92 
93  COM_new_window("str");
94 
95  COM_new_attribute("str.coor", 'n', COM_DOUBLE, 3, "m");
96  COM_new_attribute("str.npress", 'n', COM_DOUBLE, 3, "Pa");
97  COM_new_attribute("str.fpress", 'e', COM_DOUBLE, 3, "Pa");
98 
99  for ( int i=0; i<str_num_blocks; ++i) {
100  if ( i%comm_size==comm_rank) {
101  COM_set_array( "str.:st2:", i+1, dims[i]);
102  COM_set_array( "str.nc", i+1, &str_mesh_coors[i][0]);
103 
104  COM_set_array( "str.coor", i+1, &str_mesh_nd[i][0]);
105  COM_set_array( "str.npress", i+1, &str_mesh_npress[i][0]);
106  COM_set_array( "str.fpress", i+1, &str_mesh_fpress[i][0]);
107  }
108  }
109  COM_window_init_done( "str");
110 
111  std::vector<double> tri_mesh_coors[5];
112  std::vector<int> tri_mesh_elems[5];
113  std::vector<double> tri_mesh_nd[5];
114  std::vector<double> tri_mesh_npress[5];
115  std::vector<double> tri_mesh_fpress[5];
116 
117  for ( int i=0; i<tri_num_blocks; ++i) {
118  if ( i%comm_size==comm_rank) {
119  char fname[100];
120  std::sprintf( fname, "%s%d%s", tri_prefix, i+1, tri_suffix);
121  ifstream is( fname); assert( is != NULL);
122  read_obj( is, tri_mesh_coors[i], tri_mesh_elems[i]);
123 
124  tri_mesh_nd[i] = tri_mesh_coors[i];
125  tri_mesh_npress[i].resize( tri_mesh_coors[i].size(),3);
126  tri_mesh_fpress[i].resize( tri_mesh_elems[i].size(),3);
127  }
128  }
129 
130  COM_new_window("tri");
131  COM_new_attribute("tri.coor", 'n', COM_DOUBLE, 3, "m");
132  COM_new_attribute("tri.npress", 'n', COM_DOUBLE, 3, "Pa");
133  COM_new_attribute("tri.fpress", 'e', COM_DOUBLE, 3, "Pa");
134 
135  for ( int i=0; i<tri_num_blocks; ++i) {
136  if ( i%comm_size==comm_rank) {
137  COM_set_size( "tri.nc", i+1, tri_mesh_coors[i].size()/3);
138  COM_set_array( "tri.nc", i+1, &tri_mesh_coors[i][0]);
139  COM_set_size( "tri.:t3:", i+1, tri_mesh_elems[i].size()/3);
140  COM_set_array( "tri.:t3:", i+1, &tri_mesh_elems[i][0]);
141 
142  COM_set_array("tri.coor", i+1, &tri_mesh_nd[i][0]);
143  COM_set_array("tri.npress", i+1, &tri_mesh_npress[i][0]);
144  COM_set_array("tri.fpress", i+1, &tri_mesh_fpress[i][0]);
145  }
146  }
147  COM_window_init_done( "tri");
148 
149  int tri_mesh = COM_get_attribute_handle( "tri.mesh");
150  int str_mesh = COM_get_attribute_handle( "str.mesh");
151  int RFC_clear = COM_get_function_handle( "RFC.clear_overlay");
152  int RFC_write = COM_get_function_handle( "RFC.write_overlay");
153 
154  if ( comm_size == 1) {
155  int RFC_overlay = COM_get_function_handle( "RFC.overlay");
156 
157  COM_call_function( RFC_overlay, &tri_mesh, &str_mesh, &comm);
158  COM_call_function( RFC_write, &tri_mesh, &str_mesh, "tri", "str", "HDF");
159  COM_call_function( RFC_clear, "tri", "str");
160  }
161 
162  int RFC_read = COM_get_function_handle( "RFC.read_overlay");
163  COM_call_function( RFC_read, &tri_mesh, &str_mesh, &comm,
164  "tri", "str", "HDF");
165 
166  char prefix1[100], prefix2[100];
167  std::sprintf(prefix1, "tri_%d", comm_rank);
168  std::sprintf(prefix2, "str_%d", comm_rank);
169 
170  if ( argc>7) {
172  std::sprintf(prefix1, "tri_coor%d", comm_rank);
173  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
174  int OUT_set = COM_get_function_handle( "OUT.set_option");
175  int tri_coor = COM_get_attribute_handle( "tri.coor");
176  int str_coor = COM_get_attribute_handle( "str.coor");
177 
178  COM_call_function( OUT_set, "mode", "w");
179  COM_call_function( OUT_write, prefix1, &tri_coor, "tri", "000");
180  std::sprintf(prefix2, "str_coor%d", comm_rank);
181  COM_call_function( OUT_write, prefix2, &str_coor, "str", "000");
182 
183  int RFC_transfer = COM_get_function_handle( "RFC.least_squares_transfer");
184  COM_call_function( RFC_transfer, &tri_coor, &str_coor);
185  COM_call_function( RFC_transfer, &str_coor, &tri_coor);
186 
187  COM_call_function( OUT_set, "mode", "a");
188  COM_call_function( OUT_write, prefix1, &tri_coor, "tri", "001", "a");
189  COM_call_function( OUT_write, prefix2, &str_coor, "str", "001", "a");
190 
191  int tri_npress = COM_get_attribute_handle( "tri.npress");
192  int str_fpress = COM_get_attribute_handle( "str.fpress");
193  std::sprintf(prefix1, "tri_press%d", comm_rank);
194  std::sprintf(prefix2, "str_press%d", comm_rank);
195 
196  COM_call_function( OUT_set, "mode", "w");
197  COM_call_function( OUT_write, prefix1, &tri_npress, "tri", "000");
198  COM_call_function( OUT_write, prefix2, &str_fpress, "str", "000");
199 
200  int tri_fpress = COM_get_attribute_handle( "tri.fpress");
201  int str_npress = COM_get_attribute_handle( "str.npress");
202  COM_call_function( RFC_transfer, &str_npress, &tri_fpress);
203  COM_call_function( RFC_transfer, &tri_fpress, &str_npress);
204 
205  COM_call_function( OUT_set, "mode", "a");
206  COM_call_function( OUT_write, prefix1, &tri_fpress, "tri", "001", "a");
207  COM_call_function( OUT_write, prefix2, &str_npress, "str", "001", "a");
208  COM_call_function( RFC_clear, "tri", "str");
209  }
210 
211  COM_delete_window( "tri");
212  COM_delete_window( "str");
213 
214  COM_print_profile( "", "");
215 
216  COM_finalize();
217 }
218 
219 
220 
221 
222 
223 
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
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.
void COM_set_verbose(int i)
Definition: roccom_c++.h:543
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
int read_obj(std::istream &is, vector< double > &coors, vector< int > &elems)
Definition: meshio.C:39
void COM_finalize()
Definition: roccom_c++.h:59
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
Contains declarations of MPI subroutines used in Roccom.
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
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
void read_ij(std::istream &is, vector< double > &coors, int dims[2])
Definition: meshio.C:81
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
#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