1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#include "TestUtil.hpp"
#include "moab/Core.hpp"
#include "moab/Range.hpp"
#include "moab/Types.hpp"
#include "MBTagConventions.hpp"
#include <cmath>
#include <algorithm>

using namespace moab;

/* Input test file: rtttest_v100.rtt
 */

std::string example1 = TestDir + "unittest/io/rtttest_v100.rtt";
std::string example2 = TestDir + "unittest/io/rtttest_v101.rtt";

void test_loadfile_1();
void test_meshset_tags_1();
void test_tets_1();
void test_tet_tags_1();
void test_triangles_1();
void test_triangles_tags_1();
void test_vertices_1();

void test_loadfile_2();
void test_meshset_tags_2();
void test_tets_2();
void test_tet_tags_2();
void test_triangles_2();
void test_triangles_tags_2();
void test_vertices_2();

void read_file( Interface& moab, const char* input_file );

int main()
{
    int result = 0;
    // first batch
    result += RUN_TEST( test_loadfile_1 );
    result += RUN_TEST( test_meshset_tags_1 );
    result += RUN_TEST( test_tets_1 );
    result += RUN_TEST( test_tet_tags_1 );
    result += RUN_TEST( test_triangles_1 );
    result += RUN_TEST( test_vertices_1 );
    // second batch
    result += RUN_TEST( test_loadfile_2 );
    result += RUN_TEST( test_meshset_tags_2 );
    result += RUN_TEST( test_tets_2 );
    result += RUN_TEST( test_tet_tags_2 );
    result += RUN_TEST( test_triangles_2 );
    result += RUN_TEST( test_vertices_2 );

    return result;
}

void read_file( Interface& moab, const char* input_file )
{
    ErrorCode rval;
    rval = moab.load_file( input_file );CHECK_ERR( rval );
}

void test_loadfile_1()
{
    Core moab;
    read_file( moab, example1.c_str() );
}

void test_meshset_tags_1()
{
    Core moab;
    // load the data into moab
    read_file( moab, example1.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBENTITYSET, entities );CHECK_ERR( rval );

    Tag id_tag = moab.globalId_tag();

    // get the entities that are tagged
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &id_tag, 0, 1, entities );CHECK_ERR( rval );

    // each tet should have the material tag
    int num_vols     = 10;
    int num_surfaces = 129;
    int num_sets     = entities.size();
    CHECK_EQUAL( num_sets, num_vols + num_surfaces + 1 + 1 );

    // from the entities, get the volume meshsets, get it from the dim tag
    Tag dim_tag;
    entities.clear();
    // get the tag handle
    rval = moab.tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, dim_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );

    // get the entities that are tagged with dim 3
    int dim3                          = 3;
    const void* const tag_vals_dim3[] = { &dim3 };
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim3, 1, entities );CHECK_ERR( rval );

    // there should only be 10 meshsets of dimension 3
    num_sets = entities.size();
    CHECK_EQUAL( num_vols, num_sets );

    entities.clear();
    // get the entities that are tagged with dim 2
    int dim2                          = 2;
    const void* const tag_vals_dim2[] = { &dim2 };
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim2, 1, entities );CHECK_ERR( rval );

    // there should only be 129 meshsets of dimension 2
    num_sets = entities.size();
    CHECK_EQUAL( num_surfaces, num_sets );
}

void test_tets_1()
{
    Core moab;
    // load the data into moab
    read_file( moab, example1.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    // cells = 26710 - number of tets
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
    int num_tets        = 26710;
    int num_tet_in_moab = entities.size();
    CHECK_EQUAL( num_tet_in_moab, num_tets );
}

void test_tet_tags_1()
{
    Core moab;
    // load the data into moab
    read_file( moab, example1.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );

    int num_tets        = 26710;
    int num_tet_in_moab = entities.size();
    CHECK_EQUAL( num_tet_in_moab, num_tets );

    // get the number of tets tagged with
    entities.clear();
    Tag material_number;
    // get the tag handle
    rval = moab.tag_get_handle( "MATERIAL_NUMBER", 1, MB_TYPE_INTEGER, material_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );

    // get the entities that are tagged
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBTET, &material_number, 0, 1, entities );
    // each tet should have the material tag
    int num_tet_tag = entities.size();
    CHECK_EQUAL( num_tet_tag, num_tets );CHECK_ERR( rval );
}

void test_triangles_1()
{
    Core moab;
    // load the data into moab
    read_file( moab, example1.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );

    int num_tri         = 6383;  // num tris annotated in rtttest.rtt
    int num_tri_in_moab = entities.size();
    CHECK_EQUAL( num_tri_in_moab, num_tri );
}

void test_triangles_tags_1()<--- The function 'test_triangles_tags_1' is never used.
{
    Core moab;
    // load the data into moab
    read_file( moab, example1.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );

    int num_tri         = 6383;  // num tris annotated in rtttest.rtt
    int num_tri_in_moab = entities.size();
    CHECK_EQUAL( num_tri_in_moab, num_tri );

    // get the number of tris tagged with SURFACE_NUMBER
    entities.clear();
    Tag surface_number;
    // get the tag handle
    rval = moab.tag_get_handle( "SURFACE_NUMBER", 1, MB_TYPE_INTEGER, surface_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );

    // get the entities that are tagged
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &surface_number, 0, 1, entities );
    // each tri should have the surface number tag
    int num_tri_tag = entities.size();
    CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );

    // get the number of tris tagged with SIDEID_TAG
    entities.clear();
    Tag sideid_tag;
    // get the tag handle
    rval = moab.tag_get_handle( "SIDEID_TAG", 1, MB_TYPE_INTEGER, sideid_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );

    // get the entities that are tagged
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &sideid_tag, 0, 1, entities );
    // each tri should have the sideid tag
    num_tri_tag = entities.size();
    CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
}

void test_vertices_1()
{
    Core moab;
    // load the data into moab
    read_file( moab, example1.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBVERTEX, entities );CHECK_ERR( rval );

    int num_verts         = 5397;  // num verts annotated in rtttest.rtt
    int num_verts_in_moab = entities.size();
    CHECK_EQUAL( num_verts_in_moab, num_verts );
}

void test_loadfile_2()
{
    Core moab;
    read_file( moab, example2.c_str() );
}

void test_meshset_tags_2()
{
    Core moab;
    // load the data into moab
    read_file( moab, example2.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBENTITYSET, entities );CHECK_ERR( rval );

    Tag id_tag = moab.globalId_tag();

    // get the entities that are tagged
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &id_tag, 0, 1, entities );CHECK_ERR( rval );

    // each tet should have the material tag
    int num_vols     = 3;
    int num_surfaces = 24;
    int num_sets     = entities.size();
    CHECK_EQUAL( num_sets, num_vols + num_surfaces + 1 + 1 );

    // from the entities, get the volume meshsets, get it from the dim tag
    Tag dim_tag;
    entities.clear();
    // get the tag handle
    rval = moab.tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, dim_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );

    // get the entities that are tagged with dim 3
    int dim3                          = 3;
    const void* const tag_vals_dim3[] = { &dim3 };
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim3, 1, entities );CHECK_ERR( rval );

    // there should only be 10 meshsets of dimension 3
    num_sets = entities.size();
    CHECK_EQUAL( num_vols, num_sets );

    entities.clear();
    // get the entities that are tagged with dim 2
    int dim2                          = 2;
    const void* const tag_vals_dim2[] = { &dim2 };
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &dim_tag, tag_vals_dim2, 1, entities );CHECK_ERR( rval );

    // there should only be 129 meshsets of dimension 2
    num_sets = entities.size();
    CHECK_EQUAL( num_surfaces, num_sets );
}

void test_tets_2()
{
    Core moab;
    // load the data into moab
    read_file( moab, example2.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    // cells = 26710 - number of tets
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );
    int num_tets        = 84;
    int num_tet_in_moab = entities.size();
    CHECK_EQUAL( num_tet_in_moab, num_tets );
}

void test_tet_tags_2()
{
    Core moab;
    // load the data into moab
    read_file( moab, example2.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTET, entities );CHECK_ERR( rval );

    int num_tets        = 84;
    int num_tet_in_moab = entities.size();
    CHECK_EQUAL( num_tet_in_moab, num_tets );

    // get the number of tets tagged with
    entities.clear();
    Tag material_number;
    // get the tag handle
    rval = moab.tag_get_handle( "MATERIAL_NUMBER", 1, MB_TYPE_INTEGER, material_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );

    // get the entities that are tagged
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBTET, &material_number, 0, 1, entities );
    // each tet should have the material tag
    int num_tet_tag = entities.size();
    CHECK_EQUAL( num_tet_tag, num_tets );CHECK_ERR( rval );
}

void test_triangles_2()
{
    Core moab;
    // load the data into moab
    read_file( moab, example2.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );

    int num_tri         = 60;  // num tris annotated in rtttest.rtt
    int num_tri_in_moab = entities.size();
    CHECK_EQUAL( num_tri_in_moab, num_tri );
}

void test_triangles_tags_2()<--- The function 'test_triangles_tags_2' is never used.
{
    Core moab;
    // load the data into moab
    read_file( moab, example2.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBTRI, entities );CHECK_ERR( rval );

    int num_tri         = 60;  // num tris annotated in rtttest.rtt
    int num_tri_in_moab = entities.size();
    CHECK_EQUAL( num_tri_in_moab, num_tri );

    // get the number of tris tagged with SURFACE_NUMBER
    entities.clear();
    Tag surface_number;
    // get the tag handle
    rval = moab.tag_get_handle( "SURFACE_NUMBER", 1, MB_TYPE_INTEGER, surface_number, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );

    // get the entities that are tagged
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &surface_number, 0, 1, entities );
    // each tri should have the surface number tag
    int num_tri_tag = entities.size();
    CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );

    // get the number of tris tagged with SIDEID_TAG
    entities.clear();
    Tag sideid_tag;
    // get the tag handle
    rval = moab.tag_get_handle( "SIDEID_TAG", 1, MB_TYPE_INTEGER, sideid_tag, MB_TAG_SPARSE | MB_TAG_CREAT );CHECK_ERR( rval );

    // get the entities that are tagged
    rval = moab.get_entities_by_type_and_tag( 0, moab::MBTRI, &sideid_tag, 0, 1, entities );
    // each tri should have the sideid tag
    num_tri_tag = entities.size();
    CHECK_EQUAL( num_tri_tag, num_tri );CHECK_ERR( rval );
}

void test_vertices_2()
{
    Core moab;
    // load the data into moab
    read_file( moab, example2.c_str() );
    // query the dataset to make sure that there are the correct number of cells
    Range entities;
    ErrorCode rval = moab.get_entities_by_type( 0, moab::MBVERTEX, entities );CHECK_ERR( rval );

    int num_verts         = 40;  // num verts annotated in rtttest.rtt
    int num_verts_in_moab = entities.size();
    CHECK_EQUAL( num_verts_in_moab, num_verts );
}