MOAB: Mesh Oriented datABase  (version 5.5.0)
nastran_test.cpp File Reference
#include "TestUtil.hpp"
#include "moab/Core.hpp"
#include "MBTagConventions.hpp"
#include "moab/Range.hpp"
#include <cmath>
#include <algorithm>
+ Include dependency graph for nastran_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_prisms ()
 
void test_read_hexes ()
 
void test_read_material_set1 ()
 
void test_read_material_set2 ()
 
int main ()
 

Variables

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

Macro Definition Documentation

◆ IS_BUILDING_MB

#define IS_BUILDING_MB

Definition at line 4 of file nastran_test.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 25 of file nastran_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_prisms );
32  result += RUN_TEST( test_read_hexes );
33  result += RUN_TEST( test_read_material_set1 );
34  result += RUN_TEST( test_read_material_set2 );
35 
36  return result;
37 }

References RUN_TEST, test_read_hexes(), test_read_material_set1(), test_read_material_set2(), test_read_nodes(), test_read_prisms(), and test_read_tets().

◆ read_file()

void read_file ( Interface moab,
const char *  input_file 
)

Definition at line 39 of file nastran_test.cpp.

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

References CHECK_ERR, ErrorCode, and input_file.

Referenced by test_read_hexes(), test_read_material_set1(), test_read_material_set2(), test_read_nodes(), test_read_prisms(), and test_read_tets().

◆ test_read_hexes()

void test_read_hexes ( )

Definition at line 290 of file nastran_test.cpp.

291 {
292  ErrorCode rval;
293  Core moab;
294  Interface& mb = moab;
295  read_file( moab, example );
296 
297  std::vector< EntityHandle > hexes;
298  rval = mb.get_entities_by_type( 0, MBHEX, hexes );CHECK_ERR( rval );
299  CHECK_EQUAL( (size_t)1, hexes.size() );
300 
302 
303  std::vector< int > ids( hexes.size() );
304  rval = mb.tag_get_data( id_tag, &hexes[0], hexes.size(), &ids[0] );CHECK_ERR( rval );
305 
306  int vtx_ids[8];
307  const EntityHandle* conn;
308  int len;
309 
310  const int conn1[] = { 12, 13, 14, 15, 16, 17, 18, 19 };
311  int pos = 0;
312  // Element id 5 is the hex
313  CHECK_EQUAL( pos + 5, ids[pos] );
314  rval = mb.get_connectivity( hexes[pos], conn, len );CHECK_ERR( rval );
315  CHECK_EQUAL( 8, len );
316  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
317  CHECK_ARRAYS_EQUAL( conn1, 8, vtx_ids, len );
318 }

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_set1()

void test_read_material_set1 ( )

Definition at line 321 of file nastran_test.cpp.

322 {
323  ErrorCode rval;
324  Core moab;
325  Interface& mb = moab;
326  read_file( moab, example );
327 
328  Tag mat_tag;
329  rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mat_tag );CHECK_ERR( rval );
330 
331  Range mat_set_one;
332  const int one = 1;
333  const void* const one_val[] = { &one };
334  rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, one_val, 1, mat_set_one );CHECK_ERR( rval );
335  CHECK_EQUAL( 1, (int)mat_set_one.size() );
336 
337  std::vector< EntityHandle > tets, contents;
338  rval = mb.get_entities_by_type( 0, MBTET, tets );CHECK_ERR( rval );
339  rval = mb.get_entities_by_handle( mat_set_one.front(), contents );CHECK_ERR( rval );
340  std::sort( tets.begin(), tets.end() );
341  std::sort( contents.begin(), contents.end() );
342  CHECK_EQUAL( tets, contents );
343 }

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(), MATERIAL_SET_TAG_NAME, mb, MB_TYPE_INTEGER, MBENTITYSET, MBTET, read_file(), moab::Range::size(), and moab::Core::tag_get_handle().

Referenced by main().

◆ test_read_material_set2()

void test_read_material_set2 ( )

Definition at line 346 of file nastran_test.cpp.

347 {
348  ErrorCode rval;
349  Core moab;
350  Interface& mb = moab;
351  read_file( moab, example );
352 
353  Tag mat_tag;
354  rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mat_tag );CHECK_ERR( rval );
355 
356  Range mat_set_two;
357  const int two = 2;
358  const void* const two_val[] = { &two };
359  rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, two_val, 1, mat_set_two );CHECK_ERR( rval );
360  CHECK_EQUAL( 1, (int)mat_set_two.size() );
361 
362  std::vector< EntityHandle > prisms, contents;
363  rval = mb.get_entities_by_type( 0, MBPRISM, prisms );CHECK_ERR( rval );
364  rval = mb.get_entities_by_handle( mat_set_two.front(), contents );CHECK_ERR( rval );
365  std::sort( prisms.begin(), prisms.end() );
366  std::sort( contents.begin(), contents.end() );
367  CHECK_EQUAL( prisms, contents );
368 }

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(), MATERIAL_SET_TAG_NAME, mb, MB_TYPE_INTEGER, MBENTITYSET, MBPRISM, read_file(), moab::Range::size(), and moab::Core::tag_get_handle().

Referenced by main().

◆ test_read_nodes()

void test_read_nodes ( )

Definition at line 44 of file nastran_test.cpp.

45 {
46  const double eps = 1e-100;
47  ErrorCode rval;
48  Core moab;
49  Interface& mb = moab;
51 
52  std::vector< EntityHandle > nodes;
53  rval = mb.get_entities_by_type( 0, MBVERTEX, nodes );CHECK_ERR( rval );
54  CHECK_EQUAL( (size_t)19, nodes.size() );
55 
57 
58  std::vector< int > ids( nodes.size() );
59  rval = mb.tag_get_data( id_tag, &nodes[0], nodes.size(), &ids[0] );CHECK_ERR( rval );
60 
61  std::vector< int > sorted_ids( ids );
62  std::sort( sorted_ids.begin(), sorted_ids.end() );
63 
64  std::vector< double > coords( 3 * nodes.size() );
65  rval = mb.get_coords( &nodes[0], nodes.size(), &coords[0] );CHECK_ERR( rval );
66 
67  int idx, pos = 0;
68  // shared between 2 tets and 2 prisms
69  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
70  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
71  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
72  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
73  CHECK_REAL_EQUAL( coords[3 * idx + 2], -2.0, eps );
74 
75  ++pos;
76  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
77  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
78  CHECK_REAL_EQUAL( coords[3 * idx + 0], -1.0, eps );
79  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
80  CHECK_REAL_EQUAL( coords[3 * idx + 2], -1.0, eps );
81 
82  ++pos;
83  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
84  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
85  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
86  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
87  CHECK_REAL_EQUAL( coords[3 * idx + 2], -1.0, eps );
88 
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], 1.0, eps );
94  CHECK_REAL_EQUAL( coords[3 * idx + 2], -1.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], 0.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], 0.0, eps );
108  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.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], 0.0, eps );
114  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
115  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
116 
117  ++pos;
118  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
119  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
120  CHECK_REAL_EQUAL( coords[3 * idx + 0], -1.0, eps );
121  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
122  CHECK_REAL_EQUAL( coords[3 * idx + 2], 1.0, eps );
123 
124  ++pos;
125  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
126  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
127  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
128  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
129  CHECK_REAL_EQUAL( coords[3 * idx + 2], 1.0, eps );
130 
131  ++pos;
132  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
133  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
134  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
135  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
136  CHECK_REAL_EQUAL( coords[3 * idx + 2], 1.0, eps );
137 
138  ++pos;
139  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
140  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
141  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
142  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
143  CHECK_REAL_EQUAL( coords[3 * idx + 2], 2.0, eps );
144  // hex element
145  ++pos;
146  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
147  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
148  CHECK_REAL_EQUAL( coords[3 * idx + 0], 5.0, eps );
149  CHECK_REAL_EQUAL( coords[3 * idx + 1], 5.0, eps );
150  CHECK_REAL_EQUAL( coords[3 * idx + 2], 5.0, eps );
151 
152  ++pos;
153  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
154  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
155  CHECK_REAL_EQUAL( coords[3 * idx + 0], 10.0, eps );
156  CHECK_REAL_EQUAL( coords[3 * idx + 1], 5.0, eps );
157  CHECK_REAL_EQUAL( coords[3 * idx + 2], 5.0, eps );
158 
159  ++pos;
160  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
161  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
162  CHECK_REAL_EQUAL( coords[3 * idx + 0], 10.0, eps );
163  CHECK_REAL_EQUAL( coords[3 * idx + 1], 10.0, eps );
164  CHECK_REAL_EQUAL( coords[3 * idx + 2], 5.0, eps );
165 
166  ++pos;
167  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
168  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
169  CHECK_REAL_EQUAL( coords[3 * idx + 0], 5.0, eps );
170  CHECK_REAL_EQUAL( coords[3 * idx + 1], 10.0, eps );
171  CHECK_REAL_EQUAL( coords[3 * idx + 2], 5.0, eps );
172 
173  ++pos;
174  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
175  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
176  CHECK_REAL_EQUAL( coords[3 * idx + 0], 5.0, eps );
177  CHECK_REAL_EQUAL( coords[3 * idx + 1], 5.0, eps );
178  CHECK_REAL_EQUAL( coords[3 * idx + 2], 10.0, eps );
179 
180  ++pos;
181  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
182  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
183  CHECK_REAL_EQUAL( coords[3 * idx + 0], 10.0, eps );
184  CHECK_REAL_EQUAL( coords[3 * idx + 1], 5.0, eps );
185  CHECK_REAL_EQUAL( coords[3 * idx + 2], 10.0, eps );
186 
187  ++pos;
188  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
189  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
190  CHECK_REAL_EQUAL( coords[3 * idx + 0], 10.0, eps );
191  CHECK_REAL_EQUAL( coords[3 * idx + 1], 10.0, eps );
192  CHECK_REAL_EQUAL( coords[3 * idx + 2], 10.0, eps );
193 
194  ++pos;
195  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
196  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
197  CHECK_REAL_EQUAL( coords[3 * idx + 0], 5.0, eps );
198  CHECK_REAL_EQUAL( coords[3 * idx + 1], 10.0, eps );
199  CHECK_REAL_EQUAL( coords[3 * idx + 2], 10.0, eps );
200 }

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_prisms()

void test_read_prisms ( )

Definition at line 245 of file nastran_test.cpp.

246 {
247  ErrorCode rval;
248  Core moab;
249  Interface& mb = moab;
250  read_file( moab, example );
251 
252  std::vector< EntityHandle > prisms;
253  rval = mb.get_entities_by_type( 0, MBPRISM, prisms );CHECK_ERR( rval );
254  CHECK_EQUAL( (size_t)2, prisms.size() );
255 
257 
258  std::vector< int > ids( prisms.size() );
259  rval = mb.tag_get_data( id_tag, &prisms[0], prisms.size(), &ids[0] );CHECK_ERR( rval );
260 
261  if( ids[0] != 3 )
262  {
263  std::swap( ids[0], ids[1] );
264  std::swap( prisms[0], prisms[1] );
265  }
266 
267  int vtx_ids[6];
268  const EntityHandle* conn;
269  int len;
270 
271  const int conn1[] = { 2, 3, 4, 5, 6, 7 };
272  int pos = 0;
273  // Element ids 1 and 2 are the two tet elements.
274  // Element ids 3 and 4 are the two prism elements.
275  CHECK_EQUAL( pos + 3, ids[pos] );
276  rval = mb.get_connectivity( prisms[pos], conn, len );CHECK_ERR( rval );
277  CHECK_EQUAL( 6, len );
278  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
279  CHECK_ARRAYS_EQUAL( conn1, 6, vtx_ids, len );
280 
281  const int conn2[] = { 5, 6, 7, 8, 9, 10 };
282  ++pos;
283  CHECK_EQUAL( pos + 3, ids[pos] );
284  rval = mb.get_connectivity( prisms[pos], conn, len );CHECK_ERR( rval );
285  CHECK_EQUAL( 6, len );
286  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
287  CHECK_ARRAYS_EQUAL( conn2, 6, vtx_ids, len );
288 }

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, MBPRISM, read_file(), swap(), and moab::Core::tag_get_data().

Referenced by main().

◆ test_read_tets()

void test_read_tets ( )

Definition at line 202 of file nastran_test.cpp.

203 {
204  ErrorCode rval;
205  Core moab;
206  Interface& mb = moab;
207  read_file( moab, example );
208 
209  std::vector< EntityHandle > tets;
210  rval = mb.get_entities_by_type( 0, MBTET, tets );CHECK_ERR( rval );
211  CHECK_EQUAL( (size_t)2, tets.size() );
212 
214 
215  std::vector< int > ids( tets.size() );
216  rval = mb.tag_get_data( id_tag, &tets[0], tets.size(), &ids[0] );CHECK_ERR( rval );
217 
218  if( ids[0] != 1 )
219  {
220  std::swap( ids[0], ids[1] );
221  std::swap( tets[0], tets[1] );
222  }
223 
224  int vtx_ids[4];
225  const EntityHandle* conn;
226  int len;
227 
228  const int conn1[] = { 8, 9, 10, 11 };
229  int pos = 0;
230  CHECK_EQUAL( pos + 1, ids[pos] );
231  rval = mb.get_connectivity( tets[pos], conn, len );CHECK_ERR( rval );
232  CHECK_EQUAL( 4, len );
233  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
234  CHECK_ARRAYS_EQUAL( conn1, 4, vtx_ids, len );
235 
236  const int conn2[] = { 4, 3, 2, 1 };
237  ++pos;
238  CHECK_EQUAL( pos + 1, ids[pos] );
239  rval = mb.get_connectivity( tets[pos], conn, len );CHECK_ERR( rval );
240  CHECK_EQUAL( 4, len );
241  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
242  CHECK_ARRAYS_EQUAL( conn2, 4, vtx_ids, len );
243 }

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.nas"
static