Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
project_test.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 #include "Rocin.h"
24 #include "roccom.h"
25 
26 #include <fstream>
27 #include <iomanip>
28 #include <iostream>
29 #include <sstream>
30 #include <string>
31 #include "SurfaceProjection.h"
32 #include "Roccom_base.h"
33 
34 using namespace std;
36 
37 void project_window(const std::string& wName, const std::string& timeStr,
38  const std::string& file_in)
39 {
40  Vec3D p,q;
41  double dist;
42  double total_dist =0;
43  double total_nodes =0;
44 
45  // Obtain the list of panes
46  Window * w = COM_get_roccom()->get_window_object(wName.c_str());
47  vector<Pane*> ps;
48  unsigned int pass =0;
49  Pane * pn = NULL;
50  double * nc;
51  int nPanes;
52  int* paneIds;
53 
54  COM_get_panes(wName.c_str(), &nPanes, &paneIds);
55  w->panes(ps);
56  cerr <<"Window " << wName << " has " << nPanes << " panes." << endl;
57 
58 
59  for (unsigned int i=0; i<ps.size(); ++i)
60  {
61  pn = ps[i];
62  nc = pn->coordinates();
63  unsigned int n = pn->size_of_real_nodes();
64  total_nodes+=n;
65  SurfaceProjector_Pane sp(pn);
66 
67  cout << "PANE " << i
68  <<" projecting " << pn->size_of_real_nodes() << " nodes."
69  << endl;
70 
71  //loop through pane nodes
72  for(unsigned int j=0;j < pn->size_of_real_nodes();j++)
73  {
74  p[0] = nc[j];
75  p[1] = nc[j+ n];
76  p[2] = nc[j+2*n];
77 
78 
79  //project to surface
80 
81  dist = sp.project_point(p,q);
82  if( dist != 0)
83  {
84  total_dist+=dist;
85  }
86  else
87  pass++;
88 
89  }
90  }
91  cerr << "RESULTS: " << pass << " of " << pn->size_of_real_nodes()
92  <<" points projected to themselves, average error = " << total_dist/total_nodes << endl;
93 
94  COM_free_buffer(&paneIds);
95 }
96 
97 int main(int argc, char* argv[])
98 {
99  COM_init(&argc, &argv);
100 
101  if (argc != 2)
102  {
103  std::cerr << "Usage:project_test <hdf file>" << std::endl;
104  return 1;
105  }
106 
108 
109  int IN_obtain = COM_get_function_handle("IN.obtain_attribute");
110 
111  COM_set_verbose(0);
113 
114  std::string file_in(argv[1]);
115  std::string win_in(file_in);
116  std::string::size_type st = win_in.find_last_of('/');
117  if (st != std::string::npos)
118  win_in.erase(0, st+1);
119  st = win_in.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
120  if (st != std::string::npos)
121  win_in.erase(st);
122 
123  int len = 15;
124  char timeStr[16] = "";
125 
126 
127  std::cout << "Reading HDF file(s) " << file_in
128  << " into window " << win_in << std::endl;
129 
130  int IN_read = COM_get_function_handle("IN.read_window");
131  COM_call_function(IN_read, file_in.c_str(), win_in.c_str(), NULL, NULL,
132  timeStr, &len);
133 
134  cerr << "Finished reading HDF file into window\n";
135  int IN_all = COM_get_attribute_handle((win_in + ".all").c_str());
136  COM_call_function(IN_obtain, &IN_all, &IN_all);
137 
138  std::cout << "Projecting surface mesh to itself" << std::endl;
139  project_window(win_in, timeStr, file_in);
140  std::cout << "Done" << std::endl;
141 
142  COM_finalize();
143  return 0;
144 }
145 
146 
147 
148 
149 
150 
This file contains the prototypes for Roccom API.
NVec< 3, double > Vec3D
void COM_set_verbose(int i)
Definition: roccom_c++.h:543
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
void COM_finalize()
Definition: roccom_c++.h:59
Definition: Rocin.h:64
blockLoc i
Definition: read.cpp:79
const NT & n
void project_window(const std::string &wName, const std::string &timeStr, const std::string &file_in)
Definition: project_test.C:37
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
Rocin creates a series of Roccom windows by reading in a list of files.
int main(int argc, char *argv[])
Definition: blastest.C:94
j indices j
Definition: Indexing.h:6
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
NT q
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
long double dist(long double *coord1, long double *coord2, int size)
COM_END_NAME_SPACE COM::Roccom_base * COM_get_roccom()
Definition: Roccom_base.h:537
#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
Contains declaration of the base class for Roccom implementations.
std::vector< int > paneIds
Array of paneIds.
Definition: hdf2pltV2.C:60