MOAB: Mesh Oriented datABase  (version 5.5.0)
seqperf.cpp
Go to the documentation of this file.
1 #include <ctime>
2 #include <cassert>
3 #include <iostream>
4 #include <sstream>
5 #include "moab/Core.hpp"
6 #include "moab/ReadUtilIface.hpp"
7 
8 #define PRINT_SEQUENCE_COUNT
9 
10 #ifdef PRINT_SEQUENCE_COUNT
11 #ifndef IS_BUILDING_MB
12 #define IS_BUILDING_MB
13 #endif
14 #include "EntitySequence.hpp"
15 #ifdef MB_ENTITY_SEQUENCE_HPP
16 #include "EntitySequenceManager.hpp"
17 #else
18 #include "SequenceManager.hpp"
19 #endif
20 #endif
21 
22 using namespace moab;
23 
24 // constants
25 const bool dump_mesh = false; //!< write mesh to vtk file
26 const int default_intervals = 25; //!< defaul interval count for cubic structured hex mesh
27 const int default_query_count = 100; //!< number of times to do each query set
28 const int default_order[] = { 0, 1, 2 };
29 const int default_create[] = { 0, 1 };
30 const int default_delete[] = { 0, 10, 30, 50, 70, 90 };
31 #define ARRSIZE( A ) ( sizeof( A ) / sizeof( ( A )[0] ) )
32 
33 // input parameters
34 long numSideInt, numVert, numElem; //!< total counts;
35 int queryCount; //!< number of times to do each query set
36 
37 // misc globals
38 Core mb_core; //!< moab instance
39 Interface& mb = mb_core; //!< moab instance
40 EntityHandle vertStart, elemStart; //!< first handle
42 long* queryVertPermutation = 0; //!< pupulated by init(): "random" order for vertices
43 long* queryElemPermutation = 0; //!< pupulated by init(): "random" order for elements
44 
45 //! Generate random permutation of values in [0,count-1]
46 long* permutation( long count )
47 {
48  srand( count );
49  long* array = new long[count];
50  for( long i = 0; i < count; ++i )
51  array[i] = i;
52 
53  for( long i = 0; i < count; ++i )
54  {
55  long r = rand();
56  if( count > RAND_MAX )
57  {
58  r += RAND_MAX * rand();
59  if( count / RAND_MAX > RAND_MAX )
60  {
61  long t = (long)RAND_MAX * rand();
62  r += (long)RAND_MAX * t;
63  }
64  }
65  std::swap( array[i], array[r % count] );
66  }
67 
68  return array;
69 }
70 
71 //! Initialize global variables
72 void init()
73 {
75  if( rval || !readTool )
76  {
77  assert( false );
78  abort();
79  }
80 
83 }
84 
85 void create_vertices_single(); //!< create vertices one at a time
86 void create_vertices_block(); //!< create vertices in block using ReadUtilIface
87 void create_elements_single(); //!< create elements one at a time
88 void create_elements_block(); //!< create elements in block using ReadUtilIface
89 
90 void forward_order_query_vertices( int percent ); //!< calculate mean of all vertex coordinates
91 void reverse_order_query_vertices( int percent ); //!< calculate mean of all vertex coordinates
92 void random_order_query_vertices( int percent ); //!< calculate mean of all vertex coordinates
93 
94 void forward_order_query_elements( int percent ); //!< check all element connectivity for valid vertex handles
95 void reverse_order_query_elements( int percent ); //!< check all element connectivity for valid vertex handles
96 void random_order_query_elements( int percent ); //!< check all element connectivity for valid vertex handles
97 
98 void forward_order_query_element_verts( int percent ); //!< calculate centroid
99 void reverse_order_query_element_verts( int percent ); //!< calculate centroid
100 void random_order_query_element_verts( int percent ); //!< calculate centroid
101 
102 void forward_order_delete_vertices( int percent ); //!< delete x% of vertices
103 void reverse_order_delete_vertices( int percent ); //!< delete x% of vertices
104 void random_order_delete_vertices( int percent ); //!< delete x% of vertices
105 
106 void forward_order_delete_elements( int percent ); //!< delete x% of elements
107 void reverse_order_delete_elements( int percent ); //!< delete x% of elements
108 void random_order_delete_elements( int percent ); //!< delete x% of elements
109 
110 void create_missing_vertices( int percent ); //!< re-create deleted vertices
111 void create_missing_elements( int percent ); //!< re-create deleted elements
112 
113 #ifdef PRINT_SEQUENCE_COUNT
114 unsigned get_number_sequences( EntityType type );
115 #endif
116 
117 /* Build arrays of function pointers, indexed by the order the entities are traversed in */
118 
119 typedef void ( *naf_t )();
120 typedef void ( *iaf_t )( int );
121 
123 
125 
128 
131 
134 
135 const char* order_strs[] = { "Forward", "Reverse", "Random" };
136 
137 //! Coordinates for ith vertex in structured hex mesh
138 inline void vertex_coords( long vert_index, double& x, double& y, double& z );
139 //! Connectivity for ith hex in structured hex mesh
140 inline void element_conn( long elem_index, EntityHandle conn[8] );
141 //! True if passed index is one of the x% to be deleted
142 inline bool deleted_vert( long index, int percent );
143 //! True if passed index is one of the x% to be deleted
144 inline bool deleted_elem( long index, int percent );
145 //! if (deleted_vert(index,percent)) delete vertex
146 inline void delete_vert( long index, int percent );
147 //! if (deleted_elem(index,percent)) delete element
148 inline void delete_elem( long index, int percent );
149 
150 //! print usage and exit
151 void usage()
152 {
153  std::cerr << "Usage: seqperf [-i <intervals>] [-o <order>] [-d <percent>] [-b|-s] [-q <count>]" << std::endl;
154  std::cerr << " -i specify size of cubic structured hex mesh in intervals. Default: " << default_intervals
155  << std::endl;
156  std::cerr << " -o one of \"forward\", \"reverse\", or \"random\". May be specified multiple "
157  "times. Default is all."
158  << std::endl;
159  std::cerr << " -d percent of entities to delete. May be specified multiple times. Default is {";
160  for( unsigned i = 0; i < ARRSIZE( default_delete ) - 1; ++i )
161  std::cerr << default_delete[i] << ",";
162  std::cerr << default_delete[ARRSIZE( default_delete ) - 1] << "}" << std::endl;
163  std::cerr << " -b block creation of mesh" << std::endl;
164  std::cerr << " -s single entity mesh creation" << std::endl;
165  std::cerr << " -q number of times to repeat queries. Default: " << default_query_count << std::endl;
166  exit( 1 );
167 }
168 
169 //! convert CPU time to string
170 std::string ts( clock_t t )
171 {
172  std::ostringstream s;
173  s << ( (double)t ) / CLOCKS_PER_SEC << 's';
174  return s.str();
175 }
176 
177 //! run function, printing time spent
178 void TIME( const char* str, void ( *func )() )
179 {
180  std::cout << str << "... " << std::flush;
181  clock_t t = clock();
182  ( *func )();
183  std::cout << ts( clock() - t ) << std::endl;
184 }
185 
186 //! run function query_repeat times, printing time spent
187 void TIME_QRY( const char* str, void ( *func )( int percent ), int percent )
188 {
189  std::cout << str << "... " << std::flush;
190  clock_t t = clock();
191  for( int i = 0; i < queryCount; ++i )
192  ( *func )( percent );
193  std::cout << ts( clock() - t ) << std::endl;
194 }
195 
196 //! run function with integer argument, printing time spent
197 void TIME_DEL( const char* str, void ( *func )( int ), int percent )
198 {
199  std::cout << str << "... " << std::flush;
200  clock_t t = clock();
201  ( *func )( percent );
202  std::cout << ts( clock() - t ) << std::endl;
203 }
204 
205 //! call MB::delete_mesh(). function so can be passed to TIME
207 {
208  mb.delete_mesh();
209 }
210 
211 //! Run a single combination of test parameters
212 void do_test( int create_mode, //!< 0 == single, 1 == block
213  int order, //!< 0 == forward, 1 == reverse, 2 == random
214  int percent ) //!< percent of entities to delete
215 {
216  clock_t t = clock();
217  if( create_mode )
218  {
219  std::cout << "Block Entity Creation (all entities in single block of memory)" << std::endl;
220  TIME( " Creating initial vertices", create_vertices_block );
221  TIME( " Creating initial elements", create_elements_block );
222  if( dump_mesh && !percent && mb.write_file( "seqperf.vtk" ) == MB_SUCCESS )
223  std::cout << "Wrote mesh to file: seqperf.vtk" << std::endl;
224  }
225  else
226  {
227  std::cout << "Single Entity Creation (entities grouped in memory blocks of constant size)" << std::endl;
228  TIME( " Creating initial vertices", create_vertices_single );
229  TIME( " Creating initial elements", create_elements_single );
230  }
231 
232  std::cout << order_strs[order] << " order with deletion of " << percent << "% of vertices and elements"
233  << std::endl;
234 
235  TIME_DEL( " Deleting elements", delete_elems[order], percent );
236  TIME_DEL( " Deleting vertices", delete_verts[order], percent );
237 
238  int num_vert = 0;
239  int num_elem = 0;
240  mb.get_number_entities_by_type( 0, MBVERTEX, num_vert );
241  mb.get_number_entities_by_type( 0, MBHEX, num_elem );
242  std::cout << " " << num_vert << " vertices and " << num_elem << " elements remaining" << std::endl;
243 #ifdef PRINT_SEQUENCE_COUNT
244  std::cout << " " << get_number_sequences( MBVERTEX ) << " vertex sequences and " << get_number_sequences( MBHEX )
245  << " element sequences." << std::endl;
246 #endif
247 
248  TIME_QRY( " Querying vertex coordinates", query_verts[order], percent );
249  TIME_QRY( " Querying element connectivity", query_elems[order], percent );
250  TIME_QRY( " Querying element coordinates", query_elem_verts[order], percent );
251 
252  TIME_DEL( " Re-creating vertices", create_missing_vertices, percent );
253  TIME_DEL( " Re-creating elements", create_missing_elements, percent );
254 
255  TIME( " Clearing mesh instance", delete_mesh );
256 
257  std::cout << "Total time for test: " << ts( clock() - t ) << std::endl << std::endl;
258 }
259 
260 void parse_order( const char* str, std::vector< int >& list )
261 {
262  if( str[0] == 'f' )
263  {
264  if( strncmp( str, "forward", strlen( str ) ) != 0 ) usage();
265  list.push_back( 0 );
266  }
267  else if( str[0] != 'r' )
268  usage();
269  else if( str[1] == 'e' )
270  {
271  if( strncmp( str, "reverse", strlen( str ) ) != 0 ) usage();
272  list.push_back( 0 );
273  }
274  else
275  {
276  if( strncmp( str, "random", strlen( str ) ) != 0 ) usage();
277  list.push_back( 0 );
278  }
279 }
280 
281 void parse_percent( const char* str, std::vector< int >& list )
282 {
283  char* endptr;
284  long p = strtol( str, &endptr, 0 );
285  if( !endptr || *endptr || p < 0 || p > 100 ) usage();
286 
287  list.push_back( (int)p );
288 }
289 
290 int parse_positive_int( const char* str )
291 {
292  char* endptr;
293  long p = strtol( str, &endptr, 0 );
294  if( !endptr || *endptr || p < 1 ) usage();
295  int result = p;
296  if( p != (long)result ) // overflow
297  usage();
298 
299  return result;
300 }
301 
302 void check_default( std::vector< int >& list, const int* array, size_t array_len )
303 {
304  if( list.empty() ) std::copy( array, array + array_len, std::back_inserter( list ) );
305 }
306 
307 int main( int argc, char* argv[] )
308 {
309  // Parse arguments
310  std::vector< int > createList, orderList, deleteList;
313 
314  for( int i = 1; i < argc; ++i )
315  {
316  // check that arg is a '-' followed by a single character
317  if( argv[i][0] != '-' || argv[i][1] == '\0' || argv[i][2] != '\0' ) usage();
318 
319  const char flag = argv[i][1];
320  switch( flag )
321  {
322  case 'b':
323  createList.push_back( 1 );
324  break;
325  case 's':
326  createList.push_back( 0 );
327  break;
328  default:
329  if( ++i == argc ) usage();
330  switch( flag )
331  {
332  case 'i':
333  numSideInt = parse_positive_int( argv[i] );
334  break;
335  case 'o':
336  parse_order( argv[i], orderList );
337  break;
338  case 'd':
339  parse_percent( argv[i], deleteList );
340  break;
341  case 'q':
342  queryCount = parse_positive_int( argv[i] );
343  break;
344  default:
345  usage();
346  }
347  }
348  }
352 
353  // Do some initialization.
354 
355  int numSideVert = numSideInt + 1;
356  numVert = numSideVert * numSideVert * numSideVert;
358  if( numVert / numSideVert / numSideVert != numSideVert ) // overflow
359  usage();
360  init();
361 
362  // Echo input args
363 
364  std::cout << numSideInt << "x" << numSideInt << "x" << numSideInt << " hex grid: " << numElem << " elements and "
365  << numVert << " vertices" << std::endl;
366 
367  // Run tests
368 
369  std::vector< int >::const_iterator i, j, k;
370  clock_t t = clock();
371  for( i = createList.begin(); i != createList.end(); ++i )
372  {
373  for( j = deleteList.begin(); j != deleteList.end(); ++j )
374  {
375  for( k = orderList.begin(); k != orderList.end(); ++k )
376  {
377  do_test( *i, *k, *j );
378  }
379  }
380  }
381 
382  // Clean up
383 
384  std::cout << "TOTAL: " << ts( clock() - t ) << std::endl << std::endl;
385  delete[] queryVertPermutation;
386  delete[] queryElemPermutation;
387  return 0;
388 }
389 
390 inline void vertex_coords( long vert_index, double& x, double& y, double& z )
391 {
392  const long vs = numSideInt + 1;
393  x = vert_index % vs;
394  y = ( vert_index / vs ) % vs;
395  z = ( vert_index / vs / vs );
396 }
397 
398 inline long vert_index( long x, long y, long z )
399 {
400  const long vs = numSideInt + 1;
401  return x + vs * ( y + vs * z );
402 }
403 
404 inline void element_conn( long elem_index, EntityHandle conn[8] )
405 {
406  const long x = elem_index % numSideInt;
407  const long y = ( elem_index / numSideInt ) % numSideInt;
408  const long z = ( elem_index / numSideInt / numSideInt );
409  conn[0] = vertStart + vert_index( x, y, z );
410  conn[1] = vertStart + vert_index( x + 1, y, z );
411  conn[2] = vertStart + vert_index( x + 1, y + 1, z );
412  conn[3] = vertStart + vert_index( x, y + 1, z );
413  conn[4] = vertStart + vert_index( x, y, z + 1 );
414  conn[5] = vertStart + vert_index( x + 1, y, z + 1 );
415  conn[6] = vertStart + vert_index( x + 1, y + 1, z + 1 );
416  conn[7] = vertStart + vert_index( x, y + 1, z + 1 );
417 }
418 
419 inline bool deleted_vert( long index, int percent )
420 {
421  return index % ( numSideInt + 1 ) >= ( numSideInt + 1 ) * ( 100 - percent ) / 100;
422 }
423 
424 inline bool deleted_elem( long index, int percent )
425 {
426  return index % numSideInt + 1 >= ( numSideInt + 1 ) * ( 100 - percent ) / 100;
427 }
428 
430 {
431  double coords[3];
432  vertex_coords( 0, coords[0], coords[1], coords[2] );
433  ErrorCode rval = mb.create_vertex( coords, vertStart );
434  assert( !rval );
435  if( rval )
436  {
437  } // empty line to remove compiler warning
438 
439  EntityHandle h;
440  for( long i = 1; i < numVert; ++i )
441  {
442  vertex_coords( i, coords[0], coords[1], coords[2] );
443  rval = mb.create_vertex( coords, h );
444  assert( !rval );
445  assert( h - vertStart == (EntityHandle)i );
446  }
447 }
448 
450 {
451  std::vector< double* > arrays;
452  ErrorCode rval = readTool->get_node_coords( 3, numVert, 0, vertStart, arrays );
453  if( rval || arrays.size() != 3 )
454  {
455  assert( false );
456  abort();
457  }
458  double *x = arrays[0], *y = arrays[1], *z = arrays[2];
459  assert( x && y && z );
460 
461  for( long i = 0; i < numVert; ++i )
462  vertex_coords( i, *x++, *y++, *z++ );
463 }
464 
466 {
467  EntityHandle conn[8];
468  element_conn( 0, conn );
469  ErrorCode rval = mb.create_element( MBHEX, conn, 8, elemStart );
470  if( rval )
471  {
472  assert( false );
473  abort();
474  }
475 
476  EntityHandle h;
477  for( long i = 1; i < numElem; ++i )
478  {
479  element_conn( i, conn );
480  rval = mb.create_element( MBHEX, conn, 8, h );
481  assert( !rval );
482  assert( h - elemStart == (EntityHandle)i );
483  }
484 }
485 
487 {
488  EntityHandle* conn = 0;
489  ErrorCode rval = readTool->get_element_connect( numElem, 8, MBHEX, 0, elemStart, conn );
490  if( rval && !conn )
491  {
492  assert( false );
493  abort();
494  }
495 
496  for( long i = 0; i < numElem; ++i )
497  element_conn( i, conn + 8 * i );
498 }
499 
500 void forward_order_query_vertices( int percent )
501 {
502  ErrorCode r;
503  double coords[3];
504  long x, y, z;
505  const long vert_per_edge = numSideInt + 1;
506  const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100;
508  for( z = 0; z < vert_per_edge; ++z )
509  {
510  for( y = 0; y < vert_per_edge; ++y )
511  {
512  for( x = 0; x < deleted_x; ++x, ++h )
513  {
514  r = mb.get_coords( &h, 1, coords );
515  if( MB_SUCCESS != r )
516  {
517  assert( false );
518  abort();
519  }
520  }
521  h += ( vert_per_edge - deleted_x );
522  }
523  }
524 }
525 
526 void reverse_order_query_vertices( int percent )
527 {
528  ErrorCode r;
529  double coords[3];
530  long x, y, z;
531  const long vert_per_edge = numSideInt + 1;
532  const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100;
533  EntityHandle h = vertStart + numVert - 1;
534  ;
535  for( z = vert_per_edge - 1; z >= 0; --z )
536  {
537  for( y = vert_per_edge - 1; y >= 0; --y )
538  {
539  h -= ( vert_per_edge - deleted_x );
540  for( x = deleted_x - 1; x >= 0; --x, --h )
541  {
542  r = mb.get_coords( &h, 1, coords );
543  assert( MB_SUCCESS == r );
544  if( r )
545  {
546  } // empty line to remove compiler warning
547  }
548  }
549  }
550 }
551 
552 void random_order_query_vertices( int percent )
553 {
554  ErrorCode r;
555  EntityHandle h;
556  double coords[3];
557  for( long i = 0; i < numVert; ++i )
558  {
559  if( !deleted_vert( queryVertPermutation[i], percent ) )
560  {
562  r = mb.get_coords( &h, 1, coords );
563  assert( MB_SUCCESS == r );
564  if( r )
565  {
566  } // empty line to remove compiler warning
567  }
568  }
569 }
570 
571 void forward_order_query_elements( int percent )
572 {
573  ErrorCode r;
574  const EntityHandle* conn;
575  int len;
576  long x, y, z;
577  const long elem_per_edge = numSideInt;
578  const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
580  for( z = 0; z < elem_per_edge; ++z )
581  {
582  for( y = 0; y < elem_per_edge; ++y )
583  {
584  for( x = 0; x < deleted_x; ++x, ++h )
585  {
586  r = mb.get_connectivity( h, conn, len );
587  assert( MB_SUCCESS == r );
588  if( r )
589  {
590  } // empty line to remove compiler warning
591  assert( conn && 8 == len );
592  }
593  h += ( elem_per_edge - deleted_x );
594  }
595  }
596 }
597 
598 void reverse_order_query_elements( int percent )
599 {
600  ErrorCode r;
601  const EntityHandle* conn;
602  int len;
603  long x, y, z;
604  const long elem_per_edge = numSideInt;
605  const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
606  EntityHandle h = elemStart + numElem - 1;
607  ;
608  for( z = elem_per_edge - 1; z >= 0; --z )
609  {
610  for( y = elem_per_edge - 1; y >= 0; --y )
611  {
612  h -= ( elem_per_edge - deleted_x );
613  for( x = deleted_x - 1; x >= 0; --x, --h )
614  {
615  r = mb.get_connectivity( h, conn, len );
616  assert( MB_SUCCESS == r );
617  if( r )
618  {
619  } // empty line to remove compiler warning
620  assert( conn && 8 == len );
621  }
622  }
623  }
624 }
625 
626 void random_order_query_elements( int percent )
627 {
628  ErrorCode r;
629  const EntityHandle* conn;
630  int len;
631  for( long i = 0; i < numElem; ++i )
632  {
633  if( !deleted_elem( queryElemPermutation[i], percent ) )
634  {
635  r = mb.get_connectivity( elemStart + queryElemPermutation[i], conn, len );
636  assert( MB_SUCCESS == r );
637  if( r )
638  {
639  } // empty line to remove compiler warning
640  assert( conn && 8 == len );
641  }
642  }
643 }
644 
645 /*
646 static double hex_centroid( double coords[24], double cent[3] )
647 {
648  double a[3], b[3], c[3], vol;
649  cent[0] += 0.125*(coords[0] + coords[3] + coords[6] + coords[ 9] + coords[12] + coords[15] +
650 coords[18] + coords[21]); cent[1] += 0.125*(coords[1] + coords[4] + coords[7] + coords[10] +
651 coords[13] + coords[16] + coords[19] + coords[22]); cent[2] += 0.125*(coords[2] + coords[5] +
652 coords[8] + coords[11] + coords[14] + coords[17] + coords[20] + coords[23]); a[0] = coords[0] +
653 coords[3] + coords[15] + coords[12] - coords[ 9] - coords[6] - coords[18] - coords[21]; a[1] =
654 coords[1] + coords[4] + coords[16] + coords[13] - coords[10] - coords[7] - coords[19] - coords[22];
655  a[2] = coords[2] + coords[5] + coords[17] + coords[14] - coords[11] - coords[8] - coords[20] -
656 coords[23]; b[0] = coords[0] + coords[ 9] + coords[21] + coords[12] - coords[3] - coords[6] -
657 coords[18] - coords[15]; b[1] = coords[1] + coords[10] + coords[22] + coords[13] - coords[4] -
658 coords[7] - coords[19] - coords[16]; b[2] = coords[2] + coords[11] + coords[23] + coords[14] -
659 coords[5] - coords[8] - coords[20] - coords[17]; c[0] = coords[0] + coords[3] + coords[6] + coords[
660 9] - coords[12] - coords[15] - coords[18] - coords[21]; c[1] = coords[1] + coords[4] + coords[7] +
661 coords[10] - coords[13] - coords[16] - coords[19] - coords[22]; c[2] = coords[2] + coords[5] +
662 coords[8] + coords[11] - coords[14] - coords[17] - coords[20] - coords[23]; vol = c[0]*(a[1]*b[2] -
663 a[2]*b[1]) + c[1]*(a[2]*b[0] - a[0]*b[2]) + c[2]*(a[0]*b[1] - a[1]*b[0]); return (1./64.) * vol;
664 }
665 */
666 
668 {
669  ErrorCode r = MB_SUCCESS;
670  if( r )
671  {
672  } // empty line to remove compiler warning
673  const EntityHandle* conn;
674  int len;
675  long x, y, z;
676  double coords[24];
677  const long elem_per_edge = numSideInt;
678  const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
680  for( z = 0; z < elem_per_edge; ++z )
681  {
682  for( y = 0; y < elem_per_edge; ++y )
683  {
684  for( x = 0; x < deleted_x; ++x, ++h )
685  {
686  r = mb.get_connectivity( h, conn, len );
687  assert( MB_SUCCESS == r );
688  assert( conn && 8 == len );
689  r = mb.get_coords( conn, len, coords );
690  assert( MB_SUCCESS == r );
691  }
692  h += ( elem_per_edge - deleted_x );
693  }
694  }
695 }
696 
698 {
699  ErrorCode r = MB_SUCCESS;
700  if( r )
701  {
702  } // empty statement to remove compiler warning
703 
704  const EntityHandle* conn;
705  int len;
706  long x, y, z;
707  double coords[24];
708  const long elem_per_edge = numSideInt;
709  const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
710  EntityHandle h = elemStart + numElem - 1;
711  ;
712  for( z = elem_per_edge - 1; z >= 0; --z )
713  {
714  for( y = elem_per_edge - 1; y >= 0; --y )
715  {
716  h -= ( elem_per_edge - deleted_x );
717  for( x = deleted_x - 1; x >= 0; --x, --h )
718  {
719  r = mb.get_connectivity( h, conn, len );
720  assert( MB_SUCCESS == r );
721  assert( conn && 8 == len );
722  r = mb.get_coords( conn, len, coords );
723  assert( MB_SUCCESS == r );
724  }
725  }
726  }
727 }
728 
730 {
731  ErrorCode r = MB_SUCCESS;
732  if( r )
733  {
734  } // empty line to remove compiler warning
735  const EntityHandle* conn;
736  int len;
737  double coords[24];
738  for( long i = 0; i < numElem; ++i )
739  {
740  if( !deleted_elem( queryElemPermutation[i], percent ) )
741  {
742  r = mb.get_connectivity( elemStart + queryElemPermutation[i], conn, len );
743  assert( MB_SUCCESS == r );
744  assert( conn && 8 == len );
745  r = mb.get_coords( conn, len, coords );
746  assert( MB_SUCCESS == r );
747  }
748  }
749 }
750 
751 void forward_order_delete_vertices( int percent )
752 {
753  for( long i = 0; i < numVert; ++i )
754  delete_vert( i, percent );
755 }
756 
757 void reverse_order_delete_vertices( int percent )
758 {
759  for( long i = numVert - 1; i >= 0; --i )
760  delete_vert( i, percent );
761 }
762 
763 void random_order_delete_vertices( int percent )
764 {
765  for( long i = 0; i < numVert; ++i )
766  delete_vert( queryVertPermutation[i], percent );
767 }
768 
769 void forward_order_delete_elements( int percent )
770 {
771  for( long i = 0; i < numElem; ++i )
772  delete_elem( i, percent );
773 }
774 
775 void reverse_order_delete_elements( int percent )
776 {
777  for( long i = numElem - 1; i >= 0; --i )
778  delete_elem( i, percent );
779 }
780 
781 void random_order_delete_elements( int percent )
782 {
783  for( long i = 0; i < numElem; ++i )
784  delete_elem( queryElemPermutation[i], percent );
785 }
786 
787 void create_missing_vertices( int percent )
788 {
789  EntityHandle h;
790  ErrorCode rval = MB_SUCCESS;
791  if( rval )
792  {
793  } // empty line to remove compiler warning
794  double coords[3];
795  for( long i = 0; i < numVert; ++i )
796  if( deleted_vert( i, percent ) )
797  {
798  vertex_coords( i, coords[0], coords[1], coords[2] );
799  rval = mb.create_vertex( coords, h );
800  assert( !rval );
801  }
802 }
803 
804 void create_missing_elements( int percent )
805 {
806  EntityHandle h;
807  ErrorCode rval;
808  EntityHandle conn[8];
809  for( long i = 0; i < numElem; ++i )
810  if( deleted_elem( i, percent ) )
811  {
812  element_conn( i, conn );
813  rval = mb.create_element( MBHEX, conn, 8, h );
814  if( rval )
815  {
816  assert( false );
817  abort();
818  }
819  }
820 }
821 
822 inline void delete_vert( long index, int percent )
823 {
824  if( deleted_vert( index, percent ) )
825  {
826  EntityHandle h = index + vertStart;
827  ErrorCode rval = mb.delete_entities( &h, 1 );
828  if( rval )
829  {
830  assert( false );
831  abort();
832  }
833  }
834 }
835 
836 inline void delete_elem( long index, int percent )
837 {
838  if( deleted_elem( index, percent ) )
839  {
840  EntityHandle h = index + elemStart;
841  ErrorCode rval = mb.delete_entities( &h, 1 );
842  if( rval )
843  {
844  assert( false );
845  abort();
846  }
847  }
848 }
849 
850 #ifdef PRINT_SEQUENCE_COUNT
851 unsigned get_number_sequences( EntityType type )
852 {
853 #ifdef MB_ENTITY_SEQUENCE_HPP
854  return mb_core.sequence_manager()->entity_map( type )->size();
855 #else
857 #endif
858 }
859 #endif