Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rfctest.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: rfctest.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 
34 COM_EXTERN_MODULE( Rocface);
36 COM_EXTERN_MODULE( Rocmap);
37 
38 using namespace std;
39 
40 void read_file( const char *fname, const string &wname, double alpha) {
41  char *lastdot=strrchr( const_cast<char *>(fname), '.');
42 
43  COM_new_window( wname.c_str());
44  // Read in HDF files or a Rocin control file
45  std::cout << "Reading file " << fname << "..." << std::endl;
46 
47  // Read in HDF format
49 
50  int IN_read;
51  // Read in HDF format using Rocin::read_window or ::read_by_control_file
52  if ( strcmp( lastdot, ".hdf")==0)
53  IN_read = COM_get_function_handle( "IN.read_window");
54  else
55  IN_read = COM_get_function_handle( "IN.read_by_control_file");
56 
57  MPI_Comm comm_null = MPI_COMM_NULL;
58  std::string bufwin("bufwin");
59  COM_call_function( IN_read, fname, bufwin.c_str(), &comm_null);
60  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
61 
62  // Check whether bcflag exists. If so, retain only the panes with flag<=1.
63  int bcflag = COM_get_attribute_handle((bufwin+".bcflag").c_str());
64  if (bcflag > 0) {
65  // Read in bcflags.
66  COM_call_function( IN_obtain, &bcflag, &bcflag);
67 
68  // Obtain the IDs of the panes of the window
69  int npanes, *pane_ids;
70  COM_get_panes( bufwin.c_str(), &npanes, &pane_ids);
71 
72  // Loop through the panes to remove those with bcflag >1.
73  for ( int i=0; i<npanes; ++i) {
74  int *flag;
75  COM_get_array( (bufwin+".bcflag").c_str(), pane_ids[i], &flag);
76  if ( flag==NULL || *flag>1)
77  COM_delete_pane( bufwin.c_str(), pane_ids[i]);
78  }
79 
80  // remove buffers.
81  COM_free_buffer( &pane_ids);
82  }
83 
84  // Remove all attributes except for the mesh
85  COM_delete_attribute( (bufwin+".atts").c_str());
86 
87  // Read in the mesh.
88  int buf_mesh = COM_get_attribute_handle((bufwin+".mesh").c_str());
89  COM_call_function( IN_obtain, &buf_mesh, &buf_mesh);
91 
92  std::cout << "Obtained window " << wname
93  << " from file " << fname << std::endl;
94 
95  // Change the memory layout to contiguous.
96  COM_clone_attribute( (wname+".mesh").c_str(), (bufwin+".mesh").c_str(), 0);
97  COM_delete_window( bufwin.c_str());
98 }
99 
100 using namespace std;
101 
102 int main(int argc, char *argv[]) {
103  COM_init( &argc, &argv);
104 
105  if ( argc < 3) {
106  std::cerr << "Usage: " << argv[0]
107  << " <HDF|RocinControlFile1> <HDF|RocinControlFile2> [<out_prefix>] [<RocfaceControlFile>]\n\n"
108  << "\t<HDF|RocinControl File1> specifies the files for the first window\n"
109  << "\t<HDF|RocinControl File2> specifies the files for the second window\n"
110  << "\t<out_prefix> specifies a prefix for output files. \n\t\tDefault is the current directory\n"
111  << "\t<RocfaceControlFile> specifies a file name for Rocface control parameters. \n"
112  << "\nExample:\t"
113  << argv[0] << " \"ifluid*.hdf\" \"isolid*.hdf\" " << "\n\t\t"
114  << argv[0] << " Rocflo/Rocin/\"ifluid*.txt\" Rocfrac/Rocin/\"isolid*.txt\" Rocman/RocfloRocfrac/" << "\n\t\t"
115  << std::endl;
116  exit(-1);
117  }
118 
119  if ( argc >= 2 && strcmp( argv[1], "-h") == 0) {
120  std::cout << "Usage: " << argv[0] << " [-v]"
121  << std::endl;
122  exit(-1);
123  }
124 
125  COM_set_profiling( 1);
126 
129 
130  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocface, "RFC");
132  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocmap, "MAP");
133 
134  string fnames[2] = {string(argv[1]), string(argv[2])};
135  const string wnames[2] = {string("solid"), string("fluid")};
136 
137  for ( int k=0; k<2; ++k) {
138  read_file( fnames[k].c_str(), wnames[k], 1.);
139 
140  COM_new_attribute( (wnames[k]+".flux").c_str(), 'e', COM_DOUBLE, 3, "m/s");
141  COM_new_attribute( (wnames[k]+".velo").c_str(), 'n', COM_DOUBLE, 3, "m/s");
142 
143  COM_resize_array( (wnames[k]+".atts").c_str());
144  COM_window_init_done( wnames[k].c_str());
145  }
146 
147  int w1_mesh = COM_get_attribute_handle( (wnames[0]+".mesh").c_str());
148  int w2_mesh = COM_get_attribute_handle( (wnames[1]+".mesh").c_str());
149 
150  int RFC_read = COM_get_function_handle( "RFC.read_overlay");
151  MPI_Comm comm=MPI_COMM_WORLD;
152  COM_call_function( RFC_read, &w1_mesh, &w2_mesh, &comm);
153 
154  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
155 
156  int BLAS_copy_scalar = COM_get_function_handle( "BLAS.copy_scalar");
157  int w1_nc = COM_get_attribute_handle( (wnames[0]+".nc").c_str());
158  int w1_flux = COM_get_attribute_handle( (wnames[0]+".flux").c_str());
159  int w1_velo = COM_get_attribute_handle( (wnames[0]+".velo").c_str());
160 
161  int w2_nc = COM_get_attribute_handle( (wnames[1]+".nc").c_str());
162  int w2_flux = COM_get_attribute_handle( (wnames[1]+".flux").c_str());
163  int w2_velo = COM_get_attribute_handle( (wnames[1]+".velo").c_str());
164 
165  double zero=0.0;
166  double dt = 1.e-5;
167  char buf[10];
168 
169  int initial = 0;
170  if ( argc>2) {
171  initial = atoi(argv[2]);
172  if (initial<0) initial = 0;
173  }
174  std::sprintf( buf, "%05d", initial);
175 
176  int MAP_compute_face_normals =
177  COM_get_function_handle( "MAP.compute_element_normals");
178  int MAP_compute_nodal_normals =
179  COM_get_function_handle( "MAP.compute_nodal_normals");
180 
181  if (initial == 0) {
182  int MAP_init = COM_get_function_handle( "MAP.initialize");
183  COM_call_function( MAP_init, &w1_nc, &comm);
184  COM_call_function( MAP_compute_face_normals, &w1_flux);
185  COM_call_function( BLAS_copy_scalar, &zero, &w2_flux);
186 
187  COM_call_function( MAP_compute_nodal_normals, &w1_velo);
188  COM_call_function( BLAS_copy_scalar, &zero, &w2_velo);
189 
190  COM_call_function( OUT_write, (wnames[0]+buf).c_str(),
191  &w1_flux, wnames[0].c_str(), buf);
192  COM_call_function( OUT_write, (wnames[1]+buf).c_str(),
193  &w2_flux, wnames[1].c_str(), buf);
194  }
195  else {
196  int IN_read = COM_get_function_handle( "IN.read_window");
197  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
198 
199  COM_call_function( IN_read, (wnames[0]+buf).c_str(),
200  &w1_flux, wnames[0].c_str(), buf);
201  COM_call_function( IN_obtain, &w1_mesh, &w1_mesh);
202  COM_call_function( IN_obtain, &w1_flux, &w1_flux);
203 
204  COM_call_function( IN_read, (wnames[1]+buf).c_str(),
205  &w2_flux, wnames[1].c_str(), buf);
206  COM_call_function( IN_obtain, &w2_mesh, &w2_mesh);
207  COM_call_function( IN_obtain, &w2_flux, &w2_flux);
208  }
209 
210  int RFC_transfer = COM_get_function_handle( "RFC.least_squares_transfer");
211  int RFC_interpolate = COM_get_function_handle( "RFC.interpolate");
212  COM_set_profiling_barrier( RFC_transfer, comm);
213  COM_set_profiling_barrier( RFC_interpolate, comm);
214  COM_call_function( RFC_transfer, &w1_flux, &w2_flux);
215  COM_call_function( RFC_transfer, &w2_flux, &w1_flux);
216  COM_set_profiling( 1);
217 
218  for ( int i=initial; i<1; ++i) {
219  COM_call_function( MAP_compute_face_normals, &w1_flux);
220  COM_call_function( BLAS_copy_scalar, &zero, &w2_flux);
221 
222  COM_call_function( RFC_transfer, &w1_flux, &w2_flux);
223  COM_call_function( RFC_transfer, &w2_flux, &w1_flux);
224  COM_call_function( RFC_interpolate, &w1_velo, &w2_velo);
225  COM_call_function( RFC_interpolate, &w2_velo, &w1_velo);
226  COM_call_function( RFC_transfer, &w1_velo, &w2_velo);
227  COM_call_function( RFC_transfer, &w2_velo, &w1_velo);
228 
229  int BLAS_axpy_scalar = COM_get_function_handle( "BLAS.axpy_scalar");
230  COM_call_function( BLAS_axpy_scalar, &dt, &w1_velo, &w1_nc, &w1_nc);
231  COM_call_function( BLAS_axpy_scalar, &dt, &w2_velo, &w2_nc, &w2_nc);
232 
233  // if ( i%1000 == 999) {
234  if ( false) {
235  std::sprintf( buf, "%05d", i+1);
236  COM_call_function( OUT_write, (wnames[0]+buf).c_str(),
237  &w1_flux, wnames[0].c_str(), buf);
238  COM_call_function( OUT_write, (wnames[1]+buf).c_str(),
239  &w2_flux, wnames[1].c_str(), buf);
240  }
241  }
242 
243  COM_print_profile( "", "");
244 
245  COM_finalize();
246 }
247 
248 
249 
250 
251 
252 
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
j indices k indices k
Definition: Indexing.h:6
void read_file(const char *fname, const string &wname, double alpha)
Definition: autosurfer.C:39
This file contains the prototypes for Roccom API.
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
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
blockLoc i
Definition: read.cpp:79
void COM_set_profiling_barrier(int hdl, MPI_Comm comm)
Definition: roccom_c++.h:554
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_delete_pane(const char *str, int pid)
Definition: roccom_c++.h:110
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
#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
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116