17 #pragma warning( disable : 4786 )
41 #define ABQ_AMBIGUOUS "AMBIGUOUS"
42 #define ABQ_UNDEFINED "UNDEFINED"
43 #define DEG2RAD 0.017453292519943295769236907684886
45 #define MB_RETURN_IF_FAIL \
46 if( MB_SUCCESS != status ) return status
54 : mdbImpl( impl ), readMeshIface( NULL ), lineNo( 0 ), next_line_type(
abq_undefined_line ), mat_id( 0 )
56 assert( impl != NULL );
78 int negone = -1, negonearr[] = { -1, -1, -1, -1 };
114 std::vector< int >& ,
135 abFile.open( abaqus_file_name );
138 bool in_unsupported =
false;
150 in_unsupported =
false;
168 in_unsupported =
true;
176 if( !in_unsupported )
182 MB_SET_ERR( MB_FAILURE,
"Invalid/unrecognized line" );
192 void* tag_data[] = { &tag_val };
200 tag_data[0] = &tag_val;
209 tag_data[0] = &tag_val;
217 Range node_list, ele_list;
257 std::vector< std::string > tokens;
258 std::map< std::string, std::string > params;
259 std::map< std::string, abaqus_assembly_params > requiredParams;
262 std::map< std::string, abaqus_assembly_params > allowableParams;
267 std::string assembly_name;
274 for( std::map< std::string, abaqus_assembly_params >::iterator thisParam = requiredParams.begin();
275 thisParam != requiredParams.end(); ++thisParam )
277 std::string param_key =
match( ( *thisParam ).first, params );
278 param = requiredParams[param_key];
282 assembly_name = params[param_key];
283 params.erase( param_key );
295 for( std::map< std::string, std::string >::iterator thisParam = params.begin(); thisParam != params.end();
299 param = allowableParams[
match( ( *thisParam ).first, allowableParams )];
319 bool end_assembly =
false;
320 bool in_unsupported =
false;
327 in_unsupported =
false;
340 in_unsupported =
true;
351 if( !in_unsupported )
378 std::vector< std::string > tokens;
379 std::map< std::string, std::string > params;
380 std::map< std::string, abaqus_instance_params > requiredParams;
384 std::map< std::string, abaqus_instance_params > allowableParams;
389 std::string instance_name, part_name;
396 for( std::map< std::string, abaqus_instance_params >::iterator thisParam = requiredParams.begin();
397 thisParam != requiredParams.end(); ++thisParam )
399 std::string param_key =
match( ( *thisParam ).first, params );
400 param = requiredParams[param_key];
404 instance_name = params[param_key];
405 params.erase( param_key );
408 part_name = params[param_key];
409 params.erase( param_key );
421 for( std::map< std::string, std::string >::iterator thisParam = params.begin(); thisParam != params.end();
425 param = allowableParams[
match( ( *thisParam ).first, allowableParams )];
442 bool read_translation =
false;
443 bool read_rotation =
false;
444 std::vector< double > translation( 3, 0 );
445 std::vector< double > rotation( 7, 0 );
446 bool end_instance =
false;
447 bool in_unsupported =
false;
458 in_unsupported =
false;
472 status =
read_node_set( instance_set, file_set, assembly_set );
481 in_unsupported =
true;
492 if( !in_unsupported )
495 if( !read_translation )
497 if( tokens.size() != 3 )
499 MB_SET_ERR( MB_FAILURE,
"Wrong number of entries on INSTANCE translation line" );
502 for(
unsigned int i = 0; i < 3; i++ )
503 translation[i] = atof( tokens[i].c_str() );
505 read_translation =
true;
507 else if( !read_rotation )
509 if( tokens.size() != 7 )
511 MB_SET_ERR( MB_FAILURE,
"Wrong number of entries on INSTANCE rotation line" );
513 for(
unsigned int i = 0; i < 7; i++ )
514 rotation[i] = atof( tokens[i].c_str() );
516 read_rotation =
true;
520 MB_SET_ERR( MB_FAILURE,
"Too many data lines for this INSTANCE" );
526 MB_SET_ERR( MB_FAILURE,
"Error: Blank lines are not allowed" );
528 MB_SET_ERR( MB_FAILURE,
"Error reading INSTANCE" );
543 std::vector< std::string > tokens;
544 std::map< std::string, std::string > params;
545 std::map< std::string, abaqus_part_params > requiredParams;
548 std::map< std::string, abaqus_part_params > allowableParams;
553 std::string part_name;
560 for( std::map< std::string, abaqus_part_params >::iterator thisParam = requiredParams.begin();
561 thisParam != requiredParams.end(); ++thisParam )
563 std::string param_key =
match( ( *thisParam ).first, params );
564 param = requiredParams[param_key];
568 part_name = params[param_key];
569 params.erase( param_key );
573 MB_SET_ERR( MB_FAILURE,
"Missing required PART parameter" );
578 for( std::map< std::string, std::string >::iterator thisParam = params.begin(); thisParam != params.end();
582 param = allowableParams[
match( ( *thisParam ).first, allowableParams )];
602 bool end_part =
false;
603 bool in_unsupported =
false;
610 in_unsupported =
false;
632 in_unsupported =
true;
644 if( !in_unsupported )
646 MB_SET_ERR( MB_FAILURE,
"Data lines not allowed in PART keyword" );
651 MB_SET_ERR( MB_FAILURE,
"Blank lines are not allowed" );
653 MB_SET_ERR( MB_FAILURE,
"Error reading PART" );
666 std::vector< std::string > tokens;
667 std::map< std::string, std::string > params;
668 std::map< std::string, abaqus_solid_section_params > requiredParams;
672 std::map< std::string, abaqus_solid_section_params > allowableParams;
681 std::string elset_name, mat_name;
684 for( std::map< std::string, abaqus_solid_section_params >::iterator thisParam = requiredParams.begin();
685 thisParam != requiredParams.end(); ++thisParam )
687 std::string param_key =
match( ( *thisParam ).first, params );
688 param = requiredParams[param_key];
692 elset_name = params[param_key];
693 params.erase( param_key );
696 mat_name = params[param_key];
697 params.erase( param_key );
700 MB_SET_ERR( MB_FAILURE,
"Missing required SOLID SECTION parameter" );
707 for( std::map< std::string, std::string >::iterator thisParam = params.begin(); thisParam != params.end();
711 param = allowableParams[
match( ( *thisParam ).first, allowableParams )];
751 std::vector< std::string > tokens;
752 std::map< std::string, std::string > params;
753 std::map< std::string, abaqus_elset_params > requiredParams;
756 std::map< std::string, abaqus_elset_params > allowableParams;
763 std::string elset_name;
764 bool generate_elset =
false;
765 std::string instance_name;
775 for( std::map< std::string, abaqus_elset_params >::iterator thisParam = requiredParams.begin();
776 thisParam != requiredParams.end(); ++thisParam )
778 std::string param_key =
match( ( *thisParam ).first, params );
779 param = requiredParams[param_key];
783 elset_name = params[param_key];
784 params.erase( param_key );
788 MB_SET_ERR( MB_FAILURE,
"Missing required ELSET parameter" );
793 for( std::map< std::string, std::string >::iterator thisParam = params.begin(); thisParam != params.end();
797 param = allowableParams[
match( ( *thisParam ).first, allowableParams )];
801 generate_elset =
true;
804 instance_name = ( *thisParam ).second;
819 std::vector< int > element_list;
820 Range tmp_element_range;
831 if( tokens.size() != 3 )
833 MB_SET_ERR( MB_FAILURE,
"Wrong number of entries on GENERATE element set data line" );
835 int e1 = atoi( tokens[0].c_str() );
836 int e2 = atoi( tokens[1].c_str() );
837 int incr = atoi( tokens[2].c_str() );
838 if( ( incr == 0 ) || ( ( ( e2 - e1 ) % incr ) != 0 ) )
840 MB_SET_ERR( MB_FAILURE,
"Invalid data on GENERATE element set data line" );
842 for(
int element_id = e1; element_id <= e2; element_id += incr )
843 element_list.push_back( element_id );
847 for(
unsigned int idx = 0; idx < tokens.size(); idx++ )
849 if( isalpha( tokens[idx][0] ) )
851 tmp_element_range.
clear();
856 element_range.
merge( tmp_element_range );
859 element_list.push_back( atoi( tokens[idx].c_str() ) );
867 tmp_element_range.
clear();
868 status =
get_elements_by_id( element_container_set, element_list, tmp_element_range );
871 element_range.
merge( tmp_element_range );
905 std::vector< std::string > tokens;
906 std::map< std::string, std::string > params;
907 std::map< std::string, abaqus_nset_params > requiredParams;
910 std::map< std::string, abaqus_nset_params > allowableParams;
918 std::string nset_name;
919 bool make_from_elset =
false;
920 bool generate_nset =
false;
921 std::string elset_name, instance_name;
931 for( std::map< std::string, abaqus_nset_params >::iterator thisParam = requiredParams.begin();
932 thisParam != requiredParams.end(); ++thisParam )
934 std::string param_key =
match( ( *thisParam ).first, params );
935 param = requiredParams[param_key];
939 nset_name = params[param_key];
940 params.erase( param_key );
944 MB_SET_ERR( MB_FAILURE,
"Missing required NSET parameter" );
949 for( std::map< std::string, std::string >::iterator thisParam = params.begin(); thisParam != params.end();
953 param = allowableParams[
match( ( *thisParam ).first, allowableParams )];
957 make_from_elset =
true;
958 elset_name = ( *thisParam ).second;
961 generate_nset =
true;
964 instance_name = ( *thisParam ).second;
979 if( make_from_elset && generate_nset )
981 MB_SET_ERR( MB_FAILURE,
"Incompatible NSET parameters ELSET & GENERATE" );
984 if( make_from_elset )
991 std::vector< int > node_list;
992 Range tmp_node_range;
1003 if( tokens.size() != 3 )
1005 MB_SET_ERR( MB_FAILURE,
"Wrong number of entries on GENERATE node set data line" );
1007 int n1 = atoi( tokens[0].c_str() );
1008 int n2 = atoi( tokens[1].c_str() );
1009 int incr = atoi( tokens[2].c_str() );
1010 if( ( incr == 0 ) || ( ( ( n2 - n1 ) % incr ) != 0 ) )
1012 MB_SET_ERR( MB_FAILURE,
"Invalid data on GENERATE node set data line" );
1014 for(
int node_id = n1; node_id <= n2; node_id += incr )
1015 node_list.push_back( node_id );
1019 for(
unsigned int idx = 0; idx < tokens.size(); idx++ )
1021 if( isalpha( tokens[idx][0] ) )
1023 tmp_node_range.
clear();
1027 node_range.
merge( tmp_node_range );
1030 node_list.push_back( atoi( tokens[idx].c_str() ) );
1038 tmp_node_range.
clear();
1040 status =
get_nodes_by_id( node_container_set, node_list, tmp_node_range );
1043 node_range.
merge( tmp_node_range );
1076 std::vector< std::string > tokens;
1077 std::map< std::string, std::string > params;
1078 std::map< std::string, abaqus_element_params > requiredParams;
1081 std::map< std::string, abaqus_element_params > allowableParams;
1087 std::map< std::string, abaqus_element_type > elementTypes;
1088 std::map< abaqus_element_type, unsigned int > nodes_per_element;
1089 std::map< abaqus_element_type, EntityType > entityTypeMap;
1116 bool make_element_set =
false;
1117 std::string element_set_name;
1124 for( std::map< std::string, abaqus_element_params >::iterator thisParam = requiredParams.begin();
1125 thisParam != requiredParams.end(); ++thisParam )
1127 std::string param_key =
match( ( *thisParam ).first, params );
1128 param = requiredParams[param_key];
1132 element_type = elementTypes[params[param_key]];
1135 MB_SET_ERR( MB_FAILURE,
"MOAB doesn't currently support this element type" );
1139 params.erase( param_key );
1142 MB_SET_ERR( MB_FAILURE,
"Missing required ELEMENT parameter" );
1149 for( std::map< std::string, std::string >::iterator thisParam = params.begin(); thisParam != params.end();
1153 param = allowableParams[
match( ( *thisParam ).first, allowableParams )];
1157 make_element_set =
true;
1158 element_set_name = ( *thisParam ).second;
1171 std::vector< int > connect_list, element_ids;
1180 if( tokens.size() < nodes_per_element[element_type] + 1 )
1182 MB_SET_ERR( MB_FAILURE,
"Not enough data on node data line" );
1184 element_ids.push_back( atoi( tokens[0].c_str() ) );
1185 for(
unsigned int i = 1; i < nodes_per_element[element_type] + 1; i++ )
1186 connect_list.push_back( atoi( tokens[i].c_str() ) );
1192 int num_elements = element_ids.size();
1199 entityTypeMap[element_type],
MB_START_ID, start_element, connect );
1201 if( 0 == start_element )
return MB_FAILURE;
1209 std::vector< int > node_ids( node_list.
size() );
1213 std::map< int, EntityHandle > nodeIdMap;
1214 for(
unsigned int idx = 0; idx < node_list.
size(); idx++ )
1215 nodeIdMap[node_ids[idx]] = node_list[idx];
1217 for(
unsigned int node = 0; node < connect_list.size(); node++ )
1218 connect[node] = nodeIdMap[connect_list[node]];
1220 Range element_range( start_element, start_element + num_elements - 1 );
1239 std::vector< EntityHandle > tmp_assembly_handles;
1240 tmp_assembly_handles.assign( element_range.
size(), assembly_set );
1247 if( make_element_set )
1270 std::vector< std::string > tokens;
1271 std::map< std::string, std::string > params;
1272 std::map< std::string, abaqus_node_params > allowableParams;
1280 bool make_node_set =
false;
1281 std::string node_set_name;
1283 char coord_system =
'R';
1292 for( std::map< std::string, std::string >::iterator thisParam = params.begin(); thisParam != params.end();
1296 param = allowableParams[
match( ( *thisParam ).first, allowableParams )];
1300 make_node_set =
true;
1301 node_set_name = ( *thisParam ).second;
1305 coord_system = ( *thisParam ).second[0];
1318 std::vector< double > coord_list;
1319 std::vector< int > node_ids;
1328 if( tokens.size() < 4 )
1330 MB_SET_ERR( MB_FAILURE,
"Not enough data on node data line" );
1332 node_ids.push_back( atoi( tokens[0].c_str() ) );
1333 for(
unsigned int i = 1; i < 4; i++ )
1334 coord_list.push_back( atof( tokens[i].c_str() ) );
1340 unsigned int num_nodes = node_ids.size();
1343 switch( coord_system )
1360 std::vector< double* > coord_arrays( 3 );
1365 if( 0 == start_node )
return MB_FAILURE;
1369 for(
unsigned int idx = 0; idx < num_nodes; idx++ )
1371 coord_arrays[0][idx] = coord_list[idx * 3];
1372 coord_arrays[1][idx] = coord_list[idx * 3 + 1];
1373 coord_arrays[2][idx] = coord_list[idx * 3 + 2];
1376 Range node_range( start_node, start_node + num_nodes - 1 );
1394 std::vector< EntityHandle > tmp_assembly_handles;
1395 tmp_assembly_handles.assign( node_range.
size(), assembly_set );
1424 std::vector< int > element_ids_subset,
1425 Range& element_range )
1433 std::vector< int > element_ids( all_elements.
size() );
1437 std::map< int, EntityHandle > elementIdMap;
1438 for(
unsigned int idx = 0; idx < all_elements.
size(); idx++ )
1439 elementIdMap[element_ids[idx]] = all_elements[idx];
1441 for( std::vector< int >::iterator element = element_ids_subset.begin(); element != element_ids_subset.end();
1443 element_range.
insert( elementIdMap[*element] );
1456 std::vector< int > node_ids( all_nodes.
size() );
1460 std::map< int, EntityHandle > nodeIdMap;
1461 for(
unsigned int idx = 0; idx < all_nodes.
size(); idx++ )
1462 nodeIdMap[node_ids[idx]] = all_nodes[idx];
1464 for( std::vector< int >::iterator node = node_ids_subset.begin(); node != node_ids_subset.end(); ++node )
1465 node_range.
insert( nodeIdMap[*node] );
1472 const std::string& set_name,
1482 void* tag_data[] = { &ABQ_set_type };
1491 if( set_name == std::string( this_set_name ) ) set_handle = *this_set;
1494 if( 0 == set_handle )
1496 MB_SET_ERR( MB_FAILURE,
"Did not find requested set" );
1511 dim_ent_list.
clear();
1515 element_range.
merge( dim_ent_list );
1523 const std::string& set_name,
1524 Range& element_range )
1529 status =
get_set_by_name( parent_set, ABQ_set_type, set_name, set_handle );
1535 if( element_range.
size() == 0 )
1545 const std::string& set_name,
1551 status =
get_set_by_name( parent_set, ABQ_set_type, set_name, set_handle );
1559 dim_ent_list.
clear();
1563 ent_list.
merge( dim_ent_list );
1569 if( node_range.
size() == 0 )
1571 std::cout <<
"No nodes were found in set " << set_name << std::endl;
1581 const void* def_val )
1593 const std::string& part_name,
1594 const std::string& ,
1596 const std::vector< double >& translation,
1597 const std::vector< double >& rotation )
1621 std::map< EntityHandle, EntityHandle > p2i_nodes, p2i_elements;
1626 Range part_node_list;
1630 if( 0 < part_node_list.
size() )
1632 std::vector< int > node_ids( part_node_list.
size() );
1641 std::vector< double* > coord_arrays( 3 );
1646 if( 0 == start_node )
return MB_FAILURE;
1649 status =
mdbImpl->
get_coords( part_node_list, coord_arrays[0], coord_arrays[1], coord_arrays[2] );
1653 rot_axis[0] = rotation[3] - rotation[0];
1654 rot_axis[1] = rotation[4] - rotation[1];
1655 rot_axis[2] = rotation[5] - rotation[2];
1661 for(
unsigned int idx = 0; idx < part_node_list.
size(); idx++ )
1666 for(
unsigned int dim = 0;
dim < 3;
dim++ )
1667 coords[
dim] = coord_arrays[
dim][idx] + translation[
dim] - rotation[
dim];
1670 if( rotation[6] != 0 ) rotationXform.
xform_vector( coords );
1673 for(
unsigned int dim = 0;
dim < 3;
dim++ )
1674 coord_arrays[
dim][idx] = coords[
dim] + rotation[
dim];
1677 Range instance_node_list( start_node, start_node + part_node_list.
size() - 1 );
1696 for(
unsigned int idx = 0; idx < part_node_list.
size(); idx++ )
1697 p2i_nodes[part_node_list[idx]] = instance_node_list[idx];
1702 Range part_element_list;
1706 if( 0 < part_element_list.
size() )
1708 std::vector< int > part_element_ids( part_element_list.
size() );
1717 Range instance_element_list;
1718 instance_element_list.
clear();
1721 std::vector< int > instance_element_ids;
1722 std::vector< int >::iterator part_element_id = part_element_ids.begin();
1725 ++part_element, ++part_element_id )
1728 std::vector< EntityHandle > part_connectivity, instance_connectivity;
1733 instance_connectivity.clear();
1734 for( std::vector< EntityHandle >::iterator connectivity_node = part_connectivity.begin();
1735 connectivity_node != part_connectivity.end(); ++connectivity_node )
1736 instance_connectivity.push_back( p2i_nodes[*connectivity_node] );
1738 status =
mdbImpl->
create_element( element_type, &instance_connectivity[0], instance_connectivity.size(),
1742 instance_element_list.
insert( new_element );
1743 p2i_elements[*part_element] = new_element;
1744 instance_element_ids.push_back( *part_element_id );
1767 Range part_node_sets;
1769 void* tag_data[] = { &tag_val };
1773 Range part_node_set_list, instance_node_set_list;
1782 part_node_set_list.
clear();
1785 instance_node_set_list.
clear();
1786 for(
Range::iterator set_node = part_node_set_list.
begin(); set_node != part_node_set_list.
end(); ++set_node )
1787 instance_node_set_list.
insert( p2i_nodes[*set_node] );
1810 Range part_element_sets;
1812 tag_data[0] = &tag_val;
1817 Range part_element_set_list, instance_element_set_list;
1818 for(
Range::iterator part_element_set = part_element_sets.
begin(); part_element_set != part_element_sets.
end();
1819 ++part_element_set )
1826 part_element_set_list.
clear();
1829 instance_element_set_list.
clear();
1832 instance_element_set_list.
insert( p2i_elements[*set_element] );
1865 int element_set_mat_id;
1879 Range instance_entity_list;
1883 std::vector< EntityHandle > tmp_instance_handles;
1884 tmp_instance_handles.assign( instance_entity_list.
size(), instance_set );
1888 instance_entity_list.
clear();
1892 tmp_instance_handles.clear();
1893 tmp_instance_handles.assign( instance_entity_list.
size(), instance_set );
1898 instance_entity_list.
clear();
1900 tag_data[0] = &tag_val;
1902 instance_entity_list );
1905 tmp_instance_handles.clear();
1906 tmp_instance_handles.assign( instance_entity_list.
size(), instance_set );
1911 instance_entity_list.
clear();
1913 tag_data[0] = &tag_val;
1915 instance_entity_list );
1918 tmp_instance_handles.clear();
1919 tmp_instance_handles.assign( instance_entity_list.
size(), instance_set );
1928 const std::string& set_name,
1950 int num_nodes = coord_list.size() / 3;
1953 for(
int node = 0; node < num_nodes; node++ )
1955 r = coord_list[3 * node];
1956 t = coord_list[3 * node + 1] *
DEG2RAD;
1961 coord_list[3 * node] = x;
1962 coord_list[3 * node + 1] = y;
1968 int num_nodes = coord_list.size() / 3;
1969 double x, y, z, r, t, p;
1971 for(
int node = 0; node < num_nodes; node++ )
1973 r = coord_list[3 * node];
1974 t = coord_list[3 * node + 1] *
DEG2RAD;
1975 p = coord_list[3 * node + 2] *
DEG2RAD;
1977 x = r * cos( p ) * cos( t );
1978 y = r * cos( p ) * sin( t );
1981 coord_list[3 * node] = x;
1982 coord_list[3 * node + 1] = y;
1983 coord_list[3 * node + 2] = z;
1997 std::string::size_type pos =
readline.find_first_not_of(
' ' );
2012 std::vector< std::string > tokens;
2013 std::map< std::string, abaqus_keyword_type > keywords;
2038 return keywords[
match( tokens[0], keywords )];
2045 template <
typename T >
2049 bool found_match =
false;
2053 for(
typename std::map< std::string, T >::iterator thisToken = tokenList.begin(); thisToken != tokenList.end();
2057 if( token == ( *thisToken ).first )
2065 ( token.length() < ( *thisToken ).first.length() ? token.length() : ( *thisToken ).first.length() );
2068 if( token.substr( short_length ) == ( *thisToken ).first.substr( short_length ) )
2074 best_match = ( *thisToken ).first;
2090 converted = toBeConverted;
2092 for(
unsigned int i = 0; i < toBeConverted.length(); i++ )
2093 converted[i] = toupper( toBeConverted[i] );
2098 std::map< std::string, std::string >& params )
2100 std::string key, value;
2103 for( std::vector< std::string >::const_iterator token = tokens.begin() + 1; token != tokens.end(); ++token )
2105 std::string::size_type pos = token->find(
'=' );
2107 if( std::string::npos != pos )
2108 value = token->substr( pos + 1 );
2111 pos = key.find_first_not_of(
' ', 0 );
2112 key = key.substr( pos );
2113 params[key] = value;
2122 std::string::size_type pos, last = str.find_first_not_of( delimiters, 0 );
2124 while( std::string::npos != last )
2126 pos = str.find_first_of( delimiters, last );
2127 if( std::string::npos == pos )
2129 tokens.push_back( str.substr( last ) );
2130 last = std::string::npos;
2134 tokens.push_back( str.substr( last, pos - last ) );
2135 last = str.find_first_not_of( delimiters, pos );