80 #define CHK_SET_CCMERR( ccm_err_code, ccm_err_msg ) \
82 if( kCCMIONoErr != ( ccm_err_code ) && kCCMIONoFileErr != ( ccm_err_code ) && \
83 kCCMIONoNodeErr != ( ccm_err_code ) ) \
84 MB_SET_ERR( MB_FAILURE, ccm_err_msg ); \
93 : mMaterialIdTag( 0 ), mMaterialTypeTag( 0 ), mRadiationTag( 0 ), mPorosityIdTag( 0 ), mSpinIdTag( 0 ),
94 mGroupIdTag( 0 ), mColorIdxTag( 0 ), mProcessorIdTag( 0 ), mLightMaterialTag( 0 ), mFreeSurfaceMaterialTag( 0 ),
95 mThicknessTag( 0 ), mProstarRegionNumberTag( 0 ), mBoundaryTypeTag( 0 ), mCreatingProgramTag( 0 ), mbImpl( impl ),
98 assert( impl != NULL );
111 const int negone = -1;
121 const int negonearr[] = { -1, -1, -1, -1 };
142 CCMIOID rootID, problemID, stateID, processorID, verticesID, topologyID, solutionID;
143 CCMIOError
error = kCCMIONoErr;
150 CCMIOOpenFile( &
error, file_name, kCCMIORead, &rootID );
157 std::vector< CCMIOSize_t > procs;
158 bool has_solution =
false;
159 rval =
get_processors( stateID, processorID, verticesID, topologyID, solutionID, procs, has_solution );
MB_CHK_SET_ERR( rval,
"Failed to get processors" );
161 std::vector< CCMIOSize_t >::iterator vit;
162 Range new_ents, *new_ents_ptr = NULL;
163 if( file_set ) new_ents_ptr = &new_ents;
165 for( vit = procs.begin(); vit != procs.end(); ++vit )
167 rval =
read_processor( stateID, problemID, processorID, verticesID, topologyID, *vit, new_ents_ptr );
MB_CHK_SET_ERR( rval,
"Failed to read processors" );
184 CCMIOError
error = kCCMIONoErr;
187 CCMIOGetState( &
error, rootID,
"default", &problemID, &stateID );
188 if( kCCMIONoErr !=
error )
190 CCMIOSize_t i = CCMIOSIZEC( 0 );
191 CCMIOError tmp_error = kCCMIONoErr;
192 CCMIONextEntity( &tmp_error, rootID, kCCMIOState, &i, &stateID );
193 if( kCCMIONoErr == tmp_error ) CCMIONextEntity( &
error, rootID, kCCMIOProblemDescription, &i, &problemID );
207 CCMIOError
error = kCCMIONoErr;
210 if( kCCMIONoErr == CCMIOGetEntityNode( &
error, rootID, &rootNode ) )
213 CCMIOGetTitle( &
error, rootNode, &name );
215 if( NULL != name && strlen( name ) != 0 )
224 if( name ) free( name );
244 CCMIOSize_t i = CCMIOSIZEC( 0 );
246 CCMIOError
error = kCCMIONoErr;
248 while( CCMIONextEntity( NULL, problemID, kCCMIOCellType, &i, &next ) == kCCMIONoErr )
252 CCMIOGetEntityIndex( &
error, next, &mindex );
253 std::map< int, EntityHandle >::iterator mit =
newMatsets.find( mindex );
263 CCMIOEntityLabel( &
error, next, &len, NULL );
264 std::vector< char > opt_string2( GETINT32( len ) + 1,
'\0' );
265 CCMIOEntityLabel( &
error, next, NULL, &opt_string2[0] );
303 if( kCCMIONoErr == CCMIOReadOpti( NULL, node, opt_str, &idum ) )
319 if( kCCMIONoErr == CCMIOReadOptf( NULL, node, opt_str, &fdum ) )
327 double dum_dbl = fdum;
338 const char* other_tag_name )
341 CCMIOError
error = kCCMIONoErr;
342 std::vector< char > opt_string;
343 if( kCCMIONoErr != CCMIOReadOptstr( NULL, node, opt_str, &len, NULL ) )
return MB_SUCCESS;
345 opt_string.resize( len );
346 CCMIOReadOptstr( &
error, node, opt_str, &len, &opt_string[0] );
366 CCMIOSize_t i = CCMIOSIZEC( 0 );
372 while( CCMIONextEntity( NULL, problemID, kCCMIOBoundaryRegion, &i, &next ) == kCCMIONoErr )
376 CCMIOError
error = kCCMIONoErr;
377 CCMIOGetEntityIndex( &
error, next, &mindex );
378 std::map< int, EntityHandle >::iterator mit =
newNeusets.find( mindex );
412 rval =
read_vertices( proc, processorID, verticesID, topologyID, new_ents, vert_map );
MB_CHK_SET_ERR( rval,
"Failed to read vertices" );
414 rval =
read_cells( proc, problemID, verticesID, topologyID, vert_map, new_ents );
MB_CHK_SET_ERR( rval,
"Failed to read cells" );
442 std::map< int, int > cell_topo_types;
447 rval = face_map.sort( 1 );
MB_CHK_SET_ERR( rval,
"Couldn't sort face map by cell id" );
449 std::vector< EntityHandle > new_cells;
454 vert_map, cell_topo_types, new_cells );
MB_CHK_SET_ERR( rval,
"Failed to construct cells" );
458 std::vector< EntityHandle >::reverse_iterator vit;
459 for( vit = new_cells.rbegin(); vit != new_cells.rend(); ++vit )
460 rit = new_ents->
insert( rit, *vit );
470 CCMIOError
error = kCCMIONoErr;
471 CCMIOID cellID, mapID;
473 CCMIOGetEntity( &
error, topologyID, kCCMIOCells, 0, &cellID );
474 CCMIOEntitySize( &
error, cellID, &ncells, NULL );
475 int num_cells = GETINT32( ncells );
479 CCMIOReadOpt1i( &
error, cellID,
"CellTopologyType", &dum_int, CCMIOINDEXC( kCCMIOStart ),
480 CCMIOINDEXC( kCCMIOStart ) + 1 );
484 std::vector< int > dum_ints( num_cells );
485 CCMIOReadCells( &
error, cellID, &mapID, &dum_ints[0], CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOStart ) + 1 );
489 CCMIOReadMap( &
error, mapID, &dum_ints[0], CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
492 for( i = 0; i < num_cells; i++ )
493 cell_topo_types[dum_ints[i]] = 0;
496 std::vector< int > topo_types( num_cells );
497 CCMIOReadOpt1i( &
error, cellID,
"CellTopologyType", &topo_types[0], CCMIOINDEXC( kCCMIOStart ),
498 CCMIOINDEXC( kCCMIOEnd ) );
500 for( i = 0; i < num_cells; i++ )
501 cell_topo_types[dum_ints[i]] = topo_types[i];
508 std::vector< EntityHandle >& cells )
511 CCMIOSize_t dum_cells;
513 CCMIOError
error = kCCMIONoErr;
514 CCMIOID cellsID, mapID;
515 CCMIOGetEntity( &
error, topologyID, kCCMIOCells, 0, &cellsID );
516 CCMIOEntitySize( &
error, cellsID, &dum_cells, NULL );
517 num_cells = GETINT32( dum_cells );
520 if( num_cells != (
int)cells.size() )
MB_SET_ERR( MB_FAILURE,
"Number of cells doesn't agree" );
523 std::vector< int > cell_gids( num_cells );
524 CCMIOReadCells( &
error, cellsID, &mapID, NULL, CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
526 CCMIOReadMap( &
error, mapID, &cell_gids[0], CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
532 CCMIOReadCells( &
error, cellsID, NULL, &cell_gids[0], CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
536 std::map< int, Range > matset_ents;
537 for(
int i = 0; i < num_cells; i++ )
538 matset_ents[cell_gids[i]].insert( cells[i] );
540 for( std::map< int, Range >::iterator mit = matset_ents.begin(); mit != matset_ents.end(); ++mit )
557 std::map< int, int >& cell_topo_types,
558 std::vector< EntityHandle >& new_cells )
560 std::vector< EntityHandle > facehs;
561 std::vector< int > senses;
565 bool has_mid_nodes =
false;
568 while( i < face_map.n )
572 int this_id = face_map.get_int( i );
573 unsigned int inext = i;
574 while( face_map.get_int( inext ) == this_id && inext <= face_map.n )
578 facehs.push_back(
face );
579 senses.push_back( face_map.get_short( inext ) );
582 has_mid_nodes =
false;
584 std::map< int, std::vector< EntityHandle > >::iterator fmit;
585 std::map< int, std::vector< int > >::iterator smit;
586 std::map< int, int >::iterator typeit;
587 for( fmit = face_map.begin(), smit = sense_map.begin(); fmit != face_map.end(); ++fmit, ++smit )
591 int this_id = ( *fmit ).first;
592 facehs = ( *fmit ).second;
594 senses = ( *smit ).second;
595 typeit = cell_topo_types.find( this_id );
596 if( typeit != cell_topo_types.end() )
603 has_mid_nodes =
false;
611 new_cells.push_back( cell );
670 has_mid_nodes =
true;
680 std::vector< int >& senses,
681 EntityType this_type,
689 bool same_type =
true;
690 for( std::vector< EntityHandle >::iterator vit = facehs.begin(); vit != facehs.end(); ++vit )
699 std::vector< EntityHandle > verts;
700 EntityType input_type = this_type;
701 std::vector< EntityHandle > storage;
707 if( (
MBTET == input_type ||
MBMAXTYPE == input_type ) && same_type && face_type ==
MBTRI && facehs.size() == 4 )
714 if( senses[0] > 0 ) std::reverse( verts.begin(), verts.end() );
721 while( std::find( verts.begin(), verts.end(), conn[i] ) != verts.end() && i < conn_size )
728 verts.push_back( conn[i] );
731 else if( (
MBHEX == input_type ||
MBMAXTYPE == input_type ) && same_type &&
MBQUAD == face_type &&
745 Range tmp_faces, tmp_verts;
749 if( senses[0] > 0 ) std::reverse( verts.begin(), verts.end() );
752 std::copy( facehs.begin(), facehs.end(),
range_inserter( tmp_faces ) );
755 tmp_faces.
erase( facehs[0] );
759 tmp_verts.
erase( verts[0] );
760 tmp_verts.
erase( verts[1] );
762 std::copy( facehs.begin(), facehs.end(),
range_inserter( tmp_faces ) );
765 tmp_faces.
erase( q1 );
777 unsigned int ioff = std::find( storage.begin(), storage.end(), v0 ) - storage.begin();
778 if( 4 == ioff )
MB_SET_ERR( MB_FAILURE,
"Trouble finding offset" );
780 if( storage[( ioff + 1 ) % 4] != v1 )
782 std::reverse( storage.begin(), storage.end() );
783 ioff = std::find( storage.begin(), storage.end(), v0 ) - storage.begin();
785 if( 0 != ioff ) std::rotate( storage.begin(), storage.begin() + ioff, storage.end() );
788 std::copy( storage.begin(), storage.end(), std::back_inserter( verts ) );
793 if(
MBMAXTYPE == this_type && facehs.size() == 5 )
796 std::vector< EntityHandle > tris, quads;
797 for(
unsigned int i = 0; i < 5; i++ )
800 tris.push_back( facehs[i] );
802 quads.push_back( facehs[i] );
806 if( 2 == tris.size() && 3 == quads.size() )
811 int index = std::find( facehs.begin(), facehs.end(), tris[0] ) - facehs.begin();
813 if( senses[index] > 0 ) std::reverse( verts.begin(), verts.end() );
817 Range tmp_faces, tmp_verts;
818 std::copy( facehs.begin(), facehs.end(),
range_inserter( tmp_faces ) );
821 tmp_faces.
erase( tris[0] );
836 index = std::find( facehs.begin(), facehs.end(), tris[1] ) - facehs.begin();
837 if( senses[index] < 0 ) std::reverse( storage.begin(), storage.end() );
838 unsigned int ioff = std::find( storage.begin(), storage.end(), v0 ) - storage.begin();
839 if( 3 == ioff )
MB_SET_ERR( MB_FAILURE,
"Trouble finding offset" );
840 for(
unsigned int i = 0; i < 3; i++ )
841 verts.push_back( storage[( ioff + i ) % 3] );
846 else if( tris.size() == 4 && quads.size() == 1 )
850 int index = std::find( facehs.begin(), facehs.end(), quads[0] ) - facehs.begin();
852 if( senses[index] > 0 ) std::reverse( verts.begin(), verts.end() );
856 for(
unsigned int i = 0; i < 3; i++ )
858 if( std::find( verts.begin(), verts.end(), storage[i] ) == verts.end() )
860 verts.push_back( storage[i] );
865 if( 5 == verts.size() ) this_type =
MBPYRAMID;
875 std::cerr <<
"Warning: types disagree (cell_topo_type = " <<
CN::EntityTypeName( input_type )
879 std::cerr <<
"Warning: couldn't find proper connectivity for specified topo_type = "
906 CCMIOError
error = kCCMIONoErr;
910 index = CCMIOSIZEC( 0 );
914 while( kCCMIONoErr == CCMIONextEntity( NULL, topologyID, kCCMIOBoundaryFaces, &index, &faceID ) )
916 CCMIOEntitySize( &
error, faceID, &nf, NULL );
919 CCMIOGetEntity( &
error, topologyID, kCCMIOInternalFaces, 0, &faceID );
920 CCMIOEntitySize( &
error, faceID, &nf, NULL );
923 face_map.resize( 2 * nint_faces + nbdy_faces );
927 index = CCMIOSIZEC( 0 );
928 while( kCCMIONoErr == CCMIONextEntity( NULL, topologyID, kCCMIOBoundaryFaces, &index, &faceID ) )
930 rval =
read_faces( faceID, kCCMIOBoundaryFaces, vert_map, face_map,
934 new_faces );
MB_CHK_SET_ERR( rval,
"Trouble reading boundary faces" );
938 CCMIOGetEntity( &
error, topologyID, kCCMIOInternalFaces, 0, &faceID );
941 rval =
read_faces( faceID, kCCMIOInternalFaces, vert_map, face_map,
945 new_faces );
MB_CHK_SET_ERR( rval,
"Trouble reading internal faces" );
951 CCMIOEntity bdy_or_int,
959 if( kCCMIOInternalFaces != bdy_or_int && kCCMIOBoundaryFaces != bdy_or_int )
960 MB_SET_ERR( MB_FAILURE,
"Face type isn't boundary or internal" );
962 CCMIOSize_t dum_faces;
963 CCMIOError
error = kCCMIONoErr;
964 CCMIOEntitySize( &
error, faceID, &dum_faces, NULL );
965 int num_faces = GETINT32( dum_faces );
969 CCMIOSize_t farray_size = CCMIOSIZEC( 0 );
970 CCMIOReadFaces( &
error, faceID, bdy_or_int, NULL, &farray_size, NULL, CCMIOINDEXC( kCCMIOStart ),
971 CCMIOINDEXC( kCCMIOEnd ) );
976 int num_sides = ( kCCMIOInternalFaces == bdy_or_int ? 2 : 1 );
977 int* farray =
new int[GETINT32( farray_size )];
981 CCMIOReadFaces( &
error, faceID, bdy_or_int, &mapID, NULL, farray, CCMIOINDEXC( kCCMIOStart ),
982 CCMIOINDEXC( kCCMIOEnd ) );
985 std::vector< EntityHandle > face_handles;
990 if( num_sides * num_faces < farray_size )
991 face_cells =
new int[num_sides * num_faces];
994 CCMIOReadFaceCells( &
error, faceID, bdy_or_int, face_cells, CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
997 int* tmp_ptr = face_cells;
998 for(
unsigned int i = 0; i < face_handles.size(); i++ )
1001 short forward = 1, reverse = -1;
1002 face_map.push_back( &forward, tmp_ptr++, &face_handles[i], NULL );
1003 if( 2 == num_sides ) face_map.push_back( &reverse, tmp_ptr++, &face_handles[i], NULL );
1005 face_map[*tmp_ptr].push_back( face_handles[i] );
1006 sense_map[*tmp_ptr++].push_back( 1 );
1007 if( 2 == num_sides )
1009 face_map[*tmp_ptr].push_back( face_handles[i] );
1010 sense_map[*tmp_ptr++].push_back( -1 );
1016 CCMIOReadMap( &
error, mapID, face_cells, CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
1022 if( kCCMIOBoundaryFaces == bdy_or_int )
1029 CCMIOGetEntityIndex( &
error, faceID, &index );
1041 std::sort( face_handles.begin(), face_handles.end() );
1042 std::copy( face_handles.rbegin(), face_handles.rend(),
range_inserter( *new_faces ) );
1050 std::vector< EntityHandle >& new_faces,
1053 std::vector< EntityHandle > verts;
1056 for(
int i = 0; i < num_faces; i++ )
1058 int num_verts = *farray++;
1059 verts.resize( num_verts );
1062 for(
int j = 0; j < num_verts; j++ )
1065 int tindex = vert_map.find( 1, farray[j] );
1068 tmp_rval = MB_FAILURE;
1071 verts[j] = vert_map.get_ulong( tindex, 0 );
1073 verts[j] = ( vert_map[farray[j]] )[0];
1076 farray += num_verts;
1084 if( faceh ) new_faces.push_back( faceh );
1087 if(
MB_SUCCESS != tmp_rval ) rval = tmp_rval;
1100 CCMIOError
error = kCCMIONoErr;
1103 CCMIOSize_t nverts = CCMIOSIZEC( 0 );
1104 CCMIOEntitySize( &
error, verticesID, &nverts, NULL );
1110 CCMIOReadVerticesf( &
error, verticesID, &dims, NULL, NULL, NULL, CCMIOINDEXC( 0 ), CCMIOINDEXC( 1 ) );
1115 std::vector< double* > arrays;
1120 std::vector< double > tmp_coords( GETINT32( dims ) * GETINT32( nverts ) );
1121 CCMIOReadVerticesd( &
error, verticesID, &dims, &scale, &mapID, &tmp_coords[0], CCMIOINDEXC( 0 ),
1122 CCMIOINDEXC( 0 + nverts ) );
1126 int i = 0, threei = 0;
1127 for( ; i < nverts; i++ )
1129 arrays[0][i] = tmp_coords[threei++];
1130 arrays[1][i] = tmp_coords[threei++];
1131 if( 3 == GETINT32( dims ) )
1132 arrays[2][i] = tmp_coords[threei++];
1140 for( i = 0; i < nverts; i++ )
1142 arrays[0][i] *= scale;
1143 arrays[1][i] *= scale;
1144 if( 3 == GETINT32( dims ) ) arrays[2][i] *= scale;
1149 std::vector< int > gids( GETINT32( nverts ) );
1150 CCMIOReadMap( &
error, mapID, &gids[0], CCMIOINDEXC( kCCMIOStart ), CCMIOINDEXC( kCCMIOEnd ) );
1154 Range new_verts( node_handle, node_handle + nverts - 1 );
1159 vert_map.resize( GETINT32( nverts ) );
1160 for( i = 0; i < GETINT32( nverts ); i++ )
1162 vert_map.push_back( NULL, &gids[i], &node_handle, NULL );
1164 for( i = 0; i < GETINT32( nverts ); i++ )
1166 ( vert_map[gids[i]] ).push_back( node_handle );
1171 if( verts ) verts->
merge( new_verts );
1177 CCMIOID& processorID,
1178 CCMIOID& verticesID,
1179 CCMIOID& topologyID,
1180 CCMIOID& solutionID,
1181 std::vector< CCMIOSize_t >& procs,
1184 CCMIOSize_t proc = CCMIOSIZEC( 0 );
1185 CCMIOError
error = kCCMIONoErr;
1187 CCMIONextEntity( &
error, stateID, kCCMIOProcessor, &proc, &processorID );
1189 if( CCMIOReadProcessor( NULL, processorID, &verticesID, &topologyID, NULL, &solutionID ) != kCCMIONoErr )
1192 CCMIOReadProcessor( &
error, processorID, &verticesID, &topologyID, NULL, NULL );
1197 procs.push_back( proc );
1205 std::vector< int >& ,