Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
outtest.C File Reference
#include "Roccom_base.h"
#include "roccom.h"
#include "roccom_devel.h"
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cassert>
#include <map>
#include <sstream>
Include dependency graph for outtest.C:

Go to the source code of this file.

Functions

 COM_EXTERN_MODULE (Rocin)
 
 COM_EXTERN_MODULE (Rocout)
 
int main (int argc, char *argv[])
 

Function Documentation

COM_EXTERN_MODULE ( Rocin  )
COM_EXTERN_MODULE ( Rocout  )
int main ( int  argc,
char *  argv[] 
)

Definition at line 43 of file outtest.C.

References COM_BOOL, COM_BYTE, COM_call_function(), COM_CHAR, COM_CHARACTER, COM_COMPLEX, COM_DOUBLE, COM_DOUBLE_COMPLEX, COM_DOUBLE_PRECISION, COM_F90POINTER, COM_finalize(), COM_FLOAT, COM_free_buffer(), COM_get_attribute(), COM_get_attribute_handle(), COM_get_attributes(), COM_get_connectivities(), COM_get_function_handle(), COM_get_panes(), COM_get_size(), COM_init(), COM_INT, COM_INTEGER, COM_LOAD_MODULE_STATIC_DYNAMIC, COM_LOGICAL, COM_LONG, COM_LONG_DOUBLE, COM_METADATA, COM_MPI_COMMC, COM_MPI_COMMF, COM_new_attribute(), COM_new_window(), COM_OBJECT, COM_print_profile(), COM_RAWDATA, COM_REAL, COM_resize_array(), COM_set_array_const(), COM_set_profiling(), COM_set_size(), COM_set_verbose(), COM_SHORT, COM_STRING, COM_UNLOAD_MODULE_STATIC_DYNAMIC, COM_UNSIGNED, COM_UNSIGNED_CHAR, COM_UNSIGNED_LONG, COM_UNSIGNED_SHORT, COM_VOID, COM_window_init_done(), i, and k.

43  {
44  map<int, string> typeAsString;
45  typeAsString[COM_CHAR] = "COM_CHAR";
46  typeAsString[COM_UNSIGNED_CHAR] = "COM_UNSIGNED_CHAR";
47  typeAsString[COM_BYTE] = "COM_BYTE";
48  typeAsString[COM_SHORT] = "COM_SHORT";
49  typeAsString[COM_UNSIGNED_SHORT] = "COM_UNSIGNED_SHORT";
50  typeAsString[COM_INT] = "COM_INT";
51  typeAsString[COM_UNSIGNED] = "COM_UNSIGNED";
52  typeAsString[COM_LONG] = "COM_LONG";
53  typeAsString[COM_UNSIGNED_LONG] = "COM_UNSIGNED_LONG";
54  typeAsString[COM_FLOAT] = "COM_FLOAT";
55  typeAsString[COM_DOUBLE] = "COM_DOUBLE";
56  typeAsString[COM_LONG_DOUBLE] = "COM_LONG_DOUBLE";
57  typeAsString[COM_BOOL] = "COM_BOOL";
58  typeAsString[COM_CHARACTER] = "COM_CHARACTER";
59  typeAsString[COM_LOGICAL] = "COM_LOGICAL";
60  typeAsString[COM_INTEGER] = "COM_INTEGER";
61  typeAsString[COM_REAL] = "COM_REAL";
62  typeAsString[COM_DOUBLE_PRECISION] = "COM_DOUBLE_PRECISION";
63  typeAsString[COM_COMPLEX] = "COM_COMPLEX";
64  typeAsString[COM_DOUBLE_COMPLEX] = "COM_DOUBLE_COMPLEX";
65  typeAsString[COM_MPI_COMMC] = "COM_MPI_COMMC";
66  typeAsString[COM_MPI_COMMF] = "COM_MPI_COMMF";
67  typeAsString[COM_STRING] = "COM_STRING";
68  typeAsString[COM_RAWDATA] = "COM_RAWDATA";
69  typeAsString[COM_METADATA] = "COM_METADATA";
70  typeAsString[COM_VOID] = "COM_VOID";
71  typeAsString[COM_F90POINTER] = "COM_F90POINTER";
72  typeAsString[COM_OBJECT] = "COM_OBJECT";
73 
74  COM_init( &argc, &argv);
75 
78 
79  int IN_read = COM_get_function_handle( "IN.read_windows");
80  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
81  int OUT_set = COM_get_function_handle( "OUT.set_option");
82  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
83 
84  COM_set_verbose(11);
86 
87  if ( argc < 3) {
88  cout << "Usage: " << argv[0] << " <inputfile> <outputfile> " << endl;
89  exit(-1);
90  }
91 
92  const char *file_in = argv[1];
93  const char *file_out = argv[2];
94 
95  const char *win_in = "rocin_win";
96  const char *win_out= "user_win";
97 
98  string win_in_pre( win_in); win_in_pre.append(".");
99  string win_out_pre( win_out); win_out_pre.append(".");
100 
101  COM_call_function( IN_read, file_in, win_in);
102 
103  // Obtain the list of panes
104  int np, *pane_ids;
105  COM_get_panes( win_in, &np, &pane_ids);
106 
107  // Create a new window and register the attributes
108  COM_new_window( win_out);
109 
110  // Loop through the panes to register the meshes
111  for ( int i=0; i<np; ++i) {
112  int nconn; // Number of connectivity tables
113  char *cnames; // Names of connectivity tables separated by space
114 
115  // Obtain the connectivity tables
116  COM_get_connectivities( win_in, pane_ids[i], &nconn, &cnames);
117 
118  if ( nconn == 1 && strncmp(cnames,":st",3)==0) { // Structured mesh
119  int nelems; // Number of elements
120  int nglayers; // Number of ghost layers.
121  COM_get_size( (win_in_pre+cnames).c_str(), pane_ids[i], &nelems, &nglayers);
122  COM_set_size( (win_out_pre+cnames).c_str(), pane_ids[i], nelems, nglayers);
123 
124  // Obtain the dimensions (must be a const array) of the pane and set them
125  const int *dims;
126  COM_get_array_const( (win_in_pre+cnames).c_str(), pane_ids[i], &dims);
127  COM_set_array_const( (win_out_pre+cnames).c_str(), pane_ids[i], dims);
128 
129  cout << "Structured information" << endl;
130  cout << " nelems = " << nelems << endl;
131  cout << " nglayers = " << nglayers << endl;
132  cout << " dims[0] = " << dims[0] << endl;
133  cout << " dims[1] = " << dims[1] << endl;
134 
135  }
136  else { // Unstructured mesh
137  int nnodes; // total number of nodes
138  int ngnodes; // Number of ghost nodes
139 
140  // Obtain the size of nodes
141  COM_get_size((win_in_pre+"nc").c_str(), pane_ids[i], &nnodes, &ngnodes);
142  COM_set_size((win_out_pre+"nc").c_str(), pane_ids[i], nnodes, ngnodes);
143  cout << "# nodes in dest set to " << nnodes
144  << " & # gnodes in dest set to " << ngnodes << endl;
145 
146  // Obtain the sizes of connectivity tables
147  if ( nconn>0) {
148  istringstream is( cnames);
149  for ( int k=0; k<nconn; ++k) {
150  string cname;
151  is >> cname;
152  int nelems, ng;
153  COM_get_size((win_in_pre+cname).c_str(), pane_ids[i], &nelems, &ng);
154  COM_set_size((win_out_pre+cname).c_str(), pane_ids[i], nelems, ng);
155  cout << "Connectivity table " << i << " has " << nelems
156  << " elements and " << ng << " ghost nodes" << endl;
157  COM_resize_array( (win_out_pre+cname).c_str(), pane_ids[i]);
158  }
159  }
160 
161  // free the buffer of cnames
162  COM_free_buffer( &cnames);
163  }
164 
165  COM_resize_array( (win_out_pre+"nc").c_str(), pane_ids[i]);
166  }
167 
168  // Obtain the list of attributes
169  int na; // Number of attributes
170  char *atts; // names of attributes separated by spaces
171  COM_get_attributes( win_in, &na, &atts);
172 
173  // Add in the special cases
174  string allatts("pconn ridges ");
175  allatts += atts;
176 
177  istringstream is(allatts.c_str());
178  for ( int i=0; i<na; ++i) {
179  // Obtain the attribute name
180  string aname; is >> aname;
181  char loc;
182  int type, ncomp;
183  string unit;
184 
185  COM_get_attribute( (win_in_pre+aname).c_str(), &loc, &type, &ncomp, &unit);
186  cout << (win_in_pre+aname).c_str() << " has type " << typeAsString[type]
187  << " (" << type << ')' << endl;
188  cout << (win_in_pre+aname).c_str() << " has location '" << loc << '\''
189  << endl;
190  cout << (win_in_pre+aname).c_str() << " has " << ncomp << " components"
191  << endl;
192  string waname = win_out_pre+aname;
193  COM_new_attribute( waname.c_str(), loc, type, ncomp, unit.c_str());
194 
195  if ( loc == 'w') {
196  cout << "Windowed attribute " << endl;
197 
198  // Obtain the size for a window attribute.
199  int nitems, ng;
200  COM_get_size((win_in_pre+aname).c_str(), 0, &nitems, &ng);
201  cout << (win_in_pre+aname).c_str() << " has " << nitems << " items and "
202  << ng << " ghost items." << endl;
203 
204  COM_set_size( waname.c_str(), 0, nitems, ng);
205 
206  COM_resize_array( waname.c_str(), 0, NULL, ncomp);
207  }
208  // Loop through the panes to allocate memory
209  else {
210  cout << "Panel attribute" << endl;
211  // This is to demonstrate the loop over panes.
212  // Could be replaced by a single call with paneID=0.
213  for ( int i=0; i<np; ++i) {
214 
215  if ( loc == 'p') {
216  // Obtain the size for a pane attribute.
217  int nitems, ng;
218  COM_get_size((win_in_pre+aname).c_str(), pane_ids[i], &nitems, &ng);
219  cout << (win_in_pre+aname).c_str() << " has " << nitems
220  << " items and " << ng << " ghost items." << endl;
221  COM_set_size( waname.c_str(), pane_ids[i], nitems, ng);
222  }
223 
224  COM_resize_array( waname.c_str(), pane_ids[i], NULL, ncomp);
225  }
226  }
227  }
228 
229  // Free buffers for pane ids and attribute names
230  COM_free_buffer( &pane_ids);
231  COM_free_buffer( &atts);
232 
233  // Mark the end of initialization
234  COM_window_init_done( win_out);
235 
236  // Finally, copy data from in to out.
237 
238  int OUT_all = COM_get_attribute_handle((win_out_pre+"all").c_str());
239  int IN_all = COM_get_attribute_handle((win_in_pre+"all").c_str());
240 
241  COM_call_function(IN_obtain, &IN_all, &OUT_all);
242 
243  string fo(file_out);
244 
245  COM_call_function( OUT_set, "format", "HDF4");
246 
247  COM_call_function( OUT_write, (fo + ".hdf").c_str(), &OUT_all, win_out,
248  "0000");
249 
250  COM_call_function( OUT_set, "format", "CGNS");
251 
252  COM_call_function( OUT_write, (fo + ".cgns").c_str(), &OUT_all, win_out,
253  "0000");
254 
255  COM_print_profile("", "");
256 
259 
260  COM_finalize();
261 }
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
C/C++ Data types.
Definition: roccom_basic.h:129
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
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:113
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_print_profile(const char *fname, const char *header)
Definition: roccom_c++.h:557
Definition: Rocin.h:64
Definition: Rocout.h:81
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
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
Fortran Data types.
Definition: roccom_basic.h:133
#define COM_LOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:111
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

Here is the call graph for this function: