MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #include <ctime> 00002 #include <cassert> 00003 #include <iostream> 00004 #include <sstream> 00005 #include "moab/Core.hpp" 00006 #include "moab/ReadUtilIface.hpp" 00007 00008 #define PRINT_SEQUENCE_COUNT 00009 00010 #ifdef PRINT_SEQUENCE_COUNT 00011 #ifndef IS_BUILDING_MB 00012 #define IS_BUILDING_MB 00013 #endif 00014 #include "EntitySequence.hpp" 00015 #ifdef MB_ENTITY_SEQUENCE_HPP 00016 #include "EntitySequenceManager.hpp" 00017 #else 00018 #include "SequenceManager.hpp" 00019 #endif 00020 #endif 00021 00022 using namespace moab; 00023 00024 // constants 00025 const bool dump_mesh = false; //!< write mesh to vtk file 00026 const int default_intervals = 25; //!< defaul interval count for cubic structured hex mesh 00027 const int default_query_count = 100; //!< number of times to do each query set 00028 const int default_order[] = { 0, 1, 2 }; 00029 const int default_create[] = { 0, 1 }; 00030 const int default_delete[] = { 0, 10, 30, 50, 70, 90 }; 00031 #define ARRSIZE( A ) ( sizeof( A ) / sizeof( ( A )[0] ) ) 00032 00033 // input parameters 00034 long numSideInt, numVert, numElem; //!< total counts; 00035 int queryCount; //!< number of times to do each query set 00036 00037 // misc globals 00038 Core mb_core; //!< moab instance 00039 Interface& mb = mb_core; //!< moab instance 00040 EntityHandle vertStart, elemStart; //!< first handle 00041 ReadUtilIface* readTool = 0; 00042 long* queryVertPermutation = 0; //!< pupulated by init(): "random" order for vertices 00043 long* queryElemPermutation = 0; //!< pupulated by init(): "random" order for elements 00044 00045 //! Generate random permutation of values in [0,count-1] 00046 long* permutation( long count ) 00047 { 00048 srand( count ); 00049 long* array = new long[count]; 00050 for( long i = 0; i < count; ++i ) 00051 array[i] = i; 00052 00053 for( long i = 0; i < count; ++i ) 00054 { 00055 long r = rand(); 00056 if( count > RAND_MAX ) 00057 { 00058 r += RAND_MAX * rand(); 00059 if( count / RAND_MAX > RAND_MAX ) 00060 { 00061 long t = (long)RAND_MAX * rand(); 00062 r += (long)RAND_MAX * t; 00063 } 00064 } 00065 std::swap( array[i], array[r % count] ); 00066 } 00067 00068 return array; 00069 } 00070 00071 //! Initialize global variables 00072 void init() 00073 { 00074 ErrorCode rval = mb.query_interface( readTool ); 00075 if( rval || !readTool ) 00076 { 00077 assert( false ); 00078 abort(); 00079 } 00080 00081 queryVertPermutation = permutation( numVert ); 00082 queryElemPermutation = permutation( numElem ); 00083 } 00084 00085 void create_vertices_single(); //!< create vertices one at a time 00086 void create_vertices_block(); //!< create vertices in block using ReadUtilIface 00087 void create_elements_single(); //!< create elements one at a time 00088 void create_elements_block(); //!< create elements in block using ReadUtilIface 00089 00090 void forward_order_query_vertices( int percent ); //!< calculate mean of all vertex coordinates 00091 void reverse_order_query_vertices( int percent ); //!< calculate mean of all vertex coordinates 00092 void random_order_query_vertices( int percent ); //!< calculate mean of all vertex coordinates 00093 00094 void forward_order_query_elements( int percent ); //!< check all element connectivity for valid vertex handles 00095 void reverse_order_query_elements( int percent ); //!< check all element connectivity for valid vertex handles 00096 void random_order_query_elements( int percent ); //!< check all element connectivity for valid vertex handles 00097 00098 void forward_order_query_element_verts( int percent ); //!< calculate centroid 00099 void reverse_order_query_element_verts( int percent ); //!< calculate centroid 00100 void random_order_query_element_verts( int percent ); //!< calculate centroid 00101 00102 void forward_order_delete_vertices( int percent ); //!< delete x% of vertices 00103 void reverse_order_delete_vertices( int percent ); //!< delete x% of vertices 00104 void random_order_delete_vertices( int percent ); //!< delete x% of vertices 00105 00106 void forward_order_delete_elements( int percent ); //!< delete x% of elements 00107 void reverse_order_delete_elements( int percent ); //!< delete x% of elements 00108 void random_order_delete_elements( int percent ); //!< delete x% of elements 00109 00110 void create_missing_vertices( int percent ); //!< re-create deleted vertices 00111 void create_missing_elements( int percent ); //!< re-create deleted elements 00112 00113 #ifdef PRINT_SEQUENCE_COUNT 00114 unsigned get_number_sequences( EntityType type ); 00115 #endif 00116 00117 /* Build arrays of function pointers, indexed by the order the entities are traversed in */ 00118 00119 typedef void ( *naf_t )(); 00120 typedef void ( *iaf_t )( int ); 00121 00122 iaf_t query_verts[3] = { &forward_order_query_vertices, &reverse_order_query_vertices, &random_order_query_vertices }; 00123 00124 iaf_t query_elems[3] = { &forward_order_query_elements, &reverse_order_query_elements, &random_order_query_elements }; 00125 00126 iaf_t query_elem_verts[3] = { &forward_order_query_element_verts, &reverse_order_query_element_verts, 00127 &random_order_query_element_verts }; 00128 00129 iaf_t delete_verts[3] = { &forward_order_delete_vertices, &reverse_order_delete_vertices, 00130 &random_order_delete_vertices }; 00131 00132 iaf_t delete_elems[3] = { &forward_order_delete_elements, &reverse_order_delete_elements, 00133 &random_order_delete_elements }; 00134 00135 const char* order_strs[] = { "Forward", "Reverse", "Random" }; 00136 00137 //! Coordinates for ith vertex in structured hex mesh 00138 inline void vertex_coords( long vert_index, double& x, double& y, double& z ); 00139 //! Connectivity for ith hex in structured hex mesh 00140 inline void element_conn( long elem_index, EntityHandle conn[8] ); 00141 //! True if passed index is one of the x% to be deleted 00142 inline bool deleted_vert( long index, int percent ); 00143 //! True if passed index is one of the x% to be deleted 00144 inline bool deleted_elem( long index, int percent ); 00145 //! if (deleted_vert(index,percent)) delete vertex 00146 inline void delete_vert( long index, int percent ); 00147 //! if (deleted_elem(index,percent)) delete element 00148 inline void delete_elem( long index, int percent ); 00149 00150 //! print usage and exit 00151 void usage() 00152 { 00153 std::cerr << "Usage: seqperf [-i <intervals>] [-o <order>] [-d <percent>] [-b|-s] [-q <count>]" << std::endl; 00154 std::cerr << " -i specify size of cubic structured hex mesh in intervals. Default: " << default_intervals 00155 << std::endl; 00156 std::cerr << " -o one of \"forward\", \"reverse\", or \"random\". May be specified multiple " 00157 "times. Default is all." 00158 << std::endl; 00159 std::cerr << " -d percent of entities to delete. May be specified multiple times. Default is {"; 00160 for( unsigned i = 0; i < ARRSIZE( default_delete ) - 1; ++i ) 00161 std::cerr << default_delete[i] << ","; 00162 std::cerr << default_delete[ARRSIZE( default_delete ) - 1] << "}" << std::endl; 00163 std::cerr << " -b block creation of mesh" << std::endl; 00164 std::cerr << " -s single entity mesh creation" << std::endl; 00165 std::cerr << " -q number of times to repeat queries. Default: " << default_query_count << std::endl; 00166 exit( 1 ); 00167 } 00168 00169 //! convert CPU time to string 00170 std::string ts( clock_t t ) 00171 { 00172 std::ostringstream s; 00173 s << ( (double)t ) / CLOCKS_PER_SEC << 's'; 00174 return s.str(); 00175 } 00176 00177 //! run function, printing time spent 00178 void TIME( const char* str, void ( *func )() ) 00179 { 00180 std::cout << str << "... " << std::flush; 00181 clock_t t = clock(); 00182 ( *func )(); 00183 std::cout << ts( clock() - t ) << std::endl; 00184 } 00185 00186 //! run function query_repeat times, printing time spent 00187 void TIME_QRY( const char* str, void ( *func )( int percent ), int percent ) 00188 { 00189 std::cout << str << "... " << std::flush; 00190 clock_t t = clock(); 00191 for( int i = 0; i < queryCount; ++i ) 00192 ( *func )( percent ); 00193 std::cout << ts( clock() - t ) << std::endl; 00194 } 00195 00196 //! run function with integer argument, printing time spent 00197 void TIME_DEL( const char* str, void ( *func )( int ), int percent ) 00198 { 00199 std::cout << str << "... " << std::flush; 00200 clock_t t = clock(); 00201 ( *func )( percent ); 00202 std::cout << ts( clock() - t ) << std::endl; 00203 } 00204 00205 //! call MB::delete_mesh(). function so can be passed to TIME 00206 void delete_mesh() 00207 { 00208 mb.delete_mesh(); 00209 } 00210 00211 //! Run a single combination of test parameters 00212 void do_test( int create_mode, //!< 0 == single, 1 == block 00213 int order, //!< 0 == forward, 1 == reverse, 2 == random 00214 int percent ) //!< percent of entities to delete 00215 { 00216 clock_t t = clock(); 00217 if( create_mode ) 00218 { 00219 std::cout << "Block Entity Creation (all entities in single block of memory)" << std::endl; 00220 TIME( " Creating initial vertices", create_vertices_block ); 00221 TIME( " Creating initial elements", create_elements_block ); 00222 if( dump_mesh && !percent && mb.write_file( "seqperf.vtk" ) == MB_SUCCESS ) 00223 std::cout << "Wrote mesh to file: seqperf.vtk" << std::endl; 00224 } 00225 else 00226 { 00227 std::cout << "Single Entity Creation (entities grouped in memory blocks of constant size)" << std::endl; 00228 TIME( " Creating initial vertices", create_vertices_single ); 00229 TIME( " Creating initial elements", create_elements_single ); 00230 } 00231 00232 std::cout << order_strs[order] << " order with deletion of " << percent << "% of vertices and elements" 00233 << std::endl; 00234 00235 TIME_DEL( " Deleting elements", delete_elems[order], percent ); 00236 TIME_DEL( " Deleting vertices", delete_verts[order], percent ); 00237 00238 int num_vert = 0; 00239 int num_elem = 0; 00240 mb.get_number_entities_by_type( 0, MBVERTEX, num_vert ); 00241 mb.get_number_entities_by_type( 0, MBHEX, num_elem ); 00242 std::cout << " " << num_vert << " vertices and " << num_elem << " elements remaining" << std::endl; 00243 #ifdef PRINT_SEQUENCE_COUNT 00244 std::cout << " " << get_number_sequences( MBVERTEX ) << " vertex sequences and " << get_number_sequences( MBHEX ) 00245 << " element sequences." << std::endl; 00246 #endif 00247 00248 TIME_QRY( " Querying vertex coordinates", query_verts[order], percent ); 00249 TIME_QRY( " Querying element connectivity", query_elems[order], percent ); 00250 TIME_QRY( " Querying element coordinates", query_elem_verts[order], percent ); 00251 00252 TIME_DEL( " Re-creating vertices", create_missing_vertices, percent ); 00253 TIME_DEL( " Re-creating elements", create_missing_elements, percent ); 00254 00255 TIME( " Clearing mesh instance", delete_mesh ); 00256 00257 std::cout << "Total time for test: " << ts( clock() - t ) << std::endl << std::endl; 00258 } 00259 00260 void parse_order( const char* str, std::vector< int >& list ) 00261 { 00262 if( str[0] == 'f' ) 00263 { 00264 if( strncmp( str, "forward", strlen( str ) ) != 0 ) usage(); 00265 list.push_back( 0 ); 00266 } 00267 else if( str[0] != 'r' ) 00268 usage(); 00269 else if( str[1] == 'e' ) 00270 { 00271 if( strncmp( str, "reverse", strlen( str ) ) != 0 ) usage(); 00272 list.push_back( 0 ); 00273 } 00274 else 00275 { 00276 if( strncmp( str, "random", strlen( str ) ) != 0 ) usage(); 00277 list.push_back( 0 ); 00278 } 00279 } 00280 00281 void parse_percent( const char* str, std::vector< int >& list ) 00282 { 00283 char* endptr; 00284 long p = strtol( str, &endptr, 0 ); 00285 if( !endptr || *endptr || p < 0 || p > 100 ) usage(); 00286 00287 list.push_back( (int)p ); 00288 } 00289 00290 int parse_positive_int( const char* str ) 00291 { 00292 char* endptr; 00293 long p = strtol( str, &endptr, 0 ); 00294 if( !endptr || *endptr || p < 1 ) usage(); 00295 int result = p; 00296 if( p != (long)result ) // overflow 00297 usage(); 00298 00299 return result; 00300 } 00301 00302 void check_default( std::vector< int >& list, const int* array, size_t array_len ) 00303 { 00304 if( list.empty() ) std::copy( array, array + array_len, std::back_inserter( list ) ); 00305 } 00306 00307 int main( int argc, char* argv[] ) 00308 { 00309 // Parse arguments 00310 std::vector< int > createList, orderList, deleteList; 00311 numSideInt = default_intervals; 00312 queryCount = default_query_count; 00313 00314 for( int i = 1; i < argc; ++i ) 00315 { 00316 // check that arg is a '-' followed by a single character 00317 if( argv[i][0] != '-' || argv[i][1] == '\0' || argv[i][2] != '\0' ) usage(); 00318 00319 const char flag = argv[i][1]; 00320 switch( flag ) 00321 { 00322 case 'b': 00323 createList.push_back( 1 ); 00324 break; 00325 case 's': 00326 createList.push_back( 0 ); 00327 break; 00328 default: 00329 if( ++i == argc ) usage(); 00330 switch( flag ) 00331 { 00332 case 'i': 00333 numSideInt = parse_positive_int( argv[i] ); 00334 break; 00335 case 'o': 00336 parse_order( argv[i], orderList ); 00337 break; 00338 case 'd': 00339 parse_percent( argv[i], deleteList ); 00340 break; 00341 case 'q': 00342 queryCount = parse_positive_int( argv[i] ); 00343 break; 00344 default: 00345 usage(); 00346 } 00347 } 00348 } 00349 check_default( createList, default_create, ARRSIZE( default_create ) ); 00350 check_default( orderList, default_order, ARRSIZE( default_order ) ); 00351 check_default( deleteList, default_delete, ARRSIZE( default_delete ) ); 00352 00353 // Do some initialization. 00354 00355 int numSideVert = numSideInt + 1; 00356 numVert = numSideVert * numSideVert * numSideVert; 00357 numElem = numSideInt * numSideInt * numSideInt; 00358 if( numVert / numSideVert / numSideVert != numSideVert ) // overflow 00359 usage(); 00360 init(); 00361 00362 // Echo input args 00363 00364 std::cout << numSideInt << "x" << numSideInt << "x" << numSideInt << " hex grid: " << numElem << " elements and " 00365 << numVert << " vertices" << std::endl; 00366 00367 // Run tests 00368 00369 std::vector< int >::const_iterator i, j, k; 00370 clock_t t = clock(); 00371 for( i = createList.begin(); i != createList.end(); ++i ) 00372 { 00373 for( j = deleteList.begin(); j != deleteList.end(); ++j ) 00374 { 00375 for( k = orderList.begin(); k != orderList.end(); ++k ) 00376 { 00377 do_test( *i, *k, *j ); 00378 } 00379 } 00380 } 00381 00382 // Clean up 00383 00384 std::cout << "TOTAL: " << ts( clock() - t ) << std::endl << std::endl; 00385 delete[] queryVertPermutation; 00386 delete[] queryElemPermutation; 00387 return 0; 00388 } 00389 00390 inline void vertex_coords( long vert_index, double& x, double& y, double& z ) 00391 { 00392 const long vs = numSideInt + 1; 00393 x = vert_index % vs; 00394 y = ( vert_index / vs ) % vs; 00395 z = ( vert_index / vs / vs ); 00396 } 00397 00398 inline long vert_index( long x, long y, long z ) 00399 { 00400 const long vs = numSideInt + 1; 00401 return x + vs * ( y + vs * z ); 00402 } 00403 00404 inline void element_conn( long elem_index, EntityHandle conn[8] ) 00405 { 00406 const long x = elem_index % numSideInt; 00407 const long y = ( elem_index / numSideInt ) % numSideInt; 00408 const long z = ( elem_index / numSideInt / numSideInt ); 00409 conn[0] = vertStart + vert_index( x, y, z ); 00410 conn[1] = vertStart + vert_index( x + 1, y, z ); 00411 conn[2] = vertStart + vert_index( x + 1, y + 1, z ); 00412 conn[3] = vertStart + vert_index( x, y + 1, z ); 00413 conn[4] = vertStart + vert_index( x, y, z + 1 ); 00414 conn[5] = vertStart + vert_index( x + 1, y, z + 1 ); 00415 conn[6] = vertStart + vert_index( x + 1, y + 1, z + 1 ); 00416 conn[7] = vertStart + vert_index( x, y + 1, z + 1 ); 00417 } 00418 00419 inline bool deleted_vert( long index, int percent ) 00420 { 00421 return index % ( numSideInt + 1 ) >= ( numSideInt + 1 ) * ( 100 - percent ) / 100; 00422 } 00423 00424 inline bool deleted_elem( long index, int percent ) 00425 { 00426 return index % numSideInt + 1 >= ( numSideInt + 1 ) * ( 100 - percent ) / 100; 00427 } 00428 00429 void create_vertices_single() 00430 { 00431 double coords[3]; 00432 vertex_coords( 0, coords[0], coords[1], coords[2] ); 00433 ErrorCode rval = mb.create_vertex( coords, vertStart ); 00434 assert( !rval ); 00435 if( rval ) 00436 { 00437 } // empty line to remove compiler warning 00438 00439 EntityHandle h; 00440 for( long i = 1; i < numVert; ++i ) 00441 { 00442 vertex_coords( i, coords[0], coords[1], coords[2] ); 00443 rval = mb.create_vertex( coords, h ); 00444 assert( !rval ); 00445 assert( h - vertStart == (EntityHandle)i ); 00446 } 00447 } 00448 00449 void create_vertices_block() 00450 { 00451 std::vector< double* > arrays; 00452 ErrorCode rval = readTool->get_node_coords( 3, numVert, 0, vertStart, arrays ); 00453 if( rval || arrays.size() != 3 ) 00454 { 00455 assert( false ); 00456 abort(); 00457 } 00458 double *x = arrays[0], *y = arrays[1], *z = arrays[2]; 00459 assert( x && y && z ); 00460 00461 for( long i = 0; i < numVert; ++i ) 00462 vertex_coords( i, *x++, *y++, *z++ ); 00463 } 00464 00465 void create_elements_single() 00466 { 00467 EntityHandle conn[8]; 00468 element_conn( 0, conn ); 00469 ErrorCode rval = mb.create_element( MBHEX, conn, 8, elemStart ); 00470 if( rval ) 00471 { 00472 assert( false ); 00473 abort(); 00474 } 00475 00476 EntityHandle h; 00477 for( long i = 1; i < numElem; ++i ) 00478 { 00479 element_conn( i, conn ); 00480 rval = mb.create_element( MBHEX, conn, 8, h ); 00481 assert( !rval ); 00482 assert( h - elemStart == (EntityHandle)i ); 00483 } 00484 } 00485 00486 void create_elements_block() 00487 { 00488 EntityHandle* conn = 0; 00489 ErrorCode rval = readTool->get_element_connect( numElem, 8, MBHEX, 0, elemStart, conn ); 00490 if( rval && !conn ) 00491 { 00492 assert( false ); 00493 abort(); 00494 } 00495 00496 for( long i = 0; i < numElem; ++i ) 00497 element_conn( i, conn + 8 * i ); 00498 } 00499 00500 void forward_order_query_vertices( int percent ) 00501 { 00502 ErrorCode r; 00503 double coords[3]; 00504 long x, y, z; 00505 const long vert_per_edge = numSideInt + 1; 00506 const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100; 00507 EntityHandle h = vertStart; 00508 for( z = 0; z < vert_per_edge; ++z ) 00509 { 00510 for( y = 0; y < vert_per_edge; ++y ) 00511 { 00512 for( x = 0; x < deleted_x; ++x, ++h ) 00513 { 00514 r = mb.get_coords( &h, 1, coords ); 00515 if( MB_SUCCESS != r ) 00516 { 00517 assert( false ); 00518 abort(); 00519 } 00520 } 00521 h += ( vert_per_edge - deleted_x ); 00522 } 00523 } 00524 } 00525 00526 void reverse_order_query_vertices( int percent ) 00527 { 00528 ErrorCode r; 00529 double coords[3]; 00530 long x, y, z; 00531 const long vert_per_edge = numSideInt + 1; 00532 const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100; 00533 EntityHandle h = vertStart + numVert - 1; 00534 ; 00535 for( z = vert_per_edge - 1; z >= 0; --z ) 00536 { 00537 for( y = vert_per_edge - 1; y >= 0; --y ) 00538 { 00539 h -= ( vert_per_edge - deleted_x ); 00540 for( x = deleted_x - 1; x >= 0; --x, --h ) 00541 { 00542 r = mb.get_coords( &h, 1, coords ); 00543 assert( MB_SUCCESS == r ); 00544 if( r ) 00545 { 00546 } // empty line to remove compiler warning 00547 } 00548 } 00549 } 00550 } 00551 00552 void random_order_query_vertices( int percent ) 00553 { 00554 ErrorCode r; 00555 EntityHandle h; 00556 double coords[3]; 00557 for( long i = 0; i < numVert; ++i ) 00558 { 00559 if( !deleted_vert( queryVertPermutation[i], percent ) ) 00560 { 00561 h = vertStart + queryVertPermutation[i]; 00562 r = mb.get_coords( &h, 1, coords ); 00563 assert( MB_SUCCESS == r ); 00564 if( r ) 00565 { 00566 } // empty line to remove compiler warning 00567 } 00568 } 00569 } 00570 00571 void forward_order_query_elements( int percent ) 00572 { 00573 ErrorCode r; 00574 const EntityHandle* conn; 00575 int len; 00576 long x, y, z; 00577 const long elem_per_edge = numSideInt; 00578 const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1; 00579 EntityHandle h = elemStart; 00580 for( z = 0; z < elem_per_edge; ++z ) 00581 { 00582 for( y = 0; y < elem_per_edge; ++y ) 00583 { 00584 for( x = 0; x < deleted_x; ++x, ++h ) 00585 { 00586 r = mb.get_connectivity( h, conn, len ); 00587 assert( MB_SUCCESS == r ); 00588 if( r ) 00589 { 00590 } // empty line to remove compiler warning 00591 assert( conn && 8 == len ); 00592 } 00593 h += ( elem_per_edge - deleted_x ); 00594 } 00595 } 00596 } 00597 00598 void reverse_order_query_elements( int percent ) 00599 { 00600 ErrorCode r; 00601 const EntityHandle* conn; 00602 int len; 00603 long x, y, z; 00604 const long elem_per_edge = numSideInt; 00605 const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1; 00606 EntityHandle h = elemStart + numElem - 1; 00607 ; 00608 for( z = elem_per_edge - 1; z >= 0; --z ) 00609 { 00610 for( y = elem_per_edge - 1; y >= 0; --y ) 00611 { 00612 h -= ( elem_per_edge - deleted_x ); 00613 for( x = deleted_x - 1; x >= 0; --x, --h ) 00614 { 00615 r = mb.get_connectivity( h, conn, len ); 00616 assert( MB_SUCCESS == r ); 00617 if( r ) 00618 { 00619 } // empty line to remove compiler warning 00620 assert( conn && 8 == len ); 00621 } 00622 } 00623 } 00624 } 00625 00626 void random_order_query_elements( int percent ) 00627 { 00628 ErrorCode r; 00629 const EntityHandle* conn; 00630 int len; 00631 for( long i = 0; i < numElem; ++i ) 00632 { 00633 if( !deleted_elem( queryElemPermutation[i], percent ) ) 00634 { 00635 r = mb.get_connectivity( elemStart + queryElemPermutation[i], conn, len ); 00636 assert( MB_SUCCESS == r ); 00637 if( r ) 00638 { 00639 } // empty line to remove compiler warning 00640 assert( conn && 8 == len ); 00641 } 00642 } 00643 } 00644 00645 /* 00646 static double hex_centroid( double coords[24], double cent[3] ) 00647 { 00648 double a[3], b[3], c[3], vol; 00649 cent[0] += 0.125*(coords[0] + coords[3] + coords[6] + coords[ 9] + coords[12] + coords[15] + 00650 coords[18] + coords[21]); cent[1] += 0.125*(coords[1] + coords[4] + coords[7] + coords[10] + 00651 coords[13] + coords[16] + coords[19] + coords[22]); cent[2] += 0.125*(coords[2] + coords[5] + 00652 coords[8] + coords[11] + coords[14] + coords[17] + coords[20] + coords[23]); a[0] = coords[0] + 00653 coords[3] + coords[15] + coords[12] - coords[ 9] - coords[6] - coords[18] - coords[21]; a[1] = 00654 coords[1] + coords[4] + coords[16] + coords[13] - coords[10] - coords[7] - coords[19] - coords[22]; 00655 a[2] = coords[2] + coords[5] + coords[17] + coords[14] - coords[11] - coords[8] - coords[20] - 00656 coords[23]; b[0] = coords[0] + coords[ 9] + coords[21] + coords[12] - coords[3] - coords[6] - 00657 coords[18] - coords[15]; b[1] = coords[1] + coords[10] + coords[22] + coords[13] - coords[4] - 00658 coords[7] - coords[19] - coords[16]; b[2] = coords[2] + coords[11] + coords[23] + coords[14] - 00659 coords[5] - coords[8] - coords[20] - coords[17]; c[0] = coords[0] + coords[3] + coords[6] + coords[ 00660 9] - coords[12] - coords[15] - coords[18] - coords[21]; c[1] = coords[1] + coords[4] + coords[7] + 00661 coords[10] - coords[13] - coords[16] - coords[19] - coords[22]; c[2] = coords[2] + coords[5] + 00662 coords[8] + coords[11] - coords[14] - coords[17] - coords[20] - coords[23]; vol = c[0]*(a[1]*b[2] - 00663 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; 00664 } 00665 */ 00666 00667 void forward_order_query_element_verts( int percent ) 00668 { 00669 ErrorCode r = MB_SUCCESS; 00670 if( r ) 00671 { 00672 } // empty line to remove compiler warning 00673 const EntityHandle* conn; 00674 int len; 00675 long x, y, z; 00676 double coords[24]; 00677 const long elem_per_edge = numSideInt; 00678 const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1; 00679 EntityHandle h = elemStart; 00680 for( z = 0; z < elem_per_edge; ++z ) 00681 { 00682 for( y = 0; y < elem_per_edge; ++y ) 00683 { 00684 for( x = 0; x < deleted_x; ++x, ++h ) 00685 { 00686 r = mb.get_connectivity( h, conn, len ); 00687 assert( MB_SUCCESS == r ); 00688 assert( conn && 8 == len ); 00689 r = mb.get_coords( conn, len, coords ); 00690 assert( MB_SUCCESS == r ); 00691 } 00692 h += ( elem_per_edge - deleted_x ); 00693 } 00694 } 00695 } 00696 00697 void reverse_order_query_element_verts( int percent ) 00698 { 00699 ErrorCode r = MB_SUCCESS; 00700 if( r ) 00701 { 00702 } // empty statement to remove compiler warning 00703 00704 const EntityHandle* conn; 00705 int len; 00706 long x, y, z; 00707 double coords[24]; 00708 const long elem_per_edge = numSideInt; 00709 const long deleted_x = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1; 00710 EntityHandle h = elemStart + numElem - 1; 00711 ; 00712 for( z = elem_per_edge - 1; z >= 0; --z ) 00713 { 00714 for( y = elem_per_edge - 1; y >= 0; --y ) 00715 { 00716 h -= ( elem_per_edge - deleted_x ); 00717 for( x = deleted_x - 1; x >= 0; --x, --h ) 00718 { 00719 r = mb.get_connectivity( h, conn, len ); 00720 assert( MB_SUCCESS == r ); 00721 assert( conn && 8 == len ); 00722 r = mb.get_coords( conn, len, coords ); 00723 assert( MB_SUCCESS == r ); 00724 } 00725 } 00726 } 00727 } 00728 00729 void random_order_query_element_verts( int percent ) 00730 { 00731 ErrorCode r = MB_SUCCESS; 00732 if( r ) 00733 { 00734 } // empty line to remove compiler warning 00735 const EntityHandle* conn; 00736 int len; 00737 double coords[24]; 00738 for( long i = 0; i < numElem; ++i ) 00739 { 00740 if( !deleted_elem( queryElemPermutation[i], percent ) ) 00741 { 00742 r = mb.get_connectivity( elemStart + queryElemPermutation[i], conn, len ); 00743 assert( MB_SUCCESS == r ); 00744 assert( conn && 8 == len ); 00745 r = mb.get_coords( conn, len, coords ); 00746 assert( MB_SUCCESS == r ); 00747 } 00748 } 00749 } 00750 00751 void forward_order_delete_vertices( int percent ) 00752 { 00753 for( long i = 0; i < numVert; ++i ) 00754 delete_vert( i, percent ); 00755 } 00756 00757 void reverse_order_delete_vertices( int percent ) 00758 { 00759 for( long i = numVert - 1; i >= 0; --i ) 00760 delete_vert( i, percent ); 00761 } 00762 00763 void random_order_delete_vertices( int percent ) 00764 { 00765 for( long i = 0; i < numVert; ++i ) 00766 delete_vert( queryVertPermutation[i], percent ); 00767 } 00768 00769 void forward_order_delete_elements( int percent ) 00770 { 00771 for( long i = 0; i < numElem; ++i ) 00772 delete_elem( i, percent ); 00773 } 00774 00775 void reverse_order_delete_elements( int percent ) 00776 { 00777 for( long i = numElem - 1; i >= 0; --i ) 00778 delete_elem( i, percent ); 00779 } 00780 00781 void random_order_delete_elements( int percent ) 00782 { 00783 for( long i = 0; i < numElem; ++i ) 00784 delete_elem( queryElemPermutation[i], percent ); 00785 } 00786 00787 void create_missing_vertices( int percent ) 00788 { 00789 EntityHandle h; 00790 ErrorCode rval = MB_SUCCESS; 00791 if( rval ) 00792 { 00793 } // empty line to remove compiler warning 00794 double coords[3]; 00795 for( long i = 0; i < numVert; ++i ) 00796 if( deleted_vert( i, percent ) ) 00797 { 00798 vertex_coords( i, coords[0], coords[1], coords[2] ); 00799 rval = mb.create_vertex( coords, h ); 00800 assert( !rval ); 00801 } 00802 } 00803 00804 void create_missing_elements( int percent ) 00805 { 00806 EntityHandle h; 00807 ErrorCode rval; 00808 EntityHandle conn[8]; 00809 for( long i = 0; i < numElem; ++i ) 00810 if( deleted_elem( i, percent ) ) 00811 { 00812 element_conn( i, conn ); 00813 rval = mb.create_element( MBHEX, conn, 8, h ); 00814 if( rval ) 00815 { 00816 assert( false ); 00817 abort(); 00818 } 00819 } 00820 } 00821 00822 inline void delete_vert( long index, int percent ) 00823 { 00824 if( deleted_vert( index, percent ) ) 00825 { 00826 EntityHandle h = index + vertStart; 00827 ErrorCode rval = mb.delete_entities( &h, 1 ); 00828 if( rval ) 00829 { 00830 assert( false ); 00831 abort(); 00832 } 00833 } 00834 } 00835 00836 inline void delete_elem( long index, int percent ) 00837 { 00838 if( deleted_elem( index, percent ) ) 00839 { 00840 EntityHandle h = index + elemStart; 00841 ErrorCode rval = mb.delete_entities( &h, 1 ); 00842 if( rval ) 00843 { 00844 assert( false ); 00845 abort(); 00846 } 00847 } 00848 } 00849 00850 #ifdef PRINT_SEQUENCE_COUNT 00851 unsigned get_number_sequences( EntityType type ) 00852 { 00853 #ifdef MB_ENTITY_SEQUENCE_HPP 00854 return mb_core.sequence_manager()->entity_map( type )->size(); 00855 #else 00856 return mb_core.sequence_manager()->entity_map( type ).get_sequence_count(); 00857 #endif 00858 } 00859 #endif