MOAB: Mesh Oriented datABase  (version 5.5.0)
MOAB_iMesh_extensions_tests.cpp
Go to the documentation of this file.
1 #include "TestRunner.hpp"
2 #include "iMesh.h"
3 #include "iMesh_extensions.h"
4 #include "MBiMesh.hpp"
5 #include "moab/Core.hpp"
6 #include <algorithm>
7 
8 void test_tag_iterate();
9 void test_step_iter();
10 
11 int main( int argc, char* argv[] )
12 {
15 
16  return RUN_TESTS( argc, argv );
17 }
18 
20 {
22  int err;
23  iMesh_newMesh( "", &mesh, &err, 0 );
24  CHECK_EQUAL( iBase_SUCCESS, err );
25 
27  iMesh_getRootSet( mesh, &root_set, &err );
28  CHECK_EQUAL( iBase_SUCCESS, err );
29 
30  iBase_EntityHandle* verts = 0;
31  int verts_alloc = 0, verts_size = 0;
32  double coords[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 };
33  iMesh_createVtxArr( mesh, 6, iBase_INTERLEAVED, coords, 18, &verts, &verts_alloc, &verts_size, &err );
34  CHECK_EQUAL( iBase_SUCCESS, err );
35 
36  /* create an entity set with two subranges */
37  iMesh_createEntSet( mesh, 0, &entset, &err );
38  CHECK_EQUAL( iBase_SUCCESS, err );
39  iMesh_addEntArrToSet( mesh, verts, 2, entset, &err );
40  CHECK_EQUAL( iBase_SUCCESS, err );
41  iMesh_addEntArrToSet( mesh, &verts[3], 3, entset, &err );
42  CHECK_EQUAL( iBase_SUCCESS, err );
43 
44  /* create a dbl tag and set vertices */
45  iBase_TagHandle tagh;
46  iMesh_createTagWithOptions( mesh, "dum", "moab:TAG_STORAGE_TYPE=DENSE", 1, iBase_DOUBLE, &tagh, &err, 3, 27 );
47  CHECK_EQUAL( iBase_SUCCESS, err );
48  iMesh_setDblArrData( mesh, verts, 6, tagh, coords + 3, 6, &err );
49  CHECK_EQUAL( iBase_SUCCESS, err );
50 
51  /* get an iterator over the root set, and check tag iterator for that */
53  int count, atend;
54  double* data;
56  CHECK_EQUAL( iBase_SUCCESS, err );
57  iMesh_tagIterate( mesh, tagh, iter, &data, &count, &err );
58  CHECK_EQUAL( iBase_SUCCESS, err );
59  if( count != 6 ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
60 
61  for( int i = 0; i < 6; i++ )
62  {
63  if( data[i] != coords[i + 3] ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
64  }
65  iMesh_endEntArrIter( mesh, iter, &err );
66  CHECK_EQUAL( iBase_SUCCESS, err );
67  iter = 0; // iMesh_endEntArrIter frees iter
68 
69  /* get an iterator over the set with two subranges, and check tag iterator for that */
70  iMesh_initEntArrIter( mesh, entset, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 6, 0, &iter, &err );
71  CHECK_EQUAL( iBase_SUCCESS, err );
72  iMesh_tagIterate( mesh, tagh, iter, &data, &count, &err );
73  CHECK_EQUAL( iBase_SUCCESS, err );
74  if( count != 2 || data[0] != coords[3] || data[1] != coords[4] ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
75  iMesh_stepEntArrIter( mesh, iter, 2, &atend, &err );
76  CHECK_EQUAL( iBase_SUCCESS, err );
77  /* shouldn't be at end yet */
78  if( atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
79 
80  iMesh_tagIterate( mesh, tagh, iter, &data, &count, &err );
81  CHECK_EQUAL( iBase_SUCCESS, err );
82  if( count != 3 || data[0] != coords[6] || data[1] != coords[7] ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
83  iMesh_stepEntArrIter( mesh, iter, 3, &atend, &err );
84  CHECK_EQUAL( iBase_SUCCESS, err );
85  /* should be at end now */
86  if( !atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
87  iMesh_endEntArrIter( mesh, iter, &err );
88  CHECK_EQUAL( iBase_SUCCESS, err );
89 
90  iMesh_dtor( mesh, &err );
91  CHECK_EQUAL( iBase_SUCCESS, err );
92 
93  free( verts );
94 }
95 
97 {
99  int err;
100  iMesh_newMesh( "", &mesh, &err, 0 );
101  CHECK_EQUAL( iBase_SUCCESS, err );
102 
104  iMesh_getRootSet( mesh, &root_set, &err );
105  CHECK_EQUAL( iBase_SUCCESS, err );
106 
107  iBase_EntityHandle* verts = 0;
108  int verts_alloc = 0, verts_size = 0;
109  double coords[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 };
110  iMesh_createVtxArr( mesh, 6, iBase_INTERLEAVED, coords, 18, &verts, &verts_alloc, &verts_size, &err );
111  CHECK_EQUAL( iBase_SUCCESS, err );
112 
113  /* make a non-array iterator and test stepping over it */
115  int atend;
117  CHECK_EQUAL( iBase_SUCCESS, err );
118  iMesh_stepEntIter( mesh, iter, 2, &atend, &err );
119  CHECK_EQUAL( iBase_SUCCESS, err );
120  /* shouldn't be at end yet */
121  if( atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
122 
123  iMesh_stepEntIter( mesh, iter, 4, &atend, &err );
124  CHECK_EQUAL( iBase_SUCCESS, err );
125  /* should be at end now */
126  if( !atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
127  iMesh_endEntIter( mesh, iter, &err );
128  CHECK_EQUAL( iBase_SUCCESS, err );
129 
130  /* make an array iterator and test stepping over it */
131  iBase_EntityArrIterator arr_iter;
133  CHECK_EQUAL( iBase_SUCCESS, err );
134  iMesh_stepEntArrIter( mesh, arr_iter, 2, &atend, &err );
135  CHECK_EQUAL( iBase_SUCCESS, err );
136  /* shouldn't be at end yet */
137  if( atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
138 
139  iMesh_stepEntArrIter( mesh, arr_iter, 4, &atend, &err );
140  CHECK_EQUAL( iBase_SUCCESS, err );
141  /* should be at end now */
142  if( !atend ) CHECK_EQUAL( iBase_SUCCESS, iBase_FAILURE );
143  iMesh_endEntArrIter( mesh, arr_iter, &err );
144  CHECK_EQUAL( iBase_SUCCESS, err );
145 
146  iMesh_dtor( mesh, &err );
147  CHECK_EQUAL( iBase_SUCCESS, err );
148 
149  free( verts );
150 }