Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
imtest.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: imtest.C,v 1.6 2008/12/06 08:43:24 mtcampbe Exp $
24 
25 #include "roccom.h"
26 #include "surfbasic.h"
27 #include "IM_Reader.h"
28 #include <iostream>
29 
30 using namespace std;
31 
33 COM_EXTERN_MODULE( Rocsurf);
35 
36 int main(int argc, char *argv[]) {
37  COM_init( &argc, &argv);
38 
39  if ( argc != 3) {
40  std::cout << "Usage:\n\tTo run in serial: " << argv[0]
41  << " <surffile> <hdffile> " << endl;
42  std::cout << "\n\tTo run in parallel: <mpirun-command> " << argv[0]
43  << " -com-mpi <Rocin control file> <hdfoutput-prefix> " << endl;
44  exit(-1);
45  }
46 
47  std::cout << "Reading surface mesh file \"" << argv[1] << '"' << endl;
48 
49  std::string fname(argv[1]), wname;
50  string::size_type n0 = fname.find_last_of( "/");
51 
52  if ( n0 != std::string::npos)
53  fname = fname.substr( n0+1, fname.size());
54 
55  string::size_type ni;
56  ni = fname.find_first_of( ".:-*[]?\\\"\'0123456789");
57  COM_assertion_msg(ni, "File name must start with a letter");
58 
59  if ( ni == std::string::npos) {
60  wname = fname;
61  }
62  else {
63  while (fname[ni-1]=='_') --ni; // Remove the '_' at the end.
64  wname = fname.substr( 0, ni);
65  }
66 
67  std::cout << "Creating window \"" << wname << '"' << endl;
68 
69  // Read in IM/HDF format
70  int err = IM_Reader().read_winmesh( argv[1], wname);
71  COM_assertion( err>=0);
72 
73  // Allocate memory for normals
74  const string nrmls = wname+".normals";
75  COM_new_attribute(nrmls.c_str(), 'n', COM_DOUBLE, 3, "");
76  COM_resize_array( nrmls.c_str());
77 
78  // Allocate an element and a nodal attribute for testing elements_to_nodes
79  const string eval = wname+".eval";
80  COM_new_attribute(eval.c_str(), 'e', COM_DOUBLE, 1, "m");
81  COM_resize_array( eval.c_str());
82 
83  const string nval = wname+".nval";
84  COM_new_attribute(nval.c_str(), 'n', COM_DOUBLE, 1, "m");
85  COM_resize_array( nval.c_str());
86 
87  // Allocate memory for two window attributes
88  int *vs_int;
89  const string win1 = wname+".win1";
90  COM_new_attribute( win1.c_str(), 'w', COM_INT, 1, "");
91  COM_set_size( win1.c_str(), 0, 1);
92  COM_resize_array( win1.c_str(), 0, &(void*&)vs_int);
93  vs_int[0] = 1;
94 
95  double *vs_dbl;
96  const string win2 = wname+".win2";
97  COM_new_attribute( win2.c_str(), 'w', COM_DOUBLE, 3, "m");
98  COM_set_size( win2.c_str(), 0, 1);
99  COM_resize_array( win2.c_str(), 0, &(void*&)vs_dbl);
100  vs_dbl[0] = 1; vs_dbl[1] = 2; vs_dbl[2] = 3;
101 
102  const string rks = wname+".franks";
103  COM_new_attribute( rks.c_str(), 'n', COM_INT, 1, "");
104  COM_resize_array( rks.c_str(), 0);
105 
106  COM_window_init_done( wname.c_str());
107  int pmesh_hdl = COM_get_attribute_handle( (wname+".pmesh").c_str());
108 
110  COM_LOAD_MODULE_STATIC_DYNAMIC( Rocsurf, "SURF");
111 
112  int SURF_init = COM_get_function_handle( "SURF.initialize");
113  COM_call_function( SURF_init, &pmesh_hdl);
114 
115  cout << "Testing feature detection..." << endl;
116  int SURF_detect = COM_get_function_handle( "SURF.detect_features");
117  COM_call_function( SURF_detect, &pmesh_hdl);
118 
119  int SURF_export = COM_get_function_handle( "SURF.export_franks");
120  int franks = COM_get_attribute_handle( (wname+".franks").c_str());
121  COM_call_function( SURF_export, &franks);
122 
123  cout << "Testing elements-to-nodes..." << endl;
124 
126  int copy_scalar = COM_get_function_handle( "BLAS.copy_scalar");
127  int eval_hdl = COM_get_attribute_handle( eval.c_str());
128  double one=1;
129  COM_call_function( copy_scalar, &one, &eval_hdl);
130 
131  int SURF_e2n = COM_get_function_handle( "SURF.elements_to_nodes");
132  int nval_hdl = COM_get_attribute_handle( nval.c_str());
133  const int *scheme; COM_get_array_const( "SURF.E2N_ONE", 0, &scheme);
134  COM_call_function( SURF_e2n, &eval_hdl, &nval_hdl, &pmesh_hdl, scheme);
135 
136  std::cout << "Computing normals..." << endl;
137 
138  int SURF_normal = COM_get_function_handle( "SURF.compute_normals");
139  int nrmls_hdl = COM_get_attribute_handle( nrmls.c_str());
140 
141  COM_call_function( SURF_normal, &pmesh_hdl, &nrmls_hdl);
142 
143  std::cout << "Output window into file..." << endl;
144 
145  // Output normals
146  int OUT_set = COM_get_function_handle( "OUT.set_option");
147  int OUT_write = COM_get_function_handle( "OUT.write_attribute");
148 
149  COM_call_function( OUT_set, "mode", "w");
150  int all_hdl = COM_get_attribute_handle( (wname+".all").c_str());
151  COM_call_function( OUT_write, argv[2], &all_hdl,
152  (char*)wname.c_str(), "000");
153 
154  // Output new normals
155  COM_call_function( OUT_set, "mode", "a");
156  COM_call_function( SURF_normal, &pmesh_hdl, &nrmls_hdl);
157  COM_call_function( OUT_write, argv[2], &all_hdl,
158  (char*)wname.c_str(), "001");
159 
160  COM_finalize();
161 }
162 
163 
164 
165 
166 
167 
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
#define COM_assertion_msg(EX, msg)
double eval(const char *const expression, const double x=0, const double y=0, const double z=0, const double v=0)
Evaluate math expression.
Definition: CImg.h:37338
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
This file contains the prototypes for Roccom API.
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
static const int scheme
void COM_finalize()
Definition: roccom_c++.h:59
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_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
int read_winmesh(const char *fname, const std::string &wname, bool del=true)
Definition: IM_Reader.h:58
#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