Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
compare_normals.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: compare_normals.C,v 1.8 2008/12/06 08:45:28 mtcampbe Exp $
24 
25 #include "roccom.h"
26 
27 #include <cstdio>
28 #include <iostream>
29 #include <fstream>
30 #include <algorithm>
31 #include <cstring>
32 #include <string>
33 #include <cstdlib>
34 #include <cmath>
35 #include <cassert>
36 #include <sstream>
37 #include "roccom_assertion.h"
38 
39 #include "../Rocsurf/test/IM_Reader.h"
40 
41 using namespace std;
42 
43 typedef MAP::Vector_3<double> Vector_3;
44 
46 COM_EXTERN_MODULE( Rocmap);
50 
51 void load_modules() {
53  COM_LOAD_MODULE_STATIC_DYNAMIC(Rocmap, "MAP");
57 }
58 
59 static int rank = 0;
60 
61 void print_usage( int argc, char *argv[]) {
62  if ( argc <= 2) {
63  cout << "Usage: " << argv[0] << " <surffile> <controlfile>" << std::endl;
64 
65  exit(-1);
66  }
67 }
68 
69 struct Control_parameter {
70  Control_parameter() : perturb(0), speed(0), sploc('n'), timestep(0),
71  steps(0), interval(0), func(1) {}
72  string method;
73  string wavefrontal;
74  string normaldif;
75  string eigthres;
76  string courant;
77  string fangle;
78  double perturb;
79  double speed;
80  char sploc;
81  double timestep;
82  int steps;
83  int interval;
84 
85  int func;
86  string verbose;
87 };
88 
89 void read_control_file( const char *fname, Control_parameter &cp) {
90  /* Sample control file:
91  * method: fo # method: fo and mp
92  * wavefrontal: 1 # wavefrontal condition
93  * normaldif: 1 # normal diffusion
94  * eigthres: 1.e-4 # threshold for null space: 0..1 (1.e-4 default)
95  * courant: 0.5 # courant constant
96  * fangle: 35 # feature edge angle: between 0 and 180
97  * speed: 0.1 # Speed
98  * sploc: e # location of speed: n or e
99  * timestep: 0.001 # time step
100  * steps: 100 # number of time steps
101  * interval: 10 # output intervals
102  * function: 1 # function
103  * verbose: 1 # verbose level
104  */
105  ifstream is(fname); COM_assertion_msg( is, "File does not exist");
106 
107  while ( !is.eof()) {
108  char buf[255];
109  is.get( buf, 255, ':');
110  if ( buf[0] == '\0') { is.getline( buf, 255); continue; }
111 
112  istringstream istr(buf);
113  string keyword; istr >> keyword;
114  is.getline( buf, 255, ':');
115 
116  if ( keyword == "method")
117  is >> cp.method;
118  else if ( keyword == "wavefrontal")
119  is >> cp.wavefrontal;
120  else if ( keyword == "normaldif")
121  is >> cp.normaldif;
122  else if ( keyword == "eigthres")
123  is >> cp.eigthres;
124  else if ( keyword == "courant")
125  is >> cp.courant;
126  else if ( keyword == "fangle")
127  is >> cp.fangle;
128  else if ( keyword == "perturb")
129  is >> cp.perturb;
130  else if ( keyword == "speed")
131  is >> cp.speed;
132  else if ( keyword == "sploc")
133  is >> cp.sploc;
134  else if ( keyword == "timestep")
135  is >> cp.timestep;
136  else if ( keyword == "steps")
137  is >> cp.steps;
138  else if ( keyword == "interval")
139  is >> cp.interval;
140  else if ( keyword == "function")
141  is >> cp.func;
142  else if ( keyword == "verbose")
143  is >> cp.verbose;
144  else
145  std::cerr << "Unknow keyword " << keyword << std::endl;
146  is.getline( buf, 255);
147  }
148 
149  if ( rank==0) std::cout << " speed is " << cp.speed << std::endl;
150 }
151 
152 void init_parameters( const Control_parameter &cntr_param) {
153  int PROP_set_option = COM_get_function_handle( "PROP.set_option");
154 
155  if ( !cntr_param.method.empty()) {
156  COM_call_function( PROP_set_option, "method", cntr_param.method.c_str());
157 
158  if ( rank==0) std::cout << "Set propagation method to " << cntr_param.method << std::endl;
159  }
160 
161  if ( !cntr_param.wavefrontal.empty()) {
162  COM_call_function( PROP_set_option, "wavefrontal", cntr_param.wavefrontal.c_str());
163  if ( rank==0) std::cout << "Set wavefrontal to " << cntr_param.wavefrontal << std::endl;
164  }
165 
166  if ( !cntr_param.normaldif.empty()) {
167  COM_call_function( PROP_set_option, "normaldif", cntr_param.normaldif.c_str());
168  if ( rank==0) std::cout << "Set normaldif to " << cntr_param.normaldif << std::endl;
169  }
170 
171  if ( !cntr_param.eigthres.empty()) {
172  COM_call_function( PROP_set_option, "eigthres", cntr_param.eigthres.c_str());
173  if ( rank==0) std::cout << "Set eigthres to " << cntr_param.eigthres << std::endl;
174  }
175 
176  if ( !cntr_param.courant.empty()) {
177  COM_call_function( PROP_set_option, "courant", cntr_param.courant.c_str());
178  if ( rank==0) std::cout << "Set courant constant to " << cntr_param.courant << std::endl;
179  }
180 
181  if ( !cntr_param.fangle.empty()) {
182  COM_call_function( PROP_set_option, "fangle", cntr_param.fangle.c_str());
183  if ( rank==0) std::cout << "Set feature angle to " << cntr_param.fangle << std::endl;
184  }
185 
186  if ( !cntr_param.verbose.empty()) {
187  COM_call_function( PROP_set_option, "verbose", cntr_param.verbose.c_str());
188 
189  if ( rank==0) std::cout << "Set verbose level to " << cntr_param.verbose << std::endl;
190  }
191 
192 }
193 
194 // Read in a surface pmesh, and return its window name.
195 std::string read_in_mesh ( const char *fname) {
196  if ( rank==0) cout << "Reading surface mesh file \"" << fname << '"' << endl;
197 
198  std::string fname_str(fname);
199 
200  std::string::size_type pos = fname_str.find_first_of( ".");
201  const string wname = fname_str.substr( 0, pos);
202 
203  if ( rank==0) cout << "Creating window \"" << wname << '"' << endl;
204 
205  IM_Reader im_reader;
206  int npanes = im_reader.read_winmesh( fname, wname);
207  COM_assertion_msg( npanes>=0, "Failed to read in mesh file. File empty?");
208 
209  return wname;
210 }
211 
212 void init_attributes( const string &wname) {
213  COM_new_attribute((wname+".facenormals").c_str(), 'e', COM_DOUBLE, 3, "");
214  COM_new_attribute((wname+".facecenters").c_str(), 'e', COM_DOUBLE, 3, "");
215  COM_new_attribute((wname+".fnormals_ana").c_str(), 'e', COM_DOUBLE, 3, "");
216  COM_new_attribute((wname+".fnormals_cr").c_str(), 'e', COM_DOUBLE, 3, "");
217  COM_new_attribute((wname+".ferrs").c_str(), 'e', COM_DOUBLE, 1, "");
218  COM_new_attribute((wname+".verrs").c_str(), 'n', COM_DOUBLE, 1, "");
219 
220  COM_new_attribute((wname+".vnormals_ana").c_str(), 'n', COM_DOUBLE, 3, "");
221  COM_new_attribute((wname+".vnormals_nw").c_str(), 'n', COM_DOUBLE, 3, "");
222  COM_new_attribute((wname+".vnormals_area").c_str(), 'n', COM_DOUBLE, 3, "");
223  COM_new_attribute((wname+".vnormals_angle").c_str(), 'n', COM_DOUBLE, 3, "");
224  COM_new_attribute((wname+".vnormals_sphere").c_str(), 'n', COM_DOUBLE, 3, "");
225 
226  COM_new_attribute((wname+".vnormals_eig").c_str(), 'n', COM_DOUBLE, 3, "");
227  COM_new_attribute((wname+".vnormals_mq").c_str(), 'n', COM_DOUBLE, 3, "");
228 
229  // Attribute for storing the number of eigenvalues for each node.
230  COM_new_attribute((wname+".lambdas").c_str(), 'n', COM_DOUBLE, 3, "");
231  COM_new_attribute((wname+".eigvecs").c_str(), 'n', COM_DOUBLE, 9, "");
232  COM_new_attribute((wname+".tangranks").c_str(), 'n', COM_CHAR, 1, "");
233  COM_new_attribute((wname+".scales").c_str(), 'n', COM_DOUBLE, 1, "");
234 
235  COM_new_attribute((wname+".spds").c_str(), 'e', COM_DOUBLE, 1, "m/s");
236  COM_new_attribute((wname+".disps").c_str(), 'n', COM_DOUBLE, 3, "m");
237 
238  COM_resize_array( (wname+".atts").c_str());
239  COM_window_init_done( wname.c_str());
240 }
241 
242 void func1( Vector_3 &pnt, Vector_3 &nrm) {
243  // z=sqrt(2-x^2-y^2)
244  pnt[2] = std::sqrt(2-pnt[0]*pnt[0] - pnt[1]*pnt[1]);
245  if ( pnt[2]==0)
246  nrm = Vector_3( -pnt[0], -pnt[1], 0);
247  else
248  nrm = Vector_3::cross_product( Vector_3(0, 1, -pnt[1]/pnt[2]),
249  Vector_3(1, 0, -pnt[0]/pnt[2]));
250  nrm.normalize();
251 }
252 
253 const double pi = 3.14159265358979;
254 
255 void func2( Vector_3 &pnt, Vector_3 &nrm) {
256  // z = x^2 + 0.25*sin( 2pi*y)
257  pnt[2] = pnt[0]*pnt[0] + 0.25*std::sin(2*pi*pnt[1]);
258  nrm = Vector_3::cross_product( Vector_3(0, 1, 0.5*pi*std::cos(2*pi*pnt[1])),
259  Vector_3(1, 0, 2*pnt[0]));
260  nrm.normalize();
261 }
262 
263 void func3( Vector_3 &pnt, Vector_3 &nrm) {
264  // z = 0.25*sin( pi*x) + 0.25*cos( pi*y)
265  pnt[2] = 0.25*(std::sin(pi*pnt[0]) + std::cos(pi*pnt[1]));
266  nrm = Vector_3::cross_product( Vector_3(0, 1, -0.25*pi*std::sin(pi*pnt[1])),
267  Vector_3(1, 0, 0.25*pi*std::cos(pi*pnt[0])));
268  nrm.normalize();
269 }
270 
271 void init_normals( const string &wname, int func) {
272  int *pane_ids, npanes;
273  COM_get_panes( wname.c_str(), &npanes, &pane_ids);
274 
275  // Compute vertex normals
276  for ( int i=0; i<npanes; ++i) {
277  int stride, nn;
278  Vector_3 *coors, *nrms;
279  COM_get_array( (wname+".nc").c_str(), pane_ids[i],
280  &(void*&)coors, &stride, &nn);
281  COM_get_array( (wname+".vnormals_ana").c_str(), pane_ids[i], &(void*&)nrms);
282 
283  for ( int j=0; j<nn; ++j) {
284  switch (func) {
285  case 1: { func1( coors[j], nrms[j]); break; }
286  case 2: { func2( coors[j], nrms[j]); break; }
287  case 3: { func3( coors[j], nrms[j]); break; }
288  }
289  }
290  }
291 
292  // Interpolate coordinates to face centers
293  int SURF_n2f = COM_get_function_handle( "SURF.interpolate_to_centers");
294  int nc = COM_get_attribute_handle( (wname+".nc").c_str());
295  int cnts = COM_get_attribute_handle( (wname+".facecenters").c_str());
296  COM_call_function( SURF_n2f, &nc, &cnts);
297 
298  // Compute face normals
299  for ( int i=0; i<npanes; ++i) {
300  int stride, ne;
301  Vector_3 *coors, *nrms;
302  COM_get_array( (wname+".facecenters").c_str(), pane_ids[i],
303  &(void*&)coors, &stride, &ne);
304  COM_get_array( (wname+".fnormals_ana").c_str(), pane_ids[i], &(void*&)nrms);
305 
306  for ( int j=0; j<ne; ++j) {
307  switch (func) {
308  case 1: { func1( coors[j], nrms[j]); break; }
309  case 2: { func2( coors[j], nrms[j]); break; }
310  case 3: { func3( coors[j], nrms[j]); break; }
311  }
312  }
313  }
314 
315  COM_free_buffer( &pane_ids);
316 }
317 
318 // RMS and L-inf error in face normals
319 std::pair<double,double>
320 compute_fnormal_error( const int ref_nrms_hdl,
321  const int cur_nrms_hdl,
322  const int buf_hdl, const char *scheme=NULL) {
323  static int SURF_normals=0, SURF_integrate=0, SURF_comparea=0;
324  static int BLAS_dot=0, BLAS_mul_scalar=0, BLAS_sub_scalar=0;
325  static int BLAS_sum_scalar_MPI=0, BLAS_max_scalar_MPI=0;
326 
327  if ( SURF_normals==0) { // Load the functions
328  SURF_normals = COM_get_function_handle( "SURF.compute_element_normals");
329  SURF_integrate = COM_get_function_handle( "SURF.integrate");
330  SURF_comparea = COM_get_function_handle( "SURF.compute_element_areas");
331 
332  BLAS_dot = COM_get_function_handle( "BLAS.dot");
333  BLAS_mul_scalar = COM_get_function_handle( "BLAS.mul_scalar");
334  BLAS_sub_scalar = COM_get_function_handle( "BLAS.sub_scalar");
335  BLAS_sum_scalar_MPI = COM_get_function_handle( "BLAS.sum_scalar_MPI");
336  BLAS_max_scalar_MPI = COM_get_function_handle( "BLAS.max_scalar_MPI");
337  }
338 
339  // If two arguments are the same, then initialize ref_nrms
340  if ( ref_nrms_hdl == cur_nrms_hdl) {
341  COM_call_function( SURF_normals, &ref_nrms_hdl);
342  return std::pair<double,double>(0.,0.);
343  }
344  else {
345  MPI_Comm comm = MPI_COMM_WORLD;
346 
347  // Compute root-mean-square as \sqrt(\int_{2-ref_nrms*cur_nrm))
348  double err_rms, err_max, area, minus_two=-2;
349  // Compute area
350  COM_call_function( SURF_comparea, &buf_hdl);
351  COM_call_function( BLAS_sum_scalar_MPI, &buf_hdl, &area, &comm);
352 
353  COM_call_function( BLAS_dot, &cur_nrms_hdl, &ref_nrms_hdl, &buf_hdl);
354  COM_call_function( BLAS_mul_scalar, &buf_hdl, &minus_two, &buf_hdl);
355  COM_call_function( BLAS_sub_scalar, &buf_hdl, &minus_two, &buf_hdl);
356 
357  COM_call_function( BLAS_max_scalar_MPI, &buf_hdl, &err_max, &comm);
358  COM_call_function( SURF_integrate, &buf_hdl, &err_rms);
359 
360  std::pair<double,double> errs(err_rms/area, err_max);
361  if ( scheme) {
362  std::cout << "Root-mean-square error in " << scheme
363  << " is " << std::sqrt(errs.first) << std::endl;
364  std::cout << "Max square-root of error in " << scheme
365  << " is " << std::sqrt(errs.second) << std::endl;
366  }
367  return errs;
368  }
369 }
370 
371 // RMS and L-inf error in vertex normals
372 std::pair<double,double>
373 compute_vnormal_error( const int ref_nrms_hdl,
374  const int cur_nrms_hdl,
375  const int vbuf_hdl,
376  const int fbuf_hdl, const char *scheme=NULL) {
377  static int SURF_normals=0, SURF_integrate=0, SURF_v2f=0, SURF_comparea=0;
378  static int BLAS_dot=0, BLAS_mul_scalar=0, BLAS_sub_scalar=0;
379  static int BLAS_sum_scalar_MPI=0, BLAS_max_scalar_MPI=0;
380 
381  if ( SURF_normals==0) { // Load the functions
382  SURF_normals = COM_get_function_handle( "SURF.compute_element_normals");
383  SURF_v2f = COM_get_function_handle( "SURF.interpolate_to_centers");
384  SURF_integrate = COM_get_function_handle( "SURF.integrate");
385  SURF_comparea = COM_get_function_handle( "SURF.compute_element_areas");
386 
387  BLAS_dot = COM_get_function_handle( "BLAS.dot");
388  BLAS_mul_scalar = COM_get_function_handle( "BLAS.mul_scalar");
389  BLAS_sub_scalar = COM_get_function_handle( "BLAS.sub_scalar");
390  BLAS_sum_scalar_MPI = COM_get_function_handle( "BLAS.sum_scalar_MPI");
391  BLAS_max_scalar_MPI = COM_get_function_handle( "BLAS.max_scalar_MPI");
392  }
393 
394  // If two arguments are the same, then initialize ref_nrms
395  if ( ref_nrms_hdl == cur_nrms_hdl) {
396  COM_call_function( SURF_normals, &ref_nrms_hdl);
397  return std::pair<double,double>(0.,0.);
398  }
399  else {
400  MPI_Comm comm = MPI_COMM_WORLD;
401 
402  // Compute root-mean-square as \sqrt(\int_{2-ref_nrms*cur_nrm))
403  double err_rms, err_max, area, minus_two=-2;
404  // Compute area
405  COM_call_function( SURF_comparea, &fbuf_hdl);
406  COM_call_function( BLAS_sum_scalar_MPI, &fbuf_hdl, &area, &comm);
407 
408  COM_call_function( BLAS_dot, &cur_nrms_hdl, &ref_nrms_hdl, &vbuf_hdl);
409  COM_call_function( BLAS_mul_scalar, &vbuf_hdl, &minus_two, &vbuf_hdl);
410  COM_call_function( BLAS_sub_scalar, &vbuf_hdl, &minus_two, &vbuf_hdl);
411 
412  COM_call_function( BLAS_max_scalar_MPI, &vbuf_hdl, &err_max, &comm);
413 
414  COM_call_function( SURF_v2f, &vbuf_hdl, &fbuf_hdl);
415  COM_call_function( SURF_integrate, &fbuf_hdl, &err_rms);
416 
417  std::pair<double,double> errs(err_rms/area, err_max);
418  if ( scheme) {
419  std::cout << "Root-mean-square error in " << scheme
420  << " is " << std::sqrt(errs.first) << std::endl;
421  std::cout << "Max square-root of error in " << scheme
422  << " is " << std::sqrt(errs.second) << std::endl;
423  }
424  return errs;
425  }
426 }
427 
428 // Compute weighted schemes
429 void compute_weighted_normals( const string &wname) {
430  int SURF_compnrm = COM_get_function_handle( "SURF.compute_normals");
431  int mesh_handle = COM_get_attribute_handle( (wname+".mesh").c_str());
432 
433  int nrm_ana = COM_get_attribute_handle( (wname+".vnormals_ana").c_str());
434  int vbuf_hdl = COM_get_attribute_handle( (wname+".verrs").c_str());
435  int fbuf_hdl = COM_get_attribute_handle( (wname+".ferrs").c_str());
436 
437  int scheme = SURF::E2N_ONE;
438  int nrm_nw = COM_get_attribute_handle( (wname+".vnormals_nw").c_str());
439  COM_call_function( SURF_compnrm, &mesh_handle, &nrm_nw, &scheme);
440 
441  compute_vnormal_error( nrm_ana, nrm_nw, vbuf_hdl, fbuf_hdl, "no-weight");
442 
443  scheme = SURF::E2N_AREA;
444  int nrm_area = COM_get_attribute_handle( (wname+".vnormals_area").c_str());
445  COM_call_function( SURF_compnrm, &mesh_handle, &nrm_area, &scheme);
446  compute_vnormal_error( nrm_ana, nrm_area, vbuf_hdl, fbuf_hdl, "area-weighted");
447 
448  scheme = SURF::E2N_ANGLE;
449  int nrm_angle = COM_get_attribute_handle( (wname+".vnormals_angle").c_str());
450  COM_call_function( SURF_compnrm, &mesh_handle, &nrm_angle, &scheme);
451  compute_vnormal_error( nrm_ana, nrm_angle, vbuf_hdl, fbuf_hdl, "angle-weighted");
452 
453  scheme = SURF::E2N_SPHERE;
454  int nrm_sphere = COM_get_attribute_handle( (wname+".vnormals_sphere").c_str());
455  COM_call_function( SURF_compnrm, &mesh_handle, &nrm_sphere, &scheme);
456  compute_vnormal_error( nrm_ana, nrm_sphere, vbuf_hdl, fbuf_hdl, "sphere-weighted");
457 }
458 
459 // Compute weighted schemes
460 void compute_quadric_normals( const string &wname) {
461  int PROP_set = COM_get_function_handle( "PROP.set_option");
462  int PROP_propagate = COM_get_function_handle( "PROP.propagate");
463  int BLAS_add = COM_get_function_handle( "BLAS.add");
464  int nc = COM_get_attribute_handle( (wname+".nc").c_str());
465  int pmesh = COM_get_attribute_handle( (wname+".pmesh").c_str());
466  int spds = COM_get_attribute_handle( (wname+".spds").c_str());
467  int disps = COM_get_attribute_handle( (wname+".disps").c_str());
468 
469  double timestep = 1.e-4;
470 
471  int nrm_ana = COM_get_attribute_handle( (wname+".vnormals_ana").c_str());
472  int vbuf_hdl = COM_get_attribute_handle( (wname+".verrs").c_str());
473  int fbuf_hdl = COM_get_attribute_handle( (wname+".ferrs").c_str());
474  int nrm_eig = COM_get_attribute_handle( (wname+".vnormals_eig").c_str());
475 
476  COM_call_function( PROP_set, "rediter", "0");
477 
478 #if 0
479  COM_call_function( PROP_set, "reorthog", "0");
480 
481  COM_call_function( PROP_set, "weight", "1");
482  COM_call_function( PROP_propagate, &pmesh, &spds, &timestep, &disps);
483  compute_vnormal_error( nrm_ana, nrm_eig, vbuf_hdl, fbuf_hdl, "eigen-noweight");
484 
485  COM_call_function( PROP_set, "weight", "2");
486  COM_call_function( PROP_propagate, &pmesh, &spds, &timestep, &disps);
487  compute_vnormal_error( nrm_ana, nrm_eig, vbuf_hdl, fbuf_hdl, "eigen-area");
488 
489  COM_call_function( PROP_set, "weight", "3");
490  COM_call_function( PROP_propagate, &pmesh, &spds, &timestep, &disps);
491  compute_vnormal_error( nrm_ana, nrm_eig, vbuf_hdl, fbuf_hdl, "eigen-angle");
492 
493  COM_call_function( PROP_set, "weight", "4");
494  COM_call_function( PROP_propagate, &pmesh, &spds, &timestep, &disps);
495  compute_vnormal_error( nrm_ana, nrm_eig, vbuf_hdl, fbuf_hdl, "eigen-sphere");
496 #endif
497 
498 #if 1
499  COM_call_function( PROP_set, "reorthog", "1");
500  COM_call_function( PROP_set, "weight", "3");
501  COM_call_function( PROP_propagate, &pmesh, &spds, &timestep, &disps);
502  COM_call_function( BLAS_add, &nc, &disps, &nc);
503 
504  compute_vnormal_error( nrm_ana, nrm_eig, vbuf_hdl, fbuf_hdl, "mq-angle");
505  int nrm_mq = COM_get_attribute_handle( (wname+".vnormals_mq").c_str());
506  int BLAS_copy = COM_get_function_handle( "BLAS.copy");
507  COM_call_function( BLAS_copy, &nrm_eig, &nrm_mq);
508 #endif
509 
510 // COM_call_function( PROP_set, "reorthog", "0");
511 // COM_call_function( PROP_set, "weight", "2");
512 // COM_call_function( PROP_propagate, &pmesh, &spds, &timestep, &disps);
513 // compute_vnormal_error( nrm_ana, nrm_eig, vbuf_hdl, fbuf_hdl, "eigen-area");
514 }
515 
516 void output_solution( const string &wname, const char *timelevel) {
517  static int OUT_write = 0, hdl;
518 
519  if ( OUT_write==0) {
520  OUT_write = COM_get_function_handle( "OUT.write_attribute");
521  hdl = COM_get_attribute_handle( (wname+".all").c_str());
522  }
523 
524  std::string fname = wname+"_"+timelevel;
525 
526  if ( !COMMPI_Initialized()) fname.append(".hdf");
527  else fname.append("_");
528 
529  COM_call_function( OUT_write, (char*)fname.c_str(),
530  &hdl, (char*)wname.c_str(), timelevel);
531 }
532 
533 int main(int argc, char *argv[]) {
534  COM_init( &argc, &argv);
535  load_modules();
536  print_usage( argc, argv);
537 
539 
540  // Read in mesh file.
541  string wname = read_in_mesh( argv[1]);
542 
543  // Read in control parameters
544  Control_parameter cntr_param;
545  read_control_file( argc>2?argv[2]:"control.txt", cntr_param);
546 
547  // Initialize the attributes
548  init_attributes( wname);
549  init_normals( wname, cntr_param.func);
550 
551  if ( cntr_param.perturb > 0) {
552  int PROP_perturb = COM_get_function_handle( "PROP.perturb_mesh");
553  int pmesh = COM_get_attribute_handle( (wname+".pmesh").c_str());
554  COM_call_function( PROP_perturb, &pmesh, &cntr_param.perturb);
555  }
556  output_solution( wname, "00000");
557 
558 // compute_weighted_normals( wname);
559 
560  // Initialize control parameters
561  init_parameters( cntr_param);
562  for ( int i=0; i<cntr_param.steps; ++i) {
563  char str[6];
565  std::sprintf( str, "%05d", i+1);
566  output_solution( wname, str);
567  }
568 
569  COM_print_profile( "", "Compute-normals");
570 
571  COM_finalize();
572 }
573 
574 
575 
576 
577 
578 
int COMMPI_Comm_rank(MPI_Comm c)
Definition: commpi.h:162
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 func2(Vector_3 &pnt, Vector_3 &nrm)
#define COM_assertion_msg(EX, msg)
static int rank
std::pair< double, double > compute_vnormal_error(const int ref_nrms_hdl, const int cur_nrms_hdl, const int vbuf_hdl, const int fbuf_hdl, const char *scheme=NULL)
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.
C/C++ Data types.
Definition: roccom_basic.h:129
SURF::Vector_3< Real > Vector_3
Definition: rfc_basic.h:42
double sqrt(double d)
Definition: double.h:73
int COM_get_attribute_handle(const char *waname)
Definition: roccom_c++.h:412
void init_parameters(const Control_parameter &cntr_param)
Definition: advectest.C:217
std::string read_in_mesh(const char *fname)
Definition: advectest.C:283
void compute_quadric_normals(const string &wname)
Point object that represents a single point.
Definition: datatypedef.h:68
static const int scheme
string normaldif
Definition: advectest.C:84
void COM_finalize()
Definition: roccom_c++.h:59
NT & sin
void COM_print_profile(const char *fname, const char *header)
Definition: roccom_c++.h:557
void init_normals(const string &wname, int func)
Definition: Rocout.h:81
blockLoc i
Definition: read.cpp:79
void compute_weighted_normals(const string &wname)
void COM_window_init_done(const char *w_str, int pane_changed=true)
Definition: roccom_c++.h:102
This file contains a set of routines for error assertion.
static Vector_3 cross_product(const Vector_3 &v, const Vector_3 &w)
Definition: mapbasic.h:104
string wavefrontal
Definition: advectest.C:83
void print_usage(int argc, char *argv[])
Definition: advectest.C:68
void COM_call_function(const int wf, int argc,...)
Definition: roccom_c.C:48
void load_modules()
Definition: advectest.C:58
int main(int argc, char *argv[])
Definition: blastest.C:94
std::pair< double, double > compute_fnormal_error(const int ref_nrms_hdl, const int cur_nrms_hdl, const int buf_hdl, const char *scheme=NULL)
j indices j
Definition: Indexing.h:6
void COM_init(int *argc, char ***argv)
Definition: roccom_c++.h:57
const double pi
void func3(Vector_3 &pnt, Vector_3 &nrm)
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
int read_winmesh(const char *fname, const std::string &wname, bool del=true)
Definition: IM_Reader.h:58
int COMMPI_Initialized()
Definition: commpi.h:168
double output_solution(const string &wname, const char *timelevel, double ref=0.)
Definition: advectest.C:357
void init_attributes(const string &wname, const Control_parameter &cntr_param)
Definition: advectest.C:323
NT & cos
#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
void read_control_file(const char *fname, Control_parameter &cp)
Definition: advectest.C:115
void func1(Vector_3 &pnt, Vector_3 &nrm)
#define COM_EXTERN_MODULE(moduleName)
Definition: roccom_basic.h:116