MOAB: Mesh Oriented datABase  (version 5.4.1)
readrtt_test.cpp
Go to the documentation of this file.
00001 #include "TestUtil.hpp"
00002 #include "moab/Core.hpp"
00003 #include "moab/Range.hpp"
00004 #include "moab/Types.hpp"
00005 #include "MBTagConventions.hpp"
00006 #include <cmath>
00007 #include <algorithm>
00008 
00009 using namespace moab;
00010 
00011 /* Input test file: rtttest_v100.rtt
00012  */
00013 
00014 std::string example1 = TestDir + "unittest/io/rtttest_v100.rtt";
00015 std::string example2 = TestDir + "unittest/io/rtttest_v101.rtt";
00016 
00017 void test_loadfile_1();
00018 void test_meshset_tags_1();
00019 void test_tets_1();
00020 void test_tet_tags_1();
00021 void test_triangles_1();
00022 void test_triangles_tags_1();
00023 void test_vertices_1();
00024 
00025 void test_loadfile_2();
00026 void test_meshset_tags_2();
00027 void test_tets_2();
00028 void test_tet_tags_2();
00029 void test_triangles_2();
00030 void test_triangles_tags_2();
00031 void test_vertices_2();
00032 
00033 void read_file( Interface& moab, const char* input_file );
00034 
00035 int main()
00036 {
00037     int result = 0;
00038     // first batch
00039     result += RUN_TEST( test_loadfile_1 );
00040     result += RUN_TEST( test_meshset_tags_1 );
00041     result += RUN_TEST( test_tets_1 );
00042     result += RUN_TEST( test_tet_tags_1 );
00043     result += RUN_TEST( test_triangles_1 );
00044     result += RUN_TEST( test_vertices_1 );
00045     // second batch
00046     result += RUN_TEST( test_loadfile_2 );
00047     result += RUN_TEST( test_meshset_tags_2 );
00048     result += RUN_TEST( test_tets_2 );
00049     result += RUN_TEST( test_tet_tags_2 );
00050     result += RUN_TEST( test_triangles_2 );
00051     result += RUN_TEST( test_vertices_2 );
00052 
00053     return result;
00054 }
00055 
00056 void read_file( Interface& moab, const char* input_file )
00057 {
00058     ErrorCode rval;
00059     rval = moab.load_file( input_file );CHECK_ERR( rval );
00060 }
00061 
00062 void test_loadfile_1()
00063 {
00064     Core moab;
00065     read_file( moab, example1.c_str() );
00066 }
00067 
00068 void test_meshset_tags_1()
00069 {
00070     Core moab;
00071     // load the data into moab
00072     read_file( moab, example1.c_str() );
00073     // query the dataset to make sure that there are the correct number of cells
00074     Range entities;
00075     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBENTITYSET, entities );CHECK_ERR( rval );
00076 
00077     Tag id_tag = moab.globalId_tag();
00078 
00079     // get the entities that are tagged
00080     rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &id_tag, 0, 1, entities );CHECK_ERR( rval );
00081 
00082     // each tet should have the material tag
00083     int num_vols     = 10;
00084     int num_surfaces = 129;
00085     int num_sets     = entities.size();
00086     CHECK_EQUAL( num_sets, num_vols + num_surfaces + 1 + 1 );
00087 
00088     // from the entities, get the volume meshsets, get it from the dim tag
00089     Tag dim_tag;
00090     entities.clear();
00091     // get the tag handle
00092     rval = moab.tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, dim_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
00093 
00094     // get the entities that are tagged with dim 3
00095     int dim3                          = 3;
00096     const void* const tag_vals_dim3[] = { &dim3 };
00097     rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim3, 1, entities );CHECK_ERR( rval );
00098 
00099     // there should only be 10 meshsets of dimension 3
00100     num_sets = entities.size();
00101     CHECK_EQUAL( num_vols, num_sets );
00102 
00103     entities.clear();
00104     // get the entities that are tagged with dim 2
00105     int dim2                          = 2;
00106     const void* const tag_vals_dim2[] = { &dim2 };
00107     rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim2, 1, entities );CHECK_ERR( rval );
00108 
00109     // there should only be 129 meshsets of dimension 2
00110     num_sets = entities.size();
00111     CHECK_EQUAL( num_surfaces, num_sets );
00112 }
00113 
00114 void test_tets_1()
00115 {
00116     Core moab;
00117     // load the data into moab
00118     read_file( moab, example1.c_str() );
00119     // query the dataset to make sure that there are the correct number of cells
00120     // cells = 26710 - number of tets
00121     Range entities;
00122     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
00123     int num_tets        = 26710;
00124     int num_tet_in_moab = entities.size();
00125     CHECK_EQUAL( num_tet_in_moab, num_tets );
00126 }
00127 
00128 void test_tet_tags_1()
00129 {
00130     Core moab;
00131     // load the data into moab
00132     read_file( moab, example1.c_str() );
00133     // query the dataset to make sure that there are the correct number of cells
00134     Range entities;
00135     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
00136 
00137     int num_tets        = 26710;
00138     int num_tet_in_moab = entities.size();
00139     CHECK_EQUAL( num_tet_in_moab, num_tets );
00140 
00141     // get the number of tets tagged with
00142     entities.clear();
00143     Tag material_number;
00144     // get the tag handle
00145     rval = moab.tag_get_handle( "MATERIAL_NUMBER", 1, MB_TYPE_INTEGER, material_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
00146 
00147     // get the entities that are tagged
00148     rval = moab.get_entities_by_type_and_tag( 0, moab::MBTET, &material_number, 0, 1, entities );
00149     // each tet should have the material tag
00150     int num_tet_tag = entities.size();
00151     CHECK_EQUAL( num_tet_tag, num_tets );CHECK_ERR( rval );
00152 }
00153 
00154 void test_triangles_1()
00155 {
00156     Core moab;
00157     // load the data into moab
00158     read_file( moab, example1.c_str() );
00159     // query the dataset to make sure that there are the correct number of cells
00160     Range entities;
00161     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );
00162 
00163     int num_tri         = 6383;  // num tris annotated in rtttest.rtt
00164     int num_tri_in_moab = entities.size();
00165     CHECK_EQUAL( num_tri_in_moab, num_tri );
00166 }
00167 
00168 void test_triangles_tags_1()
00169 {
00170     Core moab;
00171     // load the data into moab
00172     read_file( moab, example1.c_str() );
00173     // query the dataset to make sure that there are the correct number of cells
00174     Range entities;
00175     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );
00176 
00177     int num_tri         = 6383;  // num tris annotated in rtttest.rtt
00178     int num_tri_in_moab = entities.size();
00179     CHECK_EQUAL( num_tri_in_moab, num_tri );
00180 
00181     // get the number of tris tagged with SURFACE_NUMBER
00182     entities.clear();
00183     Tag surface_number;
00184     // get the tag handle
00185     rval = moab.tag_get_handle( "SURFACE_NUMBER", 1, MB_TYPE_INTEGER, surface_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
00186 
00187     // get the entities that are tagged
00188     rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &surface_number, 0, 1, entities );
00189     // each tri should have the surface number tag
00190     int num_tri_tag = entities.size();
00191     CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
00192 
00193     // get the number of tris tagged with SIDEID_TAG
00194     entities.clear();
00195     Tag sideid_tag;
00196     // get the tag handle
00197     rval = moab.tag_get_handle( "SIDEID_TAG", 1, MB_TYPE_INTEGER, sideid_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
00198 
00199     // get the entities that are tagged
00200     rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &sideid_tag, 0, 1, entities );
00201     // each tri should have the sideid tag
00202     num_tri_tag = entities.size();
00203     CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
00204 }
00205 
00206 void test_vertices_1()
00207 {
00208     Core moab;
00209     // load the data into moab
00210     read_file( moab, example1.c_str() );
00211     // query the dataset to make sure that there are the correct number of cells
00212     Range entities;
00213     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBVERTEX, entities );CHECK_ERR( rval );
00214 
00215     int num_verts         = 5397;  // num verts annotated in rtttest.rtt
00216     int num_verts_in_moab = entities.size();
00217     CHECK_EQUAL( num_verts_in_moab, num_verts );
00218 }
00219 
00220 void test_loadfile_2()
00221 {
00222     Core moab;
00223     read_file( moab, example2.c_str() );
00224 }
00225 
00226 void test_meshset_tags_2()
00227 {
00228     Core moab;
00229     // load the data into moab
00230     read_file( moab, example2.c_str() );
00231     // query the dataset to make sure that there are the correct number of cells
00232     Range entities;
00233     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBENTITYSET, entities );CHECK_ERR( rval );
00234 
00235     Tag id_tag = moab.globalId_tag();
00236 
00237     // get the entities that are tagged
00238     rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &id_tag, 0, 1, entities );CHECK_ERR( rval );
00239 
00240     // each tet should have the material tag
00241     int num_vols     = 3;
00242     int num_surfaces = 24;
00243     int num_sets     = entities.size();
00244     CHECK_EQUAL( num_sets, num_vols + num_surfaces + 1 + 1 );
00245 
00246     // from the entities, get the volume meshsets, get it from the dim tag
00247     Tag dim_tag;
00248     entities.clear();
00249     // get the tag handle
00250     rval = moab.tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, dim_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
00251 
00252     // get the entities that are tagged with dim 3
00253     int dim3                          = 3;
00254     const void* const tag_vals_dim3[] = { &dim3 };
00255     rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim3, 1, entities );CHECK_ERR( rval );
00256 
00257     // there should only be 10 meshsets of dimension 3
00258     num_sets = entities.size();
00259     CHECK_EQUAL( num_vols, num_sets );
00260 
00261     entities.clear();
00262     // get the entities that are tagged with dim 2
00263     int dim2                          = 2;
00264     const void* const tag_vals_dim2[] = { &dim2 };
00265     rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim2, 1, entities );CHECK_ERR( rval );
00266 
00267     // there should only be 129 meshsets of dimension 2
00268     num_sets = entities.size();
00269     CHECK_EQUAL( num_surfaces, num_sets );
00270 }
00271 
00272 void test_tets_2()
00273 {
00274     Core moab;
00275     // load the data into moab
00276     read_file( moab, example2.c_str() );
00277     // query the dataset to make sure that there are the correct number of cells
00278     // cells = 26710 - number of tets
00279     Range entities;
00280     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
00281     int num_tets        = 84;
00282     int num_tet_in_moab = entities.size();
00283     CHECK_EQUAL( num_tet_in_moab, num_tets );
00284 }
00285 
00286 void test_tet_tags_2()
00287 {
00288     Core moab;
00289     // load the data into moab
00290     read_file( moab, example2.c_str() );
00291     // query the dataset to make sure that there are the correct number of cells
00292     Range entities;
00293     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
00294 
00295     int num_tets        = 84;
00296     int num_tet_in_moab = entities.size();
00297     CHECK_EQUAL( num_tet_in_moab, num_tets );
00298 
00299     // get the number of tets tagged with
00300     entities.clear();
00301     Tag material_number;
00302     // get the tag handle
00303     rval = moab.tag_get_handle( "MATERIAL_NUMBER", 1, MB_TYPE_INTEGER, material_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
00304 
00305     // get the entities that are tagged
00306     rval = moab.get_entities_by_type_and_tag( 0, moab::MBTET, &material_number, 0, 1, entities );
00307     // each tet should have the material tag
00308     int num_tet_tag = entities.size();
00309     CHECK_EQUAL( num_tet_tag, num_tets );CHECK_ERR( rval );
00310 }
00311 
00312 void test_triangles_2()
00313 {
00314     Core moab;
00315     // load the data into moab
00316     read_file( moab, example2.c_str() );
00317     // query the dataset to make sure that there are the correct number of cells
00318     Range entities;
00319     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );
00320 
00321     int num_tri         = 60;  // num tris annotated in rtttest.rtt
00322     int num_tri_in_moab = entities.size();
00323     CHECK_EQUAL( num_tri_in_moab, num_tri );
00324 }
00325 
00326 void test_triangles_tags_2()
00327 {
00328     Core moab;
00329     // load the data into moab
00330     read_file( moab, example2.c_str() );
00331     // query the dataset to make sure that there are the correct number of cells
00332     Range entities;
00333     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );
00334 
00335     int num_tri         = 60;  // num tris annotated in rtttest.rtt
00336     int num_tri_in_moab = entities.size();
00337     CHECK_EQUAL( num_tri_in_moab, num_tri );
00338 
00339     // get the number of tris tagged with SURFACE_NUMBER
00340     entities.clear();
00341     Tag surface_number;
00342     // get the tag handle
00343     rval = moab.tag_get_handle( "SURFACE_NUMBER", 1, MB_TYPE_INTEGER, surface_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
00344 
00345     // get the entities that are tagged
00346     rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &surface_number, 0, 1, entities );
00347     // each tri should have the surface number tag
00348     int num_tri_tag = entities.size();
00349     CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
00350 
00351     // get the number of tris tagged with SIDEID_TAG
00352     entities.clear();
00353     Tag sideid_tag;
00354     // get the tag handle
00355     rval = moab.tag_get_handle( "SIDEID_TAG", 1, MB_TYPE_INTEGER, sideid_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
00356 
00357     // get the entities that are tagged
00358     rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &sideid_tag, 0, 1, entities );
00359     // each tri should have the sideid tag
00360     num_tri_tag = entities.size();
00361     CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
00362 }
00363 
00364 void test_vertices_2()
00365 {
00366     Core moab;
00367     // load the data into moab
00368     read_file( moab, example2.c_str() );
00369     // query the dataset to make sure that there are the correct number of cells
00370     Range entities;
00371     ErrorCode rval = moab.get_entities_by_type( 0, moab::MBVERTEX, entities );CHECK_ERR( rval );
00372 
00373     int num_verts         = 40;  // num verts annotated in rtttest.rtt
00374     int num_verts_in_moab = entities.size();
00375     CHECK_EQUAL( num_verts_in_moab, num_verts );
00376 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines