Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
addpconn.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: addpconn.C,v 1.6 2009/01/22 23:56:54 gzagaris Exp $
24 
25 #include <iostream>
26 #include <cstring>
27 #include <cstdlib>
28 #include "roccom.h"
29 #include "mapbasic.h"
30 
33 COM_EXTERN_MODULE( Rocmap);
34 
35 using namespace std;
36 
37 int main(int argc, char *argv[]) {
38  COM_init( &argc, &argv);
39 
40  if ( argc < 3) {
41  std::cout << "Add pane connectivity to a given mesh." << std::endl;
42  std::cout << "Usage:\n\tTo run in serial: " << argv[0]
43  << " <input filename patterns or Rocin control file> <output file prefix> " << endl;
44  std::cout << "\n\tTo run in parallel: <mpirun-command> " << argv[0]
45  << " -com-mpi <Rocin control file> <output file prefix> " << endl;
46  std::cout << "If the second argument does not end with .hdf, then each pane is written into a separate file." << std::endl;
47  exit(-1);
48  }
49 
50  std::cout << "Reading mesh file \"" << argv[1] << '"' << endl;
51 
52  std::string fname(argv[1]), wname;
53  string::size_type n0 = fname.find_last_of( "/");
54 
55  if ( n0 != std::string::npos)
56  fname = fname.substr( n0+1, fname.size());
57 
58  string::size_type ni;
59  ni = fname.find_first_of( ".:-*[]?\\\"\'0123456789");
60  COM_assertion_msg(ni, "File name must start with a letter");
61 
62  if ( ni == std::string::npos) {
63  wname = fname;
64  }
65  else {
66  while (fname[ni-1]=='_') --ni; // Remove the '_' at the end.
67  wname = fname.substr( 0, ni);
68  }
69 
70  std::cout << "Creating window \"" << wname << '"' << endl;
71 
72  // Read in HDF format
74  std::cout << "Reading window " << endl;
75 
76  const char *lastdot=std::strrchr( argv[1], '.');
77  int IN_read;
78  if ( lastdot && std::strcmp( lastdot, ".txt")==0)
79  IN_read = COM_get_function_handle( "IN.read_by_control_file");
80  else
81  IN_read = COM_get_function_handle( "IN.read_window");
82 
83  COM_call_function( IN_read, argv[1], wname.c_str());
84 
85  int IN_obtain = COM_get_function_handle( "IN.obtain_attribute");
86  int mesh_hdl = COM_get_attribute_handle((wname+".mesh").c_str());
87  std::cout << "Obtaining the mesh " << endl;
88  COM_call_function( IN_obtain, &mesh_hdl, &mesh_hdl);
89 
90  // Change the memory layout to contiguous.
91  std::cout << "Resizing the array " << endl;
92  COM_resize_array( (wname+".mesh").c_str(), 0, NULL, 0);
93  // Delete all attributes and leave alone the mesh.
94  std::cout << "deleting the attribute" << endl;
95  COM_delete_attribute( (wname+".atts").c_str());
96 
97  int npanes; COM_get_panes( wname.c_str(), &npanes, NULL);
98 
99  COM_assertion( npanes>=0);
100 
101  std::cout << "finishing up window initialization" << endl;
102  COM_window_init_done( wname.c_str());
103 
104  std::cout << "Computing connectivity map... " << endl;
105 
106  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocmap, "MAP");
107  // Invoke compute_pconn to obtain pane connectivity.
108  int MAP_compute_pconn = COM_get_function_handle( "MAP.compute_pconn");
109  const string pconn = wname+".pconn";
110  int pconn_hdl = COM_get_attribute_handle( pconn.c_str());
111  COM_call_function( MAP_compute_pconn, &mesh_hdl, &pconn_hdl);
112 
113  std::cout << "Output window into file..." << endl;
114 
115  std::cout << "loading Rocout" << endl;
117 
118  // Output pconn
119  int OUT_set = COM_get_function_handle( "OUT.set_option");
120  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
121 
122  COM_call_function( OUT_set, "mode", "w");
123  COM_call_function( OUT_set, "rankwidth", "0");
124  COM_call_function( OUT_set, "pnidwidth", "6");
125 
126  int all_hdl = COM_get_attribute_handle( (wname+".all").c_str());
127  COM_call_function( OUT_write, argv[2], &all_hdl,
128  (char*)wname.c_str(), "000");
129 
130  COM_finalize();
131 }
132 
133 
134 
135 
136 
137 
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
#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
void COM_finalize()
Definition: roccom_c++.h:59
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_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
void COM_get_panes(const char *wname, std::vector< int > &pane_ids, int rank=-2)
Definition: roccom_c++.h:350
#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