58 :
MBI( impl ), geom_tag( 0 ), id_tag( 0 ), name_tag( 0 ), category_tag( 0 ), faceting_tol_tag( 0 )
60 assert( NULL != impl );
116 std::cout <<
"Subset reading not supported for RTT meshes" << std::endl;
122 file = fopen( filename,
"r" );
141 std::vector< node > node_data;
146 std::vector< facet > facet_data;
151 std::vector< tet > tet_data;
156 std::map< int, EntityHandle > surface_map;
157 std::map< int, EntityHandle > volume_map;
172 std::vector< cell > cell_data,
173 std::vector< tet > tet_data,
174 std::map< int, EntityHandle >& surface_map,
175 std::map< int, EntityHandle >& volume_map )
179 std::vector< EntityHandle > entmap[4];
182 const char geom_categories[][
CATEGORY_TAG_SIZE] = {
"Vertex\0",
"Curve\0",
"Surface\0",
"Volume\0",
"Group\0" };
184 std::vector< int > surface_numbers;
191 for(
int dim = 2; dim <= 3; dim++ )
193 for(
int i = 0; i != num_ents[dim]; i++ )
202 entmap[dim].push_back( handle );
249 std::vector< facet > facet_data,
250 std::vector< tet > tet_data,
251 const std::map< int, EntityHandle > surface_map,
252 const std::map< int, EntityHandle > volume_map )
262 for(
const auto& n : node_data )
264 double coords[3] = { n.x, n.y, n.z };
281 if( have_material_flag )
289 for(
const auto& t : tet_data )
291 EntityHandle tet_nodes[4] = { mb_coords[t.connectivity[0] - 1], mb_coords[t.connectivity[1] - 1],
292 mb_coords[t.connectivity[2] - 1], mb_coords[t.connectivity[3] - 1] };
298 if( have_material_flag )
305 if( volume_map.find( volume_no ) != volume_map.end() )
312 std::cout <<
"Warning: volume number " << volume_no <<
" not found in volume map" << std::endl;
329 for(
auto it = volume_map.begin(); it != volume_map.end(); ++it )
336 if( vol_tets.
empty() )
continue;
382 std::strncpy( name_val, material_name.c_str(),
NAME_TAG_SIZE - 1 );
401 const std::map< int, EntityHandle >& surface_map,
405 Tag side_id_tag, surface_number_tag;
414 for(
const auto& tmp : facet_data )
416 EntityHandle tri_nodes[3] = { mb_coords[tmp.connectivity[0] - 1], mb_coords[tmp.connectivity[1] - 1],
417 mb_coords[tmp.connectivity[2] - 1] };
424 EntityHandle meshset_handle = surface_map.at( tmp.surface_number );
433 mb_tris.
insert( triangle );
461 std::cout <<
"Problems reading file = " << filename << std::endl;
472 if( line.compare(
"header" ) == 0 )
476 else if( line.compare(
"dims" ) == 0 )
480 else if( line.compare(
"cell_defs" ) == 0 )
492 std::vector< int > n_flags,
495 std::map< std::string, int >& flag_idx )
497 std::string start_flag = flag_id +
"_flags";
498 std::string end_flag =
"end_" + start_flag +
"\0";
501 std::vector< std::string > flag_order;
505 std::cout <<
"Problems reading file = " << filename << std::endl;
513 if( line.compare( start_flag ) == 0 )
518 if( line.compare( end_flag ) == 0 )
break;
520 if( token.size() != 2 )
522 std::cout <<
"Error reading side flags" << std::endl;
525 int flag_key = std::stoi( token[0] ) - 1;
526 std::string key = token[1];
527 flag_order.push_back( key );
528 for(
int i = 0; i < n_flags[flag_key]; i++ )
531 flags[key].push_back( line );
538 for(
size_t i = 0; i < flag_order.size(); i++ )
540 std::string key = flag_order[i];
570 if( side_flags.find(
"FACES" ) != side_flags.end() )
572 for(
size_t i = 0; i < side_flags[
"FACES"].size(); i++ )
584 std::string material_ref_flag =
"";
587 material_ref_flag =
"MATERIAL";
589 return material_ref_flag;
594 std::string part_ref_flag =
"REGIONS";
597 part_ref_flag =
"MCNP_PSEUDO-CELLS";
601 part_ref_flag =
"ABAQUS_PARTS";
603 return part_ref_flag;
616 for(
auto it = cell_flags.begin(); it != cell_flags.end(); ++it )
618 std::string key = it->first;
637 if( cell_flags.find( key ) != cell_flags.end() )
639 for(
size_t i = 0; i < cell_flags[key].size(); i++ )
644 if(
cell_data.size() == 0 )
return MB_FAILURE;
649 for(
size_t i = 0; i <
cell_data.size(); ++i )
670 std::cout <<
"Problems reading file = " << filename << std::endl;
679 if( line.compare(
"nodes\0" ) == 0 )
684 if( line.compare(
"end_nodes\0" ) == 0 )
break;
686 node_data.push_back( data );
692 if( node_data.size() == 0 )
return MB_FAILURE;
706 std::cout <<
"Problems reading file = " << filename << std::endl;
715 if( line.compare(
"sides\0" ) == 0 )
720 if( line.compare(
"end_sides\0" ) == 0 )
break;
722 facet_data.push_back( data );
742 std::cout <<
"Problems reading file = " << filename << std::endl;
750 if( line.compare(
"cells\0" ) == 0 )
755 if( line.compare(
"end_cells\0" ) == 0 )
break;
757 tet_data.push_back( data );
763 if( tet_data.size() == 0 )
return MB_FAILURE;
777 std::istringstream iss( line );
781 std::string sub_string;
787 if( line.find(
"version" ) != std::string::npos )
790 split_string[0].find(
"version" ) != std::string::npos )
795 else if( line.find(
"title" ) != std::string::npos )
799 else if( line.find(
"date" ) != std::string::npos )
803 else if( line.find(
"contiguity" ) != std::string::npos )
807 else if( line.find(
"end_header" ) != std::string::npos )
820 std::cout <<
"Problems reading file" << std::endl;
826 int nnodes_side_max_val = -1;
827 int ndim_topo_val = -1;
830 std::vector< std::string > tokens;
833 if( line ==
"" )
continue;
834 if( line.find(
"end_dims" ) != std::string::npos )
break;
837 if( tokens[0] ==
"coor_units" )
841 else if( tokens[0] ==
"prob_time_units" )
845 else if( tokens[0] ==
"ncell_defs" )
849 else if( tokens[0] ==
"nnodes_max" )
853 else if( tokens[0] ==
"nsides_max" )
857 else if( tokens[0] ==
"nnodes_side_max" )
859 nnodes_side_max_val = std::atoi( tokens[1].c_str() );
861 else if( tokens[0] ==
"ndim_topo" )
863 ndim_topo_val = std::atoi( tokens[1].c_str() );
865 else if( tokens[0] ==
"ndim" )
869 else if( tokens[0] ==
"nnodes" )
873 else if( tokens[0] ==
"nnode_flag_types" )
877 else if( tokens[0] ==
"nnode_flags" )
879 for(
size_t i = 1; i < tokens.size(); i++ )
884 else if( tokens[0] ==
"nnode_data" )
888 else if( tokens[0] ==
"nsides" )
892 else if( tokens[0] ==
"nside_types" )
896 else if( tokens[0] ==
"side_types" )
900 else if( tokens[0] ==
"nside_flag_types" )
904 else if( tokens[0] ==
"nside_flags" )
906 for(
size_t i = 1; i < tokens.size(); i++ )
911 else if( tokens[0] ==
"nside_data" )
915 else if( tokens[0] ==
"ncells" )
919 else if( tokens[0] ==
"ncell_types" )
923 else if( tokens[0] ==
"cell_types" )
927 else if( tokens[0] ==
"ncell_flag_types" )
931 else if( tokens[0] ==
"ncell_flags" )
933 for(
size_t i = 1; i < tokens.size(); i++ )
938 else if( tokens[0] ==
"ncell_data" )
945 if( nnodes_side_max_val == -1 )
946 std::cerr <<
"Warning: nnodes_side_max not found in dims block; expected 3 for a tet mesh." << std::endl;
947 else if( nnodes_side_max_val != 3 )
948 std::cerr <<
"Warning: nnodes_side_max is " << nnodes_side_max_val
949 <<
"; expected 3 for a tet mesh. Results may be incorrect." << std::endl;
951 if( ndim_topo_val == -1 )
952 std::cerr <<
"Warning: ndim_topo not found in dims block; expected 3 for a tet mesh." << std::endl;
953 else if( ndim_topo_val != 3 )
954 std::cerr <<
"Warning: ndim_topo is " << ndim_topo_val
955 <<
"; expected 3 for a tet mesh. Results may be incorrect." << std::endl;
970 std::cout <<
"Problems reading file" << std::endl;
975 std::vector< std::string > tokens;
978 if( line ==
"" )
continue;
979 if( line.find(
"end_cell_defs" ) != std::string::npos )
break;
983 new_cell_def.
id = std::atoi( tokens[0].c_str() );
984 new_cell_def.
name = tokens[1];
989 new_cell_def.
nnodes = std::atoi( tokens[0].c_str() );
990 new_cell_def.
nsides = std::atoi( tokens[1].c_str() );
995 for(
int i = 0; i < new_cell_def.
nsides; i++ )
997 int side_type = std::atoi( tokens[i].c_str() );
998 new_cell_def.
side_type.push_back( side_type );
1001 for(
int i = 0; i < new_cell_def.
nsides; i++ )
1003 std::vector< int > side_nodes;
1007 for(
int j = 0; j < new_cell_def.
nnodes; j++ )
1009 side_nodes.push_back( std::atoi( tokens[i].c_str() ) );
1014 cell_def_data.insert( std::make_pair( new_cell_def.
id, new_cell_def ) );
1026 std::vector< std::string > tokens;
1030 if( tokens.size() != 2 )
1035 new_side.
id = std::atoi( tokens[0].c_str() );
1044 if( cell_names.size() > 1 )
1053 new_side.
names[1] =
"\0";
1065 std::vector< std::string > tokens;
1069 if( tokens.size() != 2 )
1074 new_cell.
id = std::atoi( tokens[0].c_str() );
1075 new_cell.
name = tokens[1];
1086 std::vector< std::string > tokens;
1090 if( tokens.size() != 5 )
1094 new_node.
id = std::atoi( tokens[0].c_str() );
1095 new_node.
x = std::atof( tokens[1].c_str() );
1096 new_node.
y = std::atof( tokens[2].c_str() );
1097 new_node.
z = std::atof( tokens[3].c_str() );
1107 std::vector< std::string > tokens;
1111 int base_token_size = 0;
1116 base_token_size = 4;
1120 base_token_size = 5;
1130 std::cout << facetdata << std::endl;
1131 std::cout <<
header_data.
version <<
" " << (int)tokens.size() <<
" " << base_token_size <<
" "
1137 new_facet.
id = std::atoi( tokens[0].c_str() );
1138 new_facet.
connectivity[0] = std::atoi( tokens[idx_offset + 1].c_str() );
1139 new_facet.
connectivity[1] = std::atoi( tokens[idx_offset + 2].c_str() );
1140 new_facet.
connectivity[2] = std::atoi( tokens[idx_offset + 3].c_str() );
1141 new_facet.
side_id = std::atoi( tokens[idx_offset + 4].c_str() );
1142 new_facet.
surface_number = std::atoi( tokens[idx_offset + 5].c_str() );
1154 std::vector< std::string > tokens;
1158 int base_token_size = 0;
1163 base_token_size = 1;
1169 base_token_size = 2;
1172 new_tet.
type_id = std::atoi( tokens[1].c_str() );
1176 std::cout <<
"Error: cell type " << new_tet.
type_id <<
" not found in cell definitions." << std::endl;
1181 if( n_nodes != 4 || n_sides != 4 )
1183 std::cout <<
"Error: cell type " << new_tet.
type_id <<
" does not have 4 nodes and 4 sides." << std::endl;
1192 new_tet.
id = std::atoi( tokens[0].c_str() );
1196 MB_SET_ERR_RET_VAL(
"Error, unexpected number of tokens found from get_tet_data", new_tet );
1198 for(
int i = 0; i < n_nodes; i++ )
1200 new_tet.
connectivity[i] = std::atoi( tokens[i + base_token_size].c_str() );
1204 new_tet.
flag_values.push_back( std::atoi( tokens[i + base_token_size + n_nodes].c_str() ) );
1216 for(
size_t i = 0; i <
cell_data.size(); i++ )
1218 if( (
int)
cell_data[i].name.length() > max_size ) max_size =
cell_data[i].name.length();
1231 new_boundary.
sense = 0;
1232 new_boundary.
name =
"\0";
1234 if( atilla_cellname.find(
"+" ) != std::string::npos )
1236 new_boundary.
sense = 1;
1238 std::size_t found = atilla_cellname.find(
"@" );
1239 if( found != std::string::npos )
1240 new_boundary.
name = atilla_cellname.substr( 3, found );
1242 new_boundary.
name = atilla_cellname.substr( 3, atilla_cellname.length() );
1244 else if( atilla_cellname.find(
"-" ) != std::string::npos )
1247 new_boundary.
sense = -1;
1248 new_boundary.
name = atilla_cellname.substr( 3, atilla_cellname.length() );
1250 return new_boundary;
1258 std::istringstream ss( string_to_split );
1259 std::vector< std::string > tokens;
1263 std::getline( ss, x, split_char );
1264 tokens.push_back( x );
1268 std::vector< std::string >::iterator it;
1269 for( it = tokens.begin(); it != tokens.end(); )
1271 std::string
string = *it;
1272 if(
string.compare(
"\0" ) == 0 )
1273 it = tokens.erase( it );
1284 std::vector< EntityHandle > entity_map[4],
1285 std::vector< side > side_data,
1286 std::vector< cell > cell_data )
1290 for(
int i = 0; i < num_ents[2]; i++ )
1295 for(
unsigned int shared = 0; shared <= 1; shared++ )
1297 std::string parent_name =
side_data[i].names[shared];
1299 unsigned pos = parent_name.find(
"@" );
1300 parent_name = parent_name.substr( 0, pos );
1303 for(
int j = 0; j < num_ents[3]; j++ )
1306 if(
cell_data[j].name.compare( parent_name ) == 0 )
1313 std::cerr <<
"Failed to add parent child relationship" << std::endl;
1326 std::vector< EntityHandle > entity_map[4],
1327 std::vector< side > side_data,
1328 std::vector< cell > cell_data )
1333 for(
int i = 0; i < num_ents[2]; i++ )
1337 for(
unsigned int shared = 0; shared <= 1; shared++ )
1339 std::string parent_name =
side_data[i].names[shared];
1340 unsigned pos = parent_name.find(
"@" );
1341 parent_name = parent_name.substr( 0, pos );
1343 for(
int j = 0; j < num_ents[3]; j++ )
1346 if(
cell_data[j].name.compare( parent_name ) == 0 )
1353 else if(
side_data[i].senses[shared] == -1 )
1360 std::cerr <<
"Failed to set sense appropriately" << std::endl;
1373 std::vector< tet > tet_data,
1374 std::map< int, EntityHandle >& volume_map )
1379 if( handle == 0 )
return MB_FAILURE;
1393 std::map< int, int > volume2mat;
1394 std::map< int, EntityHandle > mat_groups;
1396 for(
const auto& t : tet_data )
1402 auto it = volume2mat.find( vol_no );
1403 if( it == volume2mat.end() )
1404 volume2mat[vol_no] = mat_no;
1405 else if( it->second != mat_no )
1407 std::cerr <<
"Volume " << vol_no <<
" has conflicting material numbers: " << it->second <<
" and "
1408 << mat_no << std::endl;
1413 if( mat_groups.find( mat_no ) == mat_groups.end() )
1415 std::string name = mat_cells[mat_idx.at( mat_no )].name;
1416 if( name.rfind(
"mat:", 0 ) != 0 ) name =
"mat:" + name;
1420 mat_groups[mat_no] = mat_grp;
1425 for(
const auto& vp : volume2mat )
1427 int vol_no = vp.first;
1428 int mat_no = vp.second;
1429 auto v_it = volume_map.find( vol_no );
1430 auto m_it = mat_groups.find( mat_no );
1432 if( v_it == volume_map.end() || m_it == mat_groups.end() )
1434 std::cerr <<
"Missing handle while adding volume " << vol_no <<
" to material " << mat_no << std::endl;
1454 const char geom_categories[][
CATEGORY_TAG_SIZE] = {
"Vertex\0",
"Curve\0",
"Surface\0",
"Volume\0",
"Group\0" };
1460 std::strncpy( name_buf, group_name.c_str(),
NAME_TAG_SIZE - 1 );