MOAB: Mesh Oriented datABase  (version 5.5.0)
mbcn_test.cpp
Go to the documentation of this file.
1 #include "TestUtil.hpp"
2 #include "moab/CN.hpp"
3 
4 using namespace moab;
5 
7 void test_type_names();
8 void test_dimension();
11 
21 
30 
37 
42 
43 void test_has_mid_nodes( EntityType type );
45 {
47 }
49 {
51 }
53 {
55 }
57 {
59 }
61 {
63 }
65 {
67 }
69 {
71 }
73 {
75 }
76 
77 void test_ho_node_parent();
78 void test_ho_node_index();
79 
80 void test_sub_entity_nodes( EntityType parent, int sub_dimension );
81 void test_sub_entity_nodes( EntityType parent, int num_nodes, int sub_dimension );
83 {
85 }
87 {
89 }
91 {
93 }
95 {
97 }
99 {
101 }
103 {
105 }
107 {
109 }
111 {
113 }
115 {
117 }
119 {
121 }
123 {
125 }
127 {
129 }
130 void prism_issue();
131 void test_wedges();
132 
133 int main()
134 {
135  int result = 0;
136  result += RUN_TEST( test_dimension_pair );
137  result += RUN_TEST( test_type_names );
138  result += RUN_TEST( test_dimension );
139  result += RUN_TEST( test_vertices_per_entity );
140  result += RUN_TEST( test_num_sub_entities );
141 
142  result += RUN_TEST( test_sub_entity_type_vtx );
143  result += RUN_TEST( test_sub_entity_type_edge );
144  result += RUN_TEST( test_sub_entity_type_tri );
145  result += RUN_TEST( test_sub_entity_type_quad );
146  result += RUN_TEST( test_sub_entity_type_tet );
147  result += RUN_TEST( test_sub_entity_type_pyr );
148  result += RUN_TEST( test_sub_entity_type_pri );
150  result += RUN_TEST( test_sub_entity_type_hex );
151 
160 
161  result += RUN_TEST( test_side_number_tri );
162  result += RUN_TEST( test_side_number_quad );
163  result += RUN_TEST( test_side_number_tet );
164  result += RUN_TEST( test_side_number_pyr );
165  result += RUN_TEST( test_side_number_pri );
166  result += RUN_TEST( test_side_number_hex );
167 
168  result += RUN_TEST( test_opposite_side_tri );
169  result += RUN_TEST( test_opposite_side_quad );
170  result += RUN_TEST( test_opposite_side_tet );
171  result += RUN_TEST( test_opposite_side_hex );
172 
173  result += RUN_TEST( test_has_mid_nodes_edge );
174  result += RUN_TEST( test_has_mid_nodes_tri );
175  result += RUN_TEST( test_has_mid_nodes_quad );
176  result += RUN_TEST( test_has_mid_nodes_tet );
177  result += RUN_TEST( test_has_mid_nodes_pyr );
178  result += RUN_TEST( test_has_mid_nodes_pri );
179  result += RUN_TEST( test_has_mid_nodes_knife );
180  result += RUN_TEST( test_has_mid_nodes_hex );
181 
194 
195  result += RUN_TEST( test_ho_node_parent );
196  result += RUN_TEST( test_ho_node_index );
197  result += RUN_TEST( prism_issue );
198  result += RUN_TEST( test_wedges );
199  return result;
200 }
201 
202 const EntityType elem_types[] = { MBTRI, MBQUAD, MBTET, MBPYRAMID, MBPRISM, MBHEX, MBMAXTYPE };
203 // const int num_elem_types = sizeof(elem_types)/sizeof(elem_types[0]) - 1;
204 
206 {
207  DimensionPair dp;
208 
209  dp = CN::TypeDimensionMap[0];
210  CHECK_EQUAL( MBVERTEX, dp.first );
211  CHECK_EQUAL( MBVERTEX, dp.second );
212 
213  dp = CN::TypeDimensionMap[1];
214  CHECK_EQUAL( MBEDGE, dp.first );
215  CHECK_EQUAL( MBEDGE, dp.second );
216 
217  dp = CN::TypeDimensionMap[2];
218  CHECK_EQUAL( MBTRI, dp.first );
219  CHECK_EQUAL( MBPOLYGON, dp.second );
220 
221  dp = CN::TypeDimensionMap[3];
222  CHECK_EQUAL( MBTET, dp.first );
223  CHECK_EQUAL( MBPOLYHEDRON, dp.second );
224 }
225 
227 {
228  for( EntityType t = MBVERTEX; t != MBMAXTYPE; ++t )
229  {
230  const char* name = CN::EntityTypeName( t );
232  }
233 }
234 
236 {
248 }
249 
251 {
261 }
262 
264 {
266 
269 
273 
277 
281 
285 
289 
293 
295  CHECK_EQUAL( 12, CN::NumSubEntities( MBHEX, 1 ) );
297 }
298 
299 void do_test_sub_entity_type_2d( EntityType type )
300 {
301  for( int j = 0; j < CN::VerticesPerEntity( type ); ++j )
302  {
303  CHECK_EQUAL( MBVERTEX, CN::SubEntityType( type, 0, j ) );
304  CHECK_EQUAL( MBEDGE, CN::SubEntityType( type, 1, j ) );
305  }
306  CHECK_EQUAL( type, CN::SubEntityType( type, 2, 0 ) );
307 }
308 
309 void do_test_sub_entity_type_3d( EntityType type, int num_faces, const EntityType* face_types )
310 {
311  for( int j = 0; j < CN::VerticesPerEntity( type ); ++j )
312  {
313  CHECK_EQUAL( MBVERTEX, CN::SubEntityType( type, 0, j ) );
314  }
315 
316  for( int j = 0; j < CN::NumSubEntities( type, 1 ); ++j )
317  {
318  CHECK_EQUAL( MBEDGE, CN::SubEntityType( type, 1, j ) );
319  }
320 
321  for( int j = 0; j < num_faces; ++j )
322  {
323  EntityType sub_type = CN::SubEntityType( type, 2, j );
324  CHECK_EQUAL( face_types[j], sub_type );
325  }
326 
327  CHECK_EQUAL( type, CN::SubEntityType( type, 3, 0 ) );
328 }
329 
331 {
333 }
334 
336 {
340 }
341 
343 {
345 }
346 
348 {
350 }
351 
353 {
354  const EntityType types[] = { MBTRI, MBTRI, MBTRI, MBTRI };
355  do_test_sub_entity_type_3d( MBTET, sizeof( types ) / sizeof( types[0] ), types );
356 }
357 
359 {
360  const EntityType types[] = { MBTRI, MBTRI, MBTRI, MBTRI, MBQUAD };
361  do_test_sub_entity_type_3d( MBPYRAMID, sizeof( types ) / sizeof( types[0] ), types );
362 }
363 
365 {
366  const EntityType types[] = { MBQUAD, MBQUAD, MBQUAD, MBTRI, MBTRI };
367  do_test_sub_entity_type_3d( MBPRISM, sizeof( types ) / sizeof( types[0] ), types );
368 }
369 
371 {
372  const EntityType types[] = { MBQUAD, MBQUAD, MBQUAD, MBQUAD, MBQUAD };
373  do_test_sub_entity_type_3d( MBKNIFE, sizeof( types ) / sizeof( types[0] ), types );
374 }
375 
377 {
378  const EntityType types[] = { MBQUAD, MBQUAD, MBQUAD, MBQUAD, MBQUAD, MBQUAD };
379  do_test_sub_entity_type_3d( MBHEX, sizeof( types ) / sizeof( types[0] ), types );
380 }
381 
382 void test_0d_sub_entity_indices( EntityType type, int num_vtx )
383 {
384  for( int i = 0; i < num_vtx; ++i )
385  {
386  // zero input array
387  int indices[2] = { 0, -100 };
388  // check correct results
389  CN::SubEntityVertexIndices( type, 0, i, indices );
390  CHECK_EQUAL( i, indices[0] );
391  // check didn't write past end of array
392  CHECK_EQUAL( -100, indices[1] );
393  }
394 }
395 
396 void test_1d_sub_entity_indices( EntityType type, int num_edges, const int ( *edge_indices )[2] )
397 {
398  for( int i = 0; i < num_edges; ++i )
399  {
400  // zero input array
401  int indices[3] = { 0, 0, -99 };
402  // check correct results
403  CN::SubEntityVertexIndices( type, 1, i, indices );
404  if( edge_indices[i][0] == indices[0] )
405  {
406  CHECK_EQUAL( edge_indices[i][1], indices[1] );
407  }
408  else
409  {
410  CHECK_EQUAL( edge_indices[i][0], indices[1] );
411  CHECK_EQUAL( edge_indices[i][1], indices[0] );
412  }
413  // check didn't write past end of array
414  CHECK_EQUAL( -99, indices[2] );
415  }
416 }
417 
418 void test_2d_sub_entity_indices( EntityType type, int num_faces, const int ( *face_indices )[5] )
419 {
420  for( int i = 0; i < num_faces; ++i )
421  {
422  // zero input array
423  int indices[5] = { 0, 0, 0, -99, -99 };
424  // check correct results
425  CN::SubEntityVertexIndices( type, 2, i, indices );
426  const int num_vtx = face_indices[i][0];
427  if( num_vtx != 3 ) CHECK_EQUAL( 4, num_vtx );
428  const int* exp_index = face_indices[i] + 1;
429  int off = std::find( indices, indices + num_vtx, exp_index[0] ) - indices;
430  CHECK( off < num_vtx );
431  /* Expect faces to be ordered such that CCW normal is outwards
432  *
433  bool reverse = indices[(off+num_vtx-1)%num_vtx] == exp_index[1];
434  if (reverse) {
435  CHECK_EQUAL( exp_index[1], indices[(off+num_vtx-1)%num_vtx] );
436  CHECK_EQUAL( exp_index[2], indices[(off+num_vtx-2)%num_vtx] );
437  if (num_vtx == 4)
438  CHECK_EQUAL( exp_index[3], indices[(off+num_vtx-3)%num_vtx] );
439  }
440  else {
441  */
442  CHECK_EQUAL( exp_index[1], indices[( off + 1 ) % num_vtx] );
443  CHECK_EQUAL( exp_index[2], indices[( off + 2 ) % num_vtx] );
444  if( num_vtx == 4 ) CHECK_EQUAL( exp_index[3], indices[( off + 3 ) % num_vtx] );
445  /*
446  }
447  */
448 
449  // check didn't write past end of array
450  if( num_vtx == 3 ) CHECK_EQUAL( -99, indices[3] );
451  CHECK_EQUAL( -99, indices[4] );
452  }
453 }
454 
455 void test_elem_as_sub_entity( EntityType type, int dim, int num_vertices )
456 {
457  int indices[9] = { -2, -2, -2, -2, -2, -2, -2, -2, -2 };
458  CN::SubEntityVertexIndices( type, dim, 0, indices );
459  for( int i = 0; i < num_vertices; ++i )
460  CHECK_EQUAL( i, indices[i] );
461  // make sure didn't write past end
462  CHECK_EQUAL( -2, indices[num_vertices] );
463 }
464 
466 {
468 }
469 
471 {
474 }
475 
477 {
478  const int edges[3][2] = { { 0, 1 }, { 1, 2 }, { 2, 0 } };
480  test_1d_sub_entity_indices( MBTRI, 3, edges );
482 }
483 
485 {
486  const int edges[4][2] = { { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 } };
488  test_1d_sub_entity_indices( MBQUAD, 4, edges );
490 }
491 
493 {
494  const EntityType type = MBTET;
495  const int num_vtx = 4;
496  const int edges[][2] = { { 0, 1 }, { 1, 2 }, { 2, 0 }, { 0, 3 }, { 1, 3 }, { 2, 3 } };
497  const int faces[][5] = { { 3, 0, 1, 3, 0 }, { 3, 1, 2, 3, 0 }, { 3, 2, 0, 3, 0 }, { 3, 2, 1, 0, 0 } };
498  test_0d_sub_entity_indices( type, num_vtx );
499  test_1d_sub_entity_indices( type, sizeof( edges ) / sizeof( edges[0] ), edges );
500  test_2d_sub_entity_indices( type, sizeof( faces ) / sizeof( faces[0] ), faces );
501  test_elem_as_sub_entity( type, 3, num_vtx );
502 }
503 
505 {
506  const EntityType type = MBPYRAMID;
507  const int num_vtx = 5;
508  const int edges[][2] = { { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }, { 0, 4 }, { 1, 4 }, { 2, 4 }, { 3, 4 } };
509  const int faces[][5] = {
510  { 3, 0, 1, 4, 0 }, { 3, 1, 2, 4, 0 }, { 3, 2, 3, 4, 0 }, { 3, 3, 0, 4, 0 }, { 4, 3, 2, 1, 0 } };
511  test_0d_sub_entity_indices( type, num_vtx );
512  test_1d_sub_entity_indices( type, sizeof( edges ) / sizeof( edges[0] ), edges );
513  test_2d_sub_entity_indices( type, sizeof( faces ) / sizeof( faces[0] ), faces );
514  test_elem_as_sub_entity( type, 3, num_vtx );
515 }
516 
518 {
519  const EntityType type = MBPRISM;
520  const int num_vtx = 6;
521  const int edges[][2] = { { 0, 1 }, { 1, 2 }, { 2, 0 }, { 0, 3 }, { 1, 4 }, { 2, 5 }, { 3, 4 }, { 4, 5 }, { 5, 3 } };
522  const int faces[][5] = {
523  { 4, 0, 1, 4, 3 }, { 4, 1, 2, 5, 4 }, { 4, 2, 0, 3, 5 }, { 3, 2, 1, 0, 0 }, { 3, 3, 4, 5, 0 } };
524  test_0d_sub_entity_indices( type, num_vtx );
525  test_1d_sub_entity_indices( type, sizeof( edges ) / sizeof( edges[0] ), edges );
526  test_2d_sub_entity_indices( type, sizeof( faces ) / sizeof( faces[0] ), faces );
527  test_elem_as_sub_entity( type, 3, num_vtx );
528 }
529 
531 {
532  const EntityType type = MBHEX;
533  const int num_vtx = 8;
534  const int edges[][2] = { { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }, { 0, 4 }, { 1, 5 },
535  { 2, 6 }, { 3, 7 }, { 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 } };
536  const int faces[][5] = { { 4, 0, 1, 5, 4 }, { 4, 1, 2, 6, 5 }, { 4, 2, 3, 7, 6 },
537  { 4, 3, 0, 4, 7 }, { 4, 3, 2, 1, 0 }, { 4, 4, 5, 6, 7 } };
538  test_0d_sub_entity_indices( type, num_vtx );
539  test_1d_sub_entity_indices( type, sizeof( edges ) / sizeof( edges[0] ), edges );
540  test_2d_sub_entity_indices( type, sizeof( faces ) / sizeof( faces[0] ), faces );
541  test_elem_as_sub_entity( type, 3, num_vtx );
542 }
543 
544 static void do_test_side_number_1d( EntityType type, int idx )
545 {
546  // define a random handle list
547  const int elem_verts[] = { 7400, 6233, 3027, 0454, 6839, 5391, 7735, 3603 };
548  // get side indices
549  int side_idx[4] = { 0, 0 };
550  CN::SubEntityVertexIndices( type, 1, idx, side_idx );
551 
552  // "reversed" and "offset" are the same thing for edges.
553  int side_conn[2] = { elem_verts[side_idx[0]], elem_verts[side_idx[1]] };
554  int rev_conn[2] = { elem_verts[side_idx[1]], elem_verts[side_idx[0]] };
555  int result_side = -100, result_sense = -100, result_offset = -100;
556  int err = CN::SideNumber( type, elem_verts, side_conn, 2, 1, result_side, result_sense, result_offset );
557  CHECK_EQUAL( 0, err );
558  CHECK_EQUAL( idx, result_side );
559  CHECK_EQUAL( 1, result_sense );
560  CHECK_EQUAL( 0, result_offset );
561  err = CN::SideNumber( type, elem_verts, rev_conn, 2, 1, result_side, result_sense, result_offset );
562  CHECK_EQUAL( 0, err );
563  CHECK_EQUAL( idx, result_side );
564  CHECK( result_offset == 1 || result_sense == -1 );
565 }
566 
567 static void do_test_side_number_2d( EntityType type, int idx )
568 {
569  // define a random handle list
570  const int elem_verts[] = { 7400, 6233, 3027, 0454, 6839, 5391, 7735, 3603 };
571  // get side indices
572  const int side_size = CN::VerticesPerEntity( CN::SubEntityType( type, 2, idx ) );
573  int side_idx[4] = { 0, 0, 0, 0 };
574  CN::SubEntityVertexIndices( type, 2, idx, side_idx );
575 
576  // for each possible forward or reverse offset
577  for( int rev = -1; rev < 2; rev += 2 )
578  {
579  for( int off = 0; off < side_size; ++off )
580  {
581  int side_conn[4];
582  side_conn[3] = 0;
583  for( int i = 0; i < side_size; ++i )
584  side_conn[( side_size + rev * i ) % side_size] = elem_verts[side_idx[( i + off ) % side_size]];
585 
586  int result_side = -100, result_sense = -100, result_offset = -100;
587  int err =
588  CN::SideNumber( type, elem_verts, side_conn, side_size, 2, result_side, result_sense, result_offset );
589  CHECK_EQUAL( 0, err );
590  CHECK_EQUAL( idx, result_side );
591  CHECK_EQUAL( rev, result_sense );
592  CHECK_EQUAL( off, result_offset );
593  }
594  }
595 }
596 
598 {
599  for( int side = 0; side < 3; ++side )
600  do_test_side_number_1d( MBTRI, side );
601 }
602 
604 {
605  for( int side = 0; side < 4; ++side )
607 }
608 
610 {
611  for( int edge = 0; edge < 6; ++edge )
613  for( int face = 0; face < 4; ++face )
615 }
616 
618 {
619  for( int edge = 0; edge < 8; ++edge )
621  for( int face = 0; face < 5; ++face )
623 }
624 
626 {
627  for( int edge = 0; edge < 9; ++edge )
629  for( int face = 0; face < 5; ++face )
631 }
632 
634 {
635  for( int edge = 0; edge < 12; ++edge )
637  for( int face = 0; face < 6; ++face )
639 }
640 
642 {
643  int idx, dim, err;
644  err = CN::OppositeSide( MBTRI, 0, 0, idx, dim );
645  CHECK_EQUAL( 0, err );
646  CHECK_EQUAL( 1, dim );
647  CHECK_EQUAL( 1, idx );
648  err = CN::OppositeSide( MBTRI, 1, 0, idx, dim );
649  CHECK_EQUAL( 0, err );
650  CHECK_EQUAL( 1, dim );
651  CHECK_EQUAL( 2, idx );
652  err = CN::OppositeSide( MBTRI, 2, 0, idx, dim );
653  CHECK_EQUAL( 0, err );
654  CHECK_EQUAL( 1, dim );
655  CHECK_EQUAL( 0, idx );
656  err = CN::OppositeSide( MBTRI, 0, 1, idx, dim );
657  CHECK_EQUAL( 0, err );
658  CHECK_EQUAL( 0, dim );
659  CHECK_EQUAL( 2, idx );
660  err = CN::OppositeSide( MBTRI, 1, 1, idx, dim );
661  CHECK_EQUAL( 0, err );
662  CHECK_EQUAL( 0, dim );
663  CHECK_EQUAL( 0, idx );
664  err = CN::OppositeSide( MBTRI, 2, 1, idx, dim );
665  CHECK_EQUAL( 0, err );
666  CHECK_EQUAL( 0, dim );
667  CHECK_EQUAL( 1, idx );
668 }
669 
671 {
672  int idx, dim, err;
673  err = CN::OppositeSide( MBQUAD, 0, 0, idx, dim );
674  CHECK_EQUAL( 0, err );
675  CHECK_EQUAL( 0, dim );
676  CHECK_EQUAL( 2, idx );
677  err = CN::OppositeSide( MBQUAD, 1, 0, idx, dim );
678  CHECK_EQUAL( 0, err );
679  CHECK_EQUAL( 0, dim );
680  CHECK_EQUAL( 3, idx );
681  err = CN::OppositeSide( MBQUAD, 2, 0, idx, dim );
682  CHECK_EQUAL( 0, err );
683  CHECK_EQUAL( 0, dim );
684  CHECK_EQUAL( 0, idx );
685  err = CN::OppositeSide( MBQUAD, 3, 0, idx, dim );
686  CHECK_EQUAL( 0, err );
687  CHECK_EQUAL( 0, dim );
688  CHECK_EQUAL( 1, idx );
689 
690  err = CN::OppositeSide( MBQUAD, 0, 1, idx, dim );
691  CHECK_EQUAL( 0, err );
692  CHECK_EQUAL( 1, dim );
693  CHECK_EQUAL( 2, idx );
694  err = CN::OppositeSide( MBQUAD, 1, 1, idx, dim );
695  CHECK_EQUAL( 0, err );
696  CHECK_EQUAL( 1, dim );
697  CHECK_EQUAL( 3, idx );
698  err = CN::OppositeSide( MBQUAD, 2, 1, idx, dim );
699  CHECK_EQUAL( 0, err );
700  CHECK_EQUAL( 1, dim );
701  CHECK_EQUAL( 0, idx );
702  err = CN::OppositeSide( MBQUAD, 3, 1, idx, dim );
703  CHECK_EQUAL( 0, err );
704  CHECK_EQUAL( 1, dim );
705  CHECK_EQUAL( 1, idx );
706 }
707 
709 {
710  int idx, dim, err;
711 
712  err = CN::OppositeSide( MBTET, 0, 0, idx, dim );
713  CHECK_EQUAL( 0, err );
714  CHECK_EQUAL( 2, dim );
715  CHECK_EQUAL( 1, idx );
716  err = CN::OppositeSide( MBTET, 1, 0, idx, dim );
717  CHECK_EQUAL( 0, err );
718  CHECK_EQUAL( 2, dim );
719  CHECK_EQUAL( 2, idx );
720  err = CN::OppositeSide( MBTET, 2, 0, idx, dim );
721  CHECK_EQUAL( 0, err );
722  CHECK_EQUAL( 2, dim );
723  CHECK_EQUAL( 0, idx );
724  err = CN::OppositeSide( MBTET, 3, 0, idx, dim );
725  CHECK_EQUAL( 0, err );
726  CHECK_EQUAL( 2, dim );
727  CHECK_EQUAL( 3, idx );
728 
729  err = CN::OppositeSide( MBTET, 0, 2, idx, dim );
730  CHECK_EQUAL( 0, err );
731  CHECK_EQUAL( 0, dim );
732  CHECK_EQUAL( 2, idx );
733  err = CN::OppositeSide( MBTET, 1, 2, idx, dim );
734  CHECK_EQUAL( 0, err );
735  CHECK_EQUAL( 0, dim );
736  CHECK_EQUAL( 0, idx );
737  err = CN::OppositeSide( MBTET, 2, 2, idx, dim );
738  CHECK_EQUAL( 0, err );
739  CHECK_EQUAL( 0, dim );
740  CHECK_EQUAL( 1, idx );
741  err = CN::OppositeSide( MBTET, 3, 2, idx, dim );
742  CHECK_EQUAL( 0, err );
743  CHECK_EQUAL( 0, dim );
744  CHECK_EQUAL( 3, idx );
745 
746  err = CN::OppositeSide( MBTET, 0, 1, idx, dim );
747  CHECK_EQUAL( 0, err );
748  CHECK_EQUAL( 1, dim );
749  CHECK_EQUAL( 5, idx );
750  err = CN::OppositeSide( MBTET, 1, 1, idx, dim );
751  CHECK_EQUAL( 0, err );
752  CHECK_EQUAL( 1, dim );
753  CHECK_EQUAL( 3, idx );
754  err = CN::OppositeSide( MBTET, 2, 1, idx, dim );
755  CHECK_EQUAL( 0, err );
756  CHECK_EQUAL( 1, dim );
757  CHECK_EQUAL( 4, idx );
758  err = CN::OppositeSide( MBTET, 3, 1, idx, dim );
759  CHECK_EQUAL( 0, err );
760  CHECK_EQUAL( 1, dim );
761  CHECK_EQUAL( 1, idx );
762  err = CN::OppositeSide( MBTET, 4, 1, idx, dim );
763  CHECK_EQUAL( 0, err );
764  CHECK_EQUAL( 1, dim );
765  CHECK_EQUAL( 2, idx );
766  err = CN::OppositeSide( MBTET, 5, 1, idx, dim );
767  CHECK_EQUAL( 0, err );
768  CHECK_EQUAL( 1, dim );
769  CHECK_EQUAL( 0, idx );
770 }
771 
773 {
774  int idx, dim, err;
775 
776  err = CN::OppositeSide( MBHEX, 0, 0, idx, dim );
777  CHECK_EQUAL( 0, err );
778  CHECK_EQUAL( 0, dim );
779  CHECK_EQUAL( 6, idx );
780  err = CN::OppositeSide( MBHEX, 1, 0, idx, dim );
781  CHECK_EQUAL( 0, err );
782  CHECK_EQUAL( 0, dim );
783  CHECK_EQUAL( 7, idx );
784  err = CN::OppositeSide( MBHEX, 2, 0, idx, dim );
785  CHECK_EQUAL( 0, err );
786  CHECK_EQUAL( 0, dim );
787  CHECK_EQUAL( 4, idx );
788  err = CN::OppositeSide( MBHEX, 3, 0, idx, dim );
789  CHECK_EQUAL( 0, err );
790  CHECK_EQUAL( 0, dim );
791  CHECK_EQUAL( 5, idx );
792  err = CN::OppositeSide( MBHEX, 4, 0, idx, dim );
793  CHECK_EQUAL( 0, err );
794  CHECK_EQUAL( 0, dim );
795  CHECK_EQUAL( 2, idx );
796  err = CN::OppositeSide( MBHEX, 5, 0, idx, dim );
797  CHECK_EQUAL( 0, err );
798  CHECK_EQUAL( 0, dim );
799  CHECK_EQUAL( 3, idx );
800  err = CN::OppositeSide( MBHEX, 6, 0, idx, dim );
801  CHECK_EQUAL( 0, err );
802  CHECK_EQUAL( 0, dim );
803  CHECK_EQUAL( 0, idx );
804  err = CN::OppositeSide( MBHEX, 7, 0, idx, dim );
805  CHECK_EQUAL( 0, err );
806  CHECK_EQUAL( 0, dim );
807  CHECK_EQUAL( 1, idx );
808 
809  err = CN::OppositeSide( MBHEX, 0, 1, idx, dim );
810  CHECK_EQUAL( 0, err );
811  CHECK_EQUAL( 1, dim );
812  CHECK_EQUAL( 10, idx );
813  err = CN::OppositeSide( MBHEX, 1, 1, idx, dim );
814  CHECK_EQUAL( 0, err );
815  CHECK_EQUAL( 1, dim );
816  CHECK_EQUAL( 11, idx );
817  err = CN::OppositeSide( MBHEX, 2, 1, idx, dim );
818  CHECK_EQUAL( 0, err );
819  CHECK_EQUAL( 1, dim );
820  CHECK_EQUAL( 8, idx );
821  err = CN::OppositeSide( MBHEX, 3, 1, idx, dim );
822  CHECK_EQUAL( 0, err );
823  CHECK_EQUAL( 1, dim );
824  CHECK_EQUAL( 9, idx );
825  err = CN::OppositeSide( MBHEX, 4, 1, idx, dim );
826  CHECK_EQUAL( 0, err );
827  CHECK_EQUAL( 1, dim );
828  CHECK_EQUAL( 6, idx );
829  err = CN::OppositeSide( MBHEX, 5, 1, idx, dim );
830  CHECK_EQUAL( 0, err );
831  CHECK_EQUAL( 1, dim );
832  CHECK_EQUAL( 7, idx );
833  err = CN::OppositeSide( MBHEX, 6, 1, idx, dim );
834  CHECK_EQUAL( 0, err );
835  CHECK_EQUAL( 1, dim );
836  CHECK_EQUAL( 4, idx );
837  err = CN::OppositeSide( MBHEX, 7, 1, idx, dim );
838  CHECK_EQUAL( 0, err );
839  CHECK_EQUAL( 1, dim );
840  CHECK_EQUAL( 5, idx );
841  err = CN::OppositeSide( MBHEX, 8, 1, idx, dim );
842  CHECK_EQUAL( 0, err );
843  CHECK_EQUAL( 1, dim );
844  CHECK_EQUAL( 2, idx );
845  err = CN::OppositeSide( MBHEX, 9, 1, idx, dim );
846  CHECK_EQUAL( 0, err );
847  CHECK_EQUAL( 1, dim );
848  CHECK_EQUAL( 3, idx );
849  err = CN::OppositeSide( MBHEX, 10, 1, idx, dim );
850  CHECK_EQUAL( 0, err );
851  CHECK_EQUAL( 1, dim );
852  CHECK_EQUAL( 0, idx );
853  err = CN::OppositeSide( MBHEX, 11, 1, idx, dim );
854  CHECK_EQUAL( 0, err );
855  CHECK_EQUAL( 1, dim );
856  CHECK_EQUAL( 1, idx );
857 
858  err = CN::OppositeSide( MBHEX, 0, 2, idx, dim );
859  CHECK_EQUAL( 0, err );
860  CHECK_EQUAL( 2, dim );
861  CHECK_EQUAL( 2, idx );
862  err = CN::OppositeSide( MBHEX, 1, 2, idx, dim );
863  CHECK_EQUAL( 0, err );
864  CHECK_EQUAL( 2, dim );
865  CHECK_EQUAL( 3, idx );
866  err = CN::OppositeSide( MBHEX, 2, 2, idx, dim );
867  CHECK_EQUAL( 0, err );
868  CHECK_EQUAL( 2, dim );
869  CHECK_EQUAL( 0, idx );
870  err = CN::OppositeSide( MBHEX, 3, 2, idx, dim );
871  CHECK_EQUAL( 0, err );
872  CHECK_EQUAL( 2, dim );
873  CHECK_EQUAL( 1, idx );
874  err = CN::OppositeSide( MBHEX, 4, 2, idx, dim );
875  CHECK_EQUAL( 0, err );
876  CHECK_EQUAL( 2, dim );
877  CHECK_EQUAL( 5, idx );
878  err = CN::OppositeSide( MBHEX, 5, 2, idx, dim );
879  CHECK_EQUAL( 0, err );
880  CHECK_EQUAL( 2, dim );
881  CHECK_EQUAL( 4, idx );
882 }
883 
884 void test_has_mid_nodes( EntityType type )
885 {
886  const int combinations[][4] = { { 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 1, 1, 0 },
887  { 0, 0, 0, 1 }, { 0, 1, 0, 1 }, { 0, 0, 1, 1 }, { 0, 1, 1, 1 } };
888 
889  const int dim = CN::Dimension( type );
890  // calculate number of valid combinations of ho node flags
891  int num_comb = 1;
892  for( int i = 0; i < dim; ++i )
893  num_comb *= 2;
894  // for each valid combination
895  for( int c = 0; c < num_comb; ++c )
896  {
897  // calculate corresponding number of vertices in element
898  const int* ho_nodes = combinations[c];
899  int num_vtx = CN::VerticesPerEntity( type );
900  switch( dim )
901  {
902  case 3:
903  case 2:
904  // extra clauses to avoid fall-through error
905  if( 3 == dim && ho_nodes[2] ) num_vtx += CN::NumSubEntities( type, 2 );
906  if( 2 <= dim && ho_nodes[1] ) num_vtx += CN::NumSubEntities( type, 1 );
907  }
908  if( ho_nodes[dim] ) ++num_vtx;
909 
910  CHECK_EQUAL( ho_nodes[1], (int)CN::HasMidEdgeNodes( type, num_vtx ) );
911  CHECK_EQUAL( ho_nodes[2], (int)CN::HasMidFaceNodes( type, num_vtx ) );
912  CHECK_EQUAL( ho_nodes[3], (int)CN::HasMidRegionNodes( type, num_vtx ) );
913 
914  int results[4] = { 0, -1, -1, -1 };
915  CN::HasMidNodes( type, num_vtx, results );
916  CHECK_EQUAL( 0, !!results[0] );
917  CHECK_EQUAL( ho_nodes[1], !!results[1] );
918  CHECK_EQUAL( ho_nodes[2], !!results[2] );
919  CHECK_EQUAL( ho_nodes[3], !!results[3] );
920  }
921 }
922 
924 {
925  const int combinations[][4] = { { 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 1, 1, 0 },
926  { 0, 0, 0, 1 }, { 0, 1, 0, 1 }, { 0, 0, 1, 1 }, { 0, 1, 1, 1 } };
927 
928  for( const EntityType* t = elem_types; *t != MBMAXTYPE; ++t )
929  {
930  const EntityType type = *t;
931  const int dim = CN::Dimension( type );
932  // calculate number of valid combinations of ho node flags
933  int num_comb = 1;
934  for( int i = 0; i < dim; ++i )
935  num_comb *= 2;
936  // for each valid combination
937  for( int c = 0; c < num_comb; ++c )
938  {
939  // calculate corresponding number of vertices in element
940  const int* ho_nodes = combinations[c];
941  int num_vtx = CN::VerticesPerEntity( type );
942  switch( dim )
943  {
944  case 3:
945  case 2:
946  // extra clauses to avoid fall-through error
947  if( 3 == dim && ho_nodes[2] ) num_vtx += CN::NumSubEntities( type, 2 );
948  if( 2 <= dim && ho_nodes[1] ) num_vtx += CN::NumSubEntities( type, 1 );
949  }
950  if( ho_nodes[dim] ) ++num_vtx;
951 
952  // start at first higher-order node
953  int pos = CN::VerticesPerEntity( type );
954 
955  // check mid-edge
956  if( dim > 1 && ho_nodes[1] )
957  {
958  for( int i = 0; i < CN::NumSubEntities( type, 1 ); ++i )
959  {
960  int pdim = -1, pidx = -1;
961  CN::HONodeParent( type, num_vtx, pos++, pdim, pidx );
962  CHECK_EQUAL( 1, pdim );
963  CHECK_EQUAL( i, pidx );
964  }
965  }
966 
967  // check mid-face
968  if( dim > 2 && ho_nodes[2] )
969  {
970  for( int i = 0; i < CN::NumSubEntities( type, 2 ); ++i )
971  {
972  int pdim = -1, pidx = -1;
973  CN::HONodeParent( type, num_vtx, pos++, pdim, pidx );
974  CHECK_EQUAL( 2, pdim );
975  CHECK_EQUAL( i, pidx );
976  }
977  }
978 
979  // check mid-volume
980  if( ho_nodes[dim] )
981  {
982  int pdim = -1, pidx = -1;
983  CN::HONodeParent( type, num_vtx, pos++, pdim, pidx );
984  CHECK_EQUAL( dim, pdim );
985  CHECK_EQUAL( 0, pidx );
986  }
987  } // for ho_node combinatinos
988  } // for each type
989 }
990 
992 {
993  const int combinations[][4] = { { 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 1, 1, 0 },
994  { 0, 0, 0, 1 }, { 0, 1, 0, 1 }, { 0, 0, 1, 1 }, { 0, 1, 1, 1 } };
995 
996  for( const EntityType* t = elem_types; *t != MBMAXTYPE; ++t )
997  {
998  const EntityType type = *t;
999  const int dim = CN::Dimension( type );
1000  // calculate number of valid combinations of ho node flags
1001  int num_comb = 1;
1002  for( int i = 0; i < dim; ++i )
1003  num_comb *= 2;
1004  // for each valid combination
1005  for( int c = 0; c < num_comb; ++c )
1006  {
1007  // calculate corresponding number of vertices in element
1008  const int* ho_nodes = combinations[c];
1009  int num_vtx = CN::VerticesPerEntity( type );
1010  switch( dim )
1011  {
1012  case 3:
1013  case 2:
1014  // extra clauses to avoid fall-through error
1015  if( 3 == dim && ho_nodes[2] ) num_vtx += CN::NumSubEntities( type, 2 );
1016  if( 2 <= dim && ho_nodes[1] ) num_vtx += CN::NumSubEntities( type, 1 );
1017  }
1018  if( ho_nodes[dim] ) ++num_vtx;
1019 
1020  // start at first higher-order node
1021  int pos = CN::VerticesPerEntity( type );
1022 
1023  // check mid-edge
1024  if( dim > 1 && ho_nodes[1] )
1025  {
1026  for( int i = 0; i < CN::NumSubEntities( type, 1 ); ++i )
1027  {
1028  int idx = CN::HONodeIndex( type, num_vtx, 1, i );
1029  CHECK_EQUAL( pos++, idx );
1030  }
1031  }
1032 
1033  // check mid-face
1034  if( dim > 2 && ho_nodes[2] )
1035  {
1036  for( int i = 0; i < CN::NumSubEntities( type, 2 ); ++i )
1037  {
1038  int idx = CN::HONodeIndex( type, num_vtx, 2, i );
1039  CHECK_EQUAL( pos++, idx );
1040  }
1041  }
1042 
1043  // check mid-volume
1044  if( ho_nodes[dim] )
1045  {
1046  int idx = CN::HONodeIndex( type, num_vtx, dim, 0 );
1047  CHECK_EQUAL( pos++, idx );
1048  }
1049  } // for ho_node combinatinos
1050  } // for each type
1051 }
1052 
1053 void test_sub_entity_nodes( EntityType parent, int sub_dimension )
1054 {
1055  const int num_corner = CN::VerticesPerEntity( parent );
1056  const int num_edge = CN::NumSubEntities( parent, 1 );
1057  const int num_face = CN::NumSubEntities( parent, 2 );
1058 
1059  auto dim = CN::Dimension( parent );
1060  switch( dim )
1061  {
1062  case 3:
1063  case 2:
1064  case 1:
1065  test_sub_entity_nodes( parent, num_corner + num_face, sub_dimension );
1066  test_sub_entity_nodes( parent, num_corner + num_edge + num_face, sub_dimension );
1067  test_sub_entity_nodes( parent, num_corner + num_face + 1, sub_dimension );
1068  test_sub_entity_nodes( parent, num_corner + num_edge + num_face + 1, sub_dimension );
1069  if( 2 <= dim )
1070  {
1071  test_sub_entity_nodes( parent, num_corner + num_edge, sub_dimension );
1072  test_sub_entity_nodes( parent, num_corner + num_edge + 1, sub_dimension );
1073  }
1074  if( 1 <= dim )
1075  {
1076  test_sub_entity_nodes( parent, num_corner, sub_dimension );
1077  test_sub_entity_nodes( parent, num_corner + 1, sub_dimension );
1078  }
1079  break;
1080  default:
1081  CHECK( false );
1082  }
1083 }
1084 
1085 void test_sub_entity_nodes( EntityType parent, int num_nodes, int sub_dimension )
1086 {
1087  const int num_sub = CN::NumSubEntities( parent, sub_dimension );
1088  const int parent_ho = CN::HasMidNodes( parent, num_nodes );
1089  int child_ho = 0;
1090  for( int d = 1; d <= sub_dimension; ++d )
1091  child_ho |= ( parent_ho & ( 1 << d ) );
1092 
1093  // first test the types
1094  for( int i = 0; i < num_sub; ++i )
1095  {
1096  int num, conn[moab::MAX_SUB_ENTITY_VERTICES];
1097  EntityType type;
1098  CN::SubEntityNodeIndices( parent, num_nodes, sub_dimension, i, type, num, conn );
1099  CHECK_EQUAL( CN::SubEntityType( parent, sub_dimension, i ), type );
1100  }
1101 
1102  // now test that they have the correct number of higher-order node
1103  for( int i = 0; i < num_sub; ++i )
1104  {
1105  int num, conn[moab::MAX_SUB_ENTITY_VERTICES];
1106  EntityType type;
1107  CN::SubEntityNodeIndices( parent, num_nodes, sub_dimension, i, type, num, conn );
1108  const int ho = CN::HasMidNodes( type, num );
1109  CHECK_EQUAL( child_ho, ho );
1110  }
1111 
1112  // now test the actual indices
1113  for( int i = 0; i < num_sub; ++i )
1114  {
1116  EntityType type;
1117  CN::SubEntityNodeIndices( parent, num_nodes, sub_dimension, i, type, num, conn );
1118 
1119  // check corner indices against SubEntityVertexIndices
1120  const int num_corner = CN::VerticesPerEntity( type );
1121  CHECK( num >= num_corner );
1122  CN::SubEntityVertexIndices( parent, sub_dimension, i, corners );
1123  for( int j = 0; j < num_corner; ++j )
1124  CHECK_EQUAL( corners[j], conn[j] );
1125 
1126  // check mid-edge indices, if present
1127  int idx = num_corner;
1128  if( child_ho & CN::MID_EDGE_BIT )
1129  {
1130  // for each edge in the sub-entity type
1131  const int num_edge = CN::NumSubEntities( type, 1 );
1132  for( int j = 0; j < num_edge; ++j )
1133  {
1134  // get edge indices for sub-entity connectivity
1135  int edge_ends[2];
1136  CN::SubEntityVertexIndices( type, 1, j, edge_ends );
1137  // convert to indices into parent type's connectivity
1138  CHECK( edge_ends[0] < num_corner );
1139  edge_ends[0] = corners[edge_ends[0]];
1140  CHECK( edge_ends[1] < num_corner );
1141  edge_ends[1] = corners[edge_ends[1]];
1142  // find edge index in parent element
1143  int side, sense, off;
1144  int result = CN::SideNumber( parent, edge_ends, 2, 1, side, sense, off );
1145  CHECK_EQUAL( 0, result );
1146  // get location in parent entity connectivity for mid-edge node
1147  int loc = CN::HONodeIndex( parent, num_nodes, 1, side );
1148  CHECK_EQUAL( loc, conn[idx++] );
1149  }
1150  }
1151 
1152  // check mid-face indices, if present
1153  if( child_ho & CN::MID_FACE_BIT )
1154  {
1155  CHECK_EQUAL( 2, CN::Dimension( type ) );
1156  int loc = CN::HONodeIndex( parent, num_nodes, 2, i );
1157  CHECK_EQUAL( loc, conn[idx++] );
1158  }
1159 
1160  // make sure there were no extra node indices returned
1161  CHECK_EQUAL( idx, num );
1162  }
1163 }
1164 
1165 #include "moab/Core.hpp"
1167 {
1168  moab::Core mb;
1169 
1170  std::vector< moab::EntityHandle > conn;
1171  double coords[3];
1172  for( int i = 0; i < 15; ++i )
1173  {
1175  mb.create_vertex( coords, h );
1176  conn.push_back( h );
1177  }
1178 
1180  mb.create_element( moab::MBPRISM, conn.data(), 15, w );
1181 
1182  // this leads to the failure
1183  {
1184  std::vector< moab::EntityHandle > adj;
1185  mb.get_adjacencies( &w, 1, 2, true, adj );
1186  }
1187  std::vector< moab::EntityHandle > edges;
1188  std::vector< moab::EntityHandle > faces;
1189  mb.get_entities_by_dimension( 0, 1, edges );
1190  for( const auto& e : edges )
1191  {
1192  std::vector< moab::EntityHandle > conn;
1193  std::cout << "edge " << e << " connectivity: ";
1194 
1195  mb.get_connectivity( &e, 1, conn );
1196  for( const auto& n : conn )
1197  std::cout << n << " ";
1198  std::cout << "\n";
1199  }
1200  mb.get_entities_by_dimension( 0, 2, faces );
1201  for( const auto& f : faces )
1202  {
1203  std::vector< moab::EntityHandle > conn;
1204  std::cout << "face " << f << " connectivity: ";
1205 
1206  mb.get_connectivity( &f, 1, conn );
1207  for( const auto& n : conn )
1208  std::cout << n << " ";
1209  std::cout << "\n";
1210  }
1211  std::vector< moab::EntityHandle > nodes;
1212  mb.get_entities_by_dimension( 0, 0, nodes );
1213  for( const auto& n : nodes )
1214  {
1215  std::vector< moab::EntityHandle > adj;
1216  std::cout << "node " << n << " connection: ";
1217  adj.clear();
1218  mb.get_adjacencies( &n, 1, 1, true, adj );
1219  std::cout << adj.size() << " edges,";
1220  // there are either 1 or 3 adjacent edges to each vertex (1 for mid edge vertex)
1221  CHECK( 1 == adj.size() || 3 == adj.size() );
1222  adj.clear();
1223  mb.get_adjacencies( &n, 1, 2, true, adj );
1224  std::cout << adj.size() << " faces,";
1225  // there are either 2 or 3 adjacent faces to each vertex ( 2 for mid edge evertex)
1226  CHECK( 2 == adj.size() || 3 == adj.size() );
1227  adj.clear();
1228  mb.get_adjacencies( &n, 1, 3, true, adj );
1229  std::cout << adj.size() << " volumes\n";
1230  }
1231 }
1232 
1234 {
1235  moab::Core mb;
1236 
1237  //mb.load_file("./wed15_2.h5m");
1238  std::vector< moab::EntityHandle > conn;
1239  double coords[3];
1240  for( int i = 0; i < 22; ++i )
1241  {
1243  mb.create_vertex( coords, h );
1244  }
1245  moab::EntityHandle conn1[15] = { 10, 20, 14, 1, 8, 5, 21, 19, 15, 16, 22, 18, 9, 7, 6 };
1246  moab::EntityHandle conn2[15] = { 10, 14, 12, 1, 5, 3, 15, 13, 11, 16, 18, 17, 6, 4, 2 };
1247 
1249  mb.create_element( moab::MBPRISM, conn1, 15, w );
1250  mb.create_element( moab::MBPRISM, conn2, 15, w );
1251 
1252  std::vector< moab::EntityHandle > wedges;
1253  mb.get_entities_by_dimension( 0, 3, wedges );
1254 
1255  // > If I comment this block there is no problem
1256  for( const auto& w : wedges )
1257  {
1258  std::vector< moab::EntityHandle > adj;
1259  mb.get_adjacencies( &w, 1, 2, true, adj );
1260  CHECK( 5 == adj.size() );
1261  }
1262  // <
1263 
1264  for( const auto& w : wedges )
1265  {
1266  std::vector< moab::EntityHandle > conn;
1267  mb.get_connectivity( &w, 1, conn );
1268  CHECK( 15 == conn.size() );
1269  for( const auto& n : conn )
1270  {
1271  std::vector< moab::EntityHandle > edges;
1272  mb.get_adjacencies( &n, 1, 1, true, edges );
1273  if( edges.size() == 0 )
1274  {
1275  std::cout << " node " << n << " not connected to edges \n";
1276  std::vector< moab::EntityHandle > faces;
1277  mb.get_adjacencies( &n, 1, 2, false, faces );
1278  for( const auto& f : faces )
1279  {
1280  std::vector< moab::EntityHandle > connf;
1281  mb.get_connectivity( &f, 1, connf );
1282  std::cout << "face:" << mb.id_from_handle( f );
1283  for( const auto& n1 : connf )
1284  std::cout << " " << n1;
1285  std::cout << "\n";
1286  }
1287  std::vector< moab::EntityHandle > prisms;
1288  mb.get_adjacencies( &n, 1, 3, false, prisms );
1289  for( const auto& p : prisms )
1290  {
1291  std::vector< moab::EntityHandle > connf;
1292  mb.get_connectivity( &p, 1, connf );
1293  std::cout << "prism:" << mb.id_from_handle( p );
1294  for( const auto& n1 : connf )
1295  std::cout << " " << n1;
1296  std::cout << "\n";
1297  }
1298  CHECK( edges.size() != 0 );
1299  }
1300  }
1301  }
1302 }