47 #pragma warning( disable : 4786 )
53 #include "ccmioutility.h"
54 #include "ccmiocore.h"
99 #define CHK_SET_CCMERR( ccm_err_code, ccm_err_msg ) \
101 if( kCCMIONoErr != ( ccm_err_code ) ) MB_SET_ERR( MB_FAILURE, ccm_err_msg ); \
110 : mbImpl( impl ), mCurrentMeshHandle( 0 ), mPartitionSetTag( 0 ), mNameTag( 0 ), mMaterialIdTag( 0 ),
111 mMaterialTypeTag( 0 ), mRadiationTag( 0 ), mPorosityIdTag( 0 ), mSpinIdTag( 0 ), mGroupIdTag( 0 ),
112 mColorIdxTag( 0 ), mProcessorIdTag( 0 ), mLightMaterialTag( 0 ), mFreeSurfaceMaterialTag( 0 ), mThicknessTag( 0 ),
113 mProstarRegionNumberTag( 0 ), mBoundaryTypeTag( 0 ), mCreatingProgramTag( 0 ), mDimension( 0 ),
116 assert( impl != NULL );
139 int dum_val_array[] = { -1, -1, -1, -1 };
156 const bool overwrite,
160 const std::vector< std::string >& ,
172 FILE* file = fopen( file_name,
"r" );
182 std::vector< EntityHandle > matsets, dirsets, neusets, partsets;
185 result =
get_sets( ent_handles, num_sets, matsets, dirsets, neusets, partsets );
MB_CHK_SET_ERR( result,
"Failed to get material/etc. sets" );
188 if( ent_handles && matsets.empty() )
194 if( matsets.empty() ) matsets.push_back( 0 );
196 std::vector< MaterialSetData > matset_info;
204 CCMIOID rootID, topologyID, stateID, problemID, verticesID, processorID;
207 result =
open_file( file_name, overwrite, rootID );
MB_CHK_SET_ERR( result,
"Couldn't open file or create state" );
213 std::vector< NeumannSetData > neuset_info;
237 CCMIOError
error = kCCMIONoErr;
241 CCMIOWriteProcessor( &
error, processorID, NULL, &verticesID, NULL, &topologyID, NULL, NULL, NULL, NULL );
250 CCMIOError
error = kCCMIONoErr;
253 if( CCMIOGetState( NULL, rootID,
kStateName, NULL, &stateID ) != kCCMIONoErr )
260 CCMIOSize_t i = CCMIOSIZEC( 0 );
261 if( CCMIONextEntity( NULL, stateID, kCCMIOProcessor, &i, &processorID ) != kCCMIONoErr )
263 CCMIONewEntity( &
error, stateID, kCCMIOProcessor, NULL, &processorID );
270 CCMIOClearProcessor( &
error, stateID, processorID, TRUE, TRUE, TRUE, TRUE, TRUE );
286 CCMIOError
error = kCCMIONoErr;
287 CCMIOCloseFile( &
error, rootID );
304 CCMIOError
error = kCCMIONoErr;
305 CCMIOOpenFile( &
error, filename, kCCMIOWrite, &rootID );
313 std::vector< EntityHandle >& matsets,
314 std::vector< EntityHandle >& dirsets,
315 std::vector< EntityHandle >& neusets,
316 std::vector< EntityHandle >& partsets )
323 std::copy( this_range.
begin(), this_range.
end(), std::back_inserter( matsets ) );
326 std::copy( this_range.
begin(), this_range.
end(), std::back_inserter( dirsets ) );
329 std::copy( this_range.
begin(), this_range.
end(), std::back_inserter( neusets ) );
334 std::copy( this_range.
begin(), this_range.
end(), std::back_inserter( partsets ) );
340 for(
const EntityHandle* iter = ent_handles; iter < ent_handles + num_sets; ++iter )
343 matsets.push_back( *iter );
345 dirsets.push_back( *iter );
347 neusets.push_back( *iter );
349 partsets.push_back( *iter );
360 std::vector< WriteCCMIO::MaterialSetData >& matset_data,
361 std::vector< WriteCCMIO::NeumannSetData >& neuset_data )
367 CCMIOError
error = kCCMIONoErr;
371 bool root_tagged =
false, other_set_tagged =
false;
381 std::vector< char > title_tag( tag_size + 1 );
386 other_set_tagged =
true;
397 *title_tag.rbegin() =
'\0';
398 if( root_tagged || other_set_tagged )
401 if( kCCMIONoErr == CCMIOGetEntityNode( &
error, rootID, &rootNode ) )
403 CCMIOSetTitle( &
error, rootNode, &title_tag[0] );
417 std::vector< char > cp_tag( tag_size + 1 );
422 other_set_tagged =
true;
433 *cp_tag.rbegin() =
'\0';
434 if( root_tagged || other_set_tagged )
437 if( kCCMIONoErr == CCMIOGetEntityNode( &
error, rootID, &rootNode ) )
439 CCMIOWriteOptstr( &
error, processorID,
"CreatingProgram", &cp_tag[0] );
446 CCMIONewEntity( &
error, rootID, kCCMIOProblemDescription, NULL, &problemID );
450 for(
unsigned int i = 0; i < matset_data.size(); i++ )
452 if( !matset_data[i].setName.empty() )
454 CCMIONewIndexedEntity( &
error, problemID, kCCMIOCellType, matset_data[i].matsetId,
455 matset_data[i].setName.c_str(), &
id );
458 CCMIOWriteOptstr( &
error,
id,
"MaterialType", matset_data[i].setName.c_str() );
464 std::ostringstream os;
465 std::string mat_name =
"Material", temp_str;
466 os << mat_name << ( i + 1 );
468 strcpy( dum_name, temp_str.c_str() );
469 CCMIONewIndexedEntity( &
error, problemID, kCCMIOCellType, matset_data[i].matsetId, dum_name, &
id );
472 CCMIOWriteOptstr( &
error,
id,
"MaterialType", dum_name );
501 for(
unsigned int i = 0; i < neuset_data.size(); i++ )
504 std::ostringstream dum_id;
505 dum_id << neuset_data[i].neusetId;
506 CCMIONewIndexedEntity( &
error, problemID, kCCMIOBoundaryRegion, neuset_data[i].neusetId, dum_id.str().c_str(),
517 CCMIOWriteState( &
error, stateID, problemID,
"Example state" );
545 CCMIOError
error = kCCMIONoErr;
546 CCMIOWriteOpti( &
error, node, opt_name, dum_val );
568 CCMIOError
error = kCCMIONoErr;
569 CCMIOWriteOptf( &
error, node, opt_name, dum_val );
579 const char* other_name )
593 std::vector< char > opt_val( tag_size + 1 );
599 if( std::find( opt_val.begin(), opt_val.end(),
'\0' ) == opt_val.end() ) *opt_val.rbegin() =
'\0';
601 CCMIOError
error = kCCMIONoErr;
604 CCMIOWriteOptstr( &
error, node, other_name, &opt_val[0] );
609 CCMIOWriteOptstr( &
error, node, opt_name, &opt_val[0] );
617 std::vector< MaterialSetData >& matset_data,
621 matset_data.resize( matsets.size() );
622 if( 1 == matsets.size() && 0 == matsets[0] )
633 std::vector< unsigned char > marks;
634 for(
unsigned int i = 0; i < matsets.size(); i++ )
636 EntityHandle this_set = matset_data[i].setHandle = matsets[i];
647 matset_data[i].entityType = start_type;
650 marks.resize( matset_data[i].elems.size(), 0x1 );
661 if(
MB_SUCCESS == result ) matset_data[i].setName = dum_name;
668 if( all_verts.
empty() )
677 std::vector< NeumannSetData >& neuset_info )
681 neuset_info.resize( neusets.size() );
682 for(
unsigned int i = 0; i < neusets.size(); i++ )
684 EntityHandle this_set = neuset_info[i].setHandle = neusets[i];
695 neuset_info[i].neusetId = i;
703 if(
MB_SUCCESS == result ) neuset_info[i].setName = dum_name;
715 int num_ents = ents.
size();
716 gids =
new int[num_ents];
718 minid = *std::min_element( gids, gids + num_ents );
719 maxid = *std::max_element( gids, gids + num_ents );
723 for(
int i = 1; i <= num_ents; i++ )
735 unsigned int num_verts = verts.
size();
736 std::vector< int > vgids( num_verts );
741 CCMIOError
error = kCCMIONoErr;
742 CCMIONewEntity( &
error, rootID, kCCMIOMap,
"Vertex map", &mapID );
745 int maxid = *std::max_element( vgids.begin(), vgids.end() );
747 CCMIOWriteMap( &
error, mapID, CCMIOSIZEC( num_verts ), CCMIOSIZEC( maxid ), &vgids[0], CCMIOINDEXC( kCCMIOStart ),
748 CCMIOINDEXC( kCCMIOEnd ) );
752 CCMIONewEntity( &
error, rootID, kCCMIOVertices,
"Vertices", &verticesID );
756 double* coords =
new double[3 * num_verts];
757 std::vector< double* > coord_arrays( 3 );
760 coord_arrays[0] = coords;
761 coord_arrays[1] = coords + num_verts;
762 coord_arrays[2] = ( dimension == 3 ? coords + 2 * num_verts : NULL );
775 MB_SET_ERR( result,
"Trouble transforming vertex coordinates" );
779 CCMIOWriteVerticesd( &
error, verticesID, CCMIOSIZEC( dimension ), 1.0, mapID, coords, CCMIOINDEXC( kCCMIOStart ),
780 CCMIOINDEXC( kCCMIOEnd ) );
797 double trans_matrix[16];
801 double* tmp_coords = coords;
802 for(
int i = 0; i < num_nodes; i++, tmp_coords += 1 )
804 double vec1[3] = { 0.0, 0.0, 0.0 };
805 for(
int row = 0; row < 3; row++ )
807 vec1[row] += ( trans_matrix[( row * 4 ) + 0] * coords[0] );
808 vec1[row] += ( trans_matrix[( row * 4 ) + 1] * coords[num_nodes] );
809 if( 3 == dimension ) vec1[row] += ( trans_matrix[( row * 4 ) + 2] * coords[2 * num_nodes] );
813 coords[num_nodes] = vec1[1];
814 coords[2 * num_nodes] = vec1[2];
821 std::vector< MaterialSetData >& matset_data,
822 std::vector< NeumannSetData >& neuset_data,
824 CCMIOID& topologyID )
826 std::vector< int > connect;
828 CCMIOID cellMapID, cells;
829 CCMIOError
error = kCCMIONoErr;
832 connect.reserve( 31 );
836 CCMIONewEntity( &
error, rootID, kCCMIOTopology,
"Topology", &topologyID );
839 CCMIONewEntity( &
error, rootID, kCCMIOMap,
"Cell map", &cellMapID );
842 CCMIONewEntity( &
error, topologyID, kCCMIOCells,
"Cells", &cells );
849 unsigned int i, num_elems = 0;
851 std::vector< int > egids;
854 for(
unsigned int m = 0; m < matset_data.size(); m++ )
855 tot_elems += matset_data[m].elems.
size();
857 for(
unsigned int m = 0; m < matset_data.size(); m++ )
859 unsigned int this_num = matset_data[m].elems.size();
864 all_elems.
merge( matset_data[m].elems );
869 egids.resize( matset_data[m].elems.size() );
870 for( i = 0; i < this_num; i++ )
877 CCMIOWriteMap( &
error, cellMapID, CCMIOSIZEC( tot_elems ), CCMIOSIZEC( tot_elems ), &egids[0],
878 CCMIOINDEXC( 0 == m ? kCCMIOStart : num_elems ),
879 CCMIOINDEXC( matset_data.size() == m ? kCCMIOEnd : num_elems + this_num ) );
882 if( -1 == matset_data[m].matsetId )
884 for( i = 0; i < this_num; i++ )
889 for( i = 0; i < this_num; i++ )
890 egids[i] = matset_data[m].matsetId;
893 CCMIOWriteCells( &
error, cells, cellMapID, &egids[0], CCMIOINDEXC( 0 == m ? kCCMIOStart : num_elems ),
894 CCMIOINDEXC( matset_data.size() == m ? kCCMIOEnd : num_elems + this_num ) );
902 int has_mid_nodes[4];
903 std::vector< EntityHandle > storage;
904 for( i = 0, rit = matset_data[m].elems.begin(); i < this_num; i++, ++rit )
911 CCMIOWriteOpt1i( &
error, cells,
"CellTopologyType", CCMIOSIZEC( tot_elems ), &egids[0],
912 CCMIOINDEXC( 0 == m ? kCCMIOStart : num_elems ),
913 CCMIOINDEXC( matset_data.size() == m ? kCCMIOEnd : num_elems + this_num ) );
916 num_elems += this_num;
922 Range neuset_facets, skin_facets;
928 for( i = 0; i < neuset_data.size(); i++ )
929 neuset_facets.
merge( neuset_data[i].elems );
931 skin_facets -= neuset_facets;
933 neuset_facets.
merge( skin_facets );
936 int fmaxid = neuset_facets.
size();
941 for( i = 0; i < neuset_data.size(); i++ )
944 unsigned char cmarks[2];
946 std::vector< EntityHandle > mcells;
948 for( rrit = neuset_data[i].elems.rbegin(); rrit != neuset_data[i].elems.rend(); ++rrit )
955 if( mcells.size() == 2 && (
mWholeMesh || ( cmarks[0] && cmarks[1] ) ) )
961 ext_faces.
insert( *rrit );
964 if( ext_faces.
size() != 0 && neuset_data[i].neusetId != 0 )
971 if( !skin_facets.
empty() )
984 unsigned char mval = 0x0, omval;
987 std::vector< EntityHandle > tmp_face_cells, storage;
988 std::vector< int > iface_connect, iface_cells;
995 for( i = 0, rit = all_elems.
begin(); i < num_elems; i++, ++rit )
1020 for(
int f = 0; f < num_facets; f++ )
1025 if( !is_polyh && ( ( mval >> f ) & 0x1 ) )
continue;
1034 connectf = tmp_connect;
1046 tmp_face_cells.clear();
1053 if( tmp_face_cells.size() != 2 )
continue;
1059 int side_num = 0, sense = 0, offset = 0;
1060 if( !is_polyh && tmp_face_cells[0] != *rit )
1063 tmp_face_cells[0] = tmp_face_cells[1];
1064 tmp_face_cells[1] = tmph;
1070 assert( tmp_face_cells[0] != tmp_face_cells[1] );
1071 iface_cells.resize( iface_cells.size() + 2 );
1073 &iface_cells[iface_cells.size() - 2] );
MB_CHK_SET_ERR( result,
"Trouble getting global ids for bounded cells" );
1074 iface_connect.push_back( num_connectf );
1079 unsigned int tmp_size = iface_connect.size();
1080 iface_connect.resize( tmp_size + num_connectf );
1099 omval |= ( 0x1 << (
unsigned int)side_num );
1109 CCMIONewEntity( &
error, rootID, kCCMIOMap, NULL, &mapID );
1112 unsigned int num_ifaces = iface_cells.size() / 2;
1115 egids.resize( num_ifaces );
1116 for( i = 1; i <= num_ifaces; i++ )
1117 egids[i - 1] = fmaxid + i;
1118 CCMIOWriteMap( &
error, mapID, CCMIOSIZEC( num_ifaces ), CCMIOSIZEC( fmaxid + num_ifaces ), &egids[0],
1119 CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
1123 CCMIONewEntity( &
error, topologyID, kCCMIOInternalFaces,
"Internal faces", &
id );
1125 CCMIOWriteFaces( &
error,
id, kCCMIOInternalFaces, mapID, CCMIOSIZEC( iface_connect.size() ), &iface_connect[0],
1126 CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
1128 CCMIOWriteFaceCells( &
error,
id, kCCMIOInternalFaces, mapID, &iface_cells[0], CCMIOINDEXC( kCCMIOStart ),
1129 CCMIOINDEXC( kCCMIOEnd ) );
1139 if( has_mid_nodes[0] || has_mid_nodes[2] || has_mid_nodes[3] )
return ctype;
1147 if( !has_mid_nodes[1] )
1153 if( has_mid_nodes[1] )
1159 if( has_mid_nodes[1] )
1165 if( has_mid_nodes[1] )
1171 if( has_mid_nodes[1] )
1177 if( has_mid_nodes[1] )
1194 CCMIOError
error = kCCMIONoErr;
1198 int *gids = NULL, minid, maxid;
1202 CCMIONewEntity( &
error, rootID, kCCMIOMap, NULL, &mapID );
1205 CCMIOWriteMap( &
error, mapID, CCMIOSIZEC( facets.
size() ), CCMIOSIZEC( maxid ), gids, CCMIOINDEXC( kCCMIOStart ),
1206 CCMIOINDEXC( kCCMIOEnd ) );
1213 std::vector< int > fconnect( facets.
size() * ( num_connect + 1 ) );
1216 &fconnect[0],
true );
MB_CHK_SET_ERR( result,
"Failed to get facet connectivity" );
1219 CCMIONewIndexedEntity( &
error, topologyID, kCCMIOBoundaryFaces, set_num,
"Boundary faces", &
id );
1222 CCMIOWriteFaces( &
error,
id, kCCMIOBoundaryFaces, mapID, CCMIOSIZEC( fconnect.size() ), &fconnect[0],
1223 CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
1227 std::vector< EntityHandle > cells;
1228 unsigned char cmarks[2];
1235 for( rit = facets.
begin(), i = 0; rit != facets.
end(); ++rit, i++ )
1248 if( cells.size() == 2 && (
mWholeMesh || ( cmarks[0] && cmarks[1] ) ) )
1252 else if( 1 == cells.size() && !
mWholeMesh && !cmarks[0] )
1258 if( 2 == cells.size() && !( cmarks[0] | 0x0 ) && ( cmarks[1] & 0x1 ) ) cells[0] = cells[1];
1267 CCMIOWriteFaceCells( &
error,
id, kCCMIOBoundaryFaces, mapID, &fconnect[0], CCMIOINDEXC( kCCMIOStart ),
1268 CCMIOINDEXC( kCCMIOEnd ) );
1276 Range& forward_elems,
1277 Range& reverse_elems )
1279 Range neuset_elems, neuset_meshsets;
1288 if( MB_FAILURE == result )
return result;
1296 if( range_iter != neuset_elems.
end() )
1299 neuset_elems.
erase( range_iter, neuset_elems.
end() );
1309 dum_it = neuset_elems.
begin();
1313 if( current_sense == 1 || current_sense == 0 )
1315 if( current_sense == -1 || current_sense == 0 )
1320 for( range_iter = neuset_meshsets.
begin(); range_iter != neuset_meshsets.
end(); ++range_iter )
1324 if( 0 == sense_tag || MB_FAILURE ==
mbImpl->
tag_get_data( sense_tag, &( *range_iter ), 1, &this_sense ) )
1328 get_neuset_elems( *range_iter, this_sense * current_sense, forward_elems, reverse_elems );