MOAB: Mesh Oriented datABase  (version 5.5.0)
ideas_test.cpp File Reference
#include "TestUtil.hpp"
#include "moab/Core.hpp"
#include "MBTagConventions.hpp"
#include "ReadIDEAS.hpp"
#include "moab/Range.hpp"
#include <cmath>
#include <algorithm>
+ Include dependency graph for ideas_test.cpp:

Go to the source code of this file.

Macros

#define IS_BUILDING_MB
 

Functions

void read_file (Interface &moab, const char *input_file)
 
void test_read_nodes ()
 
void test_read_tets ()
 
void test_read_hexes ()
 
void test_read_material_set ()
 
void test_read_physical_set ()
 
int main ()
 

Variables

static const char example [] = "test.unv"
 

Macro Definition Documentation

◆ IS_BUILDING_MB

#define IS_BUILDING_MB

Definition at line 4 of file ideas_test.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 25 of file ideas_test.cpp.

26 {
27  int result = 0;
28 
29  result += RUN_TEST( test_read_nodes );
30  result += RUN_TEST( test_read_tets );
31  result += RUN_TEST( test_read_hexes );
32  result += RUN_TEST( test_read_material_set );
33  result += RUN_TEST( test_read_physical_set );
34 
35  return result;
36 }

References RUN_TEST, test_read_hexes(), test_read_material_set(), test_read_nodes(), test_read_physical_set(), and test_read_tets().

◆ read_file()

void read_file ( Interface moab,
const char *  input_file 
)

Definition at line 38 of file ideas_test.cpp.

39 {
40  ErrorCode rval = moab.load_file( input_file );CHECK_ERR( rval );
41 }

References CHECK_ERR, ErrorCode, and input_file.

Referenced by test_read_hexes(), test_read_material_set(), test_read_nodes(), test_read_physical_set(), and test_read_tets().

◆ test_read_hexes()

void test_read_hexes ( )

Definition at line 236 of file ideas_test.cpp.

237 {
238  ErrorCode rval;
239  Core moab;
240  Interface& mb = moab;
241  read_file( moab, example );
242 
243  std::vector< EntityHandle > hexes;
244  rval = mb.get_entities_by_type( 0, MBHEX, hexes );CHECK_ERR( rval );
245  CHECK_EQUAL( (size_t)2, hexes.size() );
246 
248 
249  std::vector< int > ids( hexes.size() );
250  rval = mb.tag_get_data( id_tag, &hexes[0], hexes.size(), &ids[0] );CHECK_ERR( rval );
251 
252  int vtx_ids[8];
253  const EntityHandle* conn;
254  int len;
255 
256  const int conn1[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
257  int pos = 0, offset = 1;
258  // Element id 1 is a hex
259  CHECK_EQUAL( pos + offset, ids[pos] );
260  rval = mb.get_connectivity( hexes[pos], conn, len );CHECK_ERR( rval );
261  CHECK_EQUAL( 8, len );
262  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
263  CHECK_ARRAYS_EQUAL( conn1, 8, vtx_ids, len );
264 
265  const int conn2[] = { 2, 9, 10, 3, 6, 11, 12, 7 };
266  ++pos;
267  // Element id 2 is a hex
268  CHECK_EQUAL( pos + offset, ids[pos] );
269  rval = mb.get_connectivity( hexes[pos], conn, len );CHECK_ERR( rval );
270  CHECK_EQUAL( 8, len );
271  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
272  CHECK_ARRAYS_EQUAL( conn2, 8, vtx_ids, len );
273 }

References CHECK_ARRAYS_EQUAL, CHECK_EQUAL, CHECK_ERR, ErrorCode, example, moab::Core::get_connectivity(), moab::Core::get_entities_by_type(), moab::Core::globalId_tag(), id_tag, mb, MBHEX, read_file(), and moab::Core::tag_get_data().

Referenced by main().

◆ test_read_material_set()

void test_read_material_set ( )

Definition at line 276 of file ideas_test.cpp.

277 {
278  ErrorCode rval;
279  Core moab;
280  Interface& mb = moab;
281  read_file( moab, example );
282 
283  Tag mat_tag;
284  rval = mb.tag_get_handle( MAT_PROP_TABLE_TAG, 1, MB_TYPE_INTEGER, mat_tag );CHECK_ERR( rval );
285 
286  Range mat_set;
287  const int mat_set_id = 100;
288  const void* const mat_set_id_val[] = { &mat_set_id };
289  rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, mat_set_id_val, 1, mat_set );CHECK_ERR( rval );
290  CHECK_EQUAL( 1, (int)mat_set.size() );
291 
292  std::vector< EntityHandle > elements, contents;
293  rval = mb.get_entities_by_type( 0, MBTET, elements );CHECK_ERR( rval );
294  rval = mb.get_entities_by_type( 0, MBHEX, elements );CHECK_ERR( rval );
295  rval = mb.get_entities_by_handle( mat_set.front(), contents );CHECK_ERR( rval );
296  std::sort( elements.begin(), elements.end() );
297  std::sort( contents.begin(), contents.end() );
298  CHECK_EQUAL( elements, contents );
299 }

References CHECK_EQUAL, CHECK_ERR, ErrorCode, example, moab::Range::front(), moab::Core::get_entities_by_handle(), moab::Core::get_entities_by_type(), moab::Core::get_entities_by_type_and_tag(), MAT_PROP_TABLE_TAG, mb, MB_TYPE_INTEGER, MBENTITYSET, MBHEX, MBTET, read_file(), moab::Range::size(), and moab::Core::tag_get_handle().

Referenced by main().

◆ test_read_nodes()

void test_read_nodes ( )

Definition at line 43 of file ideas_test.cpp.

44 {
45  const double eps = 1e-6;
46  ErrorCode rval;
47  Core moab;
48  Interface& mb = moab;
50 
51  std::vector< EntityHandle > nodes;
52  rval = mb.get_entities_by_type( 0, MBVERTEX, nodes );CHECK_ERR( rval );
53  CHECK_EQUAL( (size_t)17, nodes.size() );
54 
56 
57  std::vector< int > ids( nodes.size() );
58  rval = mb.tag_get_data( id_tag, &nodes[0], nodes.size(), &ids[0] );CHECK_ERR( rval );
59 
60  std::vector< int > sorted_ids( ids );
61  std::sort( sorted_ids.begin(), sorted_ids.end() );
62 
63  std::vector< double > coords( 3 * nodes.size() );
64  rval = mb.get_coords( &nodes[0], nodes.size(), &coords[0] );CHECK_ERR( rval );
65 
66  int idx, pos = 0;
67  // shared between 2 tets and 2 prisms
68  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
69  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
70  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
71  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
72  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
73 
74  ++pos;
75  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
76  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
77  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
78  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
79  CHECK_REAL_EQUAL( coords[3 * idx + 2], 1.0, eps );
80 
81  ++pos;
82  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
83  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
84  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
85  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
86  CHECK_REAL_EQUAL( coords[3 * idx + 2], 1.0, eps );
87 
88  // id=4
89  ++pos;
90  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
91  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
92  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
93  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
94  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
95 
96  ++pos;
97  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
98  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
99  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
100  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
101  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
102 
103  ++pos;
104  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
105  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
106  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
107  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
108  CHECK_REAL_EQUAL( coords[3 * idx + 2], 1.0, eps );
109 
110  ++pos;
111  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
112  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
113  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
114  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
115  CHECK_REAL_EQUAL( coords[3 * idx + 2], 1.0, eps );
116 
117  // id=8
118  ++pos;
119  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
120  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
121  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
122  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
123  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
124 
125  ++pos;
126  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
127  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
128  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
129  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
130  CHECK_REAL_EQUAL( coords[3 * idx + 2], 2.0, eps );
131 
132  ++pos;
133  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
134  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
135  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
136  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
137  CHECK_REAL_EQUAL( coords[3 * idx + 2], 2.0, eps );
138 
139  ++pos;
140  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
141  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
142  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
143  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
144  CHECK_REAL_EQUAL( coords[3 * idx + 2], 2.0, eps );
145 
146  // id=12
147  ++pos;
148  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
149  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
150  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
151  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
152  CHECK_REAL_EQUAL( coords[3 * idx + 2], 2.0, eps );
153 
154  ++pos;
155  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
156  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
157  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0000022760448197, eps );
158  CHECK_REAL_EQUAL( coords[3 * idx + 1], -2.2760448196157412e-06, eps );
159  CHECK_REAL_EQUAL( coords[3 * idx + 2], 2.0, eps );
160 
161  ++pos;
162  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
163  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
164  CHECK_REAL_EQUAL( coords[3 * idx + 0], -2.2760448196157412e-6, eps );
165  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0000022760448197, eps );
166  CHECK_REAL_EQUAL( coords[3 * idx + 2], 2.0, eps );
167 
168  ++pos;
169  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
170  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
171  CHECK_REAL_EQUAL( coords[3 * idx + 0], -2.2760448197267635e-6, eps );
172  CHECK_REAL_EQUAL( coords[3 * idx + 1], -2.2760448196157412e-6, eps );
173  CHECK_REAL_EQUAL( coords[3 * idx + 2], 2.0, eps );
174 
175  // id=16
176  ++pos;
177  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
178  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
179  CHECK_REAL_EQUAL( coords[3 * idx + 0], 5.0e-1, eps );
180  CHECK_REAL_EQUAL( coords[3 * idx + 1], 5.0e-1, eps );
181  CHECK_REAL_EQUAL( coords[3 * idx + 2], 3.0, eps );
182 
183  ++pos;
184  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
185  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
186  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0000022760448197, eps );
187  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0000022760448197, eps );
188  CHECK_REAL_EQUAL( coords[3 * idx + 2], 2.0, eps );
189 }

References CHECK_EQUAL, CHECK_ERR, CHECK_REAL_EQUAL, eps, ErrorCode, example, moab::Core::get_coords(), moab::Core::get_entities_by_type(), moab::Core::globalId_tag(), id_tag, mb, MBVERTEX, read_file(), and moab::Core::tag_get_data().

Referenced by main().

◆ test_read_physical_set()

void test_read_physical_set ( )

Definition at line 302 of file ideas_test.cpp.

303 {
304  ErrorCode rval;
305  Core moab;
306  Interface& mb = moab;
307  read_file( moab, example );
308 
309  Tag phys_tag;
310  rval = mb.tag_get_handle( PHYS_PROP_TABLE_TAG, 1, MB_TYPE_INTEGER, phys_tag );CHECK_ERR( rval );
311 
312  Range phys_set;
313  const int phys_set_id = 4;
314  const void* const phys_set_id_val[] = { &phys_set_id };
315  rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &phys_tag, phys_set_id_val, 1, phys_set );CHECK_ERR( rval );
316  CHECK_EQUAL( 1, (int)phys_set.size() );
317 
318  std::vector< EntityHandle > tets, contents;
319  rval = mb.get_entities_by_type( 0, MBTET, tets );CHECK_ERR( rval );
320  rval = mb.get_entities_by_handle( phys_set.front(), contents );CHECK_ERR( rval );
321  std::sort( tets.begin(), tets.end() );
322  std::sort( contents.begin(), contents.end() );
323  CHECK_EQUAL( tets, contents );
324 }

References CHECK_EQUAL, CHECK_ERR, ErrorCode, example, moab::Range::front(), moab::Core::get_entities_by_handle(), moab::Core::get_entities_by_type(), moab::Core::get_entities_by_type_and_tag(), mb, MB_TYPE_INTEGER, MBENTITYSET, MBTET, PHYS_PROP_TABLE_TAG, read_file(), moab::Range::size(), and moab::Core::tag_get_handle().

Referenced by main().

◆ test_read_tets()

void test_read_tets ( )

Definition at line 191 of file ideas_test.cpp.

192 {
193  ErrorCode rval;
194  Core moab;
195  Interface& mb = moab;
196  read_file( moab, example );
197 
198  std::vector< EntityHandle > tets;
199  rval = mb.get_entities_by_type( 0, MBTET, tets );CHECK_ERR( rval );
200  CHECK_EQUAL( (size_t)2, tets.size() );
201 
203 
204  std::vector< int > ids( tets.size() );
205  rval = mb.tag_get_data( id_tag, &tets[0], tets.size(), &ids[0] );CHECK_ERR( rval );
206 
207  if( ids[0] != 3 )
208  {
209  std::swap( ids[0], ids[1] );
210  std::swap( tets[0], tets[1] );
211  }
212 
213  int vtx_ids[4];
214  const EntityHandle* conn;
215  int len;
216 
217  // The first tet has id=3
218  const int conn1[] = { 13, 14, 15, 16 };
219  int pos = 0, offset = 3;
220  CHECK_EQUAL( pos + offset, ids[pos] );
221  rval = mb.get_connectivity( tets[pos], conn, len );CHECK_ERR( rval );
222  CHECK_EQUAL( 4, len );
223  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
224  CHECK_ARRAYS_EQUAL( conn1, 4, vtx_ids, len );
225 
226  // The second tet has id=4
227  const int conn2[] = { 13, 17, 14, 16 };
228  ++pos;
229  CHECK_EQUAL( pos + offset, ids[pos] );
230  rval = mb.get_connectivity( tets[pos], conn, len );CHECK_ERR( rval );
231  CHECK_EQUAL( 4, len );
232  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
233  CHECK_ARRAYS_EQUAL( conn2, 4, vtx_ids, len );
234 }

References CHECK_ARRAYS_EQUAL, CHECK_EQUAL, CHECK_ERR, ErrorCode, example, moab::Core::get_connectivity(), moab::Core::get_entities_by_type(), moab::Core::globalId_tag(), id_tag, mb, MBTET, read_file(), swap(), and moab::Core::tag_get_data().

Referenced by main().

Variable Documentation

◆ example

const char example[] = "test.unv"
static