MOAB: Mesh Oriented datABase  (version 5.2.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 <stdlib.h>
00013 #include <math.h>
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 ) { exitval += RUN_TEST( test_big_tree ); }
00396 
00397 #ifdef MOAB_HAVE_MPI
00398     fail = MPI_Finalize();
00399     if( fail ) return fail;
00400 #endif
00401 
00402     return exitval;
00403 }
00404 
00405 // NOTE: this test makes some assuptions about handles:
00406 //       mainly that they will be assigned sequentially
00407 //       in the same order as defined in the file and
00408 //       beginning with ID 1
00409 void regression_mmiller_8_2010()
00410 {
00411     Core moab;
00412     Interface& mb = moab;
00413 
00414     const size_t num_vtx = 171;
00415     const size_t num_pri = 12;
00416     const size_t num_pyr = 8;
00417     const size_t num_hex = 100;
00418     const size_t num_set = 25;
00419 
00420     mb.load_file( std::string( TestDir + "/h5file/rocket_ents_in_assm.h5m" ).c_str() );
00421 
00422     /* Dump of set contents from input file:
00423      1r: 172, 4,
00424      2r: 192, 4, 204, 4, 216, 4, 228, 4, 240, 4, 252, 4, 264, 4, 276, 4,
00425      3r: 288, 4,
00426      4 : 181, 183, 185, 187,
00427      5r: 176, 5, 182, 1, 184, 1, 186, 1, 188, 4, 196, 8, 208, 8, 220, 8, 232, 8, 244, 8, 256, 8,
00428     268, 8, 280, 8, 6r: 172, 4, 192, 4, 204, 4, 216, 4, 228, 4, 240, 4, 252, 4, 264, 4, 276, 4, 288,
00429     4, 7r: 176, 4, 188, 4, 196, 8, 208, 8, 220, 8, 232, 8, 244, 8, 8r: 180, 8, 256, 8, 268, 8, 280,
00430     8, 9r: 172, 120, 301, 1, 309, 1, 10r: 176, 4, 188, 100, 302, 1, 308, 1, 11r: 176, 4, 188, 52,
00431     303, 1, 12r: 176, 4, 188, 4, 304, 4, 13 : 177, 189, 14 : 178, 190, 15 : 179, 191, 16 : 17r: 240,
00432     48, 18r: 172, 4, 180, 8, 288, 4, 310, 1, 312, 1, 19r: 180, 8, 288, 4, 311, 1, 20r: 180, 8, 21r:
00433     172, 4, 313, 4, 22 : 173, 23 : 174, 24 : 175, 25 : 176, 188
00434     */
00435 
00436     // check expected handles
00437 
00438     const EntityHandle VTX1 = CREATE_HANDLE( MBVERTEX, 1 );
00439     Range range, expected;
00440     mb.get_entities_by_type( 0, MBVERTEX, range );
00441     CHECK_EQUAL( num_vtx, range.size() );
00442     expected.insert( VTX1, VTX1 + num_vtx - 1 );
00443     CHECK_EQUAL( expected, range );
00444 
00445     const EntityHandle PRI1 = CREATE_HANDLE( MBPRISM, 1 );
00446     range.clear();
00447     expected.clear();
00448     mb.get_entities_by_type( 0, MBPRISM, range );
00449     CHECK_EQUAL( num_pri, range.size() );
00450     expected.insert( PRI1, PRI1 + num_pri - 1 );
00451     CHECK_EQUAL( expected, range );
00452 
00453     const EntityHandle PYR1 = CREATE_HANDLE( MBPYRAMID, 1 );
00454     range.clear();
00455     expected.clear();
00456     mb.get_entities_by_type( 0, MBPYRAMID, range );
00457     CHECK_EQUAL( num_pyr, range.size() );
00458     expected.insert( PYR1, PYR1 + num_pyr - 1 );
00459     CHECK_EQUAL( expected, range );
00460 
00461     const EntityHandle HEX1 = CREATE_HANDLE( MBHEX, 1 );
00462     range.clear();
00463     expected.clear();
00464     mb.get_entities_by_type( 0, MBHEX, range );
00465     CHECK_EQUAL( num_hex, range.size() );
00466     expected.insert( HEX1, HEX1 + num_hex - 1 );
00467     CHECK_EQUAL( expected, range );
00468 
00469     const EntityHandle SET1 = CREATE_HANDLE( MBENTITYSET, 1 );
00470     range.clear();
00471     expected.clear();
00472     mb.get_entities_by_type( 0, MBENTITYSET, range );
00473     CHECK_EQUAL( num_set, range.size() );
00474     expected.insert( SET1, SET1 + num_set - 1 );
00475     CHECK_EQUAL( expected, range );
00476 
00477     // Check set contents
00478 
00479     // Set 1: Pyramids 1 to 4
00480     range.clear();
00481     mb.get_entities_by_handle( SET1, range );
00482     expected.clear();
00483     expected.insert( PYR1 + 0, PYR1 + 3 );
00484     CHECK_EQUAL( expected, range );
00485 
00486     // Skip sets 2 through 8 because they're long and complicated and
00487     // I doubt I could code up the content lists explicitly from the
00488     // dump of the HDF5 file w/out many mistakes
00489 
00490     // Set 9: Pyramids 1 to 8, Prism 1 to 12, Hex 1 to 100, and Sets 10 and 18
00491     range.clear();
00492     mb.get_entities_by_handle( SET1 + 8, range );
00493     expected.clear();
00494     expected.insert( PYR1 + 0, PYR1 + 7 );
00495     expected.insert( PRI1 + 0, PRI1 + 11 );
00496     expected.insert( HEX1 + 0, HEX1 + 99 );
00497     expected.insert( SET1 + 9 );
00498     expected.insert( SET1 + 17 );
00499     CHECK_EQUAL( expected, range );
00500 
00501     // Set 10: Pyramids 5 to 8, Prism 9 to 12, Hex 1 to 96, and Sets 11 and 17
00502     range.clear();
00503     mb.get_entities_by_handle( SET1 + 9, range );
00504     expected.clear();
00505     expected.insert( PYR1 + 4, PYR1 + 7 );
00506     expected.insert( PRI1 + 8, PRI1 + 11 );
00507     expected.insert( HEX1 + 0, HEX1 + 95 );
00508     expected.insert( SET1 + 10 );
00509     expected.insert( SET1 + 16 );
00510     CHECK_EQUAL( expected, range );
00511 
00512     // Set 11: Pyramids 5 to 8, Prism 9 to 12, Hex 1 to 48, and Set 12
00513     range.clear();
00514     mb.get_entities_by_handle( SET1 + 10, range );
00515     expected.clear();
00516     expected.insert( PYR1 + 4, PYR1 + 7 );
00517     expected.insert( PRI1 + 8, PRI1 + 11 );
00518     expected.insert( HEX1 + 0, HEX1 + 47 );
00519     expected.insert( SET1 + 11 );
00520     CHECK_EQUAL( expected, range );
00521 
00522     // Set 12: Pyramids 5 to 8, Prism 9 to 12, and Sets 13 to 16
00523     range.clear();
00524     mb.get_entities_by_handle( SET1 + 11, range );
00525     expected.clear();
00526     expected.insert( PYR1 + 4, PYR1 + 7 );
00527     expected.insert( PRI1 + 8, PRI1 + 11 );
00528     expected.insert( SET1 + 12, SET1 + 15 );
00529     CHECK_EQUAL( expected, range );
00530 
00531     // Set 13: Pyramids 6 and Prism 10
00532     range.clear();
00533     mb.get_entities_by_handle( SET1 + 12, range );
00534     expected.clear();
00535     expected.insert( PYR1 + 5 );
00536     expected.insert( PRI1 + 9 );
00537     CHECK_EQUAL( expected, range );
00538 
00539     // Set 14: Pyramids 7 and Prism 11
00540     range.clear();
00541     mb.get_entities_by_handle( SET1 + 13, range );
00542     expected.clear();
00543     expected.insert( PYR1 + 6 );
00544     expected.insert( PRI1 + 10 );
00545     CHECK_EQUAL( expected, range );
00546 
00547     // Set 15: Pyramids 8 and Prism 12
00548     range.clear();
00549     mb.get_entities_by_handle( SET1 + 14, range );
00550     expected.clear();
00551     expected.insert( PYR1 + 7 );
00552     expected.insert( PRI1 + 11 );
00553     CHECK_EQUAL( expected, range );
00554 
00555     // Set 16: Empty
00556     range.clear();
00557     mb.get_entities_by_handle( SET1 + 15, range );
00558     expected.clear();
00559     CHECK_EQUAL( expected, range );
00560 
00561     // Set 17: Hex 49 to 96
00562     range.clear();
00563     mb.get_entities_by_handle( SET1 + 16, range );
00564     expected.clear();
00565     expected.insert( HEX1 + 48, HEX1 + 95 );
00566     CHECK_EQUAL( expected, range );
00567 
00568     // Set 18: Pyramids 1 to 4, Prism 1 to 8, Hex 97 to 100, and Sets 19 and 21
00569     range.clear();
00570     mb.get_entities_by_handle( SET1 + 17, range );
00571     expected.clear();
00572     expected.insert( PYR1 + 0, PYR1 + 3 );
00573     expected.insert( PRI1 + 0, PRI1 + 7 );
00574     expected.insert( HEX1 + 96, HEX1 + 99 );
00575     expected.insert( SET1 + 18 );
00576     expected.insert( SET1 + 20 );
00577     CHECK_EQUAL( expected, range );
00578 
00579     // Set 19: Prism 1 to 8, Hex 97 to 100, and Set 20
00580     range.clear();
00581     mb.get_entities_by_handle( SET1 + 18, range );
00582     expected.clear();
00583     expected.insert( PRI1 + 0, PRI1 + 7 );
00584     expected.insert( HEX1 + 96, HEX1 + 99 );
00585     expected.insert( SET1 + 19 );
00586     CHECK_EQUAL( expected, range );
00587 
00588     // Set 20: Prism 1 to 8
00589     range.clear();
00590     mb.get_entities_by_handle( SET1 + 19, range );
00591     expected.clear();
00592     expected.insert( PRI1 + 0, PRI1 + 7 );
00593     CHECK_EQUAL( expected, range );
00594 
00595     // Set 21: Pyramids 1 to 4, and Sets 22 to 25
00596     range.clear();
00597     mb.get_entities_by_handle( SET1 + 20, range );
00598     expected.clear();
00599     expected.insert( PYR1 + 0, PYR1 + 3 );
00600     expected.insert( SET1 + 21, SET1 + 24 );
00601     CHECK_EQUAL( expected, range );
00602 
00603     // Set 22: Pyramid 2
00604     range.clear();
00605     mb.get_entities_by_handle( SET1 + 21, range );
00606     expected.clear();
00607     expected.insert( PYR1 + 1 );
00608     CHECK_EQUAL( expected, range );
00609 
00610     // Set 23: Pyramid 3
00611     range.clear();
00612     mb.get_entities_by_handle( SET1 + 22, range );
00613     expected.clear();
00614     expected.insert( PYR1 + 2 );
00615     CHECK_EQUAL( expected, range );
00616 
00617     // Set 24: Pyramid 4
00618     range.clear();
00619     mb.get_entities_by_handle( SET1 + 23, range );
00620     expected.clear();
00621     expected.insert( PYR1 + 3 );
00622     CHECK_EQUAL( expected, range );
00623 
00624     // Set 25: Pyramid 5 and Prism 9
00625     range.clear();
00626     mb.get_entities_by_handle( SET1 + 24, range );
00627     expected.clear();
00628     expected.insert( PYR1 + 4 );
00629     expected.insert( PRI1 + 8 );
00630     CHECK_EQUAL( expected, range );
00631 }
00632 
00633 // Test to reproduce bug reported by brandom smith on 2011-3-7
00634 // and test other possible issues with the somewhat inconsistant
00635 // meshset creation flags.  Bug was fixed in SVN revision 4548.
00636 void test_set_flags()
00637 {
00638     const char filename2[] = "test_set_flags.h5m";
00639     ErrorCode rval;
00640     Core core;
00641     Interface& mb = core;
00642 
00643     // create a bunch of vertices so we have something to put in sets
00644     const int nverts          = 20;
00645     double coords[3 * nverts] = { 0.0 };
00646     Range verts;
00647     rval = mb.create_vertices( coords, nverts, verts );CHECK_ERR( rval );
00648 
00649     // Assign IDs to things so that we can identify them in the
00650     // data we read back in.
00651     Tag tag;
00652     rval = mb.tag_get_handle( "GLOBAL_ID", 1, MB_TYPE_INTEGER, tag );CHECK_ERR( rval );
00653     int ids[nverts];
00654     for( int i = 0; i < nverts; ++i )
00655         ids[i] = i + 1;
00656     rval = mb.tag_set_data( tag, verts, ids );CHECK_ERR( rval );
00657 
00658     // define two lists of vertex ids corresponding to the
00659     // vertices that we are going to put into different sets
00660     const int set_verts1[] = { 1, 2, 3, 4, 8, 13, 14, 15 };
00661     const int set_verts2[] = { 3, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
00662     const int num_verts1   = sizeof( set_verts1 ) / sizeof( set_verts1[0] );
00663     const int num_verts2   = sizeof( set_verts1 ) / sizeof( set_verts1[0] );
00664 
00665     // convert to handle lists
00666     EntityHandle set_handles1[num_verts1], set_handles2[num_verts2];
00667     for( int i = 0; i < num_verts1; ++i )
00668         set_handles1[i] = *( verts.begin() + set_verts1[i] - 1 );
00669     for( int i = 0; i < num_verts2; ++i )
00670         set_handles2[i] = *( verts.begin() + set_verts2[i] - 1 );
00671 
00672     // now create some sets with different flag combinations
00673     EntityHandle sets[6];
00674     rval = mb.create_meshset( 0, sets[0] );
00675     rval = mb.create_meshset( MESHSET_TRACK_OWNER, sets[1] );
00676     rval = mb.create_meshset( MESHSET_SET, sets[2] );
00677     rval = mb.create_meshset( MESHSET_SET | MESHSET_TRACK_OWNER, sets[3] );
00678     rval = mb.create_meshset( MESHSET_ORDERED, sets[4] );
00679     rval = mb.create_meshset( MESHSET_ORDERED | MESHSET_TRACK_OWNER, sets[5] );
00680 
00681     // assign IDs to sets so that we can identify them later
00682     rval = mb.tag_set_data( tag, sets, 6, ids );CHECK_ERR( rval );
00683     // add entities to sets
00684     rval = mb.add_entities( sets[0], set_handles1, num_verts1 );CHECK_ERR( rval );
00685     rval = mb.add_entities( sets[1], set_handles2, num_verts2 );CHECK_ERR( rval );
00686     rval = mb.add_entities( sets[2], set_handles1, num_verts1 );CHECK_ERR( rval );
00687     rval = mb.add_entities( sets[3], set_handles2, num_verts2 );CHECK_ERR( rval );
00688     rval = mb.add_entities( sets[4], set_handles1, num_verts1 );CHECK_ERR( rval );
00689     rval = mb.add_entities( sets[5], set_handles2, num_verts2 );CHECK_ERR( rval );
00690 
00691     // now write the file and read it back in
00692     rval = mb.write_file( filename2, 0, "BUFFER_SIZE=1024;DEBUG_BINIO" );CHECK_ERR( rval );
00693     mb.delete_mesh();
00694     rval = mb.load_file( filename2 );
00695     if( !keep_file ) remove( filename2 );CHECK_ERR( rval );
00696     rval = mb.tag_get_handle( "GLOBAL_ID", 1, MB_TYPE_INTEGER, tag );CHECK_ERR( rval );
00697 
00698     // find our sets
00699     Range tmp;
00700     for( int i = 0; i < 6; ++i )
00701     {
00702         int id = i + 1;
00703         tmp.clear();
00704         const void* vals[] = { &id };
00705         rval               = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, vals, 1, tmp );CHECK_ERR( rval );
00706         CHECK_EQUAL( 1u, (unsigned)tmp.size() );
00707         sets[i] = tmp.front();
00708     }
00709 
00710     // check that sets have correct flags
00711     unsigned opts;
00712     rval = mb.get_meshset_options( sets[0], opts );CHECK_ERR( rval );
00713     CHECK_EQUAL( 0u, opts );
00714     rval = mb.get_meshset_options( sets[1], opts );CHECK_ERR( rval );
00715     CHECK_EQUAL( (unsigned)MESHSET_TRACK_OWNER, opts );
00716     rval = mb.get_meshset_options( sets[2], opts );CHECK_ERR( rval );
00717     CHECK_EQUAL( (unsigned)MESHSET_SET, opts );
00718     rval = mb.get_meshset_options( sets[3], opts );CHECK_ERR( rval );
00719     CHECK_EQUAL( (unsigned)( MESHSET_SET | MESHSET_TRACK_OWNER ), opts );
00720     rval = mb.get_meshset_options( sets[4], opts );CHECK_ERR( rval );
00721     CHECK_EQUAL( (unsigned)MESHSET_ORDERED, opts );
00722     rval = mb.get_meshset_options( sets[5], opts );CHECK_ERR( rval );
00723     CHECK_EQUAL( (unsigned)( MESHSET_ORDERED | MESHSET_TRACK_OWNER ), opts );
00724 
00725     // check that sets have correct contents
00726     int set_ids1[num_verts1], set_ids2[num_verts2];
00727 
00728     tmp.clear();
00729     rval = mb.get_entities_by_handle( sets[0], tmp );CHECK_ERR( rval );
00730     CHECK_EQUAL( num_verts1, (int)tmp.size() );
00731     rval = mb.tag_get_data( tag, tmp, set_ids1 );CHECK_ERR( rval );
00732     std::sort( set_ids1, set_ids1 + num_verts1 );
00733     CHECK_ARRAYS_EQUAL( set_verts1, num_verts1, set_ids1, num_verts1 );
00734 
00735     tmp.clear();
00736     rval = mb.get_entities_by_handle( sets[1], tmp );CHECK_ERR( rval );
00737     CHECK_EQUAL( num_verts2, (int)tmp.size() );
00738     rval = mb.tag_get_data( tag, tmp, set_ids2 );CHECK_ERR( rval );
00739     std::sort( set_ids2, set_ids2 + num_verts2 );
00740     CHECK_ARRAYS_EQUAL( set_verts2, num_verts2, set_ids2, num_verts2 );
00741 
00742     tmp.clear();
00743     rval = mb.get_entities_by_handle( sets[2], tmp );CHECK_ERR( rval );
00744     CHECK_EQUAL( num_verts1, (int)tmp.size() );
00745     rval = mb.tag_get_data( tag, tmp, set_ids1 );CHECK_ERR( rval );
00746     std::sort( set_ids1, set_ids1 + num_verts1 );
00747     CHECK_ARRAYS_EQUAL( set_verts1, num_verts1, set_ids1, num_verts1 );
00748 
00749     tmp.clear();
00750     rval = mb.get_entities_by_handle( sets[3], tmp );CHECK_ERR( rval );
00751     CHECK_EQUAL( num_verts2, (int)tmp.size() );
00752     rval = mb.tag_get_data( tag, tmp, set_ids2 );CHECK_ERR( rval );
00753     std::sort( set_ids2, set_ids2 + num_verts2 );
00754     CHECK_ARRAYS_EQUAL( set_verts2, num_verts2, set_ids2, num_verts2 );
00755 
00756     tmp.clear();
00757     rval = mb.get_entities_by_handle( sets[4], tmp );CHECK_ERR( rval );
00758     CHECK_EQUAL( num_verts1, (int)tmp.size() );
00759     rval = mb.tag_get_data( tag, tmp, set_ids1 );CHECK_ERR( rval );
00760     std::sort( set_ids1, set_ids1 + num_verts1 );
00761     CHECK_ARRAYS_EQUAL( set_verts1, num_verts1, set_ids1, num_verts1 );
00762 
00763     tmp.clear();
00764     rval = mb.get_entities_by_handle( sets[5], tmp );CHECK_ERR( rval );
00765     CHECK_EQUAL( num_verts2, (int)tmp.size() );
00766     rval = mb.tag_get_data( tag, tmp, set_ids2 );CHECK_ERR( rval );
00767     std::sort( set_ids2, set_ids2 + num_verts2 );
00768     CHECK_ARRAYS_EQUAL( set_verts2, num_verts2, set_ids2, num_verts2 );
00769 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines