MOAB: Mesh Oriented datABase  (version 5.5.0)
uref_hirec_test_parallel.cpp File Reference
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
#include <vector>
#include <algorithm>
#include "moab/Core.hpp"
#include "moab/Range.hpp"
#include "moab/MeshTopoUtil.hpp"
#include "moab/NestedRefine.hpp"
#include "moab/DiscreteGeometry/HiReconstruction.hpp"
#include "TestUtil.hpp"
#include "geomObject.cpp"
#include <cmath>
#include <cstdlib>
#include <cassert>
+ Include dependency graph for uref_hirec_test_parallel.cpp:

Go to the source code of this file.

Macros

#define nsamples   10
 

Functions

ErrorCode load_meshset_hirec (const char *infile, Interface *mbimpl, EntityHandle &meshset, ParallelComm *&pc, const int degree, const int dim)
 
ErrorCode closedsurface_uref_hirec_convergence_study (const char *infile, std::vector< int > &degs2fit, bool interp, int dim, geomObject *obj, int &ntestverts, std::vector< double > &geoml1errs, std::vector< double > &geoml2errs, std::vector< double > &geomlinferrs)
 
void usage ()
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ nsamples

#define nsamples   10

Definition at line 36 of file uref_hirec_test_parallel.cpp.

Function Documentation

◆ closedsurface_uref_hirec_convergence_study()

ErrorCode closedsurface_uref_hirec_convergence_study ( const char *  infile,
std::vector< int > &  degs2fit,
bool  interp,
int  dim,
geomObject obj,
int &  ntestverts,
std::vector< double > &  geoml1errs,
std::vector< double > &  geoml2errs,
std::vector< double > &  geomlinferrs 
)

Definition at line 126 of file uref_hirec_test_parallel.cpp.

135 {
136  Core moab;
137  Interface* mbImpl = &moab;
138  ParallelComm* pc = NULL;
139  EntityHandle meshset;
140 
141 #ifdef MOAB_HAVE_MPI
142  int nprocs, rank;
143  MPI_Comm comm = MPI_COMM_WORLD;
144  MPI_Comm_size( comm, &nprocs );
145  MPI_Comm_rank( comm, &rank );
146 #endif
147 
149  // mesh will be loaded and communicator pc will be updated
150  int mxdeg = 1;
151  for( size_t i = 0; i < degs2fit.size(); ++i )
152  {
153  mxdeg = std::max( degs2fit[i], mxdeg );
154  }
155  error = load_meshset_hirec( infile, mbImpl, meshset, pc, mxdeg, dim );MB_CHK_ERR( error );
156 
157  Range elems, elems_owned;
158  error = mbImpl->get_entities_by_dimension( meshset, dim, elems );MB_CHK_ERR( error );
159 
160 #ifdef MOAB_HAVE_MPI
161 
162  if( pc )
163  {
164  error = pc->filter_pstatus( elems, PSTATUS_GHOST, PSTATUS_NOT, -1, &elems_owned );MB_CHK_ERR( error );
165  }
166  else
167  {
168  elems_owned = elems;
169  }
170 
171 #endif
172 
173 #ifdef MOAB_HAVE_MPI
174  // std::cout << "Mesh has " << nelems << " elements on Processor " << rank << " in total;";
175  // std::cout << elems_owned.size() << " of which are locally owned elements" << std::endl;
176 #else
177  // std::cout << "Mesh has " << nelems << " elements" << std::endl;
178 #endif
179 
180  /************************
181  * convergence study *
182  *************************/
183  // project onto exact geometry since each level with uref has only linear coordinates
184  Range verts;
185  error = mbImpl->get_entities_by_dimension( meshset, 0, verts );MB_CHK_ERR( error );
186 
187  for( Range::iterator ivert = verts.begin(); ivert != verts.end(); ++ivert )
188  {
189  EntityHandle currvert = *ivert;
190  double currcoords[3], exactcoords[3];
191  error = mbImpl->get_coords( &currvert, 1, currcoords );MB_CHK_ERR( error );
192  obj->project_points2geom( 3, currcoords, exactcoords, NULL );
193 
194  error = mbImpl->set_coords( &currvert, 1, exactcoords );MB_CHK_ERR( error );
195  // for debug
196  /*error = mbImpl->get_coords(&currvert,1,currcoords); MB_CHK_ERR(error);
197  assert(currcoords[0]==exactcoords[0]&&currcoords[1]==exactcoords[1]&&currcoords[2]==exactcoords[2]);*/
198  }
199 
200  // test ahf on mesh with ghost layers
201  /*Range verts_owned;
202  #ifdef MOAB_HAVE_MPI
203  if(pc){
204  error =
205  pc->filter_pstatus(verts,PSTATUS_GHOST,PSTATUS_NOT,-1,&verts_owned);MB_CHK_ERR(error); }else{
206  verts_owned = verts;
207  }
208 
209  HalfFacetRep *ahf = new HalfFacetRep(&moab,pc,meshset);
210  error = ahf->initialize(); MB_CHK_ERR(error);
211 
212  for(int i=0;i<nprocs;++i){
213  if(rank==i){
214  std::cout << "Processor " << rank << " Local elements: \n";
215  for(Range::iterator ielem=elems.begin();ielem!=elems.end();++ielem){
216  EntityHandle currelem = *ielem;
217  std::vector<EntityHandle> conn;
218  error = mbImpl->get_connectivity(&currelem,1,conn); MB_CHK_ERR(error);
219  std::cout << *ielem << ": ";
220  for(size_t k=0;k<conn.size();++k) std::cout << conn[k] << " ";
221  std::cout << std::endl;
222  }
223 
224  std::cout << "Processor " << rank << " Local owned elements: \n";
225  for(Range::iterator ielem=elems_owned.begin();ielem!=elems_owned.end();++ielem){
226  EntityHandle currelem = *ielem;
227  std::vector<EntityHandle> conn;
228  error = mbImpl->get_connectivity(&currelem,1,conn); MB_CHK_ERR(error);
229  std::cout << *ielem << ": ";
230  for(size_t k=0;k<conn.size();++k) std::cout << conn[k] << " ";
231  std::cout << std::endl;
232  }
233 
234 
235  std::cout << "Processor " << rank << " Local vertices: ";
236  for(Range::iterator ivert=verts.begin();ivert!=verts.end();++ivert){
237  std::cout << *ivert << " ";
238  }
239  std::cout << std::endl;
240  std::cout << "Processor " << rank << " Local owned vertices: ";
241  for(Range::iterator ivert=verts_owned.begin();ivert!=verts_owned.end();++ivert){
242  std::cout << *ivert << " ";
243  }
244  std::cout << std::endl;
245 
246  for(Range::iterator ivert=verts_owned.begin();ivert!=verts_owned.end();++ivert){
247  EntityHandle currvid = *ivert;
248  std::cout << "Processor " << rank << " local verts: " << *ivert << " has
249  adjfaces: "; std::vector<EntityHandle> adjfaces;
250  //error = ahf->get_up_adjacencies(currvid,2,adjfaces); MB_CHK_ERR(error);
251  error = mbImpl->get_adjacencies(&currvid,1,2,false,adjfaces); MB_CHK_ERR(error);
252  for(size_t k=0;k<adjfaces.size();++k){
253  std::cout << adjfaces[k] << " ";
254  }
255  std::cout << std::endl;
256  }
257 
258  for(Range::iterator ivert=verts.begin();ivert!=verts.end();++ivert){
259  EntityHandle currvid = *ivert;
260  std::cout << "Processor " << rank << " all verts: " << *ivert << " has adjfaces:
261  "; std::vector<EntityHandle> adjfaces;
262  //error = ahf->get_up_adjacencies(*ivert,2,adjfaces); MB_CHK_ERR(error);
263  error = mbImpl->get_adjacencies(&currvid,1,2,false,adjfaces); MB_CHK_ERR(error);
264  for(size_t k=0;k<adjfaces.size();++k){
265  std::cout << adjfaces[k] << " ";
266  }
267  std::cout << std::endl;
268  }
269 
270  }else{
271  MPI_Barrier(MPI_COMM_WORLD);
272  }
273  }
274  exit(0);
275  #endif*/
276 
277  // generate random points on each elements, assument 3D coordinates
278  int nvpe = TYPE_FROM_HANDLE( *elems.begin() ) == MBTRI ? 3 : 4;
279  std::vector< double > testpnts, testnaturalcoords;
280  ntestverts = elems_owned.size() * nsamples;
281  testpnts.reserve( 3 * elems_owned.size() * nsamples );
282  testnaturalcoords.reserve( nvpe * elems_owned.size() * nsamples );
283 
284  for( Range::iterator ielem = elems_owned.begin(); ielem != elems_owned.end(); ++ielem )
285  {
286  EntityHandle currelem = *ielem;
287  std::vector< EntityHandle > conn;
288  error = mbImpl->get_connectivity( &currelem, 1, conn );MB_CHK_ERR( error );
289  std::vector< double > elemcoords( 3 * conn.size() );
290  error = mbImpl->get_coords( &( conn[0] ), conn.size(), &( elemcoords[0] ) );MB_CHK_ERR( error );
291  EntityType type = TYPE_FROM_HANDLE( currelem );
292 
293  for( int s = 0; s < nsamples; ++s )
294  {
295  if( type == MBTRI )
296  {
297  double a = (double)rand() / RAND_MAX, b = (double)rand() / RAND_MAX, c = (double)rand() / RAND_MAX, sum;
298  sum = a + b + c;
299 
300  if( sum < 1e-12 )
301  {
302  --s;
303  continue;
304  }
305  else
306  {
307  a /= sum, b /= sum, c /= sum;
308  }
309 
310  assert( a > 0 && b > 0 && c > 0 && fabs( a + b + c - 1 ) < 1e-12 );
311  testpnts.push_back( a * elemcoords[0] + b * elemcoords[3] + c * elemcoords[6] );
312  testpnts.push_back( a * elemcoords[1] + b * elemcoords[4] + c * elemcoords[7] );
313  testpnts.push_back( a * elemcoords[2] + b * elemcoords[5] + c * elemcoords[8] );
314  testnaturalcoords.push_back( a ), testnaturalcoords.push_back( b ), testnaturalcoords.push_back( c );
315  }
316  else if( type == MBQUAD )
317  {
318  double xi = (double)rand() / RAND_MAX, eta = (double)rand() / RAND_MAX, N[4];
319  xi = 2 * xi - 1;
320  eta = 2 * eta - 1;
321  N[0] = ( 1 - xi ) * ( 1 - eta ) / 4, N[1] = ( 1 + xi ) * ( 1 - eta ) / 4,
322  N[2] = ( 1 + xi ) * ( 1 + eta ) / 4, N[3] = ( 1 - xi ) * ( 1 + eta ) / 4;
323  testpnts.push_back( N[0] * elemcoords[0] + N[1] * elemcoords[3] + N[2] * elemcoords[6] +
324  N[3] * elemcoords[9] );
325  testpnts.push_back( N[0] * elemcoords[1] + N[1] * elemcoords[4] + N[2] * elemcoords[7] +
326  N[3] * elemcoords[10] );
327  testpnts.push_back( N[0] * elemcoords[2] + N[1] * elemcoords[5] + N[2] * elemcoords[8] +
328  N[3] * elemcoords[11] );
329  testnaturalcoords.push_back( N[0] ), testnaturalcoords.push_back( N[1] ),
330  testnaturalcoords.push_back( N[2] ), testnaturalcoords.push_back( N[3] );
331  }
332  else
333  {
334  throw std::invalid_argument( "NOT SUPPORTED ELEMENT TYPE" );
335  }
336  }
337  }
338 
339  // Compute error of linear interpolation in PARALLEL
340  double l1err, l2err, linferr;
341  geoml1errs.clear();
342  geoml2errs.clear();
343  geomlinferrs.clear();
344  obj->compute_projecterror( 3, elems_owned.size() * nsamples, &( testpnts[0] ), l1err, l2err, linferr );
345  geoml1errs.push_back( l1err );
346  geoml2errs.push_back( l2err );
347  geomlinferrs.push_back( linferr );
348  /*Perform high order projection and compute error*/
349  // initialize
350  HiReconstruction hirec( &moab, pc, meshset );
351 
352  for( size_t ideg = 0; ideg < degs2fit.size(); ++ideg )
353  {
354  // High order reconstruction
355  error = hirec.reconstruct3D_surf_geom( degs2fit[ideg], interp, true, true );MB_CHK_ERR( error );
356 
357  int index = 0;
358  // for debug
359  /*double maxlinferr=0,elemlinferr=0,eleml1err=0,eleml2err;
360  EntityHandle elem_maxerr;*/
361 
362  for( Range::iterator ielem = elems_owned.begin(); ielem != elems_owned.end(); ++ielem, ++index )
363  {
364  // Projection
365  error =
366  hirec.hiproj_walf_in_element( *ielem, nvpe, nsamples, &( testnaturalcoords[nvpe * nsamples * index] ),
367  &( testpnts[3 * nsamples * index] ) );MB_CHK_ERR( error );
368  // for debug
369  /*obj->compute_projecterror(3,nsamples,&(testpnts[3*nsamples*index]),eleml1err,eleml2err,elemlinferr);
370  if(elemlinferr>maxlinferr){
371  maxlinferr = elemlinferr; elem_maxerr = *ielem;
372  }*/
373  }
374 
375  assert( (size_t)index == elems_owned.size() );
376  // Estimate error
377  obj->compute_projecterror( 3, elems_owned.size() * nsamples, &( testpnts[0] ), l1err, l2err, linferr );
378  geoml1errs.push_back( l1err );
379  geoml2errs.push_back( l2err );
380  geomlinferrs.push_back( linferr );
381 
382  // for debug
383  /*std::cout << "Degree " << degs2fit[ideg] << " has L-inf error " << maxlinferr << " at
384  element " << elems_owned.index(elem_maxerr) << ":"; std::vector<EntityHandle> conn; error =
385  mbImpl->get_connectivity(&elem_maxerr,1,conn); MB_CHK_ERR(error); for(size_t
386  ii=0;ii<conn.size();++ii) std::cout << verts.index(conn[ii]) << " "; std::cout << std::endl;
387 
388  for(size_t ii=0;ii<conn.size();++ii){
389  //assume triangle
390  std::vector<double> vertexcoords(3,0);
391  error = mbImpl->get_coords(&(conn[ii]),1,&(vertexcoords[0])); MB_CHK_ERR(error);
392  std::cout << verts.index(conn[ii]) << ":" << vertexcoords[0] << " "<< vertexcoords[1] <<
393  " "<< vertexcoords[2] << "\n"; GEOMTYPE geomtype; std::vector<double> local_coords_system,
394  local_coeffs; int deg_out; bool local_interp; bool hasfit =
395  hirec.get_fittings_data(conn[ii],geomtype,local_coords_system,deg_out,local_coeffs,local_interp);
396  assert(hasfit); std::cout << "Local fitting result: " << std::endl; std::cout << "Geom Type:
397  " << geomtype << std::endl; std::cout << "Local coordinates system: " << std::endl;
398  std::cout << local_coords_system[0] << "\t" << local_coords_system[1] << "\t" <<
399  local_coords_system[2] << std::endl; std::cout << local_coords_system[3] << "\t" <<
400  local_coords_system[4] << "\t" << local_coords_system[5] << std::endl; std::cout <<
401  local_coords_system[6] << "\t" << local_coords_system[7] << "\t" << local_coords_system[8]
402  << std::endl; std::cout << "Fitting degree is " << deg_out << " interp is " << local_interp
403  << std::endl; std::cout << "Fitting coefficients are :" << std::endl; for(size_t
404  kk=0;kk<local_coeffs.size();++kk) std::cout << local_coeffs[kk] << "\t"; std::cout <<
405  std::endl;
406  }*/
407  }
408 
409  return error;
410 }

References moab::Range::begin(), geomObject::compute_projecterror(), dim, moab::Range::end(), moab::error(), ErrorCode, moab::ParallelComm::filter_pstatus(), moab::Interface::get_connectivity(), moab::Interface::get_coords(), moab::Interface::get_entities_by_dimension(), moab::HiReconstruction::hiproj_walf_in_element(), load_meshset_hirec(), MB_CHK_ERR, MBQUAD, MBTRI, MPI_COMM_WORLD, nsamples, geomObject::project_points2geom(), PSTATUS_GHOST, PSTATUS_NOT, rank, moab::HiReconstruction::reconstruct3D_surf_geom(), moab::Interface::set_coords(), moab::Range::size(), moab::sum(), and moab::TYPE_FROM_HANDLE().

Referenced by main().

◆ load_meshset_hirec()

ErrorCode load_meshset_hirec ( const char *  infile,
Interface mbimpl,
EntityHandle meshset,
ParallelComm *&  pc,
const int  degree,
const int  dim 
)

Definition at line 42 of file uref_hirec_test_parallel.cpp.

48 {
50  error = mbimpl->create_meshset( moab::MESHSET_SET, meshset );MB_CHK_ERR( error );
51 #ifdef MOAB_HAVE_MPI
52  int nprocs, rank;
53  MPI_Comm comm = MPI_COMM_WORLD;
54  MPI_Comm_size( comm, &nprocs );
55  MPI_Comm_rank( comm, &rank );
56  EntityHandle partnset;
57  error = mbimpl->create_meshset( moab::MESHSET_SET, partnset );MB_CHK_ERR( error );
58 
59  if( nprocs > 1 )
60  {
61  pc = moab::ParallelComm::get_pcomm( mbimpl, partnset, &comm );
62  }
63 
64  if( nprocs > 1 )
65  {
66  int nghlayers = degree > 0 ? HiReconstruction::estimate_num_ghost_layers( degree, true ) : 0;
67  assert( nghlayers < 10 );
68 
69  if( nghlayers )
70  {
71  // get ghost layers
72  if( dim == 2 )
73  {
74  read_options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_"
75  "SHARED_ENTS;PARALLEL_GHOSTS=2.0.";
76  }
77  else if( dim == 1 )
78  {
79  read_options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_"
80  "SHARED_ENTS;PARALLEL_GHOSTS=1.0.";
81  }
82  else
83  {
84  MB_SET_ERR( MB_FAILURE, "unsupported dimension" );
85  }
86 
87  read_options += (char)( '0' + nghlayers );
88  // std::cout << "On processor " << rank << " Degree=" << degree << " "<< read_options <<
89  // std::endl;
90  }
91  else
92  {
93  read_options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;";
94  }
95 
96  /*for debug*/
97  /*std::string outfile = std::string(infile); std::size_t dotpos = outfile.find_last_of(".");
98  std::ostringstream convert; convert << rank;
99  std::string localfile = outfile.substr(0,dotpos)+convert.str()+".vtk";
100  //write local mesh
101  EntityHandle local;
102  error = mbimpl->create_meshset(moab::MESHSET_SET,local);CHECK_ERR(error);
103  std::string local_options =
104  "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;"; error =
105  mbimpl->load_file(infile,&local,local_options.c_str()); MB_CHK_ERR(error); error =
106  mbimpl->write_file(localfile.c_str(),0,0,&local,1);*/
107 
108  error = mbimpl->load_file( infile, &meshset, read_options.c_str() );MB_CHK_ERR( error );
109  /*for debug
110  //write local mesh with ghost layers
111  localfile = outfile.substr(0,dotpos)+convert.str()+"_ghost.vtk";
112  error = mbimpl->write_file(localfile.c_str(),0,0,&meshset,1);*/
113  }
114  else
115  {
116  error = mbimpl->load_file( infile, &meshset );MB_CHK_ERR( error );
117  }
118 
119 #else
120  assert( !pc && degree && dim );
121  error = mbimpl->load_file( infile, &meshset );MB_CHK_ERR( error );
122 #endif
123  return error;
124 }

References moab::Interface::create_meshset(), dim, moab::error(), ErrorCode, moab::HiReconstruction::estimate_num_ghost_layers(), moab::ParallelComm::get_pcomm(), moab::Interface::load_file(), MB_CHK_ERR, MB_SET_ERR, MESHSET_SET, MPI_COMM_WORLD, rank, and read_options.

Referenced by closedsurface_uref_hirec_convergence_study().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 420 of file uref_hirec_test_parallel.cpp.

421 {
422 #ifdef MOAB_HAVE_MPI
423  MPI_Init( &argc, &argv );
424  int nprocs, rank;
425  MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
426  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
427 #endif
428  std::string prefix, suffix, istr, iend;
429  int dim = 2, geom = 0;
430  bool interp = false;
432 
433  if( argc == 1 )
434  {
435  usage();
436  prefix = TestDir + "unittest/sphere_quads_5_ML_";
437  suffix = ".h5m";
438  istr = "0";
439  iend = "1";
440  std::cout << "Using defaults: MeshFiles/unittest/sphere_quads_5_ML_*.h5m -str 0 -end 1 "
441  "-suffix \".h5m\" -interp 0 -dim 2 -geom s"
442  << std::endl;
443  }
444  else
445  {
446  prefix = std::string( argv[1] );
447  bool hasdim = false;
448 
449  for( int i = 2; i < argc; ++i )
450  {
451  if( i + 1 != argc )
452  {
453  if( std::string( argv[i] ) == "-suffix" )
454  {
455  suffix = std::string( argv[++i] );
456  }
457  else if( std::string( argv[i] ) == "-str" )
458  {
459  istr = std::string( argv[++i] );
460  }
461  else if( std::string( argv[i] ) == "-end" )
462  {
463  iend = std::string( argv[++i] );
464  }
465  else if( std::string( argv[i] ) == "-interp" )
466  {
467  interp = atoi( argv[++i] );
468  }
469  else if( std::string( argv[i] ) == "-dim" )
470  {
471  dim = atoi( argv[++i] );
472  hasdim = true;
473  }
474  else if( std::string( argv[i] ) == "-geom" )
475  {
476  geom = std::string( argv[++i] ) == "s" ? 0 : 1;
477  }
478  else
479  {
480 #ifdef MOAB_HAVE_MPI
481 
482  if( 0 == rank )
483  {
484  usage();
485  }
486 
487  MPI_Finalize();
488 #else
489  usage();
490 #endif
491  return 0;
492  }
493  }
494  }
495 
496  if( !hasdim )
497  {
498 #ifdef MOAB_HAVE_MPI
499 
500  if( 0 == rank )
501  {
502  std::cout << "Dimension of input mesh should be provided, positive and less than 3" << std::endl;
503  }
504 
505 #else
506  std::cout << "Dimension of input mesh should be provided, positive and less than 3" << std::endl;
507 #endif
508  return 0;
509  }
510 
511  if( dim > 2 || dim <= 0 )
512  {
513 #ifdef MOAB_HAVE_MPI
514 
515  if( 0 == rank )
516  {
517  std::cout << "Input dimesion should be positive and less than 3;" << std::endl;
518  }
519 
520 #else
521  std::cout << "Input dimesion should be positive and less than 3;" << std::endl;
522 #endif
523  return 0;
524  }
525 
526 #ifdef MOAB_HAVE_MPI
527 
528  if( 0 == rank )
529  {
530  std::cout << "Testing on " << prefix + istr + "-" + iend + suffix << " with dimension " << dim << "\n";
531  std::string opts = interp ? "interpolation" : "least square fitting";
532  std::cout << "High order reconstruction in " << opts << std::endl;
533  }
534 
535 #else
536  std::cout << "Testing on " << prefix + istr + "-" + iend + suffix << " with dimension " << dim << "\n";
537  std::string opts = interp ? "interpolation" : "least square fitting";
538  std::cout << "High order reconstruction in " << opts << std::endl;
539 #endif
540  }
541 
542  geomObject* obj;
543 
544  if( geom == 0 )
545  {
546  obj = new sphere();
547  }
548  else
549  {
550  obj = new torus();
551  }
552 
553  std::vector< int > degs2fit;
554  for( int d = 1; d <= 6; ++d )
555  {
556  degs2fit.push_back( d );
557  }
558 
559  int begin = atoi( istr.c_str() ), end = atoi( iend.c_str() ) + 1;
560 #ifdef MOAB_HAVE_MPI
561  std::vector< std::vector< double > > geoml1errs_global, geoml2errs_global, geomlinferrs_global;
562 
563  if( rank == 0 )
564  {
565  geoml1errs_global =
566  std::vector< std::vector< double > >( 1 + degs2fit.size(), std::vector< double >( end - begin, 0 ) );
567  geoml2errs_global =
568  std::vector< std::vector< double > >( 1 + degs2fit.size(), std::vector< double >( end - begin, 0 ) );
569  geomlinferrs_global =
570  std::vector< std::vector< double > >( 1 + degs2fit.size(), std::vector< double >( end - begin, 0 ) );
571  }
572 
573 #else
574  std::vector< std::vector< double > > geoml1errs_global( 1 + degs2fit.size(),
575  std::vector< double >( end - begin, 0 ) );
576  std::vector< std::vector< double > > geoml2errs_global( 1 + degs2fit.size(),
577  std::vector< double >( end - begin, 0 ) );
578  std::vector< std::vector< double > > geomlinferrs_global( 1 + degs2fit.size(),
579  std::vector< double >( end - begin, 0 ) );
580 #endif
581 
582  for( int i = begin; i < end; ++i )
583  {
584  std::ostringstream convert;
585  convert << i;
586  std::string infile = prefix + convert.str() + suffix;
587  int ntestverts;
588  std::vector< double > geoml1errs, geoml2errs, geomlinferrs;
589 
590 #ifdef MOAB_HAVE_MPI
591  std::cout << "Processor " << rank << " is working on file " << infile << std::endl;
592 #endif
593  error = closedsurface_uref_hirec_convergence_study( infile.c_str(), degs2fit, interp, dim, obj, ntestverts,
594  geoml1errs, geoml2errs, geomlinferrs );MB_CHK_ERR( error );
595  assert( geoml1errs.size() == 1 + degs2fit.size() && geoml2errs.size() == 1 + degs2fit.size() &&
596  geomlinferrs.size() == 1 + degs2fit.size() );
597 #ifdef MOAB_HAVE_MPI
598 
599  if( nprocs > 1 )
600  {
601  int ntestverts_global = 0;
602  MPI_Reduce( &ntestverts, &ntestverts_global, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD );
603 
604  for( size_t d = 0; d < degs2fit.size() + 1; ++d )
605  {
606  double local_l1err = ntestverts * geoml1errs[d],
607  local_l2err = geoml2errs[d] * ( geoml2errs[d] * ntestverts ), local_linferr = geomlinferrs[d];
608  std::cout << "On Processor " << rank << " with mesh " << i
609  << " Degree = " << ( d == 0 ? 0 : degs2fit[d - 1] ) << " L1:" << geoml1errs[d]
610  << " L2:" << geoml2errs[d] << " Li:" << geomlinferrs[d] << std::endl;
611  double global_l1err = 0, global_l2err = 0, global_linferr = 0;
612  MPI_Reduce( &local_l1err, &global_l1err, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
613  MPI_Reduce( &local_l2err, &global_l2err, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
614  MPI_Reduce( &local_linferr, &global_linferr, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
615 
616  if( rank == 0 )
617  {
618  geoml1errs_global[d][i - begin] = global_l1err / ntestverts_global;
619  geoml2errs_global[d][i - begin] = sqrt( global_l2err / ntestverts_global );
620  geomlinferrs_global[d][i - begin] = global_linferr;
621  }
622  }
623  }
624  else
625  {
626  for( size_t d = 0; d < degs2fit.size() + 1; ++d )
627  {
628  geoml1errs_global[d][i - begin] = geoml1errs[d];
629  geoml2errs_global[d][i - begin] = geoml2errs[d];
630  geomlinferrs_global[d][i - begin] = geomlinferrs[d];
631  }
632  }
633 
634 #else
635 
636  for( size_t d = 0; d < degs2fit.size() + 1; ++d )
637  {
638  geoml1errs_global[d][i - begin] = geoml1errs[d];
639  geoml2errs_global[d][i - begin] = geoml2errs[d];
640  geomlinferrs_global[d][i - begin] = geomlinferrs[d];
641  }
642 
643 #endif
644  }
645 
646 #ifdef MOAB_HAVE_MPI
647 
648  if( rank == 0 )
649  {
650  std::cout << "Degrees: 0 ";
651 
652  for( size_t ideg = 0; ideg < degs2fit.size(); ++ideg )
653  {
654  std::cout << degs2fit[ideg] << " ";
655  }
656 
657  std::cout << std::endl;
658  std::cout << "L1-norm error: \n";
659 
660  for( size_t i = 0; i < geoml1errs_global.size(); ++i )
661  {
662  for( size_t j = 0; j < geoml1errs_global[i].size(); ++j )
663  {
664  std::cout << geoml1errs_global[i][j] << " ";
665  }
666 
667  std::cout << std::endl;
668  }
669 
670  std::cout << "L2-norm error: \n";
671 
672  for( size_t i = 0; i < geoml2errs_global.size(); ++i )
673  {
674  for( size_t j = 0; j < geoml2errs_global[i].size(); ++j )
675  {
676  std::cout << geoml2errs_global[i][j] << " ";
677  }
678 
679  std::cout << std::endl;
680  }
681 
682  std::cout << "Linf-norm error: \n";
683 
684  for( size_t i = 0; i < geomlinferrs_global.size(); ++i )
685  {
686  for( size_t j = 0; j < geomlinferrs_global[i].size(); ++j )
687  {
688  std::cout << geomlinferrs_global[i][j] << " ";
689  }
690 
691  std::cout << std::endl;
692  }
693  }
694 
695 #else
696  std::cout << "Degrees: 0 ";
697 
698  for( size_t ideg = 0; ideg < degs2fit.size(); ++ideg )
699  {
700  std::cout << degs2fit[ideg] << " ";
701  }
702 
703  std::cout << std::endl;
704  std::cout << "L1-norm error: \n";
705 
706  for( size_t i = 0; i < geoml1errs_global.size(); ++i )
707  {
708  for( size_t j = 0; j < geoml1errs_global[i].size(); ++j )
709  {
710  std::cout << geoml1errs_global[i][j] << " ";
711  }
712 
713  std::cout << std::endl;
714  }
715 
716  std::cout << "L2-norm error: \n";
717 
718  for( size_t i = 0; i < geoml2errs_global.size(); ++i )
719  {
720  for( size_t j = 0; j < geoml2errs_global[i].size(); ++j )
721  {
722  std::cout << geoml2errs_global[i][j] << " ";
723  }
724 
725  std::cout << std::endl;
726  }
727 
728  std::cout << "Linf-norm error: \n";
729 
730  for( size_t i = 0; i < geomlinferrs_global.size(); ++i )
731  {
732  for( size_t j = 0; j < geomlinferrs_global[i].size(); ++j )
733  {
734  std::cout << geomlinferrs_global[i][j] << " ";
735  }
736 
737  std::cout << std::endl;
738  }
739 
740 #endif
741 #ifdef MOAB_HAVE_MPI
742  MPI_Finalize();
743 #endif
744 }

References closedsurface_uref_hirec_convergence_study(), dim, moab::error(), ErrorCode, geom, MB_CHK_ERR, MPI_COMM_WORLD, rank, and usage().

◆ usage()

void usage ( )

Definition at line 412 of file uref_hirec_test_parallel.cpp.

413 {
414  std::cout << "usage: mpirun -np <number of processors> ./uref_hirec_test_parallel <prefix of "
415  "files> -str <first number> -end <lastnumber> -suffix <suffix> -interp <0=least "
416  "square, 1=interpolation> -dim <mesh dimension> -geom <s=sphere,t=torus>"
417  << std::endl;
418 }

Referenced by main().