MOAB: Mesh Oriented datABase  (version 5.4.1)
gmsh_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 "MBTagConventions.hpp"
00005 #include <cmath>
00006 #include <algorithm>
00007 
00008 using namespace moab;
00009 
00010 /* Input test file: gmsh2.msh
00011  *
00012  * Example version 2.0 ASCII input file from Gmsh 2.4 manual.
00013  */
00014 #ifdef MESHDIR
00015 static const char example[]  = STRINGIFY( MESHDIR ) "/io/gmsh2.msh";
00016 static const char example2[] = STRINGIFY( MESHDIR ) "/io/airfoil_exterior.msh";
00017 static const char example3[] = STRINGIFY( MESHDIR ) "/io/t1.msh";
00018 static const char example4[] = STRINGIFY( MESHDIR ) "/io/ghosts.msh";
00019 static const char example5[] = STRINGIFY( MESHDIR ) "/io/gmsh3.msh";
00020 #else
00021 static const char example[]  = "gmsh2.msh";
00022 static const char example2[] = "airfoil_exterior.msh";
00023 static const char example3[] = "t1.msh";
00024 static const char example4[] = "ghosts.msh";
00025 static const char example5[] = "gmsh3.msh";
00026 #endif
00027 
00028 void test_read_nodes();
00029 void test_read_quads();
00030 void test_read_material_set();
00031 void test_read_material_on_nodes();
00032 void test_read_geom_set();
00033 void test_read_airfoil();
00034 void test_read_t1();
00035 void test_read_fgh();  // file with ghosts id for partition
00036 
00037 void read_file( Interface& moab, const char* input_file );
00038 
00039 int main()
00040 {
00041     int result = 0;
00042 
00043     result += RUN_TEST( test_read_nodes );
00044     result += RUN_TEST( test_read_quads );
00045     result += RUN_TEST( test_read_material_set );
00046     result += RUN_TEST( test_read_material_on_nodes );
00047     result += RUN_TEST( test_read_geom_set );
00048 
00049     result += RUN_TEST( test_read_airfoil );
00050     result += RUN_TEST( test_read_t1 );
00051     result += RUN_TEST( test_read_fgh );
00052     return result;
00053 }
00054 
00055 void read_file( Interface& moab, const char* input_file )
00056 {
00057     ErrorCode rval;
00058     rval = moab.load_file( input_file );CHECK_ERR( rval );
00059 }
00060 
00061 void test_read_nodes()
00062 {
00063     const double eps = 1e-100;
00064     ErrorCode rval;
00065     Core moab;
00066     Interface& mb = moab;
00067     read_file( moab, example );
00068 
00069     std::vector< EntityHandle > nodes;
00070     rval = mb.get_entities_by_type( 0, MBVERTEX, nodes );CHECK_ERR( rval );
00071     CHECK_EQUAL( (size_t)6, nodes.size() );
00072 
00073     Tag id_tag = mb.globalId_tag();
00074 
00075     std::vector< int > ids( nodes.size() );
00076     rval = mb.tag_get_data( id_tag, &nodes[0], nodes.size(), &ids[0] );CHECK_ERR( rval );
00077 
00078     std::vector< int > sorted_ids( ids );
00079     std::sort( sorted_ids.begin(), sorted_ids.end() );
00080 
00081     std::vector< double > coords( 3 * nodes.size() );
00082     rval = mb.get_coords( &nodes[0], nodes.size(), &coords[0] );CHECK_ERR( rval );
00083 
00084     int idx, pos = 0;
00085     CHECK_EQUAL( pos + 1, sorted_ids[pos] );
00086     idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
00087     CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
00088     CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
00089     CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
00090 
00091     ++pos;
00092     CHECK_EQUAL( pos + 1, sorted_ids[pos] );
00093     idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
00094     CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
00095     CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
00096     CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
00097 
00098     ++pos;
00099     CHECK_EQUAL( pos + 1, sorted_ids[pos] );
00100     idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
00101     CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
00102     CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
00103     CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
00104 
00105     ++pos;
00106     CHECK_EQUAL( pos + 1, sorted_ids[pos] );
00107     idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
00108     CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
00109     CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
00110     CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
00111 
00112     ++pos;
00113     CHECK_EQUAL( pos + 1, sorted_ids[pos] );
00114     idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
00115     CHECK_REAL_EQUAL( coords[3 * idx + 0], 2.0, eps );
00116     CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
00117     CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
00118 
00119     ++pos;
00120     CHECK_EQUAL( pos + 1, sorted_ids[pos] );
00121     idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
00122     CHECK_REAL_EQUAL( coords[3 * idx + 0], 2.0, eps );
00123     CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
00124     CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
00125 }
00126 
00127 void test_read_quads()
00128 {
00129     ErrorCode rval;
00130     Core moab;
00131     Interface& mb = moab;
00132     read_file( moab, example );
00133 
00134     std::vector< EntityHandle > quads;
00135     rval = mb.get_entities_by_type( 0, MBQUAD, quads );CHECK_ERR( rval );
00136     CHECK_EQUAL( (size_t)2, quads.size() );
00137 
00138     Tag id_tag = mb.globalId_tag();
00139 
00140     std::vector< int > ids( quads.size() );
00141     rval = mb.tag_get_data( id_tag, &quads[0], quads.size(), &ids[0] );CHECK_ERR( rval );
00142 
00143     if( ids[0] != 1 )
00144     {
00145         std::swap( ids[0], ids[1] );
00146         std::swap( quads[0], quads[1] );
00147     }
00148 
00149     int vtx_ids[4];
00150     const EntityHandle* conn;
00151     int len;
00152 
00153     const int conn1[] = { 1, 2, 3, 4 };
00154     int pos           = 0;
00155     CHECK_EQUAL( pos + 1, ids[pos] );
00156     rval = mb.get_connectivity( quads[pos], conn, len );CHECK_ERR( rval );
00157     CHECK_EQUAL( 4, len );
00158     rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
00159     CHECK_ARRAYS_EQUAL( conn1, 4, vtx_ids, len );
00160 
00161     const int conn2[] = { 2, 5, 6, 3 };
00162     ++pos;
00163     CHECK_EQUAL( pos + 1, ids[pos] );
00164     rval = mb.get_connectivity( quads[pos], conn, len );CHECK_ERR( rval );
00165     CHECK_EQUAL( 4, len );
00166     rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
00167     CHECK_ARRAYS_EQUAL( conn2, 4, vtx_ids, len );
00168 }
00169 
00170 void test_read_material_set()
00171 {
00172     ErrorCode rval;
00173     Core moab;
00174     Interface& mb = moab;
00175     read_file( moab, example );
00176 
00177     Tag mat_tag;
00178     rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mat_tag );CHECK_ERR( rval );
00179 
00180     Range sets;
00181     rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, 0, 1, sets );CHECK_ERR( rval );
00182     CHECK_EQUAL( 1, (int)sets.size() );
00183     EntityHandle set = sets.front();
00184 
00185     int id;
00186     rval = mb.tag_get_data( mat_tag, &set, 1, &id );CHECK_ERR( rval );
00187     CHECK_EQUAL( 99, id );
00188 
00189     std::vector< EntityHandle > quads, contents;
00190     rval = mb.get_entities_by_type( 0, MBQUAD, quads );CHECK_ERR( rval );
00191     rval = mb.get_entities_by_handle( set, contents );CHECK_ERR( rval );
00192     std::sort( quads.begin(), quads.end() );
00193     std::sort( contents.begin(), contents.end() );
00194     CHECK_EQUAL( quads, contents );
00195 }
00196 
00197 void test_read_material_on_nodes()
00198 {
00199     ErrorCode rval;
00200     Core moab;
00201     Interface& mb = moab;
00202     read_file( moab, example5 );
00203 
00204     Tag mat_tag;
00205     rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mat_tag );CHECK_ERR( rval );
00206 
00207     Range sets;
00208     rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, 0, 1, sets );CHECK_ERR( rval );
00209     CHECK_EQUAL( 2, (int)sets.size() );
00210 
00211     EntityHandle set_101 = sets.front();
00212     EntityHandle set_102 = sets.back();
00213 
00214     int id;
00215     rval = mb.tag_get_data( mat_tag, &set_101, 1, &id );CHECK_ERR( rval );
00216     CHECK_EQUAL( 101, id );
00217 
00218     rval = mb.tag_get_data( mat_tag, &set_102, 1, &id );CHECK_ERR( rval );
00219     CHECK_EQUAL( 102, id );
00220 }
00221 
00222 void test_read_geom_set()
00223 {
00224     ErrorCode rval;
00225     Core moab;
00226     Interface& mb = moab;
00227     read_file( moab, example );
00228 
00229     Tag dim_tag, id_tag;
00230     rval = mb.tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, dim_tag );CHECK_ERR( rval );
00231     id_tag = mb.globalId_tag();
00232 
00233     Range sets;
00234     rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, 0, 1, sets );CHECK_ERR( rval );
00235     CHECK_EQUAL( 1, (int)sets.size() );
00236     EntityHandle set = sets.front();
00237 
00238     int dim;
00239     rval = mb.tag_get_data( dim_tag, &set, 1, &dim );CHECK_ERR( rval );
00240     CHECK_EQUAL( 2, dim );
00241 
00242     int id;
00243     rval = mb.tag_get_data( id_tag, &set, 1, &id );CHECK_ERR( rval );
00244     CHECK_EQUAL( 3, id );
00245 
00246     std::vector< EntityHandle > quads, contents;
00247     rval = mb.get_entities_by_type( 0, MBQUAD, quads );CHECK_ERR( rval );
00248     rval = mb.get_entities_by_handle( set, contents );CHECK_ERR( rval );
00249     std::sort( quads.begin(), quads.end() );
00250     std::sort( contents.begin(), contents.end() );
00251     CHECK_EQUAL( quads, contents );
00252 }
00253 
00254 void test_read_airfoil()
00255 {
00256     Core moab;
00257     read_file( moab, example2 );
00258 }
00259 
00260 void test_read_t1()
00261 {
00262     Core moab;
00263     read_file( moab, example3 );
00264 }
00265 
00266 void test_read_fgh()
00267 {
00268     Core moab;
00269     read_file( moab, example4 );  // it should find 3 partitions
00270     // read partition sets
00271     Tag ptag;
00272     ErrorCode rval = moab.tag_get_handle( "PARALLEL_PARTITION", ptag );CHECK_ERR( rval );
00273     Range psets;
00274     rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &ptag, 0, 1, psets );CHECK_ERR( rval );
00275     CHECK_EQUAL( 3, (int)psets.size() );
00276     Range ents_first_set;
00277     rval = moab.get_entities_by_handle( psets[0], ents_first_set );CHECK_ERR( rval );
00278     CHECK_EQUAL( (int)ents_first_set.size(), 98 );
00279 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines