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