MOAB: Mesh Oriented datABase  (version 5.4.1)
Test_MBMeshSet.cpp
Go to the documentation of this file.
00001 #include "MeshSet.hpp"
00002 #include "AEntityFactory.hpp"
00003 #include "TestUtil.hpp"
00004 #include "moab/Core.hpp"
00005 #include "moab/SetIterator.hpp"
00006 
00007 using namespace moab;
00008 
00009 #include <iostream>
00010 
00011 //! test add_entities, get_entities, num_entities
00012 void test_add_entities( unsigned flags );
00013 //! test remove_entities, get_entities, num_entities
00014 void test_remove_entities( unsigned flags );
00015 //! test get_entities_by_type, num_entities_by_type
00016 void test_entities_by_type( unsigned flags );
00017 //! test get_entities_by_dimension, num_entities_by_dimension
00018 void test_entities_by_dimension( unsigned flags );
00019 //! test subtract_meshset
00020 void test_subtract( unsigned flags1, unsigned flags2 );
00021 //! test intersect_meshset
00022 void test_intersect( unsigned flags1, unsigned flags2 );
00023 //! test unite_meshset
00024 void test_unite( unsigned flags1, unsigned flags2 );
00025 //! test MeshSet::contains_entities
00026 void test_contains_entities( unsigned flags );
00027 //! test clear_meshset
00028 void test_clear( unsigned flags );
00029 
00030 //! Create 10x10x10 hex mesh
00031 void make_mesh( Interface& iface );
00032 //! Create 10x10x10 hex mesh, return ranges of handles
00033 void make_mesh( Interface& iface, EntityHandle& vstart, EntityHandle& vend, EntityHandle& hstart, EntityHandle& hend );
00034 //! Print std::vector<EntityHandle>
00035 void print_handle_vect( const char* prefix, const std::vector< EntityHandle >& vect );
00036 //! Print Range
00037 void print_mbrange( const char* prefix, const Range& range );
00038 //! Compare set contents against passed vector, and if MESHSET_TRACK_OWNER then check adjacencies
00039 bool check_set_contents( Core& mb, EntityHandle set, const std::vector< EntityHandle >& expected );
00040 //! Compare result of get_entities_by_type to result of get_entities_by_handle
00041 bool check_set_contents( Core& mb, EntityType type, EntityHandle set, unsigned flags );
00042 //! Compare result of get_entities_by_dimension to result of get_entities_by_handle
00043 bool check_set_contents( Core& mb, int dim, EntityHandle set, unsigned flags );
00044 //! For each entry in range, if one or more occurances in vect, remove last occurance from vect.
00045 void remove_from_back( std::vector< EntityHandle >& vect, const Range& range );
00046 enum BoolOp
00047 {
00048     UNITE,
00049     INTERSECT,
00050     SUBTRACT
00051 };
00052 //! Perform boolean op on two entity sets and verify result
00053 bool test_boolean( Core& mb,
00054                    BoolOp op,
00055                    unsigned flags1,
00056                    const Range& set1_ents,
00057                    unsigned flags2,
00058                    const Range& set2_ents );
00059 void test_iterator( Interface& moab, SetIterator* iter, EntityHandle set, EntityType etype, int dim );
00060 void test_iterators( unsigned int flags, bool type, bool dim );
00061 void test_all_iterators();
00062 
00063 void test_add_entities_ordered()
00064 {
00065     test_add_entities( MESHSET_ORDERED );
00066 }
00067 void test_add_entities_set()
00068 {
00069     test_add_entities( MESHSET_SET );
00070 }
00071 void test_add_entities_ordered_tracking()
00072 {
00073     test_add_entities( MESHSET_TRACK_OWNER | MESHSET_ORDERED );
00074 }
00075 void test_add_entities_set_tracking()
00076 {
00077     test_add_entities( MESHSET_TRACK_OWNER | MESHSET_SET );
00078 }
00079 
00080 void test_remove_entities_ordered()
00081 {
00082     test_remove_entities( MESHSET_ORDERED );
00083 }
00084 void test_remove_entities_set()
00085 {
00086     test_remove_entities( MESHSET_SET );
00087 }
00088 void test_remove_entities_ordered_tracking()
00089 {
00090     test_remove_entities( MESHSET_TRACK_OWNER | MESHSET_ORDERED );
00091 }
00092 void test_remove_entities_set_tracking()
00093 {
00094     test_remove_entities( MESHSET_TRACK_OWNER | MESHSET_SET );
00095 }
00096 
00097 void test_entities_by_type_ordered()
00098 {
00099     test_entities_by_type( MESHSET_ORDERED );
00100 }
00101 void test_entities_by_type_set()
00102 {
00103     test_entities_by_type( MESHSET_SET );
00104 }
00105 void test_entities_by_dim_ordered()
00106 {
00107     test_entities_by_dimension( MESHSET_ORDERED );
00108 }
00109 void test_entities_by_dim_set()
00110 {
00111     test_entities_by_dimension( MESHSET_SET );
00112 }
00113 
00114 void test_subtract_set_set()
00115 {
00116     test_subtract( MESHSET_SET, MESHSET_SET );
00117 }
00118 void test_subtract_set_ordered()
00119 {
00120     test_subtract( MESHSET_SET, MESHSET_ORDERED );
00121 }
00122 void test_subtract_ordered_set()
00123 {
00124     test_subtract( MESHSET_ORDERED, MESHSET_SET );
00125 }
00126 void test_subtract_ordered_ordered()
00127 {
00128     test_subtract( MESHSET_ORDERED, MESHSET_ORDERED );
00129 }
00130 void test_subtract_set_set_tracking()
00131 {
00132     test_subtract( MESHSET_TRACK_OWNER | MESHSET_SET, MESHSET_TRACK_OWNER | MESHSET_SET );
00133 }
00134 void test_subtract_set_ordered_tracking()
00135 {
00136     test_subtract( MESHSET_TRACK_OWNER | MESHSET_SET, MESHSET_TRACK_OWNER | MESHSET_ORDERED );
00137 }
00138 void test_subtract_ordered_set_tracking()
00139 {
00140     test_subtract( MESHSET_TRACK_OWNER | MESHSET_ORDERED, MESHSET_TRACK_OWNER | MESHSET_SET );
00141 }
00142 void test_subtract_ordered_ordered_tracking()
00143 {
00144     test_subtract( MESHSET_TRACK_OWNER | MESHSET_ORDERED, MESHSET_TRACK_OWNER | MESHSET_ORDERED );
00145 }
00146 
00147 void test_itersect_set_set()
00148 {
00149     test_intersect( MESHSET_SET, MESHSET_SET );
00150 }
00151 void test_itersect_set_ordered()
00152 {
00153     test_intersect( MESHSET_SET, MESHSET_ORDERED );
00154 }
00155 void test_itersect_ordered_set()
00156 {
00157     test_intersect( MESHSET_ORDERED, MESHSET_SET );
00158 }
00159 void test_itersect_ordered_ordered()
00160 {
00161     test_intersect( MESHSET_ORDERED, MESHSET_ORDERED );
00162 }
00163 void test_itersect_set_set_tracking()
00164 {
00165     test_intersect( MESHSET_TRACK_OWNER | MESHSET_SET, MESHSET_TRACK_OWNER | MESHSET_SET );
00166 }
00167 void test_itersect_set_ordered_tracking()
00168 {
00169     test_intersect( MESHSET_TRACK_OWNER | MESHSET_SET, MESHSET_TRACK_OWNER | MESHSET_ORDERED );
00170 }
00171 void test_itersect_ordered_set_tracking()
00172 {
00173     test_intersect( MESHSET_TRACK_OWNER | MESHSET_ORDERED, MESHSET_TRACK_OWNER | MESHSET_SET );
00174 }
00175 void test_itersect_ordered_ordered_tracking()
00176 {
00177     test_intersect( MESHSET_TRACK_OWNER | MESHSET_ORDERED, MESHSET_TRACK_OWNER | MESHSET_ORDERED );
00178 }
00179 
00180 void test_unite_set_set()
00181 {
00182     test_unite( MESHSET_SET, MESHSET_SET );
00183 }
00184 void test_unite_set_ordered()
00185 {
00186     test_unite( MESHSET_SET, MESHSET_ORDERED );
00187 }
00188 void test_unite_ordered_set()
00189 {
00190     test_unite( MESHSET_ORDERED, MESHSET_SET );
00191 }
00192 void test_unite_ordered_ordered()
00193 {
00194     test_unite( MESHSET_ORDERED, MESHSET_ORDERED );
00195 }
00196 void test_unite_set_set_tracking()
00197 {
00198     test_unite( MESHSET_TRACK_OWNER | MESHSET_SET, MESHSET_TRACK_OWNER | MESHSET_SET );
00199 }
00200 void test_unite_set_ordered_tracking()
00201 {
00202     test_unite( MESHSET_TRACK_OWNER | MESHSET_SET, MESHSET_TRACK_OWNER | MESHSET_ORDERED );
00203 }
00204 void test_unite_ordered_set_tracking()
00205 {
00206     test_unite( MESHSET_TRACK_OWNER | MESHSET_ORDERED, MESHSET_TRACK_OWNER | MESHSET_SET );
00207 }
00208 void test_unite_ordered_ordered_tracking()
00209 {
00210     test_unite( MESHSET_TRACK_OWNER | MESHSET_ORDERED, MESHSET_TRACK_OWNER | MESHSET_ORDERED );
00211 }
00212 
00213 void test_contains_entities_ordered()
00214 {
00215     test_contains_entities( MESHSET_ORDERED );
00216 }
00217 void test_contains_entities_set()
00218 {
00219     test_contains_entities( MESHSET_SET );
00220 }
00221 
00222 void test_clear_ordered()
00223 {
00224     test_clear( MESHSET_ORDERED );
00225 }
00226 void test_clear_set()
00227 {
00228     test_clear( MESHSET_SET );
00229 }
00230 void test_clear_ordered_tracking()
00231 {
00232     test_clear( MESHSET_TRACK_OWNER | MESHSET_ORDERED );
00233 }
00234 void test_clear_set_tracking()
00235 {
00236     test_clear( MESHSET_TRACK_OWNER | MESHSET_SET );
00237 }
00238 
00239 // Reproduce contitions that resulted in bug reported to
00240 // mailing list:
00241 // http://lists.mcs.anl.gov/pipermail/moab-dev/2010/002714.html
00242 void regression_insert_set_1();
00243 
00244 int main()
00245 {
00246     int err = 0;
00247 
00248     err += RUN_TEST( test_add_entities_ordered );
00249     err += RUN_TEST( test_add_entities_set );
00250     err += RUN_TEST( test_add_entities_ordered_tracking );
00251     err += RUN_TEST( test_add_entities_set_tracking );
00252 
00253     err += RUN_TEST( test_remove_entities_ordered );
00254     err += RUN_TEST( test_remove_entities_set );
00255     err += RUN_TEST( test_remove_entities_ordered_tracking );
00256     err += RUN_TEST( test_remove_entities_set_tracking );
00257 
00258     err += RUN_TEST( test_entities_by_type_ordered );
00259     err += RUN_TEST( test_entities_by_type_set );
00260     err += RUN_TEST( test_entities_by_dim_ordered );
00261     err += RUN_TEST( test_entities_by_dim_set );
00262 
00263     err += RUN_TEST( test_subtract_set_set );
00264     err += RUN_TEST( test_subtract_set_ordered );
00265     err += RUN_TEST( test_subtract_ordered_set );
00266     err += RUN_TEST( test_subtract_ordered_ordered );
00267     err += RUN_TEST( test_subtract_set_set_tracking );
00268     err += RUN_TEST( test_subtract_set_ordered_tracking );
00269     err += RUN_TEST( test_subtract_ordered_set_tracking );
00270     err += RUN_TEST( test_subtract_ordered_ordered_tracking );
00271 
00272     err += RUN_TEST( test_itersect_set_set );
00273     err += RUN_TEST( test_itersect_set_ordered );
00274     err += RUN_TEST( test_itersect_ordered_set );
00275     err += RUN_TEST( test_itersect_ordered_ordered );
00276     err += RUN_TEST( test_itersect_set_set_tracking );
00277     err += RUN_TEST( test_itersect_set_ordered_tracking );
00278     err += RUN_TEST( test_itersect_ordered_set_tracking );
00279     err += RUN_TEST( test_itersect_ordered_ordered_tracking );
00280 
00281     err += RUN_TEST( test_unite_set_set );
00282     err += RUN_TEST( test_unite_set_ordered );
00283     err += RUN_TEST( test_unite_ordered_set );
00284     err += RUN_TEST( test_unite_ordered_ordered );
00285     err += RUN_TEST( test_unite_set_set_tracking );
00286     err += RUN_TEST( test_unite_set_ordered_tracking );
00287     err += RUN_TEST( test_unite_ordered_set_tracking );
00288     err += RUN_TEST( test_unite_ordered_ordered_tracking );
00289 
00290     err += RUN_TEST( test_contains_entities_ordered );
00291     err += RUN_TEST( test_contains_entities_set );
00292 
00293     err += RUN_TEST( test_clear_ordered );
00294     err += RUN_TEST( test_clear_set );
00295     err += RUN_TEST( test_clear_ordered_tracking );
00296     err += RUN_TEST( test_clear_set_tracking );
00297 
00298     err += RUN_TEST( regression_insert_set_1 );
00299 
00300     err += RUN_TEST( test_all_iterators );
00301 
00302     if( !err )
00303         printf( "ALL TESTS PASSED\n" );
00304     else
00305         printf( "%d TESTS FAILED\n", err );
00306 
00307     return err;
00308 }
00309 
00310 // Create 100x100x100 hex mesh
00311 void make_mesh( Interface& iface )
00312 {
00313     const int dim = 10;
00314 
00315     // create vertices
00316     EntityHandle prev_handle = 0;
00317     for( int z = 0; z <= dim; ++z )
00318     {
00319         for( int y = 0; y <= dim; ++y )
00320         {
00321             for( int x = 0; x <= dim; ++x )
00322             {
00323                 const double coords[]   = { static_cast< double >( x ), static_cast< double >( y ),
00324                                           static_cast< double >( z ) };
00325                 EntityHandle new_handle = 0;
00326                 ErrorCode rval          = iface.create_vertex( coords, new_handle );CHECK_ERR( rval );
00327                 CHECK_EQUAL( ++prev_handle, new_handle );
00328             }
00329         }
00330     }
00331 
00332     // create hexes
00333     const int dim1 = dim + 1;
00334     const int dimq = dim1 * dim1;
00335     prev_handle    = FIRST_HANDLE( MBHEX );
00336     for( int z = 0; z < dim; ++z )
00337     {
00338         for( int y = 0; y < dim; ++y )
00339         {
00340             for( int x = 0; x < dim; ++x )
00341             {
00342                 const EntityHandle off    = 1 + x + dim1 * y + dimq * z;
00343                 const EntityHandle conn[] = { off,        off + 1,        off + 1 + dim1,        off + dim1,
00344                                               off + dimq, off + 1 + dimq, off + 1 + dim1 + dimq, off + dim1 + dimq };
00345                 EntityHandle new_handle   = 0;
00346                 ErrorCode rval            = iface.create_element( MBHEX, conn, 8, new_handle );CHECK_ERR( rval );
00347                 CHECK_EQUAL( prev_handle++, new_handle );
00348             }
00349         }
00350     }
00351 }
00352 
00353 void make_mesh( Interface& mb,
00354                 EntityHandle& first_vert,
00355                 EntityHandle& last_vert,
00356                 EntityHandle& first_hex,
00357                 EntityHandle& last_hex )
00358 {
00359     make_mesh( mb );
00360 
00361     // Get handle ranges, and validate assumption that handles
00362     // are contiguous.
00363     Range range;
00364     ErrorCode rval = mb.get_entities_by_type( 0, MBVERTEX, range );CHECK_ERR( rval );
00365     first_vert = range.front();
00366     last_vert  = range.back();
00367     CHECK_EQUAL( (EntityHandle)1331, last_vert - first_vert + 1 );
00368     range.clear();
00369     rval = mb.get_entities_by_type( 0, MBHEX, range );CHECK_ERR( rval );
00370     first_hex = range.front();
00371     last_hex  = range.back();
00372     CHECK_EQUAL( (EntityHandle)1000, last_hex - first_hex + 1 );
00373 }
00374 
00375 template < typename iter_type >
00376 void print_handles( std::ostream& str, const char* prefix, iter_type begin, iter_type end )
00377 {
00378     if( prefix ) str << prefix << ':';
00379     if( begin == end )
00380     {
00381         str << " (empty)" << std::endl;
00382         return;
00383     }
00384 
00385     iter_type i           = begin;
00386     EntityType prev_type  = TYPE_FROM_HANDLE( *i );
00387     EntityHandle prev_ent = *i;
00388     str << ' ' << CN::EntityTypeName( prev_type ) << ' ' << ID_FROM_HANDLE( *i );
00389     for( ;; )
00390     {
00391         iter_type j = i;
00392         for( ++j, ++prev_ent; j != end && *j == prev_ent; ++j, ++prev_ent )
00393             ;
00394         --prev_ent;
00395         if( prev_ent - *i > 1 )
00396             str << "-" << ID_FROM_HANDLE( prev_ent );
00397         else if( prev_ent - *i == 1 )
00398             str << ", " << ID_FROM_HANDLE( prev_ent );
00399 
00400         i = j;
00401         if( i == end ) break;
00402 
00403         str << ',';
00404         if( TYPE_FROM_HANDLE( *i ) != prev_type )
00405             str << ' ' << CN::EntityTypeName( prev_type = TYPE_FROM_HANDLE( *i ) );
00406         str << ' ' << ID_FROM_HANDLE( *i );
00407         prev_ent = *i;
00408     }
00409     str << std::endl;
00410 }
00411 
00412 void print_handle_vect( const char* prefix, const std::vector< EntityHandle >& vect )
00413 {
00414     print_handles( std::cout, prefix, vect.begin(), vect.end() );
00415 }
00416 
00417 void print_mbrange( const char* prefix, const Range& range )
00418 {
00419     print_handles( std::cout, prefix, range.begin(), range.end() );
00420 }
00421 
00422 bool compare_set_contents( unsigned flags,
00423                            const std::vector< EntityHandle >& expected,
00424                            int set_count,
00425                            std::vector< EntityHandle >& vect,
00426                            const Range& range )
00427 {
00428 
00429     std::vector< EntityHandle > sorted( expected );
00430     std::sort( sorted.begin(), sorted.end() );
00431     sorted.erase( std::unique( sorted.begin(), sorted.end() ), sorted.end() );
00432 
00433     int expected_size = 0;
00434     if( flags & MESHSET_ORDERED )
00435     {
00436         if( expected != vect )
00437         {
00438             std::cout << "Incorrect set contents from vector-based query" << std::endl;
00439             print_handle_vect( "Expected", expected );
00440             print_handle_vect( "Actual", vect );
00441             return false;
00442         }
00443         expected_size = expected.size();
00444     }
00445     else
00446     {
00447         if( sorted != vect )
00448         {
00449             std::cout << "Incorrect set contents from vector-based query" << std::endl;
00450             print_handle_vect( "Expected", sorted );
00451             print_handle_vect( "Actual", vect );
00452             return false;
00453         }
00454         expected_size = sorted.size();
00455     }
00456 
00457     if( expected_size != set_count )
00458     {
00459         std::cout << "Incorrect size for entity set" << std::endl;
00460         std::cout << "Expected: " << expected_size << std::endl;
00461         std::cout << "Actual:   " << set_count << std::endl;
00462         return false;
00463     }
00464 
00465     vect.clear();
00466     vect.resize( range.size() );
00467     std::copy( range.begin(), range.end(), vect.begin() );
00468     if( sorted != vect )
00469     {
00470         std::cout << "Incorrect set contents from mbrange-based query" << std::endl;
00471         print_handle_vect( "Expected", vect );
00472         print_mbrange( "Actual", range );
00473         return false;
00474     }
00475 
00476     return true;
00477 }
00478 
00479 bool check_set_contents( Core& mb, EntityHandle set, const std::vector< EntityHandle >& expected )
00480 {
00481     unsigned flags;
00482     ErrorCode rval = mb.get_meshset_options( set, flags );CHECK_ERR( rval );
00483 
00484     int count;
00485     std::vector< EntityHandle > vect;
00486     Range range;
00487     rval = mb.get_entities_by_handle( set, vect, false );CHECK_ERR( rval );
00488     rval = mb.get_entities_by_handle( set, range, false );CHECK_ERR( rval );
00489     rval = mb.get_number_entities_by_handle( set, count, false );CHECK_ERR( rval );
00490 
00491     if( !compare_set_contents( flags, expected, count, vect, range ) ) return false;
00492 
00493     if( !( flags & MESHSET_TRACK_OWNER ) ) return true;
00494 
00495     // get all entitites with an adjacency to the set
00496     std::vector< EntityHandle > adj;
00497     Range all, adjacent;
00498     Range::iterator in = adjacent.begin();
00499     mb.get_entities_by_handle( 0, all );
00500     for( Range::iterator i = all.begin(); i != all.end(); ++i )
00501     {
00502         adj.clear();
00503         rval = mb.a_entity_factory()->get_adjacencies( *i, adj );CHECK_ERR( rval );
00504         std::vector< EntityHandle >::iterator j = std::lower_bound( adj.begin(), adj.end(), set );
00505         if( j != adj.end() && *j == set ) in = adjacent.insert( in, *i, *i );
00506     }
00507 
00508     if( range != adjacent )
00509     {
00510         std::cout << "Incorrect adjacent entities for tracking set" << std::endl;
00511         print_mbrange( "Expected", range );
00512         print_mbrange( "Actual", adjacent );
00513         return false;
00514     }
00515 
00516     return true;
00517 }
00518 
00519 bool check_set_contents( Core& mb, EntityType type, EntityHandle set, unsigned flags )
00520 {
00521     ErrorCode rval;
00522     int count;
00523     std::vector< EntityHandle > vect, expected;
00524     Range range;
00525 
00526     rval = mb.get_entities_by_handle( set, expected, false );CHECK_ERR( rval );
00527     std::vector< EntityHandle >::iterator i = expected.begin();
00528     while( i != expected.end() )
00529     {
00530         if( TYPE_FROM_HANDLE( *i ) != type )
00531             i = expected.erase( i );
00532         else
00533             ++i;
00534     }
00535 
00536     rval = mb.get_entities_by_type( set, type, range, false );CHECK_ERR( rval );
00537     rval = mb.get_number_entities_by_type( set, type, count, false );CHECK_ERR( rval );
00538 
00539     std::copy( range.begin(), range.end(), std::back_inserter( vect ) );
00540     return compare_set_contents( flags, expected, count, vect, range );
00541 }
00542 
00543 bool check_set_contents( Core& mb, int dim, EntityHandle set, unsigned flags )
00544 {
00545     ErrorCode rval;
00546     int count;
00547     std::vector< EntityHandle > vect, expected;
00548     Range range;
00549 
00550     rval = mb.get_entities_by_handle( set, expected, false );CHECK_ERR( rval );
00551     std::vector< EntityHandle >::iterator i = expected.begin();
00552     while( i != expected.end() )
00553     {
00554         if( CN::Dimension( TYPE_FROM_HANDLE( *i ) ) != dim )
00555             i = expected.erase( i );
00556         else
00557             ++i;
00558     }
00559 
00560     rval = mb.get_entities_by_dimension( set, dim, range, false );CHECK_ERR( rval );
00561     rval = mb.get_number_entities_by_dimension( set, dim, count, false );CHECK_ERR( rval );
00562 
00563     std::copy( range.begin(), range.end(), std::back_inserter( vect ) );
00564     return compare_set_contents( flags, expected, count, vect, range );
00565 }
00566 
00567 void test_add_entities( unsigned flags )
00568 {
00569     Core mb;
00570     make_mesh( mb );
00571 
00572     EntityHandle set;
00573     ErrorCode rval = mb.create_meshset( flags, set );CHECK_ERR( rval );
00574 
00575     std::vector< EntityHandle > contents, vect;
00576     Range range;
00577 
00578     range.clear();
00579     range.insert( 11, 20 );
00580     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00581     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00582     // [11,20]
00583     CHECK( check_set_contents( mb, set, contents ) );
00584 
00585     range.clear();
00586     range.insert( 31, 40 );
00587     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00588     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00589     // [11,20],[31,40]
00590     CHECK( check_set_contents( mb, set, contents ) );
00591 
00592     range.clear();
00593     range.insert( 51, 60 );
00594     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00595     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00596     // [11,20],[31,40],[51,60]
00597     CHECK( check_set_contents( mb, set, contents ) );
00598 
00599     range.clear();
00600     range.insert( 71, 80 );
00601     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00602     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00603     // [11,20],[31,40],[51,60],[71,80]
00604     CHECK( check_set_contents( mb, set, contents ) );
00605 
00606     range.clear();
00607     range.insert( 91, 100 );
00608     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00609     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00610     // [11,20],[31,40],[51,60],[71,80],[91,100]
00611     CHECK( check_set_contents( mb, set, contents ) );
00612 
00613     range.clear();
00614     range.insert( 111, 120 );
00615     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00616     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00617     // [11,20],[31,40],[51,60],[71,80],[91,100],[111,120]
00618     CHECK( check_set_contents( mb, set, contents ) );
00619 
00620     range.clear();
00621     range.insert( 6, 12 );
00622     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00623     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00624     // [6,20],[31,40],[51,60],[71,80],[91,100],[111,120]
00625     CHECK( check_set_contents( mb, set, contents ) );
00626 
00627     range.clear();
00628     range.insert( 1, 3 );
00629     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00630     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00631     // [1,3],[6,20],[31,40],[51,60],[71,80],[91,100],[111,120]
00632     CHECK( check_set_contents( mb, set, contents ) );
00633 
00634     range.clear();
00635     range.insert( 25, 25 );
00636     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00637     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00638     // [1,3],[6,20],[25,25],[31,40],[51,60],[71,80],[91,100],[111,120]
00639     CHECK( check_set_contents( mb, set, contents ) );
00640 
00641     range.clear();
00642     range.insert( 30, 30 );
00643     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00644     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00645     // [1,3],[6,20],[25,25],[30,40],[51,60],[71,80],[91,100],[111,120]
00646     CHECK( check_set_contents( mb, set, contents ) );
00647 
00648     range.clear();
00649     range.insert( 29, 31 );
00650     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00651     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00652     // [1,3],[6,20],[25,25],[29,40],[51,60],[71,80],[91,100],[111,120]
00653     CHECK( check_set_contents( mb, set, contents ) );
00654 
00655     range.clear();
00656     range.insert( 41, 41 );
00657     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00658     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00659     // [1,3],[6,20],[25,25],[29,41],[51,60],[71,80],[91,100],[111,120]
00660     CHECK( check_set_contents( mb, set, contents ) );
00661 
00662     range.clear();
00663     range.insert( 41, 45 );
00664     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00665     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00666     // [1,3],[6,20],[25,25],[29,45],[51,60],[71,80],[91,100],[111,120]
00667     CHECK( check_set_contents( mb, set, contents ) );
00668 
00669     range.clear();
00670     range.insert( 47, 47 );
00671     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00672     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00673     // [1,3],[6,20],[25,25],[29,45],[47,47],[51,60],[71,80],[91,100],[111,120]
00674     CHECK( check_set_contents( mb, set, contents ) );
00675 
00676     range.clear();
00677     range.insert( 51, 80 );
00678     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00679     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00680     // [1,3],[6,20],[25,25],[29,45],[47,47],[51,80],[91,100],[111,120]
00681     CHECK( check_set_contents( mb, set, contents ) );
00682 
00683     range.clear();
00684     range.insert( 49, 105 );
00685     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00686     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00687     // [1,3],[6,20],[25,25],[29,45],[47,47],[49,105],[111,120]
00688     CHECK( check_set_contents( mb, set, contents ) );
00689 
00690     vect.clear();
00691     for( EntityHandle h = 1; h < 100; ++h )
00692     {
00693         vect.push_back( h );
00694         contents.push_back( h );
00695     }
00696     rval = mb.add_entities( set, &vect[0], vect.size() );CHECK_ERR( rval );
00697     // [1,105],[111,120]
00698     CHECK( check_set_contents( mb, set, contents ) );
00699 
00700     vect.clear();
00701     vect.push_back( 106 );
00702     vect.push_back( 108 );
00703     vect.push_back( 110 );
00704     std::copy( vect.begin(), vect.end(), std::back_inserter( contents ) );
00705     rval = mb.add_entities( set, &vect[0], vect.size() );CHECK_ERR( rval );
00706     // [1,106],[108,108],[110,120]
00707     CHECK( check_set_contents( mb, set, contents ) );
00708 
00709     range.clear();
00710     range.insert( 107, 200 );
00711     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00712     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00713     // [1,200]
00714     CHECK( check_set_contents( mb, set, contents ) );
00715 
00716     range.clear();
00717     range.insert( 1, 1 );
00718     range.insert( 5, 6 );
00719     range.insert( 199, 200 );
00720     range.insert( 201, 202 );
00721     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00722     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00723     // [1,202]
00724     CHECK( check_set_contents( mb, set, contents ) );
00725 
00726     range.clear();
00727     range.insert( 300, 301 );
00728     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00729     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00730     // [1,202],[300,301]
00731     CHECK( check_set_contents( mb, set, contents ) );
00732 
00733     range.clear();
00734     range.insert( 203, 203 );
00735     range.insert( 205, 205 );
00736     range.insert( 207, 207 );
00737     range.insert( 299, 299 );
00738     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00739     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00740     // [1,203],[205,205],[207,207],[299,301]
00741     CHECK( check_set_contents( mb, set, contents ) );
00742 }
00743 
00744 void remove_from_back( std::vector< EntityHandle >& vect, const Range& range )
00745 {
00746     for( Range::const_iterator r = range.begin(); r != range.end(); ++r )
00747     {
00748         std::vector< EntityHandle >::reverse_iterator i = find( vect.rbegin(), vect.rend(), *r );
00749         if( i != vect.rend() ) *i = 0;
00750     }
00751     std::vector< EntityHandle >::iterator j = vect.begin();
00752     while( j != vect.end() )
00753     {
00754         if( *j == 0 )
00755             j = vect.erase( j );
00756         else
00757             ++j;
00758     }
00759 }
00760 
00761 void test_remove_entities( unsigned flags )
00762 {
00763     Core mb;
00764     make_mesh( mb );
00765 
00766     EntityHandle set;
00767     ErrorCode rval = mb.create_meshset( flags, set );CHECK_ERR( rval );
00768 
00769     std::vector< EntityHandle > contents;
00770     Range range;
00771 
00772     range.clear();
00773     range.insert( 1, 1000 );
00774     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00775     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00776     // [1,1000]
00777     CHECK( check_set_contents( mb, set, contents ) );
00778 
00779     range.clear();
00780     range.insert( 1, 5 );
00781     remove_from_back( contents, range );
00782     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00783     // [6,1000]
00784     CHECK( check_set_contents( mb, set, contents ) );
00785 
00786     range.clear();
00787     range.insert( 6, 6 );
00788     remove_from_back( contents, range );
00789     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00790     // [7,1000]
00791     CHECK( check_set_contents( mb, set, contents ) );
00792 
00793     range.clear();
00794     range.insert( 7, 10 );
00795     remove_from_back( contents, range );
00796     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00797     // [11,1000]
00798     CHECK( check_set_contents( mb, set, contents ) );
00799 
00800     range.clear();
00801     range.insert( 1, 20 );
00802     remove_from_back( contents, range );
00803     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00804     // [21,1000]
00805     CHECK( check_set_contents( mb, set, contents ) );
00806 
00807     range.clear();
00808     range.insert( 1, 5 );
00809     remove_from_back( contents, range );
00810     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00811     // [21,1000]
00812     CHECK( check_set_contents( mb, set, contents ) );
00813 
00814     range.clear();
00815     range.insert( 22, 30 );
00816     remove_from_back( contents, range );
00817     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00818     // [21,21],[31,1000]
00819     CHECK( check_set_contents( mb, set, contents ) );
00820 
00821     range.clear();
00822     range.insert( 1000, 1000 );
00823     remove_from_back( contents, range );
00824     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00825     // [21,21],[31,999]
00826     CHECK( check_set_contents( mb, set, contents ) );
00827 
00828     range.clear();
00829     range.insert( 901, 999 );
00830     remove_from_back( contents, range );
00831     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00832     // [21,21],[31,900]
00833     CHECK( check_set_contents( mb, set, contents ) );
00834 
00835     range.clear();
00836     range.insert( 900, 999 );
00837     remove_from_back( contents, range );
00838     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00839     // [21,21],[31,899]
00840     CHECK( check_set_contents( mb, set, contents ) );
00841 
00842     range.clear();
00843     range.insert( 1000, 1001 );
00844     remove_from_back( contents, range );
00845     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00846     // [21,21],[31,899]
00847     CHECK( check_set_contents( mb, set, contents ) );
00848 
00849     range.clear();
00850     range.insert( 890, 898 );
00851     remove_from_back( contents, range );
00852     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00853     // [21,21],[31,889],[899,899]
00854     CHECK( check_set_contents( mb, set, contents ) );
00855 
00856     range.clear();
00857     range.insert( 100, 149 );
00858     remove_from_back( contents, range );
00859     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00860     // [21,21],[31,99],[150,889],[899,899]
00861     CHECK( check_set_contents( mb, set, contents ) );
00862 
00863     range.clear();
00864     range.insert( 31, 99 );
00865     remove_from_back( contents, range );
00866     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00867     // [21,21],[150,889],[899,899]
00868     CHECK( check_set_contents( mb, set, contents ) );
00869 
00870     range.clear();
00871     range.insert( 200, 249 );
00872     remove_from_back( contents, range );
00873     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00874     // [21,21],[150,199],[250,889],[899,899]
00875     CHECK( check_set_contents( mb, set, contents ) );
00876 
00877     range.clear();
00878     range.insert( 300, 349 );
00879     remove_from_back( contents, range );
00880     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00881     // [21,21],[150,199],[250,299],[350,889],[899,899]
00882     CHECK( check_set_contents( mb, set, contents ) );
00883 
00884     range.clear();
00885     range.insert( 159, 399 );
00886     remove_from_back( contents, range );
00887     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00888     // [21,21],[150,158],[400,889],[899,899]
00889     CHECK( check_set_contents( mb, set, contents ) );
00890 
00891     range.clear();
00892     range.insert( 450, 499 );
00893     remove_from_back( contents, range );
00894     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00895     // [21,21],[150,158],[400,449],[500,889],[899,899]
00896     CHECK( check_set_contents( mb, set, contents ) );
00897 
00898     range.clear();
00899     range.insert( 550, 599 );
00900     remove_from_back( contents, range );
00901     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00902     // [21,21],[150,158],[400,449],[500,549],[600,889],[899,899]
00903     CHECK( check_set_contents( mb, set, contents ) );
00904 
00905     range.clear();
00906     range.insert( 150, 549 );
00907     remove_from_back( contents, range );
00908     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00909     // [21,21],[600,889],[899,899]
00910     CHECK( check_set_contents( mb, set, contents ) );
00911 
00912     range.clear();
00913     range.insert( 650, 699 );
00914     remove_from_back( contents, range );
00915     rval = mb.remove_entities( set, range );CHECK_ERR( rval );
00916     // [21,21],[600,649],[700,889],[899,899]
00917     CHECK( check_set_contents( mb, set, contents ) );
00918 
00919     // test vector-based remove
00920     assert( contents.size() == 242 );
00921     std::vector< EntityHandle > remlist( 5 );
00922     remlist[0] = contents[240];
00923     contents.erase( contents.begin() + 240 );
00924     remlist[1] = contents[200];
00925     contents.erase( contents.begin() + 200 );
00926     remlist[2] = contents[100];
00927     contents.erase( contents.begin() + 100 );
00928     remlist[3] = contents[25];
00929     contents.erase( contents.begin() + 25 );
00930     remlist[4] = contents[0];
00931     contents.erase( contents.begin() + 0 );
00932     rval = mb.remove_entities( set, &remlist[0], remlist.size() );CHECK_ERR( rval );
00933     // [600,623],[625,649],[700,748],[750,848],[850,888],[899,899]
00934     CHECK( check_set_contents( mb, set, contents ) );
00935 
00936     // remove everything
00937     std::reverse( contents.begin(), contents.begin() + contents.size() / 2 );  // mix up a bit
00938     rval = mb.remove_entities( set, &contents[0], contents.size() );CHECK_ERR( rval );
00939     contents.clear();
00940     CHECK( check_set_contents( mb, set, contents ) );
00941 
00942     // try complicated range-based remove
00943     range.clear();
00944     contents.clear();
00945     range.insert( 100, 200 );
00946     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00947     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00948     // [1000,2000]
00949     CHECK( check_set_contents( mb, set, contents ) );
00950 
00951     Range remove;
00952     remove.insert( 1, 3 );
00953     remove.insert( 10, 100 );
00954     remove.insert( 110, 120 );
00955     remove.insert( 130, 140 );
00956     remove.insert( 150, 160 );
00957     remove.insert( 190, 200 );
00958     remove.insert( 210, 220 );
00959     remove.insert( 230, 240 );
00960     range = subtract( range, remove );
00961 
00962     contents.clear();
00963     std::copy( range.begin(), range.end(), std::back_inserter( contents ) );
00964     rval = mb.remove_entities( set, remove );CHECK_ERR( rval );
00965     CHECK( check_set_contents( mb, set, contents ) );
00966 }
00967 
00968 void test_entities_by_type( unsigned flags )
00969 {
00970     EntityHandle first_vert, last_vert, first_hex, last_hex;
00971     Core mb;
00972     make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
00973 
00974     // Create an entity set
00975     EntityHandle set;
00976     ErrorCode rval = mb.create_meshset( flags, set );CHECK_ERR( rval );
00977 
00978     // Test empty set
00979     CHECK( check_set_contents( mb, MBVERTEX, set, flags ) );
00980     CHECK( check_set_contents( mb, MBEDGE, set, flags ) );
00981     CHECK( check_set_contents( mb, MBHEX, set, flags ) );
00982 
00983     // Add stuff to set
00984     Range range;
00985     range.insert( first_vert, first_vert + 10 );
00986     range.insert( first_vert + 100, first_vert + 110 );
00987     range.insert( first_hex + 200, first_hex + 299 );
00988     range.insert( last_hex, last_hex - 99 );
00989     rval = mb.add_entities( set, range );CHECK_ERR( rval );
00990 
00991     // Test
00992     CHECK( check_set_contents( mb, MBVERTEX, set, flags ) );
00993     CHECK( check_set_contents( mb, MBEDGE, set, flags ) );
00994     CHECK( check_set_contents( mb, MBHEX, set, flags ) );
00995 }
00996 
00997 void test_entities_by_dimension( unsigned flags )
00998 {
00999     EntityHandle first_vert, last_vert, first_hex, last_hex;
01000     Core mb;
01001     make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
01002 
01003     // Create an entity set
01004     EntityHandle set;
01005     ErrorCode rval = mb.create_meshset( flags, set );CHECK_ERR( rval );
01006 
01007     // Test empty set
01008     CHECK( check_set_contents( mb, 0, set, flags ) );
01009     CHECK( check_set_contents( mb, 1, set, flags ) );
01010     CHECK( check_set_contents( mb, 2, set, flags ) );
01011     CHECK( check_set_contents( mb, 3, set, flags ) );
01012 
01013     // Add stuff to set
01014     Range range;
01015     range.insert( first_vert, first_vert + 10 );
01016     range.insert( first_vert + 100, first_vert + 110 );
01017     range.insert( first_hex + 200, first_hex + 299 );
01018     range.insert( last_hex, last_hex - 99 );
01019     rval = mb.add_entities( set, range );CHECK_ERR( rval );
01020 
01021     // Test
01022     CHECK( check_set_contents( mb, 0, set, flags ) );
01023     CHECK( check_set_contents( mb, 1, set, flags ) );
01024     CHECK( check_set_contents( mb, 2, set, flags ) );
01025     CHECK( check_set_contents( mb, 3, set, flags ) );
01026 }
01027 
01028 bool test_boolean( Core& mb,
01029                    BoolOp op,
01030                    unsigned flags1,
01031                    const Range& set1_ents,
01032                    unsigned flags2,
01033                    const Range& set2_ents )
01034 {
01035     ErrorCode rval;
01036 
01037     // make sets
01038     EntityHandle set1, set2;
01039     rval = mb.create_meshset( flags1, set1 );CHECK_ERR( rval );
01040     rval = mb.create_meshset( flags2, set2 );CHECK_ERR( rval );
01041     rval = mb.add_entities( set1, set1_ents );CHECK_ERR( rval );
01042     rval = mb.add_entities( set2, set2_ents );CHECK_ERR( rval );
01043 
01044     Range tmp_range;
01045     std::vector< EntityHandle > expected;
01046     rval = MB_INDEX_OUT_OF_RANGE;
01047     switch( op )
01048     {
01049         case UNITE:
01050             if( flags1 & MESHSET_SET )
01051             {
01052                 tmp_range = set1_ents;
01053                 tmp_range.merge( set2_ents );
01054                 expected.resize( tmp_range.size() );
01055                 std::copy( tmp_range.begin(), tmp_range.end(), expected.begin() );
01056             }
01057             else
01058             {
01059                 expected.clear();
01060                 std::copy( set1_ents.begin(), set1_ents.end(), std::back_inserter( expected ) );
01061                 std::copy( set2_ents.begin(), set2_ents.end(), std::back_inserter( expected ) );
01062             }
01063             rval = mb.unite_meshset( set1, set2 );
01064             break;
01065         case INTERSECT:
01066             tmp_range = intersect( set1_ents, set2_ents );
01067             expected.resize( tmp_range.size() );
01068             std::copy( tmp_range.begin(), tmp_range.end(), expected.begin() );
01069             rval = mb.intersect_meshset( set1, set2 );
01070             break;
01071         case SUBTRACT:
01072             tmp_range = subtract( set1_ents, set2_ents );
01073             expected.resize( tmp_range.size() );
01074             std::copy( tmp_range.begin(), tmp_range.end(), expected.begin() );
01075             rval = mb.subtract_meshset( set1, set2 );
01076             break;
01077     }
01078     CHECK_ERR( rval );
01079 
01080     return check_set_contents( mb, set1, expected );
01081 }
01082 
01083 void test_intersect( unsigned flags1, unsigned flags2 )
01084 {
01085     Range empty, set1_ents, set2_ents;
01086     EntityHandle first_vert, last_vert, first_hex, last_hex;
01087     Core mb;
01088     make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
01089 
01090     // define contents of first set
01091     set1_ents.insert( first_vert, first_vert + 10 );
01092     set1_ents.insert( first_vert + 100, first_vert + 199 );
01093     set1_ents.insert( first_hex + 100, first_hex + 200 );
01094 
01095     // define contents of second set
01096     set2_ents.insert( first_vert, first_vert );
01097     set2_ents.insert( first_vert + 10, first_vert + 10 );
01098     set2_ents.insert( first_vert + 90, first_vert + 209 );
01099     set2_ents.insert( first_hex + 50, first_hex + 300 );
01100 
01101     // check empty sets
01102     CHECK( test_boolean( mb, INTERSECT, flags1, empty, flags2, empty ) );
01103     // check intersection with 1 empty
01104     CHECK( test_boolean( mb, INTERSECT, flags1, empty, flags2, set2_ents ) );
01105     CHECK( test_boolean( mb, INTERSECT, flags1, set1_ents, flags2, empty ) );
01106     // check intersection of non-empty sets
01107     CHECK( test_boolean( mb, INTERSECT, flags1, set1_ents, flags2, set2_ents ) );
01108 }
01109 
01110 void test_unite( unsigned flags1, unsigned flags2 )
01111 {
01112     Range empty, set1_ents, set2_ents;
01113     EntityHandle first_vert, last_vert, first_hex, last_hex;
01114     Core mb;
01115     make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
01116 
01117     // define contents of first set
01118     set1_ents.insert( first_vert, first_vert + 10 );
01119     set1_ents.insert( first_vert + 100, first_vert + 199 );
01120     set1_ents.insert( first_hex + 100, first_hex + 200 );
01121 
01122     // define contents of second set
01123     set2_ents.insert( first_vert, first_vert );
01124     set2_ents.insert( first_vert + 11, first_vert + 99 );
01125     set2_ents.insert( first_vert + 150, first_vert + 209 );
01126     set2_ents.insert( first_vert + 211, first_vert + 211 );
01127     set2_ents.insert( first_hex + 50, first_hex + 99 );
01128 
01129     // check empty sets
01130     CHECK( test_boolean( mb, UNITE, flags1, empty, flags2, empty ) );
01131     // check union with 1 empty
01132     CHECK( test_boolean( mb, UNITE, flags1, empty, flags2, set2_ents ) );
01133     CHECK( test_boolean( mb, UNITE, flags1, set1_ents, flags2, empty ) );
01134     // check union of non-empty sets
01135     CHECK( test_boolean( mb, UNITE, flags1, set1_ents, flags2, set2_ents ) );
01136 }
01137 
01138 void test_subtract( unsigned flags1, unsigned flags2 )
01139 {
01140     Range empty, set1_ents, set2_ents;
01141     EntityHandle first_vert, last_vert, first_hex, last_hex;
01142     Core mb;
01143     make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
01144 
01145     // define contents of first set
01146     set1_ents.insert( first_vert, first_vert + 10 );
01147     set1_ents.insert( first_vert + 100, first_vert + 199 );
01148     set1_ents.insert( first_hex + 100, first_hex + 200 );
01149 
01150     // define contents of second set
01151     set2_ents.insert( first_vert, first_vert );
01152     set2_ents.insert( first_vert + 9, first_vert + 9 );
01153     set2_ents.insert( first_vert + 11, first_vert + 99 );
01154     set2_ents.insert( first_vert + 150, first_vert + 199 );
01155     set2_ents.insert( first_hex + 50, first_hex + 60 );
01156     set2_ents.insert( first_hex + 90, first_hex + 220 );
01157 
01158     // check empty sets
01159     CHECK( test_boolean( mb, SUBTRACT, flags1, empty, flags2, empty ) );
01160     // check union with 1 empty
01161     CHECK( test_boolean( mb, SUBTRACT, flags1, empty, flags2, set2_ents ) );
01162     CHECK( test_boolean( mb, SUBTRACT, flags1, set1_ents, flags2, empty ) );
01163     // check union of non-empty sets
01164     CHECK( test_boolean( mb, SUBTRACT, flags1, set1_ents, flags2, set2_ents ) );
01165 }
01166 
01167 void test_contains_entities( unsigned flags )
01168 {
01169     CHECK( !( flags & MESHSET_TRACK_OWNER ) );
01170     MeshSet set( flags );
01171     bool result;
01172 
01173     const EntityHandle entities[] = { 1, 2, 3, 6, 10, 11, 25, 100 };
01174     const int num_ents            = sizeof( entities ) / sizeof( EntityHandle );
01175     ErrorCode rval                = set.add_entities( entities, num_ents, 0, 0 );CHECK_ERR( rval );
01176 
01177     result = set.contains_entities( entities, num_ents, Interface::UNION );
01178     CHECK( result );
01179     result = set.contains_entities( entities, num_ents, Interface::INTERSECT );
01180     CHECK( result );
01181 
01182     result = set.contains_entities( entities, 1, Interface::UNION );
01183     CHECK( result );
01184     result = set.contains_entities( entities, 1, Interface::INTERSECT );
01185     CHECK( result );
01186 
01187     const EntityHandle entities2[] = { 3, 4, 5 };
01188     const int num_ents2            = sizeof( entities2 ) / sizeof( EntityHandle );
01189     result                         = set.contains_entities( entities2, num_ents2, Interface::UNION );
01190     CHECK( result );
01191     result = set.contains_entities( entities2, num_ents2, Interface::INTERSECT );
01192     CHECK( !result );
01193 }
01194 
01195 void test_clear( unsigned flags )
01196 {
01197     std::vector< EntityHandle > contents( 4 );
01198     Core mb;
01199     make_mesh( mb, contents[0], contents[1], contents[2], contents[3] );
01200     EntityHandle set;
01201     ErrorCode rval = mb.create_meshset( flags, set );CHECK_ERR( rval );
01202     rval = mb.add_entities( set, &contents[0], contents.size() );CHECK_ERR( rval );
01203     CHECK( check_set_contents( mb, set, contents ) );
01204     rval = mb.clear_meshset( &set, 1 );CHECK_ERR( rval );
01205     contents.clear();
01206     CHECK( check_set_contents( mb, set, contents ) );
01207 }
01208 
01209 void regression_insert_set_1()
01210 {
01211     EntityHandle e                      = CREATE_HANDLE( MBEDGE, 0 );
01212     EntityHandle q                      = CREATE_HANDLE( MBQUAD, 0 );
01213     const EntityHandle initial_ranges[] = {
01214         0x7fe,      0x7fe,      0x802,      0x80b,      0xb3a,      0xb3c,      0xb6b,      0xb6b,      0xbed,
01215         0xbee,      0x19ff,     0x19ff,     0x1a0b,     0x1a0b,     0x1a16,     0x1a17,     0x1a56,     0x1a57,
01216         0x2554,     0x255c,     e + 0x0099, e + 0x009b, e + 0x00c0, e + 0x00c2, e + 0x0729, e + 0x0732, e + 0x0a3b,
01217         e + 0x0a3d, e + 0x0ba9, e + 0x0bab, e + 0x2322, e + 0x232b, q + 0x00c,  q + 0x017,  q + 0x0e9,  q + 0x112,
01218         q + 0x2f2,  q + 0x303,  q + 0x67e,  q + 0x6a5,  q + 0x866,  q + 0x871,  q + 0x8f5,  q + 0x900,  q + 0xc06,
01219         q + 0xc17,  q + 0xc7e,  q + 0xc9b,  q + 0xce0,  q + 0xd07 };
01220 
01221     const EntityHandle new_ranges[] = { 0x7e1,  0x829,  0xb37,  0xb63,  0xb6b,  0xb6b,  0xb73,  0xb75,  0xbed,
01222                                         0xbee,  0xc0b,  0xc10,  0x19fd, 0x19fd, 0x19ff, 0x19ff, 0x1a02, 0x1a04,
01223                                         0x1a0b, 0x1a0b, 0x1a11, 0x1a17, 0x1a1b, 0x1a23, 0x1a56, 0x1a57, 0x1a7c,
01224                                         0x1a96, 0x1bb5, 0x1bba, 0x254b, 0x2565, 0x25a5, 0x25bf };
01225 
01226     Core moab;
01227     Interface& mb = moab;
01228     ErrorCode rval;
01229 
01230     EntityHandle set;
01231     rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
01232 
01233     Range init, add;
01234     for( size_t i = 0; i < sizeof( initial_ranges ) / sizeof( initial_ranges[0] ); i += 2 )
01235         init.insert( initial_ranges[i], initial_ranges[i + 1] );
01236     for( size_t i = 0; i < sizeof( new_ranges ) / sizeof( new_ranges[0] ); i += 2 )
01237         add.insert( new_ranges[i], new_ranges[i + 1] );
01238 
01239     rval = mb.add_entities( set, init );CHECK_ERR( rval );
01240     rval = mb.add_entities( set, add );CHECK_ERR( rval );
01241 
01242     std::vector< EntityHandle > contents;
01243     rval = mb.get_entities_by_handle( set, contents );CHECK_ERR( rval );
01244 
01245     init.merge( add );
01246     Range::iterator r                       = init.begin();
01247     std::vector< EntityHandle >::iterator v = contents.begin();
01248     for( ;; )
01249     {
01250         if( r == init.end() || v == contents.end() )
01251         {
01252             CHECK( r == init.end() );
01253             CHECK( v == contents.end() );
01254             break;
01255         }
01256         CHECK_EQUAL( *r, *v );
01257         ++r;
01258         ++v;
01259     }
01260 }
01261 
01262 void test_all_iterators()
01263 {
01264     test_iterators( MESHSET_SET, true, false );
01265     test_iterators( MESHSET_SET, false, true );
01266 
01267     test_iterators( MESHSET_ORDERED, true, false );
01268     test_iterators( MESHSET_ORDERED, false, true );
01269 }
01270 
01271 void test_iterators( unsigned int flags, bool test_type, bool test_dim )
01272 {
01273     if( test_type && test_dim ) CHECK_ERR( MB_FAILURE );
01274 
01275     EntityHandle first_vert, last_vert, first_hex, last_hex;
01276     Core mb;
01277     make_mesh( mb, first_vert, last_vert, first_hex, last_hex );
01278 
01279     // Create an entity set
01280     EntityHandle set;
01281     ErrorCode rval = mb.create_meshset( flags, set );CHECK_ERR( rval );
01282 
01283     // Test iteration over empty set
01284     SetIterator* iter = NULL;
01285     rval              = mb.create_set_iterator( set, MBMAXTYPE, -1, 1, false, iter );CHECK_ERR( rval );
01286     if( NULL != iter )
01287     {
01288         test_iterator( mb, iter, set, MBMAXTYPE, -1 );
01289         delete iter;
01290         iter = NULL;
01291     }
01292 
01293     rval = mb.create_set_iterator( set, MBMAXTYPE, -1, 100, false, iter );CHECK_ERR( rval );
01294     if( NULL != iter )
01295     {
01296         test_iterator( mb, iter, set, MBMAXTYPE, -1 );
01297         delete iter;
01298         iter = NULL;
01299     }
01300 
01301     rval = mb.create_set_iterator( set, MBMAXTYPE, 0, 1, false, iter );CHECK_ERR( rval );
01302     if( NULL != iter )
01303     {
01304         test_iterator( mb, iter, set, MBMAXTYPE, 0 );
01305         delete iter;
01306         iter = NULL;
01307     }
01308 
01309     rval = mb.create_set_iterator( set, MBMAXTYPE, 3, 1, false, iter );CHECK_ERR( rval );
01310     if( NULL != iter )
01311     {
01312         test_iterator( mb, iter, set, MBMAXTYPE, 3 );
01313         delete iter;
01314         iter = NULL;
01315     }
01316 
01317     // Add stuff to set
01318     Range range;
01319     range.insert( first_vert, first_vert + 10 );
01320     range.insert( first_vert + 100, first_vert + 110 );
01321     range.insert( first_hex + 200, first_hex + 299 );
01322     range.insert( last_hex, last_hex - 99 );
01323     rval = mb.add_entities( set, range );CHECK_ERR( rval );
01324 
01325     EntityType etype = MBVERTEX;
01326     int edim         = -1;
01327     if( test_dim && !test_type )
01328     {
01329         edim  = 0;
01330         etype = MBMAXTYPE;
01331     }
01332 
01333     // Test
01334     // chunk size 1
01335     rval = mb.create_set_iterator( set, etype, edim, 1, false, iter );CHECK_ERR( rval );
01336     if( NULL != iter )
01337     {
01338         test_iterator( mb, iter, set, etype, edim );
01339         delete iter;
01340         iter = NULL;
01341     }
01342 
01343     // chunk size 3
01344     rval = mb.create_set_iterator( set, etype, edim, 3, false, iter );CHECK_ERR( rval );
01345     if( NULL != iter )
01346     {
01347         test_iterator( mb, iter, set, etype, edim );
01348         delete iter;
01349         iter = NULL;
01350     }
01351 
01352     // chunk size 11
01353     rval = mb.create_set_iterator( set, etype, edim, 11, false, iter );CHECK_ERR( rval );
01354     if( NULL != iter )
01355     {
01356         test_iterator( mb, iter, set, etype, edim );
01357         delete iter;
01358         iter = NULL;
01359     }
01360 
01361     // chunk size 100
01362     rval = mb.create_set_iterator( set, etype, edim, 100, false, iter );CHECK_ERR( rval );
01363     if( NULL != iter )
01364     {
01365         test_iterator( mb, iter, set, etype, edim );
01366         delete iter;
01367         iter = NULL;
01368     }
01369 
01370     if( test_type )
01371     {
01372         // chunk size 1, all ents
01373         rval = mb.create_set_iterator( set, MBMAXTYPE, -1, 1, false, iter );CHECK_ERR( rval );
01374         if( NULL != iter )
01375         {
01376             test_iterator( mb, iter, set, MBMAXTYPE, -1 );
01377             delete iter;
01378             iter = NULL;
01379         }
01380 
01381         // chunk size 3, all ents
01382         rval = mb.create_set_iterator( set, MBMAXTYPE, -1, 3, false, iter );CHECK_ERR( rval );
01383         if( NULL != iter )
01384         {
01385             test_iterator( mb, iter, set, MBMAXTYPE, -1 );
01386             delete iter;
01387             iter = NULL;
01388         }
01389 
01390         // chunk size large, all ents
01391         rval = mb.create_set_iterator( set, MBMAXTYPE, -1, 100000, false, iter );CHECK_ERR( rval );
01392         if( NULL != iter )
01393         {
01394             test_iterator( mb, iter, set, MBMAXTYPE, -1 );
01395             delete iter;
01396             iter = NULL;
01397         }
01398 
01399         etype = MBEDGE;
01400         // edges, chunk size 1
01401         rval = mb.create_set_iterator( set, etype, edim, 1, false, iter );CHECK_ERR( rval );
01402         if( NULL != iter )
01403         {
01404             test_iterator( mb, iter, set, etype, edim );
01405             delete iter;
01406             iter = NULL;
01407         }
01408 
01409         // edges, chunk size 100
01410         rval = mb.create_set_iterator( set, etype, edim, 100, false, iter );CHECK_ERR( rval );
01411         if( NULL != iter )
01412         {
01413             test_iterator( mb, iter, set, etype, edim );
01414             delete iter;
01415             iter = NULL;
01416         }
01417 
01418         etype = MBHEX;
01419 
01420         // hexes, chunk size 1
01421         rval = mb.create_set_iterator( set, etype, edim, 1, false, iter );CHECK_ERR( rval );
01422         if( NULL != iter )
01423         {
01424             test_iterator( mb, iter, set, etype, edim );
01425             delete iter;
01426             iter = NULL;
01427         }
01428 
01429         // hexes, chunk size 3
01430         rval = mb.create_set_iterator( set, etype, edim, 3, false, iter );CHECK_ERR( rval );
01431         if( NULL != iter )
01432         {
01433             test_iterator( mb, iter, set, etype, edim );
01434             delete iter;
01435             iter = NULL;
01436         }
01437 
01438         // hexes, chunk size 1000
01439         rval = mb.create_set_iterator( set, etype, edim, 1000, false, iter );CHECK_ERR( rval );
01440         if( NULL != iter )
01441         {
01442             test_iterator( mb, iter, set, etype, edim );
01443             delete iter;
01444             iter = NULL;
01445         }
01446     }
01447 }
01448 
01449 void test_iterator( Interface& moab, SetIterator* iter, EntityHandle set, EntityType etype, int dim )
01450 {
01451     // iterate over the set, adding to contents
01452     std::vector< EntityHandle > entities, entities2;
01453     bool atend = false;
01454     ErrorCode rval;
01455 
01456     while( !atend )
01457     {
01458         rval = iter->get_next_arr( entities, atend );CHECK_ERR( rval );
01459     }
01460 
01461     // check contents against what's in the set
01462     if( MBMAXTYPE != etype )
01463     {
01464         rval = moab.get_entities_by_type( set, etype, entities2 );CHECK_ERR( rval );
01465     }
01466     else if( MBMAXTYPE == etype && -1 == dim )
01467     {
01468         rval = moab.get_entities_by_handle( set, entities2 );CHECK_ERR( rval );
01469     }
01470     else if( -1 != dim )
01471     {
01472         rval = moab.get_entities_by_dimension( set, dim, entities2 );CHECK_ERR( rval );
01473     }
01474     else
01475     {
01476         // error, one of those needs to be true
01477         CHECK_ERR( MB_FAILURE );
01478     }
01479 
01480     CHECK_EQUAL( entities.size(), entities2.size() );
01481 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines