13 #define IS_BUILDING_MB
28 #define FIXME printf( "Warning: function has incomplete implementation: %s\n", __func__ )
32 #ifndef MOAB_TEMPLATE_FUNC_SPECIALIZATION
34 template <
typename T,
typename S >
37 assert(
sizeof( S ) >=
sizeof(
T ) );
38 return reinterpret_cast< T >( handle );
43 template <
typename T,
typename S >
49 template <
typename T >
53 return reinterpret_cast< T >( h );
56 template <
typename T >
63 template <
typename T >
64 inline const EntityHandle* itaps_cast_const_ptr_(
const T* h )
70 template <
typename T >
74 return itaps_cast_internal_< T >( h );
78 #define DECLARE_ALLOWED_ITAPS_CONVERSION( ITAPS_HANDLE_TYPE ) \
80 inline ITAPS_HANDLE_TYPE itaps_cast< ITAPS_HANDLE_TYPE, EntityHandle >( EntityHandle h ) \
82 return itaps_cast_internal_< ITAPS_HANDLE_TYPE >( h ); \
86 inline EntityHandle itaps_cast< EntityHandle, ITAPS_HANDLE_TYPE >( ITAPS_HANDLE_TYPE handle ) \
88 return reinterpret_cast< EntityHandle >( handle ); \
92 inline EntityHandle* itaps_cast< EntityHandle*, ITAPS_HANDLE_TYPE* >( ITAPS_HANDLE_TYPE * ptr ) \
94 return itaps_cast_ptr_( ptr ); \
98 inline const EntityHandle* itaps_cast< const EntityHandle*, const ITAPS_HANDLE_TYPE* >( \
99 const ITAPS_HANDLE_TYPE* ptr ) \
101 return itaps_cast_const_ptr_( ptr ); \
106 #define DECLARE_ALLOWED_ITAPS_SET_CONVERSION( ITAPS_HANDLE_TYPE ) \
108 inline ITAPS_HANDLE_TYPE itaps_cast< ITAPS_HANDLE_TYPE, EntityHandle >( EntityHandle h ) \
110 return itaps_set_cast_< ITAPS_HANDLE_TYPE >( h ); \
114 inline EntityHandle itaps_cast< EntityHandle, ITAPS_HANDLE_TYPE >( ITAPS_HANDLE_TYPE handle ) \
116 return reinterpret_cast< EntityHandle >( handle ); \
120 inline EntityHandle* itaps_cast< EntityHandle*, ITAPS_HANDLE_TYPE* >( ITAPS_HANDLE_TYPE * ptr ) \
122 return itaps_cast_ptr_( ptr ); \
126 inline const EntityHandle* itaps_cast< const EntityHandle*, const ITAPS_HANDLE_TYPE* >( \
127 const ITAPS_HANDLE_TYPE* ptr ) \
129 return itaps_cast_const_ptr_( ptr ); \
140 return reinterpret_cast< Tag >( h );
150 #define PCOMM ParallelComm::get_pcomm( MOABI, itaps_cast< EntityHandle >( partition_handle ) )
165 #define RANGE_TO_ITAPS_ARRAY( RANGE, NAME ) \
168 ALLOC_CHECK_ARRAY_NOFAIL( NAME, ( RANGE ).size() ); \
169 std::copy( ( RANGE ).begin(), ( RANGE ).end(), itaps_cast< EntityHandle* >( *( NAME ) ) ); \
210 std::vector< unsigned char > pstatus( ents.
size() );
214 std::vector< unsigned char >::const_iterator j;
215 for( j = pstatus.begin(); j != pstatus.end(); ++j )
233 rval =
get_entities(
MOABI, itaps_cast< EntityHandle >( set2 ), type, topo, result );
CHKERR( rval,
"Invalid Part handle" );
237 rval =
get_entities(
MOABI, itaps_cast< EntityHandle >( set1 ), type, topo, result );
CHKERR( rval,
"Invalid set handle" );
242 rval =
get_entities(
MOABI, itaps_cast< EntityHandle >( set1 ), type, topo, r1 );
CHKERR( rval,
"Invalid Part handle" );
243 rval =
get_entities(
MOABI, itaps_cast< EntityHandle >( set2 ), type, topo, r2 );
CHKERR( rval,
"Invalid set handle" );
257 Range& entities_out )
259 int* adj_part_id_ptr = ( adj_part_id ==
iMeshP_ALL_PARTS ) ? 0 : &adj_part_id;
287 :
MBRangeIter( entity_type, entity_topology, part_handle, array_sz ), pComm( pcomm ), adjPart( adj_part_id )
295 iterPos = iterData.begin();
300 template <
class Container >
312 :
MBIter< Container >( type, topology, set, array_sz ), otherSet( other_set )
329 for(
size_t r = 0; r < list.size(); ++r )
355 MPI_Comm communicator,
359 *partition_handle = 0;
370 MOABI->delete_entities( &handle, 1 );
376 int pid = pcomm->
get_id();
377 rval =
MOABI->tag_set_data( prtn_tag, &handle, 1, &pid );
CHKERR( rval,
"tag creation failed" );
379 *partition_handle = itaps_cast< iMeshP_PartitionHandle >( handle );
386 if( pcomm )
delete pcomm;
387 EntityHandle handle = itaps_cast< EntityHandle >( partition_handle );
398 int junk1 = 1, junk2;
408 int junk1 = 1, junk2;
415 const int part_handles_size,
417 int* part_ids_allocated,
424 for(
int i = 0; i < part_handles_size; ++i )
427 rval = pcomm->
get_part_id( itaps_cast< EntityHandle >( part_handles[i] ),
id );
428 ( *part_ids )[i] = id;
CHKERR( rval,
"error getting part id" );
437 const int part_ids_size,
439 int* part_handles_allocated,
440 int* part_handles_size,
446 for(
int i = 0; i < part_ids_size; ++i )
450 ( *part_handles )[i] = itaps_cast< iMeshP_PartHandle >( handle );
458 MPI_Comm* communicator_out,
477 std::vector< ParallelComm* > pcomms;
480 std::vector< ParallelComm* >::iterator i;
481 *num_partitions_out = 0;
482 for( i = pcomms.begin(); i != pcomms.end(); ++i )
483 if( ( *i )->get_partitioning() ) ( *num_partitions_out )++;
490 int* partition_handle_allocated,
491 int* partition_handle_size,
494 std::vector< ParallelComm* > pcomms;
497 std::vector< ParallelComm* >::iterator i;
499 for( i = pcomms.begin(); i != pcomms.end(); ++i )
500 if( ( *i )->get_partitioning() ) ++count;
503 *partition_handle_size = 0;
504 for( i = pcomms.begin(); i != pcomms.end(); ++i )
505 if( ( *i )->get_partitioning() )
506 ( *partition_handle )[( *partition_handle_size )++] =
507 itaps_cast< iMeshP_PartitionHandle >( ( *i )->get_partitioning() );
514 int* num_global_part,
539 int* part_handles_allocated,
540 int* part_handles_size,
556 int junk1 = 1, junk2 = 1;
563 const int part_ids_size,
574 for(
int i = 0; i < part_ids_size; ++i )
585 const int entity_type,
598 int vals[2] = { count, rval }, sums[2];
610 const int entity_topology,
623 int vals[2] = { count, rval }, sums[2];
642 *part_handle = itaps_cast< iMeshP_PartHandle >( h );
665 int junk1 = 1, junk2 = 1;
673 const int part_handles_size,
675 int** num_part_nbors,
676 int* num_part_nbors_allocated,
677 int* num_part_nbors_size,
687 for(
int i = 0; i < part_handles_size; ++i )
689 EntityHandle h = itaps_cast< EntityHandle >( part_handles[i] );
691 ( *num_part_nbors )[i] = n;
704 int* nbor_part_ids_allocated,
705 int* nbor_part_ids_size,
708 int junk1 = 1, junk2 = 1;
709 iMeshP_getPartNborsArr( instance, partition_handle, &part_handle, 1, entity_type, &num_part_nbors, &junk1, &junk2,
710 nbor_part_ids, nbor_part_ids_allocated, nbor_part_ids_size, err );
716 const int part_handles_size,
718 int** num_part_nbors,
719 int* num_part_nbors_allocated,
720 int* num_part_nbors_size,
722 int* nbor_part_ids_allocated,
723 int* nbor_part_ids_size,
731 std::vector< int > all_neighbors;
734 for(
int i = 0; i < part_handles_size; ++i )
736 EntityHandle h = itaps_cast< EntityHandle >( part_handles[i] );
738 ( *num_part_nbors )[i] = n;
739 std::copy( pnbor, pnbor + n, std::back_inserter( all_neighbors ) );
743 memcpy( *nbor_part_ids, &all_neighbors[0],
sizeof(
int ) * all_neighbors.size() );
752 const int entity_type,
753 const int entity_topology,
760 entity_topology, target_part_id,
entities );
CHKERR( rval,
"failed to get boundary entities" );
768 const int entity_type,
769 const int entity_topology,
772 int* entity_handles_allocated,
773 int* entity_handles_size,
778 entity_topology, target_part_id,
entities );
CHKERR( rval,
"failed to get boundary entities" );
786 const int entity_type,
787 const int entity_topology,
799 const int entity_type,
800 const int entity_topology,
801 const int array_size,
810 if(
MB_SUCCESS != result )
delete *entity_iterator;
CHKERR( result,
"iMesh_initEntArrIter: ERROR getting entities of proper type or topology." );
818 const int entity_type,
824 *num_type = r.
size();
831 const int entity_topology,
837 *num_topo = r.
size();
844 int entity_type_requestor,
845 int entity_topology_requestor,
846 int entity_type_requested,
848 int* entity_handles_allocated,
849 int* entity_handles_size,
851 int* adj_entity_handles_allocated,
852 int* adj_entity_handles_size,
853 int** adj_entity_indices,
854 int* adj_entity_indices_allocated,
855 int* adj_entity_indices_size,
857 int* offset_allocated,
861 const int allocated_entity_handles = ( *entity_handles_allocated == 0 );
862 const int allocated_indices = ( *adj_entity_indices_allocated == 0 );
863 const int allocated_offset = ( *offset_allocated == 0 );
866 iMeshP_getEntities( instance, partition, part, entity_set_handle, entity_type_requestor, entity_topology_requestor,
867 entity_handles, entity_handles_allocated, entity_handles_size, err );
872 int size = 0, alloc = 0;
873 iMesh_getEntArrAdj( instance, *entity_handles, *entity_handles_size, entity_type_requested, &all_adj_handles,
874 &alloc, &
size, offset, offset_allocated, offset_size, err );
877 if( allocated_entity_handles )
879 free( *entity_handles );
881 *entity_handles_allocated = 0;
887 *adj_entity_indices_size =
size;
888 if( allocated_indices )
891 if( !*adj_entity_indices )
894 *adj_entity_indices_allocated =
size;
896 else if( *adj_entity_indices_allocated <
size )
902 free( all_adj_handles );
903 if( allocated_entity_handles )
905 free( *entity_handles );
907 *entity_handles_allocated = 0;
909 if( allocated_offset )
913 *offset_allocated = 0;
924 if( *adj_entity_handles_allocated >=
size )
926 unique_adj = *adj_entity_handles;
932 std::copy( all_adj_handles, all_adj_handles +
size, unique_adj );
933 std::sort( unique_adj, unique_adj +
size );
934 *adj_entity_handles_size = std::unique( unique_adj, unique_adj +
size ) - unique_adj;
939 if( *adj_entity_handles != unique_adj )
941 if( !*adj_entity_handles_allocated )
943 *adj_entity_handles =
945 if( !*adj_entity_handles )
948 *adj_entity_handles_allocated = *adj_entity_handles_size;
950 else if( *adj_entity_handles_allocated < *adj_entity_handles_size )
955 free( all_adj_handles );
956 if( allocated_entity_handles )
958 free( *entity_handles );
960 *entity_handles_allocated = 0;
962 if( allocated_offset )
966 *offset_allocated = 0;
968 if( allocated_indices )
970 free( *adj_entity_indices );
971 *adj_entity_indices = 0;
972 *adj_entity_indices_allocated = 0;
977 std::copy( unique_adj, unique_adj + *adj_entity_handles_size, *adj_entity_handles );
979 unique_adj = *adj_entity_handles;
983 for(
int i = 0; i < *adj_entity_indices_size; ++i )
984 ( *adj_entity_indices )[i] =
985 std::lower_bound( unique_adj, unique_adj + *adj_entity_handles_size, all_adj_handles[i] ) - unique_adj;
986 free( all_adj_handles );
993 const int entity_type,
994 const int entity_topology,
996 int* entity_handles_allocated,
997 int* entity_handles_size,
1001 set_intersection_query( instance, part_handle, entity_set_handle, entity_type, entity_topology, r, err );
1012 const int entity_type_requestor,
1013 const int entity_topology_requestor,
1014 const int entity_type_requested,
1016 int* adj_entity_handles_allocated,
1017 int* adj_entity_handles_size,
1019 int* offset_allocated,
1021 int** in_entity_set,
1022 int* in_entity_set_allocated,
1023 int* in_entity_set_size,
1028 set_intersection_query( instance, part_handle, entity_set_handle, entity_type_requestor, entity_topology_requestor,
1033 std::vector< EntityHandle > tmp_storage;
1041 tmp_storage.clear();
1042 rval =
MOABI->get_adjacencies( &*i, 1, entity_type_requested,
false, tmp_storage );
CHKERR( rval,
"get_adjacencies failed" );
1043 num_adj += tmp_storage.size();
1047 rval =
MOABI->get_connectivity( *i, conn_ptr, num_conn,
false, &tmp_storage );
CHKERR( rval,
"get_connectivity failed" );
1048 num_adj += num_conn;
1056 int* offset_iter = *offset;
1059 *offset_iter = arr_pos;
1062 tmp_storage.clear();
1063 rval =
MOABI->get_adjacencies( &*i, 1, entity_type_requested,
false, tmp_storage );
CHKERR( rval,
"get_adjacencies failed" );
1064 for( std::vector< EntityHandle >::iterator j = tmp_storage.begin(); j != tmp_storage.end(); ++j )
1066 ( *adj_entity_handles )[arr_pos] = itaps_cast< iBase_EntityHandle >( *j );
1072 iMesh_isEntArrContained( instance, entity_set_handle, *adj_entity_handles, *adj_entity_handles_size, in_entity_set,
1073 in_entity_set_allocated, in_entity_set_size, err );
1086 const int requested_entity_type,
1087 const int requested_entity_topology,
1091 iMeshP_initEntArrIter( instance, partition_handle, part_handle, entity_set_handle, requested_entity_type,
1092 requested_entity_topology, 1,
1100 const int requested_entity_type,
1101 const int requested_entity_topology,
1102 const int requested_array_size,
1106 if( !entity_set_handle || entity_set_handle == part_handle )
1109 requested_array_size,
1111 entArr_iterator, err );
1116 ErrorCode result =
MOABI->get_meshset_options( itaps_cast< EntityHandle >( entity_set_handle ), flags );
CHKERR( result,
"Invalid entity set handle" );
1117 if( flags & MESHSET_ORDERED )
1120 itaps_cast< EntityHandle >( entity_set_handle ), itaps_cast< EntityHandle >( part_handle ),
1121 requested_array_size );
1126 itaps_cast< EntityHandle >( entity_set_handle ),
1127 itaps_cast< EntityHandle >( part_handle ), requested_array_size );
1128 result = ( *entArr_iterator )->reset(
MOABI );
1129 if(
MB_SUCCESS != result )
delete *entArr_iterator;
CHKERR( result,
"iMesh_initEntArrIter: ERROR getting entities of proper type or topology." );
1140 int junk1 = 1, junk2 = 1;
1147 const int entity_handles_size,
1149 int* part_ids_allocated,
1159 for(
int i = 0; i < entity_handles_size; ++i )
1161 EntityHandle h = itaps_cast< EntityHandle >( entity_handles[i] );
1163 ( *part_ids )[i] = id;
CHKERR( rval,
"Failet get part owner" );
1176 int junk1 = 1, junk2 = 1;
1177 iMeshP_isEntOwnerArr( instance, partition_handle, part_handle, &entity_handle, 1, &is_owner, &junk1, &junk2, err );
1184 const int entity_handles_size,
1186 int* is_owner_allocated,
1195 rval = pcomm->
get_part_id( itaps_cast< EntityHandle >( part_handle ),
id );
CHKERR( rval,
"error getting part id" );
1198 *is_owner_size = entity_handles_size;
1201 for(
int i = 0; i < entity_handles_size; ++i )
1203 rval = pcomm->
get_owner( itaps_cast< EntityHandle >( entity_handles[i] ), owner );
CHKERR( rval,
"error getting owner" );
1204 ( *is_owner )[i] = ( owner == id );
1218 int junk1 = 1, junk2 = 1;
1219 iMeshP_getEntStatusArr( instance, partition_handle, part_handle, &entity_handle, 1, &par_status, &junk1, &junk2,
1227 const int entity_handles_size,
1229 int* par_status_allocated,
1230 int* par_status_size,
1236 std::vector< unsigned char > pstatus( entity_handles_size );
1238 entity_handles_size, &pstatus[0] );
CHKERR( result,
"error getting pstatus_tag" );
1241 for(
int i = 0; i < entity_handles_size; i++ )
1258 int* num_copies_ent,
1265 ErrorCode rval = pcomm->
get_sharing_parts( itaps_cast< EntityHandle >( entity_handle ), ids, *num_copies_ent );
CHKERR( rval,
"ParallelComm::get_sharing_parts failed" );
1273 int* part_ids_allocated,
1281 ErrorCode rval = pcomm->
get_sharing_parts( itaps_cast< EntityHandle >( entity_handle ), ids, num_ids );
CHKERR( rval,
"ParallelComm::get_sharing_parts failed" );
1283 std::copy( ids, ids + num_ids, *part_ids );
1291 int* part_ids_allocated,
1294 int* copies_entity_handles_allocated,
1295 int* copies_entity_handles_size,
1303 ErrorCode rval = pcomm->
get_sharing_parts( itaps_cast< EntityHandle >( entity_handle ), ids, num_ids, handles );
CHKERR( rval,
"ParallelComm::get_sharing_parts failed" );
1306 for(
int i = 0; i < num_ids; ++i )
1308 ( *part_ids )[i] = ids[i];
1309 ( *copies_entity_handles )[i] = itaps_cast< iBase_EntityHandle >( handles[i] );
1326 ErrorCode rval = pcomm->
get_sharing_parts( itaps_cast< EntityHandle >( entity_handle ), ids, num_ids, handles );
CHKERR( rval,
"ParallelComm::get_sharing_parts failed" );
1327 int idx = std::find( ids, ids + num_ids, part_id ) - ids;
1330 *copy_entity_handle = itaps_cast< iBase_EntityHandle >( handles[idx] );
1347 *owner_part_id = id;
1348 *owner_entity_handle = itaps_cast< iBase_EntityHandle >( h );
1401 const int entity_handles_size,
1408 if( command_code == 1 )
1410 std::cerr <<
"Entity migration option is not supported." << std::endl;
1414 if( update_ghost == 1 )
1416 std::cerr <<
"Gost update option is not supported." << std::endl;
1423 std::vector< unsigned int > exchange_procs;
1424 std::vector< Range* > exchange_ents;
1426 for(
int i = 0; i < entity_handles_size; i++ )
1431 rval = pcomm->
get_part_owner( target_part_ids[i], target_p );
CHKERR( rval,
"ParallelComm::get_part_owner failed" );
1433 std::vector< unsigned int >::iterator vit = std::find( exchange_procs.begin(), exchange_procs.end(), target_p );
1434 if( vit == exchange_procs.end() )
1436 ind = exchange_procs.size();
1437 exchange_procs.push_back( target_p );
1438 exchange_ents.push_back(
new Range );
1441 ind = vit - exchange_procs.begin();
1443 exchange_ents[ind]->insert( itaps_cast< EntityHandle >( entity_handles[i] ) );
1446 std::vector< MPI_Request > recv_ent_reqs, recv_remoteh_reqs;
1447 rval = pcomm->
exchange_owned_meshs( exchange_procs, exchange_ents, recv_ent_reqs, recv_remoteh_reqs,
true );
CHKERR( rval,
"ParallelComm::exchange_owned_meshs failed" );
1450 std::vector< Range* >::iterator vit;
1451 for( vit = exchange_ents.begin(); vit != exchange_ents.end(); ++vit )
1538 std::vector< Tag > src_tags( 1, itaps_cast< Tag >( source_tag ) );
1539 std::vector< Tag > dst_tags( 1, itaps_cast< Tag >( dest_tag ) );
1543 for( EntityType
t = types.first;
t <= types.second; ++
t )
1563 std::copy( ents, ents + entities_size,
range_inserter( range ) );
1565 std::vector< Tag > src_tags( 1, itaps_cast< Tag >( source_tag ) );
1566 std::vector< Tag > dst_tags( 1, itaps_cast< Tag >( dest_tag ) );
1606 if( include_copies )
1640 static bool append_option( std::string& opt,
const char* option,
const char* default_value = 0 )
1642 std::string::size_type i;
1644 const char sep =
' ';
1646 if( strchr( option, sep ) || ( default_value && strchr( default_value, sep ) ) )
1653 std::string search( &sep, 1 );
1655 const std::string::size_type sl = search.length();
1656 i = opt.find( search );
1657 while( i != std::string::npos )
1659 std::string::size_type end = i + sl;
1660 if( end == opt.size() || opt[end] == sep || opt[end] ==
'=' )
break;
1665 if( i != std::string::npos )
return false;
1671 opt += default_value;
1681 const char* options,
1692 partitioning = itaps_cast< EntityHandle >( partition );
1708 std::string opt = std::string( options, options + options_len );
1715 std::ostringstream id;
1721 iMesh_load( instance, entity_set_handle, name, opt.c_str(), err, name_len, opt.length() );
1732 const char* options,
1738 set = entity_set_handle ? itaps_cast< EntityHandle >( entity_set_handle ) : itaps_cast< EntityHandle >( partition );
1739 iMesh_save( instance, itaps_cast< iBase_EntitySetHandle >( set ), name, options, err, name_len, options_len );
1750 int* part_handles_allocated,
1751 int* part_handles_size,
1754 EntityHandle p = itaps_cast< EntityHandle >( partition_handle );
1764 ( *part_handles )[i] = itaps_cast< iMeshP_PartHandle >( *rit );
1772 const int rank_size,
1774 int* part_handles_allocated,
1775 int* part_handles_size,
1778 EntityHandle p = itaps_cast< EntityHandle >( partition_handle );
1799 const int dimension,
1801 const int largest_dim_only,
1803 const int owned_only,
1809 EntityHandle partitionset = itaps_cast< EntityHandle >( partition );
1812 rval = MB_FAILURE;
CHKERR( rval,
"failed to get partition set" );
1815 EntityHandle this_mb_set = itaps_cast< EntityHandle >( this_set );
1818 MPI_Comm default_comm;
1825 rval = pcomm->
assign_global_ids( this_mb_set, dimension, start_id, largest_dim_only, parallel, owned_only );
1832 *ccomm = MPI_Comm_f2c( *fcomm );