Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
autosurfer.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: autosurfer.C,v 1.6 2009/10/08 20:35:10 mtcampbe Exp $
24 
25 #include <iostream>
26 #include <cstring>
27 #include <cstdlib>
28 
29 #include "roccom.h"
30 #include "../Rocsurf/test/IM_Reader.h"
31 
32 COM_EXTERN_MODULE( Rocface);
36 
37 using namespace std;
38 
39 void read_file( const char *fname, const string &wname, double alpha) {
40  char *lastdot=strrchr( const_cast<char *>(fname), '.');
41 
42  COM_new_window( wname.c_str());
43  // Read in HDF files or a Rocin control file
44 
45  // Read in HDF format
47 
48  int IN_read;
49  // Read in HDF format using Rocin::read_window or ::read_by_control_file
50  if ( strcmp( lastdot, ".hdf")==0)
51  IN_read = COM_get_function_handle( "IN.read_window");
52  else
53  IN_read = COM_get_function_handle( "IN.read_by_control_file");
54 
55  // Pass MPI_COMM_NULL to Rocin so that the rank becomes a wildcard.
56  MPI_Comm comm_null = MPI_COMM_NULL;
57  std::string bufwin("bufwin");
58  std::cout << "Reading file " << fname << "..." << std::endl;
59  COM_call_function( IN_read, fname, bufwin.c_str(), &comm_null);
60  std::cout << "Done reading file " << fname << "." << std::endl;
61  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
62 
63 
64  // Remove all attributes except for the mesh
65  COM_delete_attribute( (bufwin+".atts").c_str());
66 
67  // Read in the mesh.
68  int buf_mesh = COM_get_attribute_handle((bufwin+".mesh").c_str());
69  COM_call_function( IN_obtain, &buf_mesh, &buf_mesh);
71 
72  std::cout << "Obtained window " << wname
73  << " from file " << fname << std::endl;
74 
75  // Change the memory layout to contiguous.
76  COM_clone_attribute( (wname+".mesh").c_str(), (bufwin+".mesh").c_str(), 0);
77  COM_delete_window( bufwin.c_str());
78 }
79 
80 int main(int argc, char *argv[]) {
81  COM_init( &argc, &argv);
82 
83  if ( argc < 3) {
84  std::cerr << "Usage: " << argv[0]
85  << " <HDF|RocinControlFile1> <HDF|RocinControlFile2> [<out_prefix>] [<RocfaceControlFile>]\n\n"
86  << "\t<HDF|RocinControl File1> specifies the files for the first window\n"
87  << "\t<HDF|RocinControl File2> specifies the files for the second window\n"
88  << "\t<out_prefix> specifies a prefix for output files. \n\t\tDefault is the current directory\n"
89  << "\t<RocfaceControlFile> specifies a file name for Rocface control parameters. \n"
90  << "\nExample:\t"
91  << argv[0] << " \"ifluid*.hdf\" \"isolid*.hdf\" " << "\n\t\t"
92  << argv[0] << " Rocflo/Rocin/\"ifluid*.txt\" Rocfrac/Rocin/\"isolid*.txt\" Rocman/RocfloRocfrac/" << "\n\t\t"
93  << std::endl;
94  exit(-1);
95  }
96 
98 
99  string fnames[2] = {string(argv[1]), string(argv[2])};
100  string pre = (argc>3)?argv[3]:"";
101  // Append '/' to pre if not there
102  if ( !pre.empty() && pre[pre.size()-1] != '/') pre.append("/");
103 
104  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
105 
106  int RFC_readcntr = COM_get_function_handle( "RFC.read_control_file");
107  int RFC_overlay = COM_get_function_handle( "RFC.overlay");
108  int RFC_write = COM_get_function_handle( "RFC.write_overlay");
109 
110  if ( argc>4) {
111  std::cout << "Reading Rocface control file..." << std::endl;
112  COM_call_function( RFC_readcntr, argv[4]);
113  std::cout << "Finished reading Rocface control file." << std::endl;
114  }
115 
116  string wnames[2];
117  for ( int k=0; k<2; ++k) {
118  // Discard the directory name and suffix to obtain a window name.
119  string::size_type n0 = fnames[k].find_last_of( "/");
120 
121  std::string fname;
122  if ( n0 == std::string::npos) fname=fnames[k];
123  else fname = fnames[k].substr( n0+1, fnames[k].size());
124 
125  string::size_type ni;
126  ni = fname.find_first_of( ".:_-*[]?\\\"\'0123456789");
127  COM_assertion_msg(ni, "File name must start with a letter");
128 
129  if ( ni == std::string::npos) {
130  wnames[k] = fname;
131  fnames[k].append(".hdf"); // Append the .hdf suffix to the file name.
132  }
133  else {
134  if ( fname[ni] == '_' && (fname[ni+1] == 's' || fname[ni+1] == 'f'))
135  ni += 2;
136  wnames[k] = pre+fname.substr( 0, ni);
137  }
138  COM_assertion_msg( k==0 || wnames[0]!=wnames[1],
139  "Two input files must have different alphabetic prefix");
140 
141  read_file( fnames[k].c_str(), wnames[k], 1.);
142 
143  COM_window_init_done( wnames[k].c_str());
144  }
145 
146  int tri1_mesh = COM_get_attribute_handle( (wnames[0]+".mesh").c_str());
147  int tri2_mesh = COM_get_attribute_handle( (wnames[1]+".mesh").c_str());
148 
149  const char *format = "HDF";
150 
151  std::cout << "Starting mesh overlay..." << std::endl;
152  COM_call_function( RFC_overlay, &tri1_mesh, &tri2_mesh);
153  COM_call_function( RFC_write, &tri1_mesh, &tri2_mesh,
154  wnames[0].c_str(), wnames[1].c_str(), format);
155 
156  COM_print_profile( "", "");
157 
158  COM_finalize();
159 }
160 
161 
162 
163 
164 
165 
void COM_delete_window(const char *wname)
Definition: roccom_c++.h:94
j indices k indices k
Definition: Indexing.h:6
void read_file(const char *fname, const string &wname, double alpha)
Definition: autosurfer.C:39
#define COM_assertion_msg(EX, msg)
This file contains the prototypes for Roccom API.
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
void COM_delete_attribute(const char *wa_str)
Delete an existing attribute.
Definition: roccom_c++.h:128
#define COM_UNLOAD_MODULE_STATIC_DYNAMIC(moduleName, windowString)
Definition: roccom_basic.h:113
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
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
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_set_profiling(int i)
Definition: roccom_c++.h:550
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
int main(int argc, char *argv[])
Definition: blastest.C:94
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
#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