MOAB: Mesh Oriented datABase  (version 5.3.0)
seqperf.cpp
Go to the documentation of this file.
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 ) {}  // empty line to remove compiler warning
00436 
00437     EntityHandle h;
00438     for( long i = 1; i < numVert; ++i )
00439     {
00440         vertex_coords( i, coords[0], coords[1], coords[2] );
00441         rval = mb.create_vertex( coords, h );
00442         assert( !rval );
00443         assert( h - vertStart == (EntityHandle)i );
00444     }
00445 }
00446 
00447 void create_vertices_block()
00448 {
00449     std::vector< double* > arrays;
00450     ErrorCode rval = readTool->get_node_coords( 3, numVert, 0, vertStart, arrays );
00451     if( rval || arrays.size() != 3 )
00452     {
00453         assert( false );
00454         abort();
00455     }
00456     double *x = arrays[0], *y = arrays[1], *z = arrays[2];
00457     assert( x && y && z );
00458 
00459     for( long i = 0; i < numVert; ++i )
00460         vertex_coords( i, *x++, *y++, *z++ );
00461 }
00462 
00463 void create_elements_single()
00464 {
00465     EntityHandle conn[8];
00466     element_conn( 0, conn );
00467     ErrorCode rval = mb.create_element( MBHEX, conn, 8, elemStart );
00468     if( rval )
00469     {
00470         assert( false );
00471         abort();
00472     }
00473 
00474     EntityHandle h;
00475     for( long i = 1; i < numElem; ++i )
00476     {
00477         element_conn( i, conn );
00478         rval = mb.create_element( MBHEX, conn, 8, h );
00479         assert( !rval );
00480         assert( h - elemStart == (EntityHandle)i );
00481     }
00482 }
00483 
00484 void create_elements_block()
00485 {
00486     EntityHandle* conn = 0;
00487     ErrorCode rval     = readTool->get_element_connect( numElem, 8, MBHEX, 0, elemStart, conn );
00488     if( rval && !conn )
00489     {
00490         assert( false );
00491         abort();
00492     }
00493 
00494     for( long i = 0; i < numElem; ++i )
00495         element_conn( i, conn + 8 * i );
00496 }
00497 
00498 void forward_order_query_vertices( int percent )
00499 {
00500     ErrorCode r;
00501     double coords[3];
00502     long x, y, z;
00503     const long vert_per_edge = numSideInt + 1;
00504     const long deleted_x     = ( numSideInt + 1 ) * ( 100 - percent ) / 100;
00505     EntityHandle h           = vertStart;
00506     for( z = 0; z < vert_per_edge; ++z )
00507     {
00508         for( y = 0; y < vert_per_edge; ++y )
00509         {
00510             for( x = 0; x < deleted_x; ++x, ++h )
00511             {
00512                 r = mb.get_coords( &h, 1, coords );
00513                 if( MB_SUCCESS != r )
00514                 {
00515                     assert( false );
00516                     abort();
00517                 }
00518             }
00519             h += ( vert_per_edge - deleted_x );
00520         }
00521     }
00522 }
00523 
00524 void reverse_order_query_vertices( int percent )
00525 {
00526     ErrorCode r;
00527     double coords[3];
00528     long x, y, z;
00529     const long vert_per_edge = numSideInt + 1;
00530     const long deleted_x     = ( numSideInt + 1 ) * ( 100 - percent ) / 100;
00531     EntityHandle h           = vertStart + numVert - 1;
00532     ;
00533     for( z = vert_per_edge - 1; z >= 0; --z )
00534     {
00535         for( y = vert_per_edge - 1; y >= 0; --y )
00536         {
00537             h -= ( vert_per_edge - deleted_x );
00538             for( x = deleted_x - 1; x >= 0; --x, --h )
00539             {
00540                 r = mb.get_coords( &h, 1, coords );
00541                 assert( MB_SUCCESS == r );
00542                 if( r ) {}  // empty line to remove compiler warning
00543             }
00544         }
00545     }
00546 }
00547 
00548 void random_order_query_vertices( int percent )
00549 {
00550     ErrorCode r;
00551     EntityHandle h;
00552     double coords[3];
00553     for( long i = 0; i < numVert; ++i )
00554     {
00555         if( !deleted_vert( queryVertPermutation[i], percent ) )
00556         {
00557             h = vertStart + queryVertPermutation[i];
00558             r = mb.get_coords( &h, 1, coords );
00559             assert( MB_SUCCESS == r );
00560             if( r ) {}  // empty line to remove compiler warning
00561         }
00562     }
00563 }
00564 
00565 void forward_order_query_elements( int percent )
00566 {
00567     ErrorCode r;
00568     const EntityHandle* conn;
00569     int len;
00570     long x, y, z;
00571     const long elem_per_edge = numSideInt;
00572     const long deleted_x     = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
00573     EntityHandle h           = elemStart;
00574     for( z = 0; z < elem_per_edge; ++z )
00575     {
00576         for( y = 0; y < elem_per_edge; ++y )
00577         {
00578             for( x = 0; x < deleted_x; ++x, ++h )
00579             {
00580                 r = mb.get_connectivity( h, conn, len );
00581                 assert( MB_SUCCESS == r );
00582                 if( r ) {}  // empty line to remove compiler warning
00583                 assert( conn && 8 == len );
00584             }
00585             h += ( elem_per_edge - deleted_x );
00586         }
00587     }
00588 }
00589 
00590 void reverse_order_query_elements( int percent )
00591 {
00592     ErrorCode r;
00593     const EntityHandle* conn;
00594     int len;
00595     long x, y, z;
00596     const long elem_per_edge = numSideInt;
00597     const long deleted_x     = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
00598     EntityHandle h           = elemStart + numElem - 1;
00599     ;
00600     for( z = elem_per_edge - 1; z >= 0; --z )
00601     {
00602         for( y = elem_per_edge - 1; y >= 0; --y )
00603         {
00604             h -= ( elem_per_edge - deleted_x );
00605             for( x = deleted_x - 1; x >= 0; --x, --h )
00606             {
00607                 r = mb.get_connectivity( h, conn, len );
00608                 assert( MB_SUCCESS == r );
00609                 if( r ) {}  // empty line to remove compiler warning
00610                 assert( conn && 8 == len );
00611             }
00612         }
00613     }
00614 }
00615 
00616 void random_order_query_elements( int percent )
00617 {
00618     ErrorCode r;
00619     const EntityHandle* conn;
00620     int len;
00621     for( long i = 0; i < numElem; ++i )
00622     {
00623         if( !deleted_elem( queryElemPermutation[i], percent ) )
00624         {
00625             r = mb.get_connectivity( elemStart + queryElemPermutation[i], conn, len );
00626             assert( MB_SUCCESS == r );
00627             if( r ) {}  // empty line to remove compiler warning
00628             assert( conn && 8 == len );
00629         }
00630     }
00631 }
00632 
00633 /*
00634 static double hex_centroid( double coords[24], double cent[3] )
00635 {
00636   double a[3], b[3], c[3], vol;
00637   cent[0] += 0.125*(coords[0] + coords[3] + coords[6] + coords[ 9] + coords[12] + coords[15] +
00638 coords[18] + coords[21]); cent[1] += 0.125*(coords[1] + coords[4] + coords[7] + coords[10] +
00639 coords[13] + coords[16] + coords[19] + coords[22]); cent[2] += 0.125*(coords[2] + coords[5] +
00640 coords[8] + coords[11] + coords[14] + coords[17] + coords[20] + coords[23]); a[0] = coords[0] +
00641 coords[3] + coords[15] + coords[12] - coords[ 9] - coords[6] - coords[18] - coords[21]; a[1] =
00642 coords[1] + coords[4] + coords[16] + coords[13] - coords[10] - coords[7] - coords[19] - coords[22];
00643   a[2] = coords[2] + coords[5] + coords[17] + coords[14] - coords[11] - coords[8] - coords[20] -
00644 coords[23]; b[0] = coords[0] + coords[ 9] + coords[21] + coords[12] - coords[3] - coords[6] -
00645 coords[18] - coords[15]; b[1] = coords[1] + coords[10] + coords[22] + coords[13] - coords[4] -
00646 coords[7] - coords[19] - coords[16]; b[2] = coords[2] + coords[11] + coords[23] + coords[14] -
00647 coords[5] - coords[8] - coords[20] - coords[17]; c[0] = coords[0] + coords[3] + coords[6] + coords[
00648 9] - coords[12] - coords[15] - coords[18] - coords[21]; c[1] = coords[1] + coords[4] + coords[7] +
00649 coords[10] - coords[13] - coords[16] - coords[19] - coords[22]; c[2] = coords[2] + coords[5] +
00650 coords[8] + coords[11] - coords[14] - coords[17] - coords[20] - coords[23]; vol = c[0]*(a[1]*b[2] -
00651 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;
00652 }
00653 */
00654 
00655 void forward_order_query_element_verts( int percent )
00656 {
00657     ErrorCode r = MB_SUCCESS;
00658     if( r ) {}  // empty line to remove compiler warning
00659     const EntityHandle* conn;
00660     int len;
00661     long x, y, z;
00662     double coords[24];
00663     const long elem_per_edge = numSideInt;
00664     const long deleted_x     = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
00665     EntityHandle h           = elemStart;
00666     for( z = 0; z < elem_per_edge; ++z )
00667     {
00668         for( y = 0; y < elem_per_edge; ++y )
00669         {
00670             for( x = 0; x < deleted_x; ++x, ++h )
00671             {
00672                 r = mb.get_connectivity( h, conn, len );
00673                 assert( MB_SUCCESS == r );
00674                 assert( conn && 8 == len );
00675                 r = mb.get_coords( conn, len, coords );
00676                 assert( MB_SUCCESS == r );
00677             }
00678             h += ( elem_per_edge - deleted_x );
00679         }
00680     }
00681 }
00682 
00683 void reverse_order_query_element_verts( int percent )
00684 {
00685     ErrorCode r = MB_SUCCESS;
00686     if( r ) {}  // empty statement to remove compiler warning
00687 
00688     const EntityHandle* conn;
00689     int len;
00690     long x, y, z;
00691     double coords[24];
00692     const long elem_per_edge = numSideInt;
00693     const long deleted_x     = ( numSideInt + 1 ) * ( 100 - percent ) / 100 - 1;
00694     EntityHandle h           = elemStart + numElem - 1;
00695     ;
00696     for( z = elem_per_edge - 1; z >= 0; --z )
00697     {
00698         for( y = elem_per_edge - 1; y >= 0; --y )
00699         {
00700             h -= ( elem_per_edge - deleted_x );
00701             for( x = deleted_x - 1; x >= 0; --x, --h )
00702             {
00703                 r = mb.get_connectivity( h, conn, len );
00704                 assert( MB_SUCCESS == r );
00705                 assert( conn && 8 == len );
00706                 r = mb.get_coords( conn, len, coords );
00707                 assert( MB_SUCCESS == r );
00708             }
00709         }
00710     }
00711 }
00712 
00713 void random_order_query_element_verts( int percent )
00714 {
00715     ErrorCode r = MB_SUCCESS;
00716     if( r ) {}  // empty line to remove compiler warning
00717     const EntityHandle* conn;
00718     int len;
00719     double coords[24];
00720     for( long i = 0; i < numElem; ++i )
00721     {
00722         if( !deleted_elem( queryElemPermutation[i], percent ) )
00723         {
00724             r = mb.get_connectivity( elemStart + queryElemPermutation[i], conn, len );
00725             assert( MB_SUCCESS == r );
00726             assert( conn && 8 == len );
00727             r = mb.get_coords( conn, len, coords );
00728             assert( MB_SUCCESS == r );
00729         }
00730     }
00731 }
00732 
00733 void forward_order_delete_vertices( int percent )
00734 {
00735     for( long i = 0; i < numVert; ++i )
00736         delete_vert( i, percent );
00737 }
00738 
00739 void reverse_order_delete_vertices( int percent )
00740 {
00741     for( long i = numVert - 1; i >= 0; --i )
00742         delete_vert( i, percent );
00743 }
00744 
00745 void random_order_delete_vertices( int percent )
00746 {
00747     for( long i = 0; i < numVert; ++i )
00748         delete_vert( queryVertPermutation[i], percent );
00749 }
00750 
00751 void forward_order_delete_elements( int percent )
00752 {
00753     for( long i = 0; i < numElem; ++i )
00754         delete_elem( i, percent );
00755 }
00756 
00757 void reverse_order_delete_elements( int percent )
00758 {
00759     for( long i = numElem - 1; i >= 0; --i )
00760         delete_elem( i, percent );
00761 }
00762 
00763 void random_order_delete_elements( int percent )
00764 {
00765     for( long i = 0; i < numElem; ++i )
00766         delete_elem( queryElemPermutation[i], percent );
00767 }
00768 
00769 void create_missing_vertices( int percent )
00770 {
00771     EntityHandle h;
00772     ErrorCode rval = MB_SUCCESS;
00773     if( rval ) {}  // empty line to remove compiler warning
00774     double coords[3];
00775     for( long i = 0; i < numVert; ++i )
00776         if( deleted_vert( i, percent ) )
00777         {
00778             vertex_coords( i, coords[0], coords[1], coords[2] );
00779             rval = mb.create_vertex( coords, h );
00780             assert( !rval );
00781         }
00782 }
00783 
00784 void create_missing_elements( int percent )
00785 {
00786     EntityHandle h;
00787     ErrorCode rval;
00788     EntityHandle conn[8];
00789     for( long i = 0; i < numElem; ++i )
00790         if( deleted_elem( i, percent ) )
00791         {
00792             element_conn( i, conn );
00793             rval = mb.create_element( MBHEX, conn, 8, h );
00794             if( rval )
00795             {
00796                 assert( false );
00797                 abort();
00798             }
00799         }
00800 }
00801 
00802 inline void delete_vert( long index, int percent )
00803 {
00804     if( deleted_vert( index, percent ) )
00805     {
00806         EntityHandle h = index + vertStart;
00807         ErrorCode rval = mb.delete_entities( &h, 1 );
00808         if( rval )
00809         {
00810             assert( false );
00811             abort();
00812         }
00813     }
00814 }
00815 
00816 inline void delete_elem( long index, int percent )
00817 {
00818     if( deleted_elem( index, percent ) )
00819     {
00820         EntityHandle h = index + elemStart;
00821         ErrorCode rval = mb.delete_entities( &h, 1 );
00822         if( rval )
00823         {
00824             assert( false );
00825             abort();
00826         }
00827     }
00828 }
00829 
00830 #ifdef PRINT_SEQUENCE_COUNT
00831 unsigned get_number_sequences( EntityType type )
00832 {
00833 #ifdef MB_ENTITY_SEQUENCE_HPP
00834     return mb_core.sequence_manager()->entity_map( type )->size();
00835 #else
00836     return mb_core.sequence_manager()->entity_map( type ).get_sequence_count();
00837 #endif
00838 }
00839 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines