MOAB: Mesh Oriented datABase  (version 5.5.0)
smf_test.cpp
Go to the documentation of this file.
1 #include "TestUtil.hpp"
2 #include "moab/Core.hpp"
3 #define IS_BUILDING_MB
4 #include "moab/Range.hpp"
5 
6 using namespace moab;
7 
8 #ifdef MESHDIR
9 static const char example[] = STRINGIFY( MESHDIR ) "/io/three.smf";
10 #else
11 static const char example[] = "three.smf";
12 #endif
13 
14 void read_file( Interface& moab, const char* input_file );
15 void test_read_nodes();
16 void test_read_triangles();
17 
18 int main()
19 {
20  int result = 0;
21 
22  result += RUN_TEST( test_read_nodes );
23  result += RUN_TEST( test_read_triangles );
24 
25  return result;
26 }
27 
28 void read_file( Interface& moab, const char* input_file )
29 {
30  ErrorCode rval = moab.load_file( input_file );CHECK_ERR( rval );
31 }
32 
34 {
35  const double eps = 1e-10;
36  ErrorCode rval;
37  Core moab;
38  Interface& mb = moab;
40 
41  std::vector< EntityHandle > nodes;
42  rval = mb.get_entities_by_type( 0, MBVERTEX, nodes );CHECK_ERR( rval );
43  CHECK_EQUAL( (size_t)24, nodes.size() );
44 
45  std::vector< double > coords( 3 * nodes.size() );
46  rval = mb.get_coords( &nodes[0], nodes.size(), &coords[0] );CHECK_ERR( rval );
47 
48  int idx = 0;
49  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
50  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
51  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
52 
53  ++idx;
54  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
55  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
56  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
57 
58  idx = 8; // second cube
59  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.2, eps );
60  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
61  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
62 
63  idx = 15; // last node of second cube
64  CHECK_REAL_EQUAL( coords[3 * idx + 0], 2.2, eps );
65  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
66  CHECK_REAL_EQUAL( coords[3 * idx + 2], 1.0, eps );
67 
68  idx = 16; // first node of third cube
69  CHECK_REAL_EQUAL( coords[3 * idx + 0], -1.2, eps );
70  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.5, eps );
71  CHECK_REAL_EQUAL( coords[3 * idx + 2], -0.2071067812, eps );
72 }
73 
75 {
76  ErrorCode rval;
77  Core moab;
78  Interface& mb = moab;
80 
81  std::vector< EntityHandle > triangles;
82  rval = mb.get_entities_by_type( 0, MBTRI, triangles );CHECK_ERR( rval );
83  CHECK_EQUAL( (size_t)36, triangles.size() );
84 
85  int vtx_ids[3];
86  const EntityHandle* conn;
87  int len;
88 
89  const int conn1[] = { 1, 4, 2 };
90  int pos = 0;
91  rval = mb.get_connectivity( triangles[pos], conn, len );CHECK_ERR( rval );
92  CHECK_EQUAL( 3, len );
93  int i = 0;
94  for( i = 0; i < 3; i++ )
95  vtx_ids[i] = mb.id_from_handle( conn[i] );
96  CHECK_ARRAYS_EQUAL( conn1, 3, vtx_ids, len );
97 
98  // last triangle
99  const int conn2[] = { 19, 21, 23 };
100  rval = mb.get_connectivity( triangles[35], conn, len );CHECK_ERR( rval );
101  CHECK_EQUAL( 3, len );
102  for( i = 0; i < 3; i++ )
103  vtx_ids[i] = mb.id_from_handle( conn[i] );
104  CHECK_ARRAYS_EQUAL( conn2, 3, vtx_ids, len );
105 }