Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ex4.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: ex4.C,v 1.26 2008/12/06 08:43:29 mtcampbe Exp $
24 
25 #include "roccom.h"
26 #include <cassert>
27 #include <cstdio>
28 #include <cstring>
29 #include <iostream>
30 #include <fstream>
31 #include <vector>
32 #include <algorithm>
33 #include "commpi.h"
34 
35 COM_EXTERN_MODULE( Rocface);
37 
38 using namespace std;
39 
40 extern int read_obj( std::istream &is, std::vector<double> &coors,
41  std::vector<int> &elems);
42 
43 int main(int argc, char *argv[]) {
44  COM_init( &argc, &argv);
45 
46  if ( argc < 7) {
47  std::cout << "Usage: " << argv[0]
48  << " <quad_prefix> <quad_num_blocks> <quad_suffix> "
49  << " <tri_prefix> <tri_num_blocks> <tri_suffix>" << std::endl;
50  exit(-1);
51  }
52 
53  COM_set_verbose( 1);
55 
56  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
57 
58  MPI_Comm comm = MPI_COMM_WORLD;
59  const int comm_rank=0;
60  const int comm_size=1;
61 
62  const char *quad_prefix = argv[1];
63  const int quad_num_blocks=atoi(argv[2]);
64  const char *quad_suffix = argv[3];
65  assert( quad_num_blocks <= 5);
66 
67  const char *tri_prefix = argv[4];
68  const int tri_num_blocks=atoi(argv[5]);
69  const char *tri_suffix = argv[6];
70  assert( tri_num_blocks <= 5);
71 
72  std::vector<double> quad_mesh_coors[5];
73  std::vector<int> quad_mesh_elems[5];
74  std::vector<double> quad_mesh_nd[5];
75  std::vector<double> quad_mesh_fd[5];
76 
77  for ( int i=0; i<quad_num_blocks; ++i) {
78  if ( i%comm_size==comm_rank) {
79  char fname[100];
80  std::sprintf( fname, "%s%d%s", quad_prefix, i+1, quad_suffix);
81  std::ifstream is( fname);
82  assert( is != NULL);
83  int n = read_obj( is, quad_mesh_coors[i], quad_mesh_elems[i]);
84  assert( n==4);
85 
86  quad_mesh_nd[i] = quad_mesh_coors[i];
87  quad_mesh_fd[i].resize( quad_mesh_elems[i].size()/4);
88 // evaluate_pressure( quad_mesh_coors[i], quad_mesh_elems[i],
89 // quad_mesh_fd[i], 4, 1);
90  }
91  }
92 
93  COM_new_window("quad");
94 
95  COM_new_attribute("quad.disp", 'n', COM_DOUBLE, 3, "m");
96  COM_new_attribute("quad.press", 'e', COM_DOUBLE, 1, "Pascal");
97 
98  for ( int i=0; i<quad_num_blocks; ++i) {
99  if ( i%comm_size==comm_rank) {
100  COM_set_size( "quad.nc", i+1, quad_mesh_coors[i].size()/3);
101  COM_set_array( "quad.nc", i+1, &quad_mesh_coors[i][0]);
102  COM_set_size( "quad.:q4:", i+1, quad_mesh_elems[i].size()/4);
103  COM_set_array( "quad.:q4:", i+1, &quad_mesh_elems[i][0]);
104 
105  COM_set_array( "quad.disp", i+1, &quad_mesh_nd[i][0]);
106  COM_set_array( "quad.press", i+1, &quad_mesh_fd[i][0]);
107  }
108  }
109  COM_window_init_done( "quad");
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_fd[5];
115 
116  COM_new_window("tri");
117  COM_new_attribute("tri.disp", 'n', COM_DOUBLE, 3, "m");
118  COM_new_attribute("tri.press", 'e', COM_DOUBLE, 1, "Pascal");
119 
120  for ( int i=0; i<tri_num_blocks; ++i) {
121  if ( i%comm_size==comm_rank) {
122  char fname[100];
123  std::sprintf( fname, "%s%d%s", tri_prefix, i+1, tri_suffix);
124  ifstream is( fname); assert( is != NULL);
125  int n = read_obj( is, tri_mesh_coors[i], tri_mesh_elems[i]);
126  assert( n==3 || n==6);
127 
128  tri_mesh_nd[i] = tri_mesh_coors[i];
129  tri_mesh_fd[i].resize( tri_mesh_elems[i].size()/3,1);
130 
131 // evaluate_pressure( tri_mesh_coors[i], tri_mesh_elems[i],
132 // tri_mesh_fd[i], 3, 1);
133 
134  COM_set_size( "tri.nc", i+1, tri_mesh_coors[i].size()/3);
135  COM_set_array( "tri.nc", i+1, &tri_mesh_coors[i][0]);
136  char *buf = fname;
137  std::sprintf( buf, "tri.:t%d:", n);
138  COM_set_size( buf, i+1, tri_mesh_elems[i].size()/n);
139  COM_set_array( buf, i+1, &tri_mesh_elems[i][0]);
140 
141  COM_set_array("tri.disp", i+1, &tri_mesh_nd[i][0]);
142  COM_set_array("tri.press", i+1, &tri_mesh_fd[i][0]);
143  }
144  }
145 
146  COM_window_init_done( "tri");
147 
148  int tri_mesh = COM_get_attribute_handle( "tri.mesh");
149  int quad_mesh = COM_get_attribute_handle( "quad.mesh");
150  int RFC_clear = COM_get_function_handle( "RFC.clear_overlay");
151  int RFC_write = COM_get_function_handle( "RFC.write_overlay");
152 
153  if ( comm_size == 1) {
154  int RFC_overlay = COM_get_function_handle( "RFC.overlay");
155 
156 
157  COM_call_function( RFC_overlay, &tri_mesh, &quad_mesh, &comm);
158  COM_call_function( RFC_write, &tri_mesh, &quad_mesh, "tri", "quad", "HDF");
159  COM_call_function( RFC_clear, "tri", "quad");
160  }
161 
162  int RFC_read = COM_get_function_handle( "RFC.read_overlay");
163  COM_call_function( RFC_read, &tri_mesh, &quad_mesh, &comm,
164  "tri", "quad", "HDF");
165 
166  char prefix1[100], prefix2[100];
167  std::sprintf(prefix1, "tri_%d", comm_rank);
168  std::sprintf(prefix2, "quad_%d", comm_rank);
169 
170  if ( argc > 7) {
172 
173  std::sprintf(prefix1, "tri_fields%d", comm_rank);
174  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
175  int OUT_set = COM_get_function_handle( "OUT.set_option");
176  int tri_all = COM_get_attribute_handle( "tri.all");
177  int quad_press = COM_get_attribute_handle( "quad.press");
178 
179  COM_call_function( OUT_write, prefix1, &tri_all, "tri", "001");
180  std::sprintf(prefix2, "quad_fields%d", comm_rank);
181  COM_call_function( OUT_write, prefix2, &quad_press, "quad", "001");
182 
183  int RFC_transfer = COM_get_function_handle( "RFC.least_squares_transfer");
184  int tri_press = COM_get_attribute_handle( "tri.press");
185  COM_call_function( RFC_transfer, &tri_press, &quad_press);
186  COM_call_function( RFC_transfer, &quad_press, &tri_press);
187 
188  int tri_disp = COM_get_attribute_handle( "tri.disp");
189  int quad_disp = COM_get_attribute_handle( "quad.disp");
190  COM_call_function( RFC_transfer, &quad_disp, &tri_disp);
191  COM_call_function( RFC_transfer, &tri_disp, &quad_disp);
192 
193  COM_call_function( OUT_set, "mode", "a");
194  COM_call_function( OUT_write, prefix1, &tri_all, "tri", "002");
195  std::sprintf(prefix2, "quad_fields%d", comm_rank);
196  COM_call_function( OUT_write, prefix2, &quad_press, "quad", "002");
197 
198  COM_call_function( RFC_clear, "tri", "quad");
199  }
200 
201  COM_delete_window( "tri");
202  COM_delete_window( "quad");
203 
204  COM_print_profile( "", "");
205 
206  COM_finalize();
207 }
208 
209 
210 
211 
212 
213 
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
const NT & n
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 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