3 #include "InitCGMA.hpp"
16 #define GF_CUBIT_FILE_TYPE "CUBIT"
17 #define GF_STEP_FILE_TYPE "STEP"
18 #define GF_IGES_FILE_TYPE "IGES"
19 #define GF_ACIS_TXT_FILE_TYPE "ACIS_SAT"
20 #define GF_ACIS_BIN_FILE_TYPE "ACIS_SAB"
21 #define GF_OCC_BREP_FILE_TYPE "OCC"
25 void tokenize(
const std::string& str, std::vector< std::string >& tokens,
const char* delimiters )
27 std::string::size_type last = str.find_first_not_of( delimiters, 0 );
28 std::string::size_type pos = str.find_first_of( delimiters, last );
29 if( std::string::npos == pos )
30 tokens.push_back( str );
32 while( std::string::npos != pos && std::string::npos != last )
34 tokens.push_back( str.substr( last, pos - last ) );
35 last = str.find_first_not_of( delimiters, pos );
36 pos = str.find_first_of( delimiters, last );
37 if( std::string::npos == pos ) pos = str.size();
44 std::vector< std::string >& grp_names )
52 if(
MB_TAG_NOT_FOUND != result ) grp_names.push_back( std::string( name0 ) );
61 const Tag categoryTag,
66 const bool conserve_mass,
72 const void*
const group_val[] = { &group_category };
74 rval =
MBI->get_entities_by_type_and_tag( 0,
MBENTITYSET, &categoryTag, group_val, 1, groups );
83 rval =
MBI->tag_get_data(
idTag, &( *i ), 1, &grp_id );
85 if( max_grp_id < grp_id ) max_grp_id = grp_id;
89 std::cout <<
" Altering group densities to conserve mass for each volume." << std::endl;
90 std::cout <<
" maximum group id=" << max_grp_id << std::endl;
96 std::vector< std::string > grp_names;
101 bool material_grp =
false;
104 for( std::vector< std::string >::const_iterator j = grp_names.begin(); j != grp_names.end(); ++j )
106 if( std::string::npos != ( *j ).find(
"mat" ) && std::string::npos != ( *j ).find(
"rho" ) )
109 std::cout <<
" material group: " << *j << std::endl;
112 std::vector< std::string > tokens;
114 mat_id = atoi( tokens[1].c_str() );
115 rho = atof( tokens[3].c_str() );
118 if( !material_grp )
continue;
122 const void*
const three_val[] = { &three };
124 rval =
MBI->get_entities_by_type_and_tag( *i,
MBENTITYSET, &dimTag, three_val, 1, vols );
128 double orig_grp_volume = 0, defo_grp_volume = 0;
134 double defo_size = 0, orig_size = 0;
137 defo_grp_volume += defo_size;
138 rval =
MBI->tag_get_data( sizeTag, &( *j ), 1, &orig_size );
140 orig_grp_volume += orig_size;
143 if( !conserve_mass )
continue;
144 double new_rho = rho * orig_size / defo_size;
150 std::stringstream new_name_ss;
151 new_name_ss <<
"mat_" << mat_id <<
"_rho_" << new_rho <<
"\0";
152 std::string new_name;
153 new_name_ss >> new_name;
154 rval =
MBI->tag_set_data(
nameTag, &new_grp, 1, new_name.c_str() );
157 rval =
MBI->tag_set_data(
idTag, &new_grp, 1, &max_grp_id );
160 rval =
MBI->tag_set_data( categoryTag, &new_grp, 1, group_category2 );
164 rval =
MBI->add_entities( new_grp, &( *j ), 1 );
168 rval =
MBI->add_entities( cgm_file_set, &new_grp, 1 );
172 rval =
MBI->remove_entities( *i, &( *j ), 1 );
174 if(
debug ) std::cout <<
" new group: " << new_name <<
" id=" << max_grp_id << std::endl;
177 std::cout <<
" orig_volume=" << orig_grp_volume <<
" defo_volume=" << defo_grp_volume
178 <<
" defo/orig=" << defo_grp_volume / orig_grp_volume << std::endl;
197 const void*
const two_val[] = { &two };
199 result =
MBI->get_entities_by_type_and_tag( cgm_file_set,
MBENTITYSET, &dimTag, two_val, 1, cgm_surfs );
205 result =
MBI->get_number_entities_by_type( *i,
MBTRI, n_tris );
211 result =
MBI->tag_get_data(
idTag, &( *i ), 1, &surf_id );
215 result =
MBI->get_parent_meshsets( *i, parent_vols );
219 result =
MBI->remove_parent_child( *j, *i );
223 result =
MBI->get_child_meshsets( *i, child_curves );
227 result =
MBI->remove_parent_child( *i, *j );
230 result =
MBI->remove_entities( cgm_file_set, &( *i ), 1 );
241 if(
MBI->contains_entities( *j, &( *i ), 1 ) )
243 result =
MBI->remove_entities( *j, &( *i ), 1 );
248 result =
MBI->delete_entities( &( *i ), 1 );
250 std::cout <<
" Surface " << surf_id <<
": removed because all of its mesh faces have been removed"
257 const void*
const three_val[] = { &three };
259 result =
MBI->get_entities_by_type_and_tag( cgm_file_set,
MBENTITYSET, &dimTag, three_val, 1, cgm_vols );
266 result =
MBI->num_child_meshsets( *i, &n_surfs );
273 result =
MBI->tag_get_data(
idTag, &( *i ), 1, &vol_id );
283 if(
MBI->contains_entities( *j, &( *i ), 1 ) )
285 result =
MBI->remove_entities( *j, &( *i ), 1 );
289 result =
MBI->delete_entities( &( *i ), 1 );
291 std::cout <<
" Volume " << vol_id <<
": removed because all of its surfaces have been removed"
304 const int new_surf_id,
307 const Tag categoryTag,
312 result =
MBI->create_meshset( 0, new_surf );
314 if( 0 != forward_parent_vol )
316 result =
MBI->add_parent_child( forward_parent_vol, new_surf );
319 if( 0 != reverse_parent_vol )
321 result =
MBI->add_parent_child( reverse_parent_vol, new_surf );
325 result =
MBI->tag_set_data( dimTag, &new_surf, 1, &two );
327 result =
MBI->tag_set_data(
idTag, &new_surf, 1, &new_surf_id );
332 EntityHandle vols[2] = { forward_parent_vol, reverse_parent_vol };
333 result =
MBI->tag_set_data( senseTag, &new_surf, 1, vols );
348 result =
MBI->get_adjacencies( &( *i ), 1, 3,
false, adj_elem );
355 result =
MBI->get_connectivity( adj_elem.
front(), elem_conn, elem_n_nodes );
359 result =
MBI->get_connectivity( *i, face_conn, face_n_nodes );
363 EntityType elem_type =
MBI->type_from_handle( adj_elem.
front() );
364 EntityType face_type =
MBI->type_from_handle( *i );
365 int face_num, offset;
368 int rval =
CN::SideNumber( elem_type, elem_conn, face_conn, face_n_nodes, face_dim, face_num, sense, offset );
369 if( 0 != rval )
return MB_FAILURE;
374 EntityHandle new_face_conn[4] = { face_conn[3], face_conn[2], face_conn[1], face_conn[0] };
375 result =
MBI->set_connectivity( *i, new_face_conn, 4 );
386 int handle_compare(
const void *a,
const void *b)
396 int compare_face(
const void *a,
const void *b)
402 if(*(ia+1) == *(ib+1))
404 if(*(ia+2) == *(ib+2))
406 return (
int)(*(ia+3) - *(ib+3));
410 return (
int)(*(ia+2) - *(ib+2));
415 return (
int)(*(ia+1) - *(ib+1));
420 return (
int)(*ia - *ib);
429 const int nodes_per_face = 4;
430 const unsigned int faces_per_elem = 6;
431 unsigned int n_faces = faces_per_elem*elems.
size();
438 result =
MBI->get_adjacencies( &(*i), 1, 2,
true, elem_faces );
445 ErrorCode result =
MBI->get_connectivity( *j, conn, n_nodes );
449 for(
int k=0; k<nodes_per_face; ++k) f[counter][k] = conn[k];
450 qsort( &f[counter][0], nodes_per_face,
sizeof(
EntityHandle), handle_compare );
456 qsort( &f[0][0], n_faces, nodes_per_face*
sizeof(
EntityHandle), compare_face );
460 for(
unsigned int i=0; i<n_faces; ++i)
466 result =
MBI->get_adjacencies( &(f[i][0]), nodes_per_face, 2,
false, face_handle );
472 else if( f[i][0]==f[i+1][0] && f[i][1]==f[i+1][1] &&
473 f[i][2]==f[i+1][2] && f[i][3]==f[i+1][3] )
476 while( f[i][0]==f[i+1][0] && f[i][1]==f[i+1][1] &&
477 f[i][2]==f[i+1][2] && f[i][3]==f[i+1][3] )
479 std::cout <<
" skin WARNING: non-manifold face" << std::endl;
487 result =
MBI->get_adjacencies( &(f[i][0]), nodes_per_face, 2,
false, face_handle );
501 const std::string& x_axis_label,
502 const std::string& y_axis_label,
508 double min = std::numeric_limits< double >::max();
509 double max = -std::numeric_limits< double >::max();
510 for(
int i = 0; i < n_data; ++i )
512 if( min > data[i] ) min = data[i];
513 if( max < data[i] ) max = data[i];
517 double bin_width = ( max - min ) / n_bins;
518 std::vector< int > bins( n_bins );
519 for(
int i = 0; i < n_bins; ++i )
523 for(
int i = 0; i < n_data; ++i )
525 double diff = data[i] - min;
526 int bin = diff / bin_width;
527 if( 9 < bin ) bin = 9;
528 if( 0 > bin ) bin = 0;
534 for(
int i = 0; i < n_bins; ++i )
535 if( max_bin < bins[i] ) max_bin = bins[i];
537 int max_bar_chars = 72;
538 std::vector< std::string > bars( n_bins );
539 for(
int i = 0; i < n_bins; ++i )
541 bar_height = ( max_bar_chars * bins[i] ) / max_bin;
542 for(
int j = 0; j < bar_height; ++j )
547 std::cout << std::endl;
548 std::cout <<
" " << title << std::endl;
551 std::cout.width( 15 );
552 std::cout << min << std::endl;
553 for(
int i = 0; i < n_bins; ++i )
555 std::cout.width( 15 );
556 std::cout << min + ( ( i + 1 ) * bin_width );
557 std::cout.width( max_bar_chars );
558 std::cout << bars[i] << bins[i] << std::endl;
562 std::cout.width( 15 );
563 std::cout << y_axis_label;
564 std::cout.width( max_bar_chars );
565 std::cout <<
" " << x_axis_label << std::endl;
566 std::cout << std::endl;
570 void generate_plots(
const double orig[],
const double defo[],
const int n_elems,
const std::string& time_step )
574 double* ratio =
new double[n_elems];
575 for(
int i = 0; i < n_elems; ++i )
576 ratio[i] = ( defo[i] - orig[i] ) / orig[i];
578 plot_histogram(
"Predeformed Element Volume",
"Num_Elems",
"Volume [cc]", 10, orig, n_elems );
579 std::string title =
"Element Volume Change Ratio at Time Step " + time_step;
580 plot_histogram( title,
"Num_Elems",
"Volume Ratio", 10, ratio, n_elems );
587 return 1. / 6. * ( ( ( v1 - v0 ) * ( v2 - v0 ) ) % ( v3 - v0 ) );
593 EntityType type =
MBI->type_from_handle( element );
597 ErrorCode result =
MBI->get_connectivity( element, conn, num_vertices );
600 std::vector< CartVect > coords( num_vertices );
601 result =
MBI->get_coords( conn, num_vertices, coords[0].array() );
607 return ( coords[0] - coords[1] ).length();
609 return 0.5 * ( ( coords[1] - coords[0] ) * ( coords[2] - coords[0] ) ).
length();
614 for(
int i = 0; i < num_vertices; ++i )
619 for(
int i = 0; i < num_vertices; ++i )
621 int j = ( i + 1 ) % num_vertices;
622 sum += ( ( mid - coords[i] ) * ( mid - coords[j] ) ).
length();
627 return tet_volume( coords[0], coords[1], coords[2], coords[3] );
629 return tet_volume( coords[0], coords[1], coords[2], coords[4] ) +
630 tet_volume( coords[0], coords[2], coords[3], coords[4] );
632 return tet_volume( coords[0], coords[1], coords[2], coords[5] ) +
633 tet_volume( coords[3], coords[5], coords[4], coords[0] ) +
634 tet_volume( coords[1], coords[4], coords[5], coords[0] );
636 return tet_volume( coords[0], coords[1], coords[3], coords[4] ) +
637 tet_volume( coords[7], coords[3], coords[6], coords[4] ) +
638 tet_volume( coords[4], coords[5], coords[1], coords[6] ) +
639 tet_volume( coords[1], coords[6], coords[3], coords[4] ) +
640 tet_volume( coords[2], coords[6], coords[3], coords[1] );
656 double& signed_volume )
660 rval =
MBI->get_entities_by_type( surf_set,
MBTRI, tris );
668 rval =
MBI->get_connectivity( *j, conn, len,
true );
671 rval =
MBI->get_coords( conn, 3, coords[0].array() );
676 for(
unsigned int k = 0; k < 3; ++k )
678 coords[k][0] += offset[0];
679 coords[k][1] += offset[1];
680 coords[k][2] += offset[2];
683 coords[1] -= coords[0];
684 coords[2] -= coords[0];
685 signed_volume += ( coords[0] % ( coords[1] * coords[2] ) );
704 const void*
const two_val[] = { &two };
706 result =
MBI->get_entities_by_type_and_tag( cgm_file_set,
MBENTITYSET, &dimTag, two_val, 1, cgm_surfs );
711 result =
MBI->tag_get_data(
idTag, &( *i ), 1, &surf_id );
716 const Tag tags[] = {
idTag, dimTag };
717 const void*
const tag_vals[] = { &surf_id, &two };
718 result =
MBI->get_entities_by_type_and_tag( cub_file_set,
MBENTITYSET, tags, tag_vals, 2, cub_surf );
720 if( 1 != cub_surf.
size() )
722 std::cout <<
" Surface " << surf_id <<
": no meshed representation found, using CAD representation instead"
729 result =
MBI->get_entities_by_type( cub_surf.
front(),
MBQUAD, quads );
736 result =
MBI->add_entities( cub_surf.
front(), cub_tris );
743 const int n_attempts = 100;
744 const int max_random = 10;
745 const double min_signed_vol = 0.1;
746 double cgm_signed_vol, cub_signed_vol;
747 for(
int j = 0; j < n_attempts; ++j )
751 CartVect offset( std::rand() % max_random, std::rand() % max_random, std::rand() % max_random );
757 std::cout <<
" surf_id=" << surf_id <<
" cgm_signed_vol=" << cgm_signed_vol
758 <<
" cub_signed_vol=" << cub_signed_vol << std::endl;
759 if( fabs( cgm_signed_vol ) > min_signed_vol && fabs( cub_signed_vol ) > min_signed_vol )
break;
760 if( n_attempts == j + 1 )
762 std::cout <<
"error: signed volume could not be calculated unambiguously" << std::endl;
769 if( ( cgm_signed_vol < 0 && cub_signed_vol > 0 ) || ( cgm_signed_vol > 0 && cub_signed_vol < 0 ) )
771 EntityHandle cgm_surf_volumes[2], reversed_cgm_surf_volumes[2];
772 result =
MBI->tag_get_data( senseTag, &( *i ), 1, cgm_surf_volumes );
776 reversed_cgm_surf_volumes[0] = cgm_surf_volumes[1];
777 reversed_cgm_surf_volumes[1] = cgm_surf_volumes[0];
779 result =
MBI->tag_set_data( senseTag, &( *i ), 1, reversed_cgm_surf_volumes );
800 const void*
const two_val[] = { &two };
802 result =
MBI->get_entities_by_type_and_tag( cgm_file_set,
MBENTITYSET, &dimTag, two_val, 1, cgm_surfs );
808 result =
MBI->tag_get_data(
idTag, &( *i ), 1, &surf_id );
810 if(
debug ) std::cout <<
"surf_id=" << surf_id << std::endl;
814 const Tag tags[] = {
idTag, dimTag };
815 const void*
const tag_vals[] = { &surf_id, &two };
816 result =
MBI->get_entities_by_type_and_tag( cub_file_set,
MBENTITYSET, tags, tag_vals, 2, cub_surf );
818 if( 1 != cub_surf.
size() )
820 std::cout <<
" Surface " << surf_id <<
": no meshed representation found, using CAD representation instead"
827 result =
MBI->get_entities_by_type( cub_surf.
front(),
MBQUAD, quads );
837 result =
MBI->get_entities_by_type( *i,
MBTRI, cgm_tris );
839 result =
MBI->remove_entities( *i, cgm_tris );
841 result =
MBI->remove_entities( cgm_file_set, cgm_tris );
843 result =
MBI->delete_entities( cgm_tris );
847 result =
MBI->add_entities( *i, cub_tris );
865 const Tag categoryTag,
873 const void*
const two_val[] = { &two };
875 result =
MBI->get_entities_by_type_and_tag( cgm_file_set,
MBENTITYSET, &dimTag, two_val, 1, cgm_surfs );
880 int max_surf_id = -1;
884 result =
MBI->tag_get_data(
idTag, &( *i ), 1, &surf_id );
886 if( max_surf_id < surf_id ) max_surf_id = surf_id;
888 std::cout <<
" Maximum surface id=" << max_surf_id << std::endl;
892 const void*
const three_val[] = { &three };
894 result =
MBI->get_entities_by_type_and_tag( cgm_file_set,
MBENTITYSET, &dimTag, three_val, 1, cgm_vols );
901 result =
MBI->tag_get_data(
idTag, &( *i ), 1, &vol_id );
904 std::cout <<
" Volume " << vol_id;
908 const Tag tags[] = {
idTag, dimTag };
909 const void*
const tag_vals[] = { &vol_id, &three };
910 result =
MBI->get_entities_by_type_and_tag( cub_file_set,
MBENTITYSET, tags, tag_vals, 2, cub_vol );
913 if( 1 != cub_vol.
size() )
915 std::cout <<
": no meshed representation found" << std::endl;
920 std::cout << std::endl;
925 result =
MBI->get_entities_by_type( cub_vol.
front(),
MBHEX, elems );
928 if(
debug ) std::cout <<
" found " << elems.
size() <<
" hex elems" << std::endl;
933 result = tool.
find_skin( 0, elems, 2, skin_faces,
true );
951 result =
MBI->get_child_meshsets( cub_vol.
front(), cub_surfs );
957 result =
MBI->tag_get_data(
idTag, &( *j ), 1, &surf_id );
962 result =
MBI->get_entities_by_type( *j,
MBQUAD, cub_faces );
966 if( cub_faces.
empty() )
968 std::cout <<
" Surface " << surf_id <<
": contains no meshed faces" << std::endl;
975 result =
MBI->remove_entities( *j, old_faces );
980 skin_faces =
subtract( skin_faces, common_faces );
982 if( old_faces.
empty() )
continue;
983 std::cout <<
" Surface " << surf_id <<
": " << old_faces.
size() <<
" old faces removed" << std::endl;
987 const Tag tags2[] = {
idTag, dimTag };
988 const void*
const tag_vals2[] = { &surf_id, &two };
989 result =
MBI->get_entities_by_type_and_tag( cgm_file_set,
MBENTITYSET, tags2, tag_vals2, 2, cgm_surf );
992 if( 1 != cgm_surf.
size() )
994 std::cout <<
"invalid size" << std::endl;
998 result =
MBI->tag_get_data( senseTag, cgm_surf, &cgm_vols2 );
1001 result =
MBI->tag_get_data( senseTag, &( *j ), 1, &cub_vols );
1007 if( *i == cgm_vols2[0] )
1012 if( *i == cgm_vols2[1] )
1018 if( 0 == cgm_vols2[0] && 0 == cgm_vols2[1] )
1020 std::cout <<
" New surface was not created for old faces because both parents "
1021 "are impl_compl volume "
1029 categoryTag, senseTag );
1033 categoryTag, senseTag );
1037 result =
MBI->add_entities( cgm_file_set, &new_cgm_surf, 1 );
1041 result =
MBI->add_entities( cub_file_set, &new_cub_surf, 1 );
1044 result =
MBI->add_entities( new_cub_surf, old_faces );
1048 std::cout <<
" Surface " << max_surf_id <<
": created for " << old_faces.
size() <<
" old faces"
1053 Range new_faces = skin_faces;
1056 if( new_faces.
empty() )
continue;
1057 std::cout <<
" Surface " << max_surf_id + 1 <<
": created for " << new_faces.
size() <<
" new faces"
1076 result =
MBI->add_entities( cgm_file_set, &new_cgm_surf, 1 );
1079 result =
MBI->add_entities( cub_file_set, &new_cub_surf, 1 );
1082 result =
MBI->add_entities( new_cub_surf, new_faces );
1133 const bool debug =
false;
1134 const char* file_type = NULL;
1136 const char* cub_name = 0;
1137 const char* exo_name = 0;
1138 const char* out_name = 0;
1139 const char* time_step = 0;
1140 const char* sat_name = 0;
1141 double dist_tol = 0.001, len_tol = 0.0;
1144 if( 6 != argc && 9 != argc )
1146 std::cerr <<
"To read meshed geometry for MOAB:" << std::endl;
1147 std::cerr <<
"$> <cub_file.cub> <acis_file.sat> <facet_tol> <output_file.h5m> conserve_mass<bool>" << std::endl;
1148 std::cerr <<
"To read meshed geometry for MOAB and update node coordinates:" << std::endl;
1149 std::cerr <<
"$> <cub_file.cub> <acis_file.sat> <facet_tol> <output_file.h5m> "
1150 "<deformed_exo_file.e> time_step<int> check_vol_change<bool> conserve_mass<bool>"
1158 temp.assign( cub_name );
1159 if( std::string::npos == temp.find(
".cub" ) )
1161 std::cerr <<
"cub_file does not have correct suffix" << std::endl;
1165 temp.assign( sat_name );
1166 if( std::string::npos == temp.find(
".sat" ) )
1168 std::cerr <<
"sat_file does not have correct suffix" << std::endl;
1172 temp.assign( out_name );
1173 if( std::string::npos == temp.find(
".h5m" ) )
1175 std::cerr <<
"out_file does not have correct suffix" << std::endl;
1180 dist_tol = atof( argv[3] );
1181 if( 0 > dist_tol || 1 < dist_tol )
1183 std::cout <<
"error: facet_tolerance=" << dist_tol << std::endl;
1188 bool update_coords =
false;
1192 temp.assign( exo_name );
1193 if( std::string::npos == temp.find(
".e" ) )
1195 std::cerr <<
"e_file does not have correct suffix" << std::endl;
1198 time_step = argv[6];
1199 update_coords =
true;
1203 bool determine_volume_change =
false;
1206 temp.assign( argv[7] );
1207 if( std::string::npos != temp.find(
"true" ) ) determine_volume_change =
true;
1211 bool conserve_mass =
false;
1214 temp.assign( argv[8] );
1215 if( std::string::npos != temp.find(
"true" ) ) conserve_mass =
true;
1217 else if( 6 == argc )
1219 temp.assign( argv[5] );
1220 if( std::string::npos != temp.find(
"true" ) ) conserve_mass =
true;
1229 std::cerr << cub_name <<
" : unknown file type, try '-t'" << std::endl;
1238 result =
MBI->create_meshset( 0, cub_file_set );
1245 result =
MBI->load_file( cub_name, &cub_file_set, 0, NULL, 0, 0 );
1248 std::cout <<
"error: problem reading cub file" << std::endl;
1251 std::cout <<
"Mesh file read." << std::endl;
1254 char cgm_options[256];
1255 std::cout <<
" facet tolerance=" << dist_tol << std::endl;
1256 sprintf( cgm_options,
1257 "CGM_ATTRIBS=yes;FACET_DISTANCE_TOLERANCE=%g;FACET_NORMAL_TOLERANCE=%d;MAX_FACET_EDGE_"
1259 dist_tol, norm_tol, len_tol );
1261 result =
MBI->create_meshset( 0, cgm_file_set );
1263 result =
MBI->load_file( sat_name, &cgm_file_set, cgm_options, NULL, 0, 0 );
1266 std::cout <<
"error: problem reading sat file" << std::endl;
1269 std::cout <<
"CAD file read." << std::endl;
1292 std::cout <<
"Fixed CAD surface senses to match meshed surface senses." << std::endl;
1296 std::vector< double > orig_size;
1297 if( determine_volume_change )
1299 result =
MBI->get_entities_by_dimension( 0, 3, orig_elems );
1301 orig_size.resize( orig_elems.
size() );
1302 for(
unsigned int i = 0; i < orig_elems.
size(); ++i )
1304 orig_size[i] =
measure(
MBI, orig_elems[i] );
1310 const int three = 3;
1311 const void*
const three_val[] = { &three };
1313 result =
MBI->get_entities_by_type_and_tag( cub_file_set,
MBENTITYSET, &dimTag, three_val, 1, cub_vols );
1323 result =
MBI->get_entities_by_type_and_tag( cgm_file_set,
MBENTITYSET, &dimTag, three_val, 1, vol_sets );
1334 result =
MBI->tag_set_data( sizeTag, &( *i ), 1, &
size );
1346 bool dead_elements_exist =
true;
1350 char exo_options[120] =
"tdata=coord,";
1351 strcat( exo_options, time_step );
1352 strcat( exo_options,
",set" );
1358 MBI->load_file( exo_name, &cub_file_set, exo_options );
1361 std::string last_error;
1362 MBI->get_last_error( last_error );
1363 std::cout <<
"coordinate update failed, " << last_error << std::endl;
1366 std::cout <<
"Updated mesh nodes with deformed coordinates from exodus file." << std::endl;
1369 if( determine_volume_change )
1374 result =
MBI->get_entities_by_dimension( 0, 3, defo_elems );
1379 double* orig_size_condensed =
new double[defo_elems.
size()];
1380 double* defo_size_condensed =
new double[defo_elems.
size()];
1382 for(
unsigned int i = 0; i < orig_elems.
size(); ++i )
1384 if( orig_elems[i] == defo_elems[j] )
1386 orig_size_condensed[j] = orig_size[i];
1387 defo_size_condensed[j] =
measure(
MBI, defo_elems[j] );
1391 generate_plots( orig_size_condensed, defo_size_condensed, defo_elems.
size(), std::string( time_step ) );
1392 delete[] orig_size_condensed;
1393 delete[] defo_size_condensed;
1398 if( update_coords && dead_elements_exist )
1403 std::cout <<
"Placed dead elements in implicit complement volume and added required surfaces." << std::endl;
1412 std::cout <<
"Replaced faceted CAD surfaces with meshed surfaces of triangles." << std::endl;
1416 std::cout <<
"Removed surfaces and volumes that no longer have any triangles." << std::endl;
1421 conserve_mass,
debug );
1423 std::cout <<
"Summarized the volume change of each material, with respect to the solid model." << std::endl;
1425 result =
MBI->write_mesh( out_name, &cgm_file_set, 1 );
1428 std::cout <<
"write mesh failed" << std::endl;
1431 std::cout <<
"Saved output file for mesh-based analysis." << std::endl;
1433 clock_t end_time = clock();
1434 std::cout <<
" " << (double)( end_time -
start_time ) / CLOCKS_PER_SEC <<
" seconds" << std::endl;
1435 std::cout << std::endl;
1443 const char* result = 0;
1445 file = fopen( name,
"r" );
1483 return !fseek( file, 0, SEEK_SET ) && fread(
buffer, 4, 1, file ) && !memcmp(
buffer,
"CUBE", 4 );
1489 return !fseek( file, 0, SEEK_SET ) && fread(
buffer, 9, 1, file ) && !memcmp(
buffer,
"ISO-10303", 9 );
1494 unsigned char buffer[10];
1495 return !fseek( file, 72, SEEK_SET ) && fread(
buffer, 10, 1, file ) && !memcmp(
buffer,
"S 1\r\n", 10 );
1501 return !fseek( file, 0, SEEK_SET ) && fread(
buffer, 15, 1, file ) && !memcmp(
buffer,
"ACIS BinaryFile", 9 );
1509 if( fseek( file, 0, SEEK_SET ) || 2 != fscanf( file,
"%d %*d %*d %*d %d ", &version, &
length ) )
return 0;
1511 if( version < 1 || version > 0xFFFF )
return 0;
1514 if( fseek( file,
length, SEEK_CUR ) )
return 0;
1517 if( 2 != fscanf( file,
"%d %4s", &
length,
buffer ) )
return 0;
1519 return !strcmp(
buffer,
"ACIS" );
1525 return !fseek( file, 0, SEEK_SET ) && fread(
buffer, 6, 1, file ) && !memcmp(
buffer,
"DBRep_", 6 );