MOAB: Mesh Oriented datABase  (version 5.4.1)
smf_test.cpp
Go to the documentation of this file.
00001 #include "TestUtil.hpp"
00002 #include "moab/Core.hpp"
00003 #define IS_BUILDING_MB
00004 #include "moab/Range.hpp"
00005 
00006 using namespace moab;
00007 
00008 #ifdef MESHDIR
00009 static const char example[] = STRINGIFY( MESHDIR ) "/io/three.smf";
00010 #else
00011 static const char example[] = "three.smf";
00012 #endif
00013 
00014 void read_file( Interface& moab, const char* input_file );
00015 void test_read_nodes();
00016 void test_read_triangles();
00017 
00018 int main()
00019 {
00020     int result = 0;
00021 
00022     result += RUN_TEST( test_read_nodes );
00023     result += RUN_TEST( test_read_triangles );
00024 
00025     return result;
00026 }
00027 
00028 void read_file( Interface& moab, const char* input_file )
00029 {
00030     ErrorCode rval = moab.load_file( input_file );CHECK_ERR( rval );
00031 }
00032 
00033 void test_read_nodes()
00034 {
00035     const double eps = 1e-10;
00036     ErrorCode rval;
00037     Core moab;
00038     Interface& mb = moab;
00039     read_file( moab, example );
00040 
00041     std::vector< EntityHandle > nodes;
00042     rval = mb.get_entities_by_type( 0, MBVERTEX, nodes );CHECK_ERR( rval );
00043     CHECK_EQUAL( (size_t)24, nodes.size() );
00044 
00045     std::vector< double > coords( 3 * nodes.size() );
00046     rval = mb.get_coords( &nodes[0], nodes.size(), &coords[0] );CHECK_ERR( rval );
00047 
00048     int idx = 0;
00049     CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
00050     CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
00051     CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
00052 
00053     ++idx;
00054     CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
00055     CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
00056     CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
00057 
00058     idx = 8;  // second cube
00059     CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.2, eps );
00060     CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
00061     CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
00062 
00063     idx = 15;  // last node of second cube
00064     CHECK_REAL_EQUAL( coords[3 * idx + 0], 2.2, eps );
00065     CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
00066     CHECK_REAL_EQUAL( coords[3 * idx + 2], 1.0, eps );
00067 
00068     idx = 16;  // first node of third cube
00069     CHECK_REAL_EQUAL( coords[3 * idx + 0], -1.2, eps );
00070     CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.5, eps );
00071     CHECK_REAL_EQUAL( coords[3 * idx + 2], -0.2071067812, eps );
00072 }
00073 
00074 void test_read_triangles()
00075 {
00076     ErrorCode rval;
00077     Core moab;
00078     Interface& mb = moab;
00079     read_file( moab, example );
00080 
00081     std::vector< EntityHandle > triangles;
00082     rval = mb.get_entities_by_type( 0, MBTRI, triangles );CHECK_ERR( rval );
00083     CHECK_EQUAL( (size_t)36, triangles.size() );
00084 
00085     int vtx_ids[3];
00086     const EntityHandle* conn;
00087     int len;
00088 
00089     const int conn1[] = { 1, 4, 2 };
00090     int pos           = 0;
00091     rval              = mb.get_connectivity( triangles[pos], conn, len );CHECK_ERR( rval );
00092     CHECK_EQUAL( 3, len );
00093     int i = 0;
00094     for( i = 0; i < 3; i++ )
00095         vtx_ids[i] = mb.id_from_handle( conn[i] );
00096     CHECK_ARRAYS_EQUAL( conn1, 3, vtx_ids, len );
00097 
00098     // last triangle
00099     const int conn2[] = { 19, 21, 23 };
00100     rval              = mb.get_connectivity( triangles[35], conn, len );CHECK_ERR( rval );
00101     CHECK_EQUAL( 3, len );
00102     for( i = 0; i < 3; i++ )
00103         vtx_ids[i] = mb.id_from_handle( conn[i] );
00104     CHECK_ARRAYS_EQUAL( conn2, 3, vtx_ids, len );
00105 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines