57 :
MBI( impl ), geom_tag( 0 ), id_tag( 0 ), name_tag( 0 ), category_tag( 0 ), faceting_tol_tag( 0 )
59 assert( NULL != impl );
115 std::cout <<
"Subset reading not supported for RTT meshes" << std::endl;
121 file = fopen( filename,
"r" );
140 std::vector< node > node_data;
145 std::vector< facet > facet_data;
150 std::vector< tet > tet_data;
155 std::map< int, EntityHandle > surface_map;
156 std::map< int, EntityHandle > volume_map;
171 std::vector< cell > cell_data,
172 std::vector< tet > tet_data,
173 std::map< int, EntityHandle >& surface_map,
174 std::map< int, EntityHandle >& volume_map )
178 std::vector< EntityHandle > entmap[4];
181 const char geom_categories[][
CATEGORY_TAG_SIZE] = {
"Vertex\0",
"Curve\0",
"Surface\0",
"Volume\0",
"Group\0" };
183 std::vector< int > surface_numbers;
192 for(
int i = 0; i != num_ents[
dim]; i++ )
201 entmap[
dim].push_back( handle );
248 std::vector< facet > facet_data,
249 std::vector< tet > tet_data,
250 const std::map< int, EntityHandle > surface_map,
251 const std::map< int, EntityHandle > volume_map )
261 for(
const auto& n : node_data )
263 double coords[3] = { n.x, n.y, n.z };
271 create_facets( facet_data, surface_map, mb_coords, file_set );
283 for(
const auto& t : tet_data )
285 EntityHandle tet_nodes[4] = { mb_coords[t.connectivity[0] - 1], mb_coords[t.connectivity[1] - 1],
286 mb_coords[t.connectivity[2] - 1], mb_coords[t.connectivity[3] - 1] };
309 std::strncpy( name_val, material_name.c_str(),
NAME_TAG_SIZE - 1 );
328 const std::map< int, EntityHandle >& surface_map,
333 Tag side_id_tag, surface_number_tag;
342 for(
const auto& tmp : facet_data )
344 EntityHandle tri_nodes[3] = { mb_coords[tmp.connectivity[0] - 1], mb_coords[tmp.connectivity[1] - 1],
345 mb_coords[tmp.connectivity[2] - 1] };
350 rval =
MBI->
tag_set_data( surface_number_tag, &triangle, 1, &tmp.surface_number );
352 EntityHandle meshset_handle = surface_map.at( tmp.surface_number );
354 rval =
MBI->
tag_set_data( side_id_tag, &meshset_handle, 1, &tmp.side_id );
355 rval =
MBI->
tag_set_data( surface_number_tag, &meshset_handle, 1, &tmp.surface_number );
361 mb_tris.
insert( triangle );
376 rval =
MBI->
tag_set_data( contiguity_tag, &file_set, 1, contiguity_value );
390 std::cout <<
"Problems reading file = " << filename << std::endl;
401 if( line.compare(
"header" ) == 0 )
405 else if( line.compare(
"dims" ) == 0 )
409 else if( line.compare(
"cell_defs" ) == 0 )
421 std::vector< int > n_flags,
424 std::map< std::string, int >& flag_idx )
426 std::string start_flag = flag_id +
"_flags";
427 std::string end_flag =
"end_" + start_flag +
"\0";
430 std::vector< std::string > flag_order;
434 std::cout <<
"Problems reading file = " << filename << std::endl;
442 if( line.compare( start_flag ) == 0 )
447 if( line.compare( end_flag ) == 0 )
break;
449 if( token.size() != 2 )
451 std::cout <<
"Error reading side flags" << std::endl;
454 int flag_key = std::stoi( token[0] ) - 1;
455 std::string key = token[1];
456 flag_order.push_back( key );
457 for(
int i = 0; i < n_flags[flag_key]; i++ )
460 flags[key].push_back( line );
467 for(
size_t i = 0; i < flag_order.size(); i++ )
469 std::string key = flag_order[i];
499 if( side_flags.find(
"FACES" ) != side_flags.end() )
501 for(
size_t i = 0; i < side_flags[
"FACES"].size(); i++ )
507 if(
side_data.size() == 0 )
return MB_FAILURE;
513 std::string material_ref_flag =
"";
516 material_ref_flag =
"MATERIAL";
518 return material_ref_flag;
523 std::string part_ref_flag =
"REGIONS";
526 part_ref_flag =
"MCNP_PSEUDO-CELLS";
530 part_ref_flag =
"ABAQUS_PARTS";
532 return part_ref_flag;
545 for(
auto it = cell_flags.begin(); it != cell_flags.end(); ++it )
547 std::string key = it->first;
566 if( cell_flags.find( key ) != cell_flags.end() )
568 for(
size_t i = 0; i < cell_flags[key].size(); i++ )
573 if(
cell_data.size() == 0 )
return MB_FAILURE;
578 for(
size_t i = 0; i <
cell_data.size(); ++i )
599 std::cout <<
"Problems reading file = " << filename << std::endl;
608 if( line.compare(
"nodes\0" ) == 0 )
613 if( line.compare(
"end_nodes\0" ) == 0 )
break;
615 node_data.push_back( data );
621 if( node_data.size() == 0 )
return MB_FAILURE;
635 std::cout <<
"Problems reading file = " << filename << std::endl;
644 if( line.compare(
"sides\0" ) == 0 )
649 if( line.compare(
"end_sides\0" ) == 0 )
break;
651 facet_data.push_back( data );
657 if( facet_data.size() == 0 )
return MB_FAILURE;
671 std::cout <<
"Problems reading file = " << filename << std::endl;
679 if( line.compare(
"cells\0" ) == 0 )
684 if( line.compare(
"end_cells\0" ) == 0 )
break;
686 tet_data.push_back( data );
692 if( tet_data.size() == 0 )
return MB_FAILURE;
706 std::istringstream iss( line );
710 std::string sub_string;
716 if( line.find(
"version" ) != std::string::npos )
719 split_string[0].find(
"version" ) != std::string::npos )
724 else if( line.find(
"title" ) != std::string::npos )
728 else if( line.find(
"date" ) != std::string::npos )
732 else if( line.find(
"contiguity" ) != std::string::npos )
736 else if( line.find(
"end_header" ) != std::string::npos )
749 std::cout <<
"Problems reading file" << std::endl;
754 std::vector< std::string > tokens;
757 if( line ==
"" )
continue;
758 if( line.find(
"end_dims" ) != std::string::npos )
break;
761 if( tokens[0] ==
"coor_units" )
765 else if( tokens[0] ==
"prob_time_units" )
769 else if( tokens[0] ==
"ncell_defs" )
773 else if( tokens[0] ==
"nnodes_max" )
777 else if( tokens[0] ==
"nsides_max" )
781 else if( tokens[0] ==
"nnodes_sides_max" )
785 else if( tokens[0] ==
"ndim" )
789 else if( tokens[0] ==
"n_dim_topo" )
793 else if( tokens[0] ==
"nnodes" )
797 else if( tokens[0] ==
"nnode_flag_types" )
801 else if( tokens[0] ==
"nnode_flags" )
803 for(
size_t i = 1; i < tokens.size(); i++ )
808 else if( tokens[0] ==
"nnode_data" )
812 else if( tokens[0] ==
"nsides" )
816 else if( tokens[0] ==
"nside_types" )
820 else if( tokens[0] ==
"side_types" )
824 else if( tokens[0] ==
"nside_flag_types" )
828 else if( tokens[0] ==
"nside_flags" )
830 for(
size_t i = 1; i < tokens.size(); i++ )
835 else if( tokens[0] ==
"nside_data" )
839 else if( tokens[0] ==
"ncells" )
843 else if( tokens[0] ==
"ncell_types" )
847 else if( tokens[0] ==
"cell_types" )
851 else if( tokens[0] ==
"ncell_flag_types" )
855 else if( tokens[0] ==
"ncell_flags" )
857 for(
size_t i = 1; i < tokens.size(); i++ )
862 else if( tokens[0] ==
"ncell_data" )
880 std::cout <<
"Problems reading file" << std::endl;
885 std::vector< std::string > tokens;
888 if( line ==
"" )
continue;
889 if( line.find(
"end_cell_defs" ) != std::string::npos )
break;
893 new_cell_def.
id = std::atoi( tokens[0].c_str() );
894 new_cell_def.
name = tokens[1];
899 new_cell_def.
nnodes = std::atoi( tokens[0].c_str() );
900 new_cell_def.
nsides = std::atoi( tokens[1].c_str() );
905 for(
int i = 0; i < new_cell_def.
nsides; i++ )
907 int side_type = std::atoi( tokens[i].c_str() );
911 std::cout <<
"Error: side type " << side_type <<
" not found in cell definitions." << std::endl;
914 new_cell_def.
side_type.push_back( side_type );
917 for(
int i = 0; i < new_cell_def.
nsides; i++ )
919 std::vector< int > side_nodes;
923 for(
int j = 0; j < new_cell_def.
nnodes; j++ )
925 side_nodes.push_back( std::atoi( tokens[i].c_str() ) );
930 cell_def_data.insert( std::make_pair( new_cell_def.
id, new_cell_def ) );
942 std::vector< std::string > tokens;
946 if( tokens.size() != 2 )
951 new_side.
id = std::atoi( tokens[0].c_str() );
960 if( cell_names.size() > 1 )
969 new_side.
names[1] =
"\0";
981 std::vector< std::string > tokens;
985 if( tokens.size() != 2 )
990 new_cell.
id = std::atoi( tokens[0].c_str() );
991 new_cell.
name = tokens[1];
1002 std::vector< std::string > tokens;
1006 if( tokens.size() != 5 )
1010 new_node.
id = std::atoi( tokens[0].c_str() );
1011 new_node.
x = std::atof( tokens[1].c_str() );
1012 new_node.
y = std::atof( tokens[2].c_str() );
1013 new_node.
z = std::atof( tokens[3].c_str() );
1023 std::vector< std::string > tokens;
1027 int base_token_size = 0;
1032 base_token_size = 4;
1036 base_token_size = 5;
1046 std::cout << facetdata << std::endl;
1047 std::cout <<
header_data.
version <<
" " << (int)tokens.size() <<
" " << base_token_size <<
" "
1054 new_facet.
id = std::atoi( tokens[0].c_str() );
1055 new_facet.
connectivity[0] = std::atoi( tokens[idx_offset + 1].c_str() );
1056 new_facet.
connectivity[1] = std::atoi( tokens[idx_offset + 2].c_str() );
1057 new_facet.
connectivity[2] = std::atoi( tokens[idx_offset + 3].c_str() );
1058 new_facet.
side_id = std::atoi( tokens[idx_offset + 4].c_str() );
1059 new_facet.
surface_number = std::atoi( tokens[idx_offset + 5].c_str() );
1071 std::vector< std::string > tokens;
1075 int base_token_size = 0;
1080 base_token_size = 1;
1086 base_token_size = 2;
1089 new_tet.
type_id = std::atoi( tokens[1].c_str() );
1093 std::cout <<
"Error: cell type " << new_tet.
type_id <<
" not found in cell definitions." << std::endl;
1098 if( n_nodes != 4 || n_sides != 4 )
1100 std::cout <<
"Error: cell type " << new_tet.
type_id <<
" does not have 4 nodes and 4 sides." << std::endl;
1109 new_tet.
id = std::atoi( tokens[0].c_str() );
1113 MB_SET_ERR_RET_VAL(
"Error, unexpected number of tokens found from get_tet_data", new_tet );
1115 for(
int i = 0; i < n_nodes; i++ )
1117 new_tet.
connectivity[i] = std::atoi( tokens[i + base_token_size].c_str() );
1121 new_tet.
flag_values.push_back( std::atoi( tokens[i + base_token_size + n_nodes].c_str() ) );
1133 for(
size_t i = 0; i <
cell_data.size(); i++ )
1135 if( (
int)
cell_data[i].name.length() > max_size ) max_size =
cell_data[i].name.length();
1148 new_boundary.
sense = 0;
1149 new_boundary.
name =
"\0";
1151 if( atilla_cellname.find(
"+" ) != std::string::npos )
1153 new_boundary.
sense = 1;
1155 std::size_t found = atilla_cellname.find(
"@" );
1156 if( found != std::string::npos )
1157 new_boundary.
name = atilla_cellname.substr( 3, found );
1159 new_boundary.
name = atilla_cellname.substr( 3, atilla_cellname.length() );
1161 else if( atilla_cellname.find(
"-" ) != std::string::npos )
1164 new_boundary.
sense = -1;
1165 new_boundary.
name = atilla_cellname.substr( 3, atilla_cellname.length() );
1167 return new_boundary;
1175 std::istringstream ss( string_to_split );
1176 std::vector< std::string > tokens;
1180 std::getline( ss, x, split_char );
1181 tokens.push_back( x );
1185 std::vector< std::string >::iterator it;
1186 for( it = tokens.begin(); it != tokens.end(); )
1188 std::string
string = *it;
1189 if(
string.compare(
"\0" ) == 0 )
1190 it = tokens.erase( it );
1201 std::vector< EntityHandle > entity_map[4],
1202 std::vector< side > side_data,
1203 std::vector< cell > cell_data )
1207 for(
int i = 0; i < num_ents[2]; i++ )
1212 for(
unsigned int shared = 0; shared <= 1; shared++ )
1214 std::string parent_name =
side_data[i].names[shared];
1216 unsigned pos = parent_name.find(
"@" );
1217 parent_name = parent_name.substr( 0, pos );
1220 for(
int j = 0; j < num_ents[3]; j++ )
1223 if(
cell_data[j].name.compare( parent_name ) == 0 )
1230 std::cerr <<
"Failed to add parent child relationship" << std::endl;
1243 std::vector< EntityHandle > entity_map[4],
1244 std::vector< side > side_data,
1245 std::vector< cell > cell_data )
1250 for(
int i = 0; i < num_ents[2]; i++ )
1254 for(
unsigned int shared = 0; shared <= 1; shared++ )
1256 std::string parent_name =
side_data[i].names[shared];
1257 unsigned pos = parent_name.find(
"@" );
1258 parent_name = parent_name.substr( 0, pos );
1260 for(
int j = 0; j < num_ents[3]; j++ )
1263 if(
cell_data[j].name.compare( parent_name ) == 0 )
1270 else if(
side_data[i].senses[shared] == -1 )
1277 std::cerr <<
"Failed to set sense appropriately" << std::endl;
1290 std::vector< tet > tet_data,
1291 std::map< int, EntityHandle >& volume_map )
1308 std::map< int, int > volume2mat;
1309 std::map< int, EntityHandle > mat_groups;
1311 for(
const auto& t : tet_data )
1317 auto it = volume2mat.find( vol_no );
1318 if( it == volume2mat.end() )
1319 volume2mat[vol_no] = mat_no;
1320 else if( it->second != mat_no )
1322 std::cerr <<
"Volume " << vol_no <<
" has conflicting material numbers: " << it->second <<
" and "
1323 << mat_no << std::endl;
1328 if( mat_groups.find( mat_no ) == mat_groups.end() )
1330 std::string name = mat_cells[mat_idx.at( mat_no )].name;
1331 if( name.rfind(
"mat:", 0 ) != 0 ) name =
"mat:" + name;
1335 mat_groups[mat_no] = mat_grp;
1340 for(
const auto& vp : volume2mat )
1342 int vol_no = vp.first;
1343 int mat_no = vp.second;
1344 auto v_it = volume_map.find( vol_no );
1345 auto m_it = mat_groups.find( mat_no );
1347 if( v_it == volume_map.end() || m_it == mat_groups.end() )
1349 std::cerr <<
"Missing handle while adding volume " << vol_no <<
" to material " << mat_no << std::endl;
1369 const char geom_categories[][
CATEGORY_TAG_SIZE] = {
"Vertex\0",
"Curve\0",
"Surface\0",
"Volume\0",
"Group\0" };