Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
intest2.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: intest2.C,v 1.9 2008/12/06 08:43:20 mtcampbe Exp $
24 
30 #include "Rocin.h"
31 #include "Roccom_base.h"
32 #include "roccom.h"
33 #include "roccom_devel.h"
34 
35 
36 #include <iostream>
37 #include <cstring>
38 #include <string>
39 #include <cstdlib>
40 #include <cassert>
41 #include <sstream>
42 
43 using namespace std;
44 
45 #ifdef STATIC_LINK
46 extern "C" void Rocout_load_module( const char *);
47 #endif
48 
49 int main(int argc, char *argv[]) {
50  COM_init( &argc, &argv);
51 
52 #ifdef STATIC_LINK
53  Rocin_load_module("IN");
54  Rocout_load_module("OUT");
55 #else
56  COM_load_module("Rocin", "IN");
57  COM_load_module("Rocout", "OUT");
58 #endif
59 
60  if ( argc < 3 || argc > 3 ) {
61  std::cout << "Usage: To test in serial: \n\t" << argv[0]
62  << " <input HDF file|Rocin control file> <outputfile>\n"
63  << "To test in parallel: \n\t" << argv[0]
64  << " -com-mpi <Rocin control file> <output_prefix>\n"
65  << std::endl;
66  // Note: -com-mpi option will be eaten away by COM_init.
67  exit(-1);
68  }
69 
70  COM_set_verbose(11);
72 
73  const char *file_in = argv[1];
74  const char *file_out = argv[2];
75 
76  int IN_read;
77  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
78 
79  const char *lastdot=std::strrchr( file_in, '.');
80  if ( lastdot && std::strcmp( lastdot, ".hdf")==0) {
81  IN_read = COM_get_function_handle( "IN.read_window");
82  }
83  else {
84  IN_read = COM_get_function_handle( "IN.read_by_control_file");
85  }
86 
87  const char *win_in = "rocin_win";
88  const char *win_out= "user_win";
89 
90  std::string win_in_pre( win_in); win_in_pre.append(".");
91  std::string win_out_pre( win_out); win_out_pre.append(".");
92 
93  MPI_Comm comm = MPI_COMM_WORLD;
94  COM_call_function( IN_read, file_in, win_in, &comm);
95 
96  // Obtain the list of panes
97  int np, *pane_ids;
98  COM_get_panes( win_in, &np, &pane_ids);
99 
100  // Create a new window and register the attributes
101  COM_new_window( win_out);
102 
103  // Loop through the panes to register the meshes
104  for ( int i=0; i<np; ++i) {
105  int nconn; // Number of connectivity tables
106  char *cnames; // Names of connectivity tables separated by space
107 
108  // Obtain the connectivity tables
109  COM_get_connectivities( win_in, pane_ids[i], &nconn, &cnames);
110 
111  if ( nconn == 1 && strncmp(cnames,":st",3)==0) { // Structured mesh
112  int ndims; // Number of elements
113  int nglayers; // Number of ghost layers.
114  COM_get_size( (win_in_pre+cnames).c_str(), pane_ids[i], &ndims, &nglayers);
115  COM_set_size( (win_out_pre+cnames).c_str(), pane_ids[i], ndims, nglayers);
116 
117  // Obtain the dimensions (must be a const array) of the pane and set them
118  const int *dims;
119  COM_get_array_const( (win_in_pre+cnames).c_str(), pane_ids[i], &dims);
120  COM_set_array_const( (win_out_pre+cnames).c_str(), pane_ids[i], dims);
121 
122  std::cout << "Structured information" << endl;
123  cout << " ndims = " << ndims << endl;
124  cout << " nglayers = " << nglayers << endl;
125  cout << " dims[0] = " << dims[0] << endl;
126  if ( ndims>1) cout << " dims[1] = " << dims[1] << endl;
127  if ( ndims>2) cout << " dims[2] = " << dims[2] << endl;
128 
129  }
130  else { // Unstructured mesh
131  int nnodes; // total number of nodes
132  int ngnodes; // Number of ghost nodes
133 
134  // Obtain the size of nodes
135  COM_get_size((win_in_pre+"nc").c_str(), pane_ids[i], &nnodes, &ngnodes);
136  COM_set_size((win_out_pre+"nc").c_str(), pane_ids[i], nnodes, ngnodes);
137  std::cout << "# nodes in dest set to " << nnodes
138  << " & # gnodes in dest set to " << ngnodes << std::endl;
139 
140  // Obtain the sizes of connectivity tables
141  if ( nconn>0) {
142  std::istringstream is( cnames);
143  for ( int k=0; k<nconn; ++k) {
144  std::string cname;
145  is >> cname;
146  int nelems, ng;
147  COM_get_size((win_in_pre+cname).c_str(), pane_ids[i], &nelems, &ng);
148  COM_set_size((win_out_pre+cname).c_str(), pane_ids[i], nelems, ng);
149  std::cout << "Connectivity table " << i << " has " << nelems << " elements and "
150  << ng << " ghost nodes" << std::endl;
151  COM_resize_array( (win_out_pre+cname).c_str(), pane_ids[i]);
152  }
153  }
154 
155  // free the buffer of cnames
156  COM_free_buffer( &cnames);
157  }
158 
159  COM_resize_array( (win_out_pre+"nc").c_str(), pane_ids[i]);
160  }
161 
162  // Obtain the list of attributes
163  int na; // Number of attributes
164  char *atts; // names of attributes separated by spaces
165  COM_get_attributes( win_in, &na, &atts);
166 
167  std::istringstream is(atts);
168  for ( int i=0; i<na; ++i) {
169  // Obtain the attribute name
170  std::string aname; is >> aname;
171  char loc;
172  int type, ncomp;
173  std::string unit;
174 
175  COM_get_attribute( (win_in_pre+aname).c_str(), &loc, &type, &ncomp, &unit);
176  std::cout << (win_in_pre+aname).c_str() << " has type " << type << endl;
177  std::cout << (win_in_pre+aname).c_str() << " has " << ncomp << " components" << endl;
178  std::string waname = win_out_pre+aname;
179  COM_new_attribute( waname.c_str(), loc, type, ncomp, unit.c_str());
180 
181  if ( loc == 'w') {
182  std::cout << "Windowed attribute " << endl;
183 
184  // Obtain the size for a window attribute.
185  int nitems, ng;
186  COM_get_size((win_in_pre+aname).c_str(), 0, &nitems, &ng);
187 
188  COM_set_size( waname.c_str(), 0, nitems, ng);
189 
190  COM_resize_array( waname.c_str(), 0, NULL, ncomp);
191  }
192  // Loop through the panes to allocate memory
193  else {
194  std::cout << "Panel attribute" << endl;
195  // This is to demonstrate the loop over panes.
196  // Could be replaced by a single call with paneID=0.
197  for ( int i=0; i<np; ++i) {
198 
199  if ( loc == 'p') {
200  // Obtain the size for a pane attribute.
201  int nitems, ng;
202  COM_get_size((win_in_pre+aname).c_str(), pane_ids[i], &nitems, &ng);
203  COM_set_size( waname.c_str(), pane_ids[i], nitems, ng);
204  }
205 
206  COM_resize_array( waname.c_str(), pane_ids[i], NULL, ncomp);
207  }
208  }
209  }
210 
211  // Free buffers for pane ids and attribute names
212  COM_free_buffer( &pane_ids);
213  COM_free_buffer( &atts);
214 
215  // Mark the end of initialization
216  COM_window_init_done( win_out);
217 
218  // Finally, copy data from in to out.
219 
220  int OUT_all = COM_get_attribute_handle((win_out_pre+"all").c_str());
221  int IN_all = COM_get_attribute_handle((win_in_pre+"all").c_str());
222 
223  COM_call_function(IN_obtain, &IN_all, &OUT_all);
224 
225  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
226  COM_call_function( OUT_write, file_out, &OUT_all, win_out, "000");
227 
228  COM_print_profile("", "");
229  COM_finalize();
230 }
231 
232 
233 
234 
235 
236 
void Rocin_load_module(const char *name)
Load the module Rocin into Roccom using the given module name.
Definition: Rocin.C:3063
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
j indices k indices k
Definition: Indexing.h:6
void COM_get_attribute(const std::string wa_str, char *loc, int *type, int *ncomp, std::string *unit)
Definition: roccom_c++.h:269
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
void COM_get_connectivities(const char *wname, int pane_id, int *nc, std::string &names)
Definition: roccom_c++.h:363
void COM_get_attributes(const char *wname, int *na, std::string &names)
Definition: roccom_c++.h:360
void COM_finalize()
Definition: roccom_c++.h:59
void COM_load_module(const char *libname, const char *winname)
Definition: roccom_c++.h:75
void COM_print_profile(const char *fname, const char *header)
Definition: roccom_c++.h:557
blockLoc i
Definition: read.cpp:79
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
void COM_get_size(const char *wa_str, int pane_id, int *size, int *ng=0)
Get the sizes of an attribute.
Definition: roccom_c++.h:274
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_set_array_const(const char *wa_str, int pane_id, const void *addr, int strd=0, int cap=0)
Definition: roccom_c++.h:160
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
Rocin creates a series of Roccom windows by reading in a list of files.
int main(int argc, char *argv[])
Definition: blastest.C:94
void Rocout_load_module(const char *name)
Load the module Rocout into Roccom using the given module name.
Definition: Rocout.C:934
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
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
Definition: roccom_c++.h:350
void COM_free_buffer(int **buf)
Definition: roccom_c++.h:397
void COM_resize_array(const char *wa_str, int pane_id=0, void **addr=NULL, int strd=-1, int cap=0)
Resize an attribute on a specific pane and return the address by setting addr.
Definition: roccom_c++.h:200
int COM_get_function_handle(const char *wfname)
Definition: roccom_c++.h:428
Contains declaration of the base class for Roccom implementations.