MOAB: Mesh Oriented datABase  (version 5.4.1)
h5sets_test.cpp
Go to the documentation of this file.
00001 #include "moab/Core.hpp"
00002 #include "moab/Range.hpp"
00003 #include "TestUtil.hpp"
00004 
00005 #ifdef MOAB_HAVE_MPI
00006 #include "moab_mpi.h"
00007 #endif
00008 
00009 #include <algorithm>
00010 #include <iostream>
00011 #include <sstream>
00012 #include <cstdlib>
00013 #include <cmath>
00014 
00015 using namespace moab;
00016 
00017 const char filename[] = "sets.h5m";
00018 bool keep_file        = false;
00019 
00020 void read_write_file( Interface& output, Interface& input, EntityHandle* input_set = 0 )
00021 {
00022     ErrorCode rval;
00023     rval = output.write_file( filename, 0, "DEBUG_BINIO" );CHECK_ERR( rval );
00024     if( input_set )
00025     {
00026         rval = input.create_meshset( MESHSET_SET, *input_set );CHECK_ERR( rval );
00027     }
00028     rval = input.load_file( filename, input_set );
00029     if( !keep_file ) remove( filename );CHECK_ERR( rval );
00030 }
00031 
00032 void test_ranged_set_with_stale_handles()
00033 {
00034     Core moab;
00035     Interface& mb = moab;
00036     ErrorCode rval;
00037     Range verts;
00038 
00039     const int num_vtx = 40;
00040     std::vector< double > coords( 3 * num_vtx, 0.0 );
00041     rval = mb.create_vertices( &coords[0], num_vtx, verts );CHECK_ERR( rval );
00042     CHECK_EQUAL( num_vtx, (int)verts.size() );
00043 
00044     EntityHandle set;
00045     rval = mb.create_meshset( MESHSET_SET, set );CHECK_ERR( rval );
00046     rval = mb.add_entities( set, verts );CHECK_ERR( rval );
00047 
00048     std::vector< EntityHandle > dead_verts;
00049     for( int i = num_vtx / 4; i < num_vtx; i += num_vtx / 4 )
00050     {
00051         Range::iterator j = verts.begin();
00052         j += i;
00053         dead_verts.push_back( *j );
00054     }
00055     rval = mb.delete_entities( &dead_verts[0], dead_verts.size() );CHECK_ERR( rval );
00056 
00057     Core moab2;
00058     Interface& mb2 = moab2;
00059     EntityHandle file_set;
00060     read_write_file( mb, mb2, &file_set );
00061     Range sets;
00062     rval = mb2.get_entities_by_type( 0, MBENTITYSET, sets );CHECK_ERR( rval );
00063     CHECK_EQUAL( 2, (int)sets.size() );
00064     EntityHandle other_set = sets.front() == file_set ? sets.back() : sets.front();
00065 
00066     int num_vtx2 = -5;
00067     rval         = mb2.get_number_entities_by_type( other_set, MBVERTEX, num_vtx2 );CHECK_ERR( rval );
00068     CHECK_EQUAL( (int)( num_vtx - dead_verts.size() ), num_vtx2 );
00069 }
00070 
00071 void test_list_set_with_stale_handles()
00072 {
00073     Core moab;
00074     Interface& mb = moab;
00075     ErrorCode rval;
00076     Range verts;
00077 
00078     const int num_vtx = 40;
00079     std::vector< double > coords( 3 * num_vtx, 0.0 );
00080     rval = mb.create_vertices( &coords[0], num_vtx, verts );CHECK_ERR( rval );
00081     CHECK_EQUAL( num_vtx, (int)verts.size() );
00082 
00083     EntityHandle set;
00084     rval = mb.create_meshset( MESHSET_ORDERED, set );CHECK_ERR( rval );
00085     rval = mb.add_entities( set, verts );CHECK_ERR( rval );
00086 
00087     std::vector< EntityHandle > dead_verts;
00088     for( int i = num_vtx / 4; i < num_vtx; i += num_vtx / 4 )
00089     {
00090         Range::iterator j = verts.begin();
00091         j += i;
00092         dead_verts.push_back( *j );
00093     }
00094     rval = mb.delete_entities( &dead_verts[0], dead_verts.size() );CHECK_ERR( rval );
00095 
00096     Core moab2;
00097     Interface& mb2 = moab2;
00098     EntityHandle file_set;
00099     read_write_file( mb, mb2, &file_set );
00100     Range sets;
00101     rval = mb2.get_entities_by_type( 0, MBENTITYSET, sets );CHECK_ERR( rval );
00102     CHECK_EQUAL( 2, (int)sets.size() );
00103     EntityHandle other_set = sets.front() == file_set ? sets.back() : sets.front();
00104 
00105     std::vector< EntityHandle > list;
00106     rval = mb2.get_entities_by_handle( other_set, list );CHECK_ERR( rval );
00107     CHECK_EQUAL( verts.size() - dead_verts.size(), list.size() );
00108 }
00109 
00110 void test_file_set()
00111 {
00112     ErrorCode rval;
00113     Core moab;
00114     double vtxcoords[] = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 };
00115     Range verts;
00116     rval = moab.create_vertices( vtxcoords, 3, verts );CHECK_ERR( rval );
00117     CHECK_EQUAL( 3, (int)verts.size() );
00118 
00119     EntityHandle tri;
00120     EntityHandle conn[3];
00121     std::copy( verts.begin(), verts.end(), conn );
00122     rval = moab.create_element( MBTRI, conn, 3, tri );CHECK_ERR( rval );
00123 
00124     EntityHandle set;
00125     rval = moab.create_meshset( MESHSET_ORDERED, set );CHECK_ERR( rval );
00126     rval = moab.add_entities( set, &tri, 1 );CHECK_ERR( rval );
00127 
00128     EntityHandle file;
00129     read_write_file( moab, moab, &file );
00130 
00131     int count;
00132     rval = moab.get_number_entities_by_type( 0, MBVERTEX, count );CHECK_ERR( rval );
00133     CHECK_EQUAL( 6, count );
00134     rval = moab.get_number_entities_by_type( file, MBVERTEX, count );CHECK_ERR( rval );
00135     CHECK_EQUAL( 3, count );
00136 
00137     rval = moab.get_number_entities_by_type( 0, MBTRI, count );CHECK_ERR( rval );
00138     CHECK_EQUAL( 2, count );
00139     rval = moab.get_number_entities_by_type( file, MBTRI, count );CHECK_ERR( rval );
00140     CHECK_EQUAL( 1, count );
00141 
00142     rval = moab.get_number_entities_by_type( 0, MBENTITYSET, count );CHECK_ERR( rval );
00143     CHECK_EQUAL( 3, count );
00144     rval = moab.get_number_entities_by_type( file, MBENTITYSET, count );CHECK_ERR( rval );
00145     CHECK_EQUAL( 1, count );
00146 }
00147 
00148 void test_sets_fileids()
00149 {
00150     ErrorCode rval;
00151     Core moab;
00152     double vtxcoords[] = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 };
00153     Range verts;
00154     rval = moab.create_vertices( vtxcoords, 3, verts );CHECK_ERR( rval );
00155     CHECK_EQUAL( 3, (int)verts.size() );
00156 
00157     EntityHandle tri;
00158     EntityHandle conn[3];
00159     std::copy( verts.begin(), verts.end(), conn );
00160     rval = moab.create_element( MBTRI, conn, 3, tri );CHECK_ERR( rval );
00161 
00162     EntityHandle set;
00163     rval = moab.create_meshset( MESHSET_ORDERED, set );CHECK_ERR( rval );
00164     rval = moab.add_entities( set, &tri, 1 );CHECK_ERR( rval );
00165 
00166     rval = moab.write_file( filename );CHECK_ERR( rval );
00167 
00168     moab.delete_mesh();
00169 
00170     rval = moab.load_file( filename, 0, "STORE_SETS_FILEIDS;" );CHECK_ERR( rval );
00171 
00172     Tag setFileIdTag;
00173 
00174     rval = moab.tag_get_handle( "__FILE_ID_FOR_SETS", setFileIdTag );CHECK_ERR( rval );
00175     CHECK( setFileIdTag );
00176 
00177     Range sets;
00178     rval = moab.get_entities_by_type( 0, MBENTITYSET, sets );CHECK_ERR( rval );
00179 
00180     std::vector< long > vals( sets.size() );
00181     rval = moab.tag_get_data( setFileIdTag, sets, &vals[0] );CHECK_ERR( rval );
00182 
00183     CHECK_EQUAL( 5, (int)vals[0] );
00184     if( !keep_file ) remove( filename );
00185 
00186     return;
00187 }
00188 
00189 int coords_by_idx( int idx, double coords[][3] )
00190 {
00191     coords[0][0] = idx;
00192     coords[0][1] = 0;
00193     coords[0][2] = 0;
00194     coords[1][0] = 0;
00195     coords[1][1] = idx;
00196     coords[1][2] = 0;
00197     coords[2][0] = 0;
00198     coords[2][1] = 0;
00199     coords[2][2] = idx;
00200     coords[3][0] = 3.14 * idx;
00201     coords[3][1] = 1;
00202     coords[3][2] = 1;
00203     coords[4][0] = 1;
00204     coords[4][1] = 3.14 * idx;
00205     coords[4][2] = 1;
00206     coords[5][0] = 1;
00207     coords[5][1] = 1;
00208     coords[5][2] = 3.14 * idx;
00209     return idx % 5 + 1;
00210 }
00211 
00212 void recursive_build_tree( int max_depth, Interface& mb, Tag tag, EntityHandle p, int depth, int& idx )
00213 {
00214     ErrorCode rval = mb.tag_set_data( tag, &p, 1, &idx );CHECK_ERR( rval );
00215 
00216     Range verts;
00217     double coords[6][3];
00218     int num_vtx = coords_by_idx( idx, coords );
00219     rval        = mb.create_vertices( &coords[0][0], num_vtx, verts );
00220     rval        = mb.add_entities( p, verts );
00221     ++idx;
00222     if( depth == max_depth ) return;
00223 
00224     EntityHandle l, r;
00225     rval = mb.create_meshset( MESHSET_SET, l );CHECK_ERR( rval );
00226     rval = mb.create_meshset( MESHSET_SET, r );CHECK_ERR( rval );
00227     rval = mb.add_parent_child( p, l );CHECK_ERR( rval );
00228     rval = mb.add_parent_child( p, r );CHECK_ERR( rval );
00229 
00230     recursive_build_tree( max_depth, mb, tag, l, depth + 1, idx );
00231     recursive_build_tree( max_depth, mb, tag, r, depth + 1, idx );
00232 }
00233 
00234 void recursive_check_tree( int max_depth, Interface& mb, Tag tag, EntityHandle p, int depth, int& idx )
00235 {
00236     int id;
00237     ErrorCode rval = mb.tag_get_data( tag, &p, 1, &id );CHECK_ERR( rval );
00238     CHECK_EQUAL( idx, id );
00239 
00240     Range verts;
00241     double coords[6][3];
00242     int num_vtx = coords_by_idx( idx, coords );
00243     rval        = mb.get_entities_by_handle( p, verts );
00244     CHECK( verts.all_of_type( MBVERTEX ) );
00245     CHECK_EQUAL( num_vtx, (int)verts.size() );
00246     double coords2[6][3];
00247     rval = mb.get_coords( verts, &coords2[0][0] );
00248     std::vector< bool > match( 6, true );
00249     for( int i = 0; i < num_vtx; ++i )
00250     {
00251         match[i] = false;
00252         for( int j = 0; j < num_vtx; ++j )
00253         {
00254             if( !match[j] )
00255             {
00256                 double d[3] = { coords[i][0] - coords2[j][0], coords[i][1] - coords2[j][1],
00257                                 coords[i][2] - coords2[j][2] };
00258                 double ds   = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
00259                 if( ds < 1e-12 )
00260                 {
00261                     match[j] = true;
00262                     break;
00263                 }
00264             }
00265         }
00266     }
00267     CHECK( match[0] );
00268     CHECK( match[1] );
00269     CHECK( match[2] );
00270     CHECK( match[3] );
00271     CHECK( match[4] );
00272     CHECK( match[5] );
00273 
00274     ++idx;
00275 
00276     std::vector< EntityHandle > children, parents;
00277 
00278     rval = mb.get_child_meshsets( p, children );CHECK_ERR( rval );
00279     if( depth == max_depth )
00280     {
00281         CHECK_EQUAL( (size_t)0, children.size() );
00282         return;
00283     }
00284 
00285     CHECK_EQUAL( (size_t)2, children.size() );
00286     EntityHandle l = children.front();
00287     EntityHandle r = children.back();
00288 
00289     parents.clear();
00290     rval = mb.get_parent_meshsets( l, parents );CHECK_ERR( rval );
00291     CHECK_EQUAL( (size_t)1, parents.size() );
00292     CHECK_EQUAL( p, parents.front() );
00293     parents.clear();
00294     rval = mb.get_parent_meshsets( r, parents );CHECK_ERR( rval );
00295     CHECK_EQUAL( (size_t)1, parents.size() );
00296     CHECK_EQUAL( p, parents.front() );
00297 
00298     recursive_check_tree( max_depth, mb, tag, l, depth + 1, idx );
00299     recursive_check_tree( max_depth, mb, tag, r, depth + 1, idx );
00300 }
00301 
00302 void test_tree( int max_depth )
00303 {
00304     ErrorCode rval;
00305     Core moab;
00306     Interface& mb = moab;
00307     EntityHandle root;
00308 
00309     // create tag in which to store number for each tree node,
00310     // in depth-first in-order search order.
00311     Tag tag;
00312     rval = mb.tag_get_handle( "GLOBAL_ID", 1, MB_TYPE_INTEGER, tag );CHECK_ERR( rval );
00313 
00314     // create a binary tree to a depth of 20 (about 1 million nodes)
00315     rval = mb.create_meshset( MESHSET_SET, root );CHECK_ERR( rval );
00316     int idx = 1;
00317     recursive_build_tree( max_depth, mb, tag, root, 1, idx );
00318     const int last_idx = idx;
00319     std::cerr << "Created binary tree containing " << last_idx << " nodes." << std::endl;
00320 
00321     std::ostringstream str;
00322     str << "tree-" << max_depth << ".h5m";
00323 
00324     // write file and read back in
00325     rval = mb.write_file( str.str().c_str(), 0, "BUFFER_SIZE=1024;DEBUG_BINIO" );CHECK_ERR( rval );
00326     mb.delete_mesh();
00327     rval = mb.load_file( str.str().c_str() );
00328     if( !keep_file ) remove( str.str().c_str() );CHECK_ERR( rval );
00329 
00330     // get tree root
00331     rval = mb.tag_get_handle( "GLOBAL_ID", 1, MB_TYPE_INTEGER, tag );CHECK_ERR( rval );
00332     Range roots;
00333     idx                = 1;
00334     const void* vals[] = { &idx };
00335     rval               = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, vals, 1, roots );
00336     CHECK_EQUAL( (size_t)1, roots.size() );
00337     root = roots.front();
00338 
00339     // check that tree is as we expect it
00340     idx = 1;
00341     recursive_check_tree( max_depth, mb, tag, root, 1, idx );
00342     CHECK_EQUAL( last_idx, idx );
00343 }
00344 
00345 void test_small_tree()
00346 {
00347     int max_depth   = 8;
00348     const char* str = getenv( "MAX_DEPTH" );
00349     if( str )
00350     {
00351         max_depth = atoi( str );
00352         CHECK( max_depth > 0 );
00353     }
00354     test_tree( max_depth );
00355 }
00356 
00357 void test_big_tree()
00358 {
00359     test_tree( 20 );
00360 }
00361 
00362 void regression_mmiller_8_2010();
00363 
00364 void test_set_flags();
00365 
00366 int main( int argc, char* argv[] )
00367 {
00368 #ifdef MOAB_HAVE_MPI
00369     int fail = MPI_Init( &argc, &argv );
00370     if( fail ) return fail;
00371 #endif
00372 
00373     bool do_big_tree_test = false;
00374     for( int i = 1; i < argc; ++i )
00375     {
00376         if( std::string( argv[i] ) == "-k" )
00377             keep_file = true;
00378         else if( std::string( argv[i] ) == "-b" )
00379             do_big_tree_test = true;
00380         else
00381         {
00382             std::cerr << "Usage: " << argv[0] << " [-k] [-b]" << std::endl;
00383             return 1;
00384         }
00385     }
00386 
00387     int exitval = 0;
00388     exitval += RUN_TEST( test_ranged_set_with_stale_handles );
00389     exitval += RUN_TEST( test_list_set_with_stale_handles );
00390     exitval += RUN_TEST( test_file_set );
00391     exitval += RUN_TEST( test_small_tree );
00392     exitval += RUN_TEST( test_set_flags );
00393     exitval += RUN_TEST( regression_mmiller_8_2010 );
00394     exitval += RUN_TEST( test_sets_fileids );
00395     if( do_big_tree_test )
00396     {
00397         exitval += RUN_TEST( test_big_tree );
00398     }
00399 
00400 #ifdef MOAB_HAVE_MPI
00401     fail = MPI_Finalize();
00402     if( fail ) return fail;
00403 #endif
00404 
00405     return exitval;
00406 }
00407 
00408 // NOTE: this test makes some assuptions about handles:
00409 //       mainly that they will be assigned sequentially
00410 //       in the same order as defined in the file and
00411 //       beginning with ID 1
00412 void regression_mmiller_8_2010()
00413 {
00414     Core moab;
00415     Interface& mb = moab;
00416 
00417     const size_t num_vtx = 171;
00418     const size_t num_pri = 12;
00419     const size_t num_pyr = 8;
00420     const size_t num_hex = 100;
00421     const size_t num_set = 25;
00422 
00423     mb.load_file( std::string( TestDir + "unittest/h5file/rocket_ents_in_assm.h5m" ).c_str() );
00424 
00425     /* Dump of set contents from input file:
00426      1r: 172, 4,
00427      2r: 192, 4, 204, 4, 216, 4, 228, 4, 240, 4, 252, 4, 264, 4, 276, 4,
00428      3r: 288, 4,
00429      4 : 181, 183, 185, 187,
00430      5r: 176, 5, 182, 1, 184, 1, 186, 1, 188, 4, 196, 8, 208, 8, 220, 8, 232, 8, 244, 8, 256, 8,
00431     268, 8, 280, 8, 6r: 172, 4, 192, 4, 204, 4, 216, 4, 228, 4, 240, 4, 252, 4, 264, 4, 276, 4, 288,
00432     4, 7r: 176, 4, 188, 4, 196, 8, 208, 8, 220, 8, 232, 8, 244, 8, 8r: 180, 8, 256, 8, 268, 8, 280,
00433     8, 9r: 172, 120, 301, 1, 309, 1, 10r: 176, 4, 188, 100, 302, 1, 308, 1, 11r: 176, 4, 188, 52,
00434     303, 1, 12r: 176, 4, 188, 4, 304, 4, 13 : 177, 189, 14 : 178, 190, 15 : 179, 191, 16 : 17r: 240,
00435     48, 18r: 172, 4, 180, 8, 288, 4, 310, 1, 312, 1, 19r: 180, 8, 288, 4, 311, 1, 20r: 180, 8, 21r:
00436     172, 4, 313, 4, 22 : 173, 23 : 174, 24 : 175, 25 : 176, 188
00437     */
00438 
00439     // check expected handles
00440 
00441     const EntityHandle VTX1 = CREATE_HANDLE( MBVERTEX, 1 );
00442     Range range, expected;
00443     mb.get_entities_by_type( 0, MBVERTEX, range );
00444     CHECK_EQUAL( num_vtx, range.size() );
00445     expected.insert( VTX1, VTX1 + num_vtx - 1 );
00446     CHECK_EQUAL( expected, range );
00447 
00448     const EntityHandle PRI1 = CREATE_HANDLE( MBPRISM, 1 );
00449     range.clear();
00450     expected.clear();
00451     mb.get_entities_by_type( 0, MBPRISM, range );
00452     CHECK_EQUAL( num_pri, range.size() );
00453     expected.insert( PRI1, PRI1 + num_pri - 1 );
00454     CHECK_EQUAL( expected, range );
00455 
00456     const EntityHandle PYR1 = CREATE_HANDLE( MBPYRAMID, 1 );
00457     range.clear();
00458     expected.clear();
00459     mb.get_entities_by_type( 0, MBPYRAMID, range );
00460     CHECK_EQUAL( num_pyr, range.size() );
00461     expected.insert( PYR1, PYR1 + num_pyr - 1 );
00462     CHECK_EQUAL( expected, range );
00463 
00464     const EntityHandle HEX1 = CREATE_HANDLE( MBHEX, 1 );
00465     range.clear();
00466     expected.clear();
00467     mb.get_entities_by_type( 0, MBHEX, range );
00468     CHECK_EQUAL( num_hex, range.size() );
00469     expected.insert( HEX1, HEX1 + num_hex - 1 );
00470     CHECK_EQUAL( expected, range );
00471 
00472     const EntityHandle SET1 = CREATE_HANDLE( MBENTITYSET, 1 );
00473     range.clear();
00474     expected.clear();
00475     mb.get_entities_by_type( 0, MBENTITYSET, range );
00476     CHECK_EQUAL( num_set, range.size() );
00477     expected.insert( SET1, SET1 + num_set - 1 );
00478     CHECK_EQUAL( expected, range );
00479 
00480     // Check set contents
00481 
00482     // Set 1: Pyramids 1 to 4
00483     range.clear();
00484     mb.get_entities_by_handle( SET1, range );
00485     expected.clear();
00486     expected.insert( PYR1 + 0, PYR1 + 3 );
00487     CHECK_EQUAL( expected, range );
00488 
00489     // Skip sets 2 through 8 because they're long and complicated and
00490     // I doubt I could code up the content lists explicitly from the
00491     // dump of the HDF5 file w/out many mistakes
00492 
00493     // Set 9: Pyramids 1 to 8, Prism 1 to 12, Hex 1 to 100, and Sets 10 and 18
00494     range.clear();
00495     mb.get_entities_by_handle( SET1 + 8, range );
00496     expected.clear();
00497     expected.insert( PYR1 + 0, PYR1 + 7 );
00498     expected.insert( PRI1 + 0, PRI1 + 11 );
00499     expected.insert( HEX1 + 0, HEX1 + 99 );
00500     expected.insert( SET1 + 9 );
00501     expected.insert( SET1 + 17 );
00502     CHECK_EQUAL( expected, range );
00503 
00504     // Set 10: Pyramids 5 to 8, Prism 9 to 12, Hex 1 to 96, and Sets 11 and 17
00505     range.clear();
00506     mb.get_entities_by_handle( SET1 + 9, range );
00507     expected.clear();
00508     expected.insert( PYR1 + 4, PYR1 + 7 );
00509     expected.insert( PRI1 + 8, PRI1 + 11 );
00510     expected.insert( HEX1 + 0, HEX1 + 95 );
00511     expected.insert( SET1 + 10 );
00512     expected.insert( SET1 + 16 );
00513     CHECK_EQUAL( expected, range );
00514 
00515     // Set 11: Pyramids 5 to 8, Prism 9 to 12, Hex 1 to 48, and Set 12
00516     range.clear();
00517     mb.get_entities_by_handle( SET1 + 10, range );
00518     expected.clear();
00519     expected.insert( PYR1 + 4, PYR1 + 7 );
00520     expected.insert( PRI1 + 8, PRI1 + 11 );
00521     expected.insert( HEX1 + 0, HEX1 + 47 );
00522     expected.insert( SET1 + 11 );
00523     CHECK_EQUAL( expected, range );
00524 
00525     // Set 12: Pyramids 5 to 8, Prism 9 to 12, and Sets 13 to 16
00526     range.clear();
00527     mb.get_entities_by_handle( SET1 + 11, range );
00528     expected.clear();
00529     expected.insert( PYR1 + 4, PYR1 + 7 );
00530     expected.insert( PRI1 + 8, PRI1 + 11 );
00531     expected.insert( SET1 + 12, SET1 + 15 );
00532     CHECK_EQUAL( expected, range );
00533 
00534     // Set 13: Pyramids 6 and Prism 10
00535     range.clear();
00536     mb.get_entities_by_handle( SET1 + 12, range );
00537     expected.clear();
00538     expected.insert( PYR1 + 5 );
00539     expected.insert( PRI1 + 9 );
00540     CHECK_EQUAL( expected, range );
00541 
00542     // Set 14: Pyramids 7 and Prism 11
00543     range.clear();
00544     mb.get_entities_by_handle( SET1 + 13, range );
00545     expected.clear();
00546     expected.insert( PYR1 + 6 );
00547     expected.insert( PRI1 + 10 );
00548     CHECK_EQUAL( expected, range );
00549 
00550     // Set 15: Pyramids 8 and Prism 12
00551     range.clear();
00552     mb.get_entities_by_handle( SET1 + 14, range );
00553     expected.clear();
00554     expected.insert( PYR1 + 7 );
00555     expected.insert( PRI1 + 11 );
00556     CHECK_EQUAL( expected, range );
00557 
00558     // Set 16: Empty
00559     range.clear();
00560     mb.get_entities_by_handle( SET1 + 15, range );
00561     expected.clear();
00562     CHECK_EQUAL( expected, range );
00563 
00564     // Set 17: Hex 49 to 96
00565     range.clear();
00566     mb.get_entities_by_handle( SET1 + 16, range );
00567     expected.clear();
00568     expected.insert( HEX1 + 48, HEX1 + 95 );
00569     CHECK_EQUAL( expected, range );
00570 
00571     // Set 18: Pyramids 1 to 4, Prism 1 to 8, Hex 97 to 100, and Sets 19 and 21
00572     range.clear();
00573     mb.get_entities_by_handle( SET1 + 17, range );
00574     expected.clear();
00575     expected.insert( PYR1 + 0, PYR1 + 3 );
00576     expected.insert( PRI1 + 0, PRI1 + 7 );
00577     expected.insert( HEX1 + 96, HEX1 + 99 );
00578     expected.insert( SET1 + 18 );
00579     expected.insert( SET1 + 20 );
00580     CHECK_EQUAL( expected, range );
00581 
00582     // Set 19: Prism 1 to 8, Hex 97 to 100, and Set 20
00583     range.clear();
00584     mb.get_entities_by_handle( SET1 + 18, range );
00585     expected.clear();
00586     expected.insert( PRI1 + 0, PRI1 + 7 );
00587     expected.insert( HEX1 + 96, HEX1 + 99 );
00588     expected.insert( SET1 + 19 );
00589     CHECK_EQUAL( expected, range );
00590 
00591     // Set 20: Prism 1 to 8
00592     range.clear();
00593     mb.get_entities_by_handle( SET1 + 19, range );
00594     expected.clear();
00595     expected.insert( PRI1 + 0, PRI1 + 7 );
00596     CHECK_EQUAL( expected, range );
00597 
00598     // Set 21: Pyramids 1 to 4, and Sets 22 to 25
00599     range.clear();
00600     mb.get_entities_by_handle( SET1 + 20, range );
00601     expected.clear();
00602     expected.insert( PYR1 + 0, PYR1 + 3 );
00603     expected.insert( SET1 + 21, SET1 + 24 );
00604     CHECK_EQUAL( expected, range );
00605 
00606     // Set 22: Pyramid 2
00607     range.clear();
00608     mb.get_entities_by_handle( SET1 + 21, range );
00609     expected.clear();
00610     expected.insert( PYR1 + 1 );
00611     CHECK_EQUAL( expected, range );
00612 
00613     // Set 23: Pyramid 3
00614     range.clear();
00615     mb.get_entities_by_handle( SET1 + 22, range );
00616     expected.clear();
00617     expected.insert( PYR1 + 2 );
00618     CHECK_EQUAL( expected, range );
00619 
00620     // Set 24: Pyramid 4
00621     range.clear();
00622     mb.get_entities_by_handle( SET1 + 23, range );
00623     expected.clear();
00624     expected.insert( PYR1 + 3 );
00625     CHECK_EQUAL( expected, range );
00626 
00627     // Set 25: Pyramid 5 and Prism 9
00628     range.clear();
00629     mb.get_entities_by_handle( SET1 + 24, range );
00630     expected.clear();
00631     expected.insert( PYR1 + 4 );
00632     expected.insert( PRI1 + 8 );
00633     CHECK_EQUAL( expected, range );
00634 }
00635 
00636 // Test to reproduce bug reported by brandom smith on 2011-3-7
00637 // and test other possible issues with the somewhat inconsistant
00638 // meshset creation flags.  Bug was fixed in SVN revision 4548.
00639 void test_set_flags()
00640 {
00641     const char filename2[] = "test_set_flags.h5m";
00642     ErrorCode rval;
00643     Core core;
00644     Interface& mb = core;
00645 
00646     // create a bunch of vertices so we have something to put in sets
00647     const int nverts          = 20;
00648     double coords[3 * nverts] = { 0.0 };
00649     Range verts;
00650     rval = mb.create_vertices( coords, nverts, verts );CHECK_ERR( rval );
00651 
00652     // Assign IDs to things so that we can identify them in the
00653     // data we read back in.
00654     Tag tag;
00655     rval = mb.tag_get_handle( "GLOBAL_ID", 1, MB_TYPE_INTEGER, tag );CHECK_ERR( rval );
00656     int ids[nverts];
00657     for( int i = 0; i < nverts; ++i )
00658         ids[i] = i + 1;
00659     rval = mb.tag_set_data( tag, verts, ids );CHECK_ERR( rval );
00660 
00661     // define two lists of vertex ids corresponding to the
00662     // vertices that we are going to put into different sets
00663     const int set_verts1[] = { 1, 2, 3, 4, 8, 13, 14, 15 };
00664     const int set_verts2[] = { 3, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
00665     const int num_verts1   = sizeof( set_verts1 ) / sizeof( set_verts1[0] );
00666     const int num_verts2   = sizeof( set_verts1 ) / sizeof( set_verts1[0] );
00667 
00668     // convert to handle lists
00669     EntityHandle set_handles1[num_verts1], set_handles2[num_verts2];
00670     for( int i = 0; i < num_verts1; ++i )
00671         set_handles1[i] = *( verts.begin() + set_verts1[i] - 1 );
00672     for( int i = 0; i < num_verts2; ++i )
00673         set_handles2[i] = *( verts.begin() + set_verts2[i] - 1 );
00674 
00675     // now create some sets with different flag combinations
00676     EntityHandle sets[6];
00677     rval = mb.create_meshset( 0, sets[0] );
00678     rval = mb.create_meshset( MESHSET_TRACK_OWNER, sets[1] );
00679     rval = mb.create_meshset( MESHSET_SET, sets[2] );
00680     rval = mb.create_meshset( MESHSET_SET | MESHSET_TRACK_OWNER, sets[3] );
00681     rval = mb.create_meshset( MESHSET_ORDERED, sets[4] );
00682     rval = mb.create_meshset( MESHSET_ORDERED | MESHSET_TRACK_OWNER, sets[5] );
00683 
00684     // assign IDs to sets so that we can identify them later
00685     rval = mb.tag_set_data( tag, sets, 6, ids );CHECK_ERR( rval );
00686     // add entities to sets
00687     rval = mb.add_entities( sets[0], set_handles1, num_verts1 );CHECK_ERR( rval );
00688     rval = mb.add_entities( sets[1], set_handles2, num_verts2 );CHECK_ERR( rval );
00689     rval = mb.add_entities( sets[2], set_handles1, num_verts1 );CHECK_ERR( rval );
00690     rval = mb.add_entities( sets[3], set_handles2, num_verts2 );CHECK_ERR( rval );
00691     rval = mb.add_entities( sets[4], set_handles1, num_verts1 );CHECK_ERR( rval );
00692     rval = mb.add_entities( sets[5], set_handles2, num_verts2 );CHECK_ERR( rval );
00693 
00694     // now write the file and read it back in
00695     rval = mb.write_file( filename2, 0, "BUFFER_SIZE=1024;DEBUG_BINIO" );CHECK_ERR( rval );
00696     mb.delete_mesh();
00697     rval = mb.load_file( filename2 );
00698     if( !keep_file ) remove( filename2 );CHECK_ERR( rval );
00699     rval = mb.tag_get_handle( "GLOBAL_ID", 1, MB_TYPE_INTEGER, tag );CHECK_ERR( rval );
00700 
00701     // find our sets
00702     Range tmp;
00703     for( int i = 0; i < 6; ++i )
00704     {
00705         int id = i + 1;
00706         tmp.clear();
00707         const void* vals[] = { &id };
00708         rval               = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, vals, 1, tmp );CHECK_ERR( rval );
00709         CHECK_EQUAL( 1u, (unsigned)tmp.size() );
00710         sets[i] = tmp.front();
00711     }
00712 
00713     // check that sets have correct flags
00714     unsigned opts;
00715     rval = mb.get_meshset_options( sets[0], opts );CHECK_ERR( rval );
00716     CHECK_EQUAL( 0u, opts );
00717     rval = mb.get_meshset_options( sets[1], opts );CHECK_ERR( rval );
00718     CHECK_EQUAL( (unsigned)MESHSET_TRACK_OWNER, opts );
00719     rval = mb.get_meshset_options( sets[2], opts );CHECK_ERR( rval );
00720     CHECK_EQUAL( (unsigned)MESHSET_SET, opts );
00721     rval = mb.get_meshset_options( sets[3], opts );CHECK_ERR( rval );
00722     CHECK_EQUAL( (unsigned)( MESHSET_SET | MESHSET_TRACK_OWNER ), opts );
00723     rval = mb.get_meshset_options( sets[4], opts );CHECK_ERR( rval );
00724     CHECK_EQUAL( (unsigned)MESHSET_ORDERED, opts );
00725     rval = mb.get_meshset_options( sets[5], opts );CHECK_ERR( rval );
00726     CHECK_EQUAL( (unsigned)( MESHSET_ORDERED | MESHSET_TRACK_OWNER ), opts );
00727 
00728     // check that sets have correct contents
00729     int set_ids1[num_verts1], set_ids2[num_verts2];
00730 
00731     tmp.clear();
00732     rval = mb.get_entities_by_handle( sets[0], tmp );CHECK_ERR( rval );
00733     CHECK_EQUAL( num_verts1, (int)tmp.size() );
00734     rval = mb.tag_get_data( tag, tmp, set_ids1 );CHECK_ERR( rval );
00735     std::sort( set_ids1, set_ids1 + num_verts1 );
00736     CHECK_ARRAYS_EQUAL( set_verts1, num_verts1, set_ids1, num_verts1 );
00737 
00738     tmp.clear();
00739     rval = mb.get_entities_by_handle( sets[1], tmp );CHECK_ERR( rval );
00740     CHECK_EQUAL( num_verts2, (int)tmp.size() );
00741     rval = mb.tag_get_data( tag, tmp, set_ids2 );CHECK_ERR( rval );
00742     std::sort( set_ids2, set_ids2 + num_verts2 );
00743     CHECK_ARRAYS_EQUAL( set_verts2, num_verts2, set_ids2, num_verts2 );
00744 
00745     tmp.clear();
00746     rval = mb.get_entities_by_handle( sets[2], tmp );CHECK_ERR( rval );
00747     CHECK_EQUAL( num_verts1, (int)tmp.size() );
00748     rval = mb.tag_get_data( tag, tmp, set_ids1 );CHECK_ERR( rval );
00749     std::sort( set_ids1, set_ids1 + num_verts1 );
00750     CHECK_ARRAYS_EQUAL( set_verts1, num_verts1, set_ids1, num_verts1 );
00751 
00752     tmp.clear();
00753     rval = mb.get_entities_by_handle( sets[3], tmp );CHECK_ERR( rval );
00754     CHECK_EQUAL( num_verts2, (int)tmp.size() );
00755     rval = mb.tag_get_data( tag, tmp, set_ids2 );CHECK_ERR( rval );
00756     std::sort( set_ids2, set_ids2 + num_verts2 );
00757     CHECK_ARRAYS_EQUAL( set_verts2, num_verts2, set_ids2, num_verts2 );
00758 
00759     tmp.clear();
00760     rval = mb.get_entities_by_handle( sets[4], tmp );CHECK_ERR( rval );
00761     CHECK_EQUAL( num_verts1, (int)tmp.size() );
00762     rval = mb.tag_get_data( tag, tmp, set_ids1 );CHECK_ERR( rval );
00763     std::sort( set_ids1, set_ids1 + num_verts1 );
00764     CHECK_ARRAYS_EQUAL( set_verts1, num_verts1, set_ids1, num_verts1 );
00765 
00766     tmp.clear();
00767     rval = mb.get_entities_by_handle( sets[5], tmp );CHECK_ERR( rval );
00768     CHECK_EQUAL( num_verts2, (int)tmp.size() );
00769     rval = mb.tag_get_data( tag, tmp, set_ids2 );CHECK_ERR( rval );
00770     std::sort( set_ids2, set_ids2 + num_verts2 );
00771     CHECK_ARRAYS_EQUAL( set_verts2, num_verts2, set_ids2, num_verts2 );
00772 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines