54 int do_create =
edge == 0;
62 if( hex > 0 && do_create )
71 if( quad > 0 && do_create )
80 if( tet > 0 && do_create )
89 if( tri > 0 && do_create )
105 std::vector< EntityHandle > adjacencies;
118 std::cout <<
" Vertices: " << node << std::endl;
119 cout <<
" Edges: " <<
edge << endl;
120 if( quad > 0 ) cout <<
" Quad Elements: " << quad << endl;
121 if( hex > 0 ) cout <<
" Hex Elements: " << hex << endl;
122 if( tri > 0 ) cout <<
" Tri Elements: " << tri << endl;
123 if( tet > 0 ) cout <<
" Tet Elements: " << tet << endl;
129 diff[0] =
first[0] - second[0];
130 diff[1] =
first[1] - second[1];
131 diff[2] =
first[2] - second[2];
132 double length = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2];
134 if( fabs(
length ) < .001 )
return true;
142 double first_coords[3], second_coords[3];
144 std::pair< EntityHandle, EntityHandle > coincident_pair;
147 for( iter = vertices.
begin(); iter != vertices.
end(); ++iter )
152 for( jter = iter; jter != vertices.
end(); ++jter )
161 coincident_pair.first = *iter;
162 coincident_pair.second = *jter;
163 coin_nodes.push_back( coincident_pair );
173 double coords1[3], coords2[3], coords3[3];
175 std::vector< EntityHandle > conn( 2 );
176 std::pair< EntityHandle, EntityHandle > coincident_pair;
187 for( jter = iter; jter !=
entities.end(); ++jter )
202 coincident_pair.first = *iter;
203 coincident_pair.second = *jter;
204 coin_edges.push_back( coincident_pair );
216 std::vector< std::pair< EntityHandle, EntityHandle > >& coin )
218 double coords1[8][3], coords2[8][3];
220 std::vector< EntityHandle > conn( 8 );
221 std::pair< EntityHandle, EntityHandle > coincident_pair;
222 int i = 0, j = 0, ii = 0;
228 for( ii = 0; ii < num_nodes; ii++ )
233 for( jter = iter; jter !=
entities.end(); ++jter )
243 for( i = 0; i < num_nodes; i++ )
250 for( ii = 1; ii < num_nodes; ii++ )
255 for( j = 1; j < num_nodes; j++ )
263 coincident_pair.first = *iter;
264 coincident_pair.second = *jter;
265 coin.push_back( coincident_pair );
278 std::vector< std::pair< EntityHandle, EntityHandle > > coincident;
280 if( curr_count.
node > 0 )
284 diff_count.
node = coincident.size();
288 if( curr_count.
edge > 0 )
292 diff_count.
edge = coincident.size();
296 if( curr_count.
quad > 0 )
300 diff_count.
quad = coincident.size();
304 if( curr_count.
tri > 0 )
308 diff_count.
tri = coincident.size();
312 if( curr_count.
tet > 0 )
316 diff_count.
tet = coincident.size();
320 if( curr_count.
hex > 0 )
324 diff_count.
hex = coincident.size();
336 std::vector< std::pair< EntityHandle, EntityHandle > > coincident;
342 if( diff_count.
hex > 0 )
347 else if( diff_count.
quad > 0 )
352 else if( diff_count.
tet > 0 )
357 else if( diff_count.
tri > 0 )
363 else if( diff_count.
edge > 0 )
369 std::vector< std::pair< EntityHandle, EntityHandle > >::iterator iter;
370 for( iter = coincident.begin(); iter != coincident.end(); ++iter )
377 if( init_count.
node != curr_count.
node || init_count.
edge != curr_count.
edge ||
378 init_count.
quad != curr_count.
quad || init_count.
tri != curr_count.
tri || init_count.
hex != curr_count.
hex ||
379 init_count.
tet != curr_count.
tet )
381 cout <<
"***ERROR: Merged top down when not using auto merge.***" << endl;
390 cout <<
"Merging Coincident Nodes:" << endl;
398 std::vector< std::pair< EntityHandle, EntityHandle > > coincident_nodes;
402 std::vector< std::pair< EntityHandle, EntityHandle > >::iterator iter;
403 for( iter = coincident_nodes.begin(); iter != coincident_nodes.end(); ++iter )
405 cout <<
" Coincident nodes: " << ( *iter ).first <<
"-" << ( *iter ).second << endl;
414 if( init_count.
node - curr_count.
node != coincident_nodes.size() )
416 cout <<
"***ERROR: Not all coincident nodes were merged.***" << endl;
423 if( init_count.
edge != curr_count.
edge || init_count.
quad != curr_count.
quad || init_count.
tri != curr_count.
tri ||
424 init_count.
hex != curr_count.
hex || init_count.
tet != curr_count.
tet )
426 cout <<
"***ERROR: Merged other objects when merging nodes.***" << endl;
435 cout <<
"Merging Coincident Edges:" << endl;
443 std::vector< std::pair< EntityHandle, EntityHandle > > coincident_edges;
447 unsigned long id1, id2;
448 std::vector< std::pair< EntityHandle, EntityHandle > >::iterator iter;
449 for( iter = coincident_edges.begin(); iter != coincident_edges.end(); ++iter )
453 cout <<
" Coincident edges: " << id1 <<
"-" << id2 << endl;
462 if( init_count.
edge - curr_count.
edge != coincident_edges.size() )
464 cout <<
"***ERROR: Not all coincident edges were merged.***" << endl;
471 if( init_count.
node != curr_count.
node || init_count.
quad != curr_count.
quad || init_count.
tri != curr_count.
tri ||
472 init_count.
hex != curr_count.
hex || init_count.
tet != curr_count.
tet )
474 cout <<
"***ERROR: Merged other objects when merging edges.***" << endl;
483 cout <<
"Merging Coincident 2D Elements:" << endl;
491 std::vector< std::pair< EntityHandle, EntityHandle > > coincident;
495 unsigned long id1, id2;
496 unsigned int tri_diff = coincident.size();
497 std::vector< std::pair< EntityHandle, EntityHandle > >::iterator iter;
498 for( iter = coincident.begin(); iter != coincident.end(); ++iter )
502 cout <<
" Coincident tris: " << id1 <<
"-" << id2 << endl;
518 unsigned int quad_diff = coincident.size();
519 for( iter = coincident.begin(); iter != coincident.end(); ++iter )
523 cout <<
" Coincident quads: " << id1 <<
"-" << id2 << endl;
532 if( init_count.
tri - curr_count.
tri != tri_diff )
534 cout <<
"***ERROR: Not all coincident tris were merged.***" << endl;
537 if( init_count.
quad - curr_count.
quad != quad_diff )
539 cout <<
"***ERROR: Not all coincident quads were merged.***" << endl;
543 init_count.
tri = curr_count.
tri;
547 if( init_count.
node != curr_count.
node || init_count.
edge != curr_count.
edge || init_count.
hex != curr_count.
hex ||
548 init_count.
tet != curr_count.
tet )
550 cout <<
"***ERROR: Merged other objects when merging faces.***" << endl;
559 cout <<
"Merging Coincident 3D Elements:" << endl;
567 std::vector< std::pair< EntityHandle, EntityHandle > > coincident;
571 unsigned long id1, id2;
572 unsigned int tet_diff = coincident.size();
573 std::vector< std::pair< EntityHandle, EntityHandle > >::iterator iter;
574 for( iter = coincident.begin(); iter != coincident.end(); ++iter )
578 cout <<
" Coincident tets: " << id1 <<
"-" << id2 << endl;
593 unsigned int hex_diff = coincident.size();
594 for( iter = coincident.begin(); iter != coincident.end(); ++iter )
598 cout <<
" Coincident hexs: " << id1 <<
"-" << id2 << endl;
607 if( init_count.
tet - curr_count.
tet != tet_diff )
609 cout <<
"***ERROR: Not all coincident tets were merged.***" << endl;
612 if( init_count.
hex - curr_count.
hex != hex_diff )
614 cout <<
"***ERROR: Not all coincident hexs were merged.***" << endl;
618 init_count.
tet = curr_count.
tet;
619 init_count.
hex = curr_count.
hex;
622 if( init_count.
node != curr_count.
node || init_count.
edge != curr_count.
edge ||
623 init_count.
quad != curr_count.
quad || init_count.
tri != curr_count.
tri )
625 cout <<
"***ERROR: Merged other objects when merging elements.***" << endl;
640 cout <<
"***ERROR: Unable to load mesh file.***" << endl;
647 cout <<
"***ERROR: Unable to get entity list counts.***" << endl;
669 std::vector< EntityHandle > output_list;
672 range_iter = block_range.
begin();
673 end_iter = block_range.
end();
675 for( ; range_iter != end_iter; ++range_iter )
685 output_list.push_back( *range_iter );
689 static std::string mrg_splice(
".mrg" );
690 file_name.insert( file_name.size() - 2, mrg_splice );
691 result =
gMB->
write_mesh( file_name.c_str(), &output_list[0], output_list.size() );
709 cout <<
"Initial Entities:" << endl;
714 std::vector< std::pair< EntityHandle, EntityHandle > > coincident;
720 if( diff_count.
hex > 0 )
725 else if( diff_count.
quad > 0 )
730 else if( diff_count.
tet > 0 )
735 else if( diff_count.
tri > 0 )
740 else if( diff_count.
edge > 0 )
745 else if( diff_count.
node > 0 )
751 cout <<
"Merging coincident entities(top down)..." << endl;
752 std::vector< std::pair< EntityHandle, EntityHandle > >::iterator iter;
753 for( iter = coincident.begin(); iter != coincident.end(); ++iter )
759 cout <<
"***ERROR: Unable to get entity list counts.***" << endl;
765 init_count.
quad - curr_count.
quad != diff_count.
quad || init_count.
tri - curr_count.
tri != diff_count.
tri ||
766 init_count.
hex - curr_count.
hex != diff_count.
hex || init_count.
tet - curr_count.
tet != diff_count.
tet )
768 cout <<
"***ERROR: Not all coincident objects merged automatically.***" << endl;
774 cout <<
"Final Entities:" << endl;
793 cout <<
"Initial Entities:" << endl;
798 std::vector< std::pair< EntityHandle, EntityHandle > > coincident;
804 if( diff_count.
edge > 0 )
815 cout <<
"Merging coincident entities(middle out)..." << endl;
816 std::vector< std::pair< EntityHandle, EntityHandle > >::iterator iter;
817 for( iter = coincident.begin(); iter != coincident.end(); ++iter )
824 cout <<
"***ERROR: Unable to get entity list counts.***" << endl;
830 init_count.
quad - curr_count.
quad != diff_count.
quad || init_count.
tri - curr_count.
tri != diff_count.
tri ||
831 init_count.
hex - curr_count.
hex != diff_count.
hex || init_count.
tet - curr_count.
tet != diff_count.
tet )
833 cout <<
"***ERROR: Not all coincident objects merged automatically.***" << endl;
839 cout <<
"Final Entities:" << endl;
858 cout <<
"Initial Entities:" << endl;
863 std::vector< std::pair< EntityHandle, EntityHandle > > coincident;
872 cout <<
"Merging coincident entities(bottom up)..." << endl;
873 std::vector< std::pair< EntityHandle, EntityHandle > >::iterator iter;
874 for( iter = coincident.begin(); iter != coincident.end(); ++iter )
880 cout <<
"***ERROR: Unable to get entity list counts.***" << endl;
886 init_count.
quad - curr_count.
quad != diff_count.
quad || init_count.
tri - curr_count.
tri != diff_count.
tri ||
887 init_count.
hex - curr_count.
hex != diff_count.
hex || init_count.
tet - curr_count.
tet != diff_count.
tet )
889 cout <<
"***ERROR: Not all coincident objects merged automatically.***" << endl;
896 cout <<
"Final Entities:" << endl;
914 cout <<
"Initial Entities:" << endl;
935 cout <<
"***ERROR: Unable to get entity list counts.***" << endl;
938 cout <<
"Final Entities:" << endl;
948 std::string test_files[] = {
949 std::string(
"test/2barcase1.g" ), std::string(
"test/2barcase2.g" ), std::string(
"test/2hexcase1.g" ),
950 std::string(
"test/2hexcase2.g" ), std::string(
"test/2hexcase3.g" ), std::string(
"test/2hexcase4.g" ),
951 std::string(
"test/2hexcase5.g" ), std::string(
"test/2quadcase1.g" ), std::string(
"test/2quadcase2.g" ),
952 std::string(
"test/2quadcase3.g" ), std::string(
"test/2quadcase4.g" ), std::string(
"test/2tetcase1.g" ),
953 std::string(
"test/2tetcase2.g" ), std::string(
"test/2tetcase3.g" ), std::string(
"test/2tetcase4.g" ),
954 std::string(
"test/2tricase1.g" ), std::string(
"test/2tricase2.g" ), std::string(
"test/2tricase3.g" ) };
961 cout <<
"---Starting Top Down Auto Merge Tests---" << endl << endl;
962 for( i = 0; i < (
sizeof( test_files ) /
sizeof( std::string ) ); i++ )
964 cout <<
"---Testing:\"" << test_files[i] <<
"\"---" << endl;
967 cout <<
"---Success---";
969 cout <<
"---Failure---";
970 cout << endl << endl;
973 cout <<
"---Starting Bottom Up Auto Merge Tests---" << endl << endl;
974 for( i = 0; i < (
sizeof( test_files ) /
sizeof( std::string ) ); i++ )
976 cout <<
"---Testing:\"" << test_files[i] <<
"\"---" << endl;
980 cout <<
"---Success---";
982 cout <<
"---Failure---";
983 cout << endl << endl;
986 cout <<
"---Starting Middle Out Auto Merge Tests---" << endl << endl;
987 for( i = 0; i < (
sizeof( test_files ) /
sizeof( std::string ) ); i++ )
989 cout <<
"---Testing:\"" << test_files[i] <<
"\"---" << endl;
992 cout <<
"---Success---";
994 cout <<
"---Failure---";
996 cout << endl << endl;
999 cout <<
"---Starting Merge Tests---" << endl << endl;
1000 for( i = 0; i < (
sizeof( test_files ) /
sizeof( std::string ) ); i++ )
1002 cout <<
"---Testing:\"" << test_files[i] <<
"\"---" << endl;
1005 cout <<
"---Success---";
1007 cout <<
"---Failure---";
1008 cout << endl << endl;