Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
surfjumper.C File Reference
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include "roccom.h"
#include "../Rocsurf/test/IM_Reader.h"
Include dependency graph for surfjumper.C:

Go to the source code of this file.

Functions

 COM_EXTERN_MODULE (Rocface)
 
 COM_EXTERN_MODULE (Rocout)
 
 COM_EXTERN_MODULE (Rocblas)
 
 COM_EXTERN_MODULE (Rocsurf)
 
void read_file (const char *fname, const string &wname, double alpha, bool with_ghost)
 
int main (int argc, char *argv[])
 

Function Documentation

COM_EXTERN_MODULE ( Rocface  )
COM_EXTERN_MODULE ( Rocout  )
COM_EXTERN_MODULE ( Rocblas  )
COM_EXTERN_MODULE ( Rocsurf  )
int main ( int  argc,
char *  argv[] 
)

Definition at line 84 of file surfjumper.C.

References COM_assertion_msg, COM_call_function(), COM_DOUBLE, COM_finalize(), COM_free_buffer(), COM_get_array(), COM_get_attribute(), COM_get_attribute_handle(), COM_get_attributes(), COM_get_function_handle(), COM_get_panes(), COM_init(), COM_LOAD_MODULE_STATIC_DYNAMIC, COM_new_attribute(), COM_print_profile(), COM_resize_array(), COM_set_profiling(), COM_UNLOAD_MODULE_STATIC_DYNAMIC, COM_window_init_done(), i, k, MPI_COMM_WORLD, ni, rank, and read_file().

84  {
85  MPI_Init(&argc,&argv);
86  COM_init( &argc, &argv);
87  int rank= 0;
88  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
89  if(!rank){
90  if ( argc < 3) {
91  std::cerr << "Usage: " << argv[0]
92  << " <src Rocin control> <targ Rocin control> [<out_prefix>] [<RocfaceControlFile>]\n\n"
93  << "\t<src Rocin control> specifies the Rocin control file for the old window\n"
94  << "\t<targ Rocin control> specifies the Rocin control file for the new window\n"
95  << "\t<out_prefix> specifies a prefix for output files. \n\t\tDefault is the current directory\n"
96  << "\t<RocfaceControlFile> specifies a file name for Rocface control parameters. \n"
97  << "\nExample:\t"
98  << argv[0] << " Rocflo/Rocin/\"ifluid*.txt\" Rocfrac/Rocin/\"isolid*.txt\" Rocman/RocfloRocfrac/" << "\n\t\t"
99  << std::endl;
100  exit(-1);
101  }
102  }
103 
104  COM_set_profiling( 1);
105 
106  string fnames[3];
107  fnames[0]=(string(argv[1]));
108  fnames[1]=(string(argv[2]));
109  fnames[2]=(string(argv[2]));
110  string pre = (argc>3)?argv[3]:"";
111  // Append '/' to pre if not there
112  if ( !pre.empty() && pre[pre.size()-1] != '/') pre.append("/");
113 
114  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
115 
116  int RFC_readcntr = COM_get_function_handle( "RFC.read_control_file");
117  int RFC_transfer = COM_get_function_handle("RFC.least_squares_transfer");
118  int RFC_read = COM_get_function_handle( "RFC.read_overlay");
119 
120  if ( argc>4) {
121  if(!rank)
122  std::cout << "Reading Rocface control file..." << std::endl;
123  COM_call_function( RFC_readcntr, argv[4]);
124  if(!rank)
125  std::cout << "Finished reading Rocface control file." << std::endl;
126  }
127 
128  string wnames[3];
129  for ( int k=0; k<3; ++k) {
130  // Discard the directory name and suffix to obtain a window name.
131  string::size_type n0 = fnames[k].find_last_of( "/");
132 
133  std::string fname;
134  if ( n0 == std::string::npos) fname=fnames[k];
135  else fname = fnames[k].substr( n0+1, fnames[k].size());
136 
137  string::size_type ni;
138  ni = fname.find_first_of( ".:_-*[]?\\\"\'0123456789");
139  COM_assertion_msg(ni, "File name must start with a letter");
140 
141  if ( ni == std::string::npos) {
142  wnames[k] = fname;
143  fnames[k].append(".hdf"); // Append the .hdf suffix to the file name.
144  }
145  else {
146  if ( fname[ni] == '_' && (fname[ni+1] == 's' || fname[ni+1] == 'f'))
147  ni += 2;
148  wnames[k] = pre+fname.substr( 0, ni);
149  }
150  COM_assertion_msg( k==0 || wnames[0]!=wnames[1],
151  "Two input files must have different alphabetic prefix");
152 
153  if(k == 2)
154  wnames[2] = "new_surf";
155  read_file( fnames[k].c_str(), wnames[k], 1.,k>1);
156  COM_window_init_done( wnames[k].c_str());
157  }
158  string srcwin(wnames[0]);
159  string trgwin(wnames[1]);
160  string r_trgwin(wnames[2]);
161  int srcmesh = COM_get_attribute_handle( (wnames[0]+".mesh").c_str());
162  int trgmesh = COM_get_attribute_handle( (wnames[1]+".mesh").c_str());
163  std::vector<int> pane_id;
164 
165  if(!rank)
166  std::cout << "Reading mesh overlay..." << std::endl;
167  MPI_Comm comm = MPI_COMM_WORLD;
168  COM_call_function( RFC_read, &srcmesh, &trgmesh, &comm,"src","trg","HDF");
169 
170  int num_attributes;
171  string names;
172  COM_get_attributes( srcwin.c_str(),&num_attributes,names);
173  char loc;
174  COM_Type comtype;
175  int ncomp;
176  std::string unit;
177  istringstream Istr(names);
178  for(int i = 0;i < num_attributes;i++){
179  string aname;
180  Istr >> aname;
181  COM_get_attribute(srcwin+"."+aname,&loc,&comtype,&ncomp,&unit);
182  if((loc == 'e' || loc == 'n') && comtype == COM_DOUBLE){
183  if(!rank)
184  cout << "Transferring attribute: " << aname << " on "
185  << (loc == 'e' ? "elements" : "nodes") << "." << endl;
186  COM_resize_array((srcwin+"."+aname).c_str());
187  COM_new_attribute((trgwin+"."+aname).c_str(),(char)loc,
188  COM_DOUBLE,(int)ncomp,unit.c_str());
189  COM_new_attribute((r_trgwin+"."+aname).c_str(),(char)loc,
190  COM_DOUBLE,(int)ncomp,unit.c_str());
191  COM_resize_array((r_trgwin+"."+aname).c_str());
192  COM_resize_array((trgwin+"."+aname).c_str());
193  int src_ahdl = COM_get_attribute_handle((srcwin+"."+aname).c_str());
194  int trg_ahdl = COM_get_attribute_handle((trgwin+"."+aname).c_str());
195  COM_call_function( RFC_transfer, &src_ahdl, &trg_ahdl);
196  int *srcpane_ids;
197  int npanes;
198  COM_get_panes( trgwin.c_str(), &npanes, &srcpane_ids);
199  pane_id.resize(npanes);
200  for(int i = 0;i < npanes;i++)
201  pane_id[i] = srcpane_ids[i];
202  // These are no longer necessary as we've duped the info into
203  // a locally allocated array
204  COM_free_buffer( &srcpane_ids);
205  for(int p = 0;p < npanes;p++){
206  void *src_ptr = NULL;
207  int src_std = 0;
208  int src_cap = 0;
209  void *trg_ptr = NULL;
210  int trg_std = 0;
211  int trg_cap = 0;
212  COM_get_array((trgwin+"."+aname).c_str(),pane_id[p],&src_ptr,&src_std,&src_cap);
213  // COM_assertion_msg((src_ptr && (src_std*src_cap >= 0)),"Source array missing or of 0 size.");
214  COM_get_array((r_trgwin+"."+aname).c_str(),pane_id[p],&trg_ptr,&trg_std,&trg_cap);
215  // COM_assertion_msg((trg_ptr && (trg_std*trg_cap >= 0)),"Target array missing or of 0 size.");
216  if(src_ptr && trg_ptr && (trg_std*trg_cap*src_std*src_cap >=0))
217  memcpy(trg_ptr,src_ptr,sizeof(double)*src_std*src_cap);
218  }
219  }
220  }
221 
223  int OUT_set_option = COM_get_function_handle( "Rocout.set_option");
224  std::string rankstr("0");
225  COM_call_function( OUT_set_option, "rankwidth", rankstr.c_str());
226  std::ostringstream Ostr;
227  Ostr << "new_surf_" << setw(5) << setfill('0') << rank+1;
228  int whand = COM_get_function_handle("Rocout.write_attribute");
229  int all = COM_get_attribute_handle((r_trgwin+".all"));
230  COM_call_function(whand,Ostr.str().c_str(),&all,r_trgwin.c_str(),"");
231  std::ofstream Ouf;
232  string controlfilename(Ostr.str() + "_in.txt");
233  Ouf.open(controlfilename.c_str());
234  Ouf << "@Proc: " << rank << endl
235  << "@Files: " << "new_surf_" << setw(5)
236  << setfill('0') << rank+1 << ".hdf" << endl;
237  Ouf.clear();
238  Ouf << "@Panes: ";
239  std::vector<int>::iterator pii = pane_id.begin();
240  while(pii != pane_id.end())
241  Ouf << *pii++ << " ";
242  Ouf << endl;
243  Ouf.close();
244 
246  COM_UNLOAD_MODULE_STATIC_DYNAMIC(Rocface,"RFC");
247 
248  COM_print_profile( "", "");
249 
250  COM_finalize();
251  MPI_Finalize();
252 }
int COM_Type
Indices for derived data types.
Definition: roccom_basic.h:122
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 read_file(const char *fname, const string &wname, double alpha)
Definition: autosurfer.C:39
#define COM_assertion_msg(EX, msg)
void COM_get_array(const char *wa_str, int pane_id, void **addr, int *strd, int *cap)
Get the address for an attribute on a specific pane.
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
#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: 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_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 int int REAL REAL REAL *z blockDim dim * ni
Definition: read.cpp:77
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
static int rank
Definition: advectest.C:66
#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:

void read_file ( const char *  fname,
const string &  wname,
double  alpha,
bool  with_ghost 
)

Definition at line 42 of file surfjumper.C.

References COM_call_function(), COM_clone_attribute(), COM_delete_window(), COM_get_attribute_handle(), COM_get_function_handle(), COM_LOAD_MODULE_STATIC_DYNAMIC, COM_new_window(), COM_UNLOAD_MODULE_STATIC_DYNAMIC, MPI_COMM_WORLD, and rank.

42  {
43  char *lastdot=strrchr( const_cast<char *>(fname), '.');
44  int rank = 0;
45  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
46  COM_new_window( wname.c_str());
47  // Read in HDF files or a Rocin control file
48  if(!rank)
49  std::cout << "Reading file " << fname << "..." << std::endl;
50 
51  // Read in HDF format
53 
54  int IN_read;
55  // Read in HDF format using Rocin::read_window or ::read_by_control_file
56  if ( strcmp( lastdot, ".hdf")==0)
57  IN_read = COM_get_function_handle( "IN.read_window");
58  else
59  IN_read = COM_get_function_handle( "IN.read_by_control_file");
60 
61  // Pass MPI_COMM_NULL to Rocin so that the rank becomes a wildcard.
62  MPI_Comm comm_null = MPI_COMM_WORLD;
63  std::string bufwin("bufwin");
64  COM_call_function( IN_read, fname, bufwin.c_str(), &comm_null);
65  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
66 
67  int buf_all = COM_get_attribute_handle((bufwin+".all").c_str());
68  COM_call_function( IN_obtain, &buf_all, &buf_all);
70 
71  if(!rank)
72  std::cout << "Obtained window " << wname
73  << " from file " << fname << std::endl;
74 
75  // Change the memory layout to contiguous.
76  if(with_ghost)
77  COM_clone_attribute( (wname+".all").c_str(), (bufwin+".all").c_str(), 1);
78  else
79  COM_clone_attribute( (wname+".all").c_str(), (bufwin+".all").c_str(), 0);
80 
81  COM_delete_window( bufwin.c_str());
82 }
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
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:113
Definition: Rocin.h:64
void COM_clone_attribute(const char *wname, const char *attr, int wg=1, const char *ptnname=0, int val=0)
Clone the subset of panes of another window of which the given pane attribute has value val...
Definition: roccom_c++.h:234
void COM_new_window(const char *wname, MPI_Comm c=MPI_COMM_NULL)
Definition: roccom_c++.h:86
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
static int rank
Definition: advectest.C:66
#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

Here is the call graph for this function: