MOAB: Mesh Oriented datABase  (version 5.5.0)
readrtt_test.cpp
Go to the documentation of this file.
1 #include "TestUtil.hpp"
2 #include "moab/Core.hpp"
3 #include "moab/Range.hpp"
4 #include "moab/Types.hpp"
5 #include "MBTagConventions.hpp"
6 #include <cmath>
7 #include <algorithm>
8 
9 using namespace moab;
10 
11 /* Input test file: rtttest_v100.rtt
12  */
13 
14 std::string example1 = TestDir + "unittest/io/rtttest_v100.rtt";
15 std::string example2 = TestDir + "unittest/io/rtttest_v101.rtt";
16 
17 void test_loadfile_1();
18 void test_meshset_tags_1();
19 void test_tets_1();
20 void test_tet_tags_1();
21 void test_triangles_1();
23 void test_vertices_1();
24 
25 void test_loadfile_2();
26 void test_meshset_tags_2();
27 void test_tets_2();
28 void test_tet_tags_2();
29 void test_triangles_2();
31 void test_vertices_2();
32 
33 void read_file( Interface& moab, const char* input_file );
34 
35 int main()
36 {
37  int result = 0;
38  // first batch
39  result += RUN_TEST( test_loadfile_1 );
40  result += RUN_TEST( test_meshset_tags_1 );
41  result += RUN_TEST( test_tets_1 );
42  result += RUN_TEST( test_tet_tags_1 );
43  result += RUN_TEST( test_triangles_1 );
44  result += RUN_TEST( test_vertices_1 );
45  // second batch
46  result += RUN_TEST( test_loadfile_2 );
47  result += RUN_TEST( test_meshset_tags_2 );
48  result += RUN_TEST( test_tets_2 );
49  result += RUN_TEST( test_tet_tags_2 );
50  result += RUN_TEST( test_triangles_2 );
51  result += RUN_TEST( test_vertices_2 );
52 
53  return result;
54 }
55 
56 void read_file( Interface& moab, const char* input_file )
57 {
58  ErrorCode rval;
59  rval = moab.load_file( input_file );CHECK_ERR( rval );
60 }
61 
63 {
64  Core moab;
65  read_file( moab, example1.c_str() );
66 }
67 
69 {
70  Core moab;
71  // load the data into moab
72  read_file( moab, example1.c_str() );
73  // query the dataset to make sure that there are the correct number of cells
75  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBENTITYSET, entities );CHECK_ERR( rval );
76 
77  Tag id_tag = moab.globalId_tag();
78 
79  // get the entities that are tagged
80  rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &id_tag, 0, 1, entities );CHECK_ERR( rval );
81 
82  // each tet should have the material tag
83  int num_vols = 10;
84  int num_surfaces = 129;
85  int num_sets = entities.size();
86  CHECK_EQUAL( num_sets, num_vols + num_surfaces + 1 + 1 );
87 
88  // from the entities, get the volume meshsets, get it from the dim tag
89  Tag dim_tag;
90  entities.clear();
91  // get the tag handle
93 
94  // get the entities that are tagged with dim 3
95  int dim3 = 3;
96  const void* const tag_vals_dim3[] = { &dim3 };
97  rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim3, 1, entities );CHECK_ERR( rval );
98 
99  // there should only be 10 meshsets of dimension 3
100  num_sets = entities.size();
101  CHECK_EQUAL( num_vols, num_sets );
102 
103  entities.clear();
104  // get the entities that are tagged with dim 2
105  int dim2 = 2;
106  const void* const tag_vals_dim2[] = { &dim2 };
107  rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim2, 1, entities );CHECK_ERR( rval );
108 
109  // there should only be 129 meshsets of dimension 2
110  num_sets = entities.size();
111  CHECK_EQUAL( num_surfaces, num_sets );
112 }
113 
115 {
116  Core moab;
117  // load the data into moab
118  read_file( moab, example1.c_str() );
119  // query the dataset to make sure that there are the correct number of cells
120  // cells = 26710 - number of tets
121  Range entities;
122  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
123  int num_tets = 26710;
124  int num_tet_in_moab = entities.size();
125  CHECK_EQUAL( num_tet_in_moab, num_tets );
126 }
127 
129 {
130  Core moab;
131  // load the data into moab
132  read_file( moab, example1.c_str() );
133  // query the dataset to make sure that there are the correct number of cells
134  Range entities;
135  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
136 
137  int num_tets = 26710;
138  int num_tet_in_moab = entities.size();
139  CHECK_EQUAL( num_tet_in_moab, num_tets );
140 
141  // get the number of tets tagged with
142  entities.clear();
143  Tag material_number;
144  // get the tag handle
145  rval = moab.tag_get_handle( "MATERIAL_NUMBER", 1, MB_TYPE_INTEGER, material_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
146 
147  // get the entities that are tagged
148  rval = moab.get_entities_by_type_and_tag( 0, moab::MBTET, &material_number, 0, 1, entities );
149  // each tet should have the material tag
150  int num_tet_tag = entities.size();
151  CHECK_EQUAL( num_tet_tag, num_tets );CHECK_ERR( rval );
152 }
153 
155 {
156  Core moab;
157  // load the data into moab
158  read_file( moab, example1.c_str() );
159  // query the dataset to make sure that there are the correct number of cells
160  Range entities;
161  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );
162 
163  int num_tri = 6383; // num tris annotated in rtttest.rtt
164  int num_tri_in_moab = entities.size();
165  CHECK_EQUAL( num_tri_in_moab, num_tri );
166 }
167 
169 {
170  Core moab;
171  // load the data into moab
172  read_file( moab, example1.c_str() );
173  // query the dataset to make sure that there are the correct number of cells
174  Range entities;
175  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );
176 
177  int num_tri = 6383; // num tris annotated in rtttest.rtt
178  int num_tri_in_moab = entities.size();
179  CHECK_EQUAL( num_tri_in_moab, num_tri );
180 
181  // get the number of tris tagged with SURFACE_NUMBER
182  entities.clear();
183  Tag surface_number;
184  // get the tag handle
185  rval = moab.tag_get_handle( "SURFACE_NUMBER", 1, MB_TYPE_INTEGER, surface_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
186 
187  // get the entities that are tagged
188  rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &surface_number, 0, 1, entities );
189  // each tri should have the surface number tag
190  int num_tri_tag = entities.size();
191  CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
192 
193  // get the number of tris tagged with SIDEID_TAG
194  entities.clear();
195  Tag sideid_tag;
196  // get the tag handle
197  rval = moab.tag_get_handle( "SIDEID_TAG", 1, MB_TYPE_INTEGER, sideid_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
198 
199  // get the entities that are tagged
200  rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &sideid_tag, 0, 1, entities );
201  // each tri should have the sideid tag
202  num_tri_tag = entities.size();
203  CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
204 }
205 
207 {
208  Core moab;
209  // load the data into moab
210  read_file( moab, example1.c_str() );
211  // query the dataset to make sure that there are the correct number of cells
212  Range entities;
213  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBVERTEX, entities );CHECK_ERR( rval );
214 
215  int num_verts = 5397; // num verts annotated in rtttest.rtt
216  int num_verts_in_moab = entities.size();
217  CHECK_EQUAL( num_verts_in_moab, num_verts );
218 }
219 
221 {
222  Core moab;
223  read_file( moab, example2.c_str() );
224 }
225 
227 {
228  Core moab;
229  // load the data into moab
230  read_file( moab, example2.c_str() );
231  // query the dataset to make sure that there are the correct number of cells
232  Range entities;
233  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBENTITYSET, entities );CHECK_ERR( rval );
234 
235  Tag id_tag = moab.globalId_tag();
236 
237  // get the entities that are tagged
238  rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &id_tag, 0, 1, entities );CHECK_ERR( rval );
239 
240  // each tet should have the material tag
241  int num_vols = 3;
242  int num_surfaces = 24;
243  int num_sets = entities.size();
244  CHECK_EQUAL( num_sets, num_vols + num_surfaces + 1 + 1 );
245 
246  // from the entities, get the volume meshsets, get it from the dim tag
247  Tag dim_tag;
248  entities.clear();
249  // get the tag handle
251 
252  // get the entities that are tagged with dim 3
253  int dim3 = 3;
254  const void* const tag_vals_dim3[] = { &dim3 };
255  rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim3, 1, entities );CHECK_ERR( rval );
256 
257  // there should only be 10 meshsets of dimension 3
258  num_sets = entities.size();
259  CHECK_EQUAL( num_vols, num_sets );
260 
261  entities.clear();
262  // get the entities that are tagged with dim 2
263  int dim2 = 2;
264  const void* const tag_vals_dim2[] = { &dim2 };
265  rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim2, 1, entities );CHECK_ERR( rval );
266 
267  // there should only be 129 meshsets of dimension 2
268  num_sets = entities.size();
269  CHECK_EQUAL( num_surfaces, num_sets );
270 }
271 
273 {
274  Core moab;
275  // load the data into moab
276  read_file( moab, example2.c_str() );
277  // query the dataset to make sure that there are the correct number of cells
278  // cells = 26710 - number of tets
279  Range entities;
280  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
281  int num_tets = 84;
282  int num_tet_in_moab = entities.size();
283  CHECK_EQUAL( num_tet_in_moab, num_tets );
284 }
285 
287 {
288  Core moab;
289  // load the data into moab
290  read_file( moab, example2.c_str() );
291  // query the dataset to make sure that there are the correct number of cells
292  Range entities;
293  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
294 
295  int num_tets = 84;
296  int num_tet_in_moab = entities.size();
297  CHECK_EQUAL( num_tet_in_moab, num_tets );
298 
299  // get the number of tets tagged with
300  entities.clear();
301  Tag material_number;
302  // get the tag handle
303  rval = moab.tag_get_handle( "MATERIAL_NUMBER", 1, MB_TYPE_INTEGER, material_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
304 
305  // get the entities that are tagged
306  rval = moab.get_entities_by_type_and_tag( 0, moab::MBTET, &material_number, 0, 1, entities );
307  // each tet should have the material tag
308  int num_tet_tag = entities.size();
309  CHECK_EQUAL( num_tet_tag, num_tets );CHECK_ERR( rval );
310 }
311 
313 {
314  Core moab;
315  // load the data into moab
316  read_file( moab, example2.c_str() );
317  // query the dataset to make sure that there are the correct number of cells
318  Range entities;
319  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );
320 
321  int num_tri = 60; // num tris annotated in rtttest.rtt
322  int num_tri_in_moab = entities.size();
323  CHECK_EQUAL( num_tri_in_moab, num_tri );
324 }
325 
327 {
328  Core moab;
329  // load the data into moab
330  read_file( moab, example2.c_str() );
331  // query the dataset to make sure that there are the correct number of cells
332  Range entities;
333  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );
334 
335  int num_tri = 60; // num tris annotated in rtttest.rtt
336  int num_tri_in_moab = entities.size();
337  CHECK_EQUAL( num_tri_in_moab, num_tri );
338 
339  // get the number of tris tagged with SURFACE_NUMBER
340  entities.clear();
341  Tag surface_number;
342  // get the tag handle
343  rval = moab.tag_get_handle( "SURFACE_NUMBER", 1, MB_TYPE_INTEGER, surface_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
344 
345  // get the entities that are tagged
346  rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &surface_number, 0, 1, entities );
347  // each tri should have the surface number tag
348  int num_tri_tag = entities.size();
349  CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
350 
351  // get the number of tris tagged with SIDEID_TAG
352  entities.clear();
353  Tag sideid_tag;
354  // get the tag handle
355  rval = moab.tag_get_handle( "SIDEID_TAG", 1, MB_TYPE_INTEGER, sideid_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );
356 
357  // get the entities that are tagged
358  rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &sideid_tag, 0, 1, entities );
359  // each tri should have the sideid tag
360  num_tri_tag = entities.size();
361  CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
362 }
363 
365 {
366  Core moab;
367  // load the data into moab
368  read_file( moab, example2.c_str() );
369  // query the dataset to make sure that there are the correct number of cells
370  Range entities;
371  ErrorCode rval = moab.get_entities_by_type( 0, moab::MBVERTEX, entities );CHECK_ERR( rval );
372 
373  int num_verts = 40; // num verts annotated in rtttest.rtt
374  int num_verts_in_moab = entities.size();
375  CHECK_EQUAL( num_verts_in_moab, num_verts );
376 }