30 mbi->tag_get_data( glid, &eh, 1, &gidval );
37 mbi->tag_get_data( glid, &eh, 1, &tagval );
38 return (
int)( tagval );
44 :
mb( mbimpl ), mbs1( 0 ), mbs2( 0 ), outSet( 0 ), gid( 0 ), TgtFlagTag( 0 ), tgtParentTag( 0 ), srcParentTag( 0 ),
45 countTag( 0 ), srcNeighTag( 0 ), tgtNeighTag( 0 ), neighTgtEdgeTag( 0 ), orgSendProcTag( 0 ), imaskTag( 0 ),
46 tgtConn( nullptr ), srcConn( nullptr ), epsilon_1( 0.0 ), epsilon_area( 0.0 ), box_error( 0.0 ), localRoot( 0 ),
50 parcomm( nullptr ), remote_cells( nullptr ), remote_cells_with_tracers( nullptr )
53 max_edges_1( 0 ), max_edges_2( 0 ), counting( 0 )
65 remote_cells =
nullptr;
82 if( nnodes > max_edges ) max_edges = nnodes;
89 int local_max_edges = max_edges;
92 MPI_Allreduce( &local_max_edges, &max_edges, 1, MPI_INT, MPI_MAX, parcomm->proc_config().proc_comm() );
93 if( MPI_SUCCESS != mpi_err )
return MB_FAILURE;
118 MB_SET_ERR( MB_FAILURE,
"mesh contains a cell with "
119 << max_edges <<
" vertices, which exceeds MAXEDGES (" <<
MAXEDGES
122 <<
". Increase MAXEDGES in moab/IntxMesh/IntxUtils.hpp and rebuild." );
134 unsigned char def_data_bit = 0;
138 "can't get tgt flag tag" );
150 std::vector< EntityHandle >* nv =
new std::vector< EntityHandle >;
158 "can't create TargetParent tag" );
162 "can't create SourceParent tag" );
166 "can't create Counting tag" );
171 "can't determine neighbors for set 1" );
173 "can't determine neighbors for set 2" );
177 std::vector< EntityHandle > zeroh(
max_edges_2, 0 );
182 "can't create target edge neighbors tag" );
189 while(
tgtConn[num_nodes - 2] ==
tgtConn[num_nodes - 1] && num_nodes > 3 )
193 for( i = 0; i < num_nodes; i++ )
196 tgtConn[( i + 1 ) % num_nodes] };
197 std::vector< EntityHandle > adj_entities;
199 "can't get adjacencies" );
200 if( !adj_entities.size() )
MB_CHK_SET_ERR( MB_FAILURE,
"no adjacencies found" );
201 zeroh[i] = adj_entities[0];
210 "can't set edge target edge neighbors tag" );
220 std::vector< EntityHandle > neighbors( max_edges );
221 std::vector< EntityHandle > zeroh( max_edges, 0 );
226 "can't create neighbors tag" );
238 while( conn4[nsides - 2] == conn4[nsides - 1] && nsides > 3 )
241 for(
int i = 0; i < nsides; i++ )
245 v[1] = conn4[( i + 1 ) % nsides];
247 std::vector< EntityHandle > adjcells;
248 std::vector< EntityHandle > cellsInSet;
250 "can't get adjacency to 2 verts" );
253 size_t siz = adjcells.size();
254 for(
size_t j = 0; j < siz; j++ )
255 if(
mb->
contains_entities( inputSet, &( adjcells[j] ), 1 ) ) cellsInSet.push_back( adjcells[j] );
256 siz = cellsInSet.size();
260 std::cout <<
"non manifold mesh, error" <<
mb->
list_entities( &( cellsInSet[0] ), cellsInSet.size() )
273 if( cell == cellsInSet[0] )
274 neighbors[i] = cellsInSet[1];
276 neighbors[i] = cellsInSet[0];
279 for(
int i = nsides; i < max_edges; i++ )
365 "can't get adjacent target edges" );
371 std::vector< EntityHandle >* nv =
new std::vector< EntityHandle >;
379 "can't create target parent tag" );
382 "can't create source parent tag" );
385 "can't create Counting tag" );
392 std::vector< EntityHandle > zeroh(
max_edges_2, 0 );
395 "can't create tgt edge neighbors tag" );
403 while(
tgtConn[num_nodes - 2] ==
tgtConn[num_nodes - 1] && num_nodes > 3 )
406 for(
int i = 0; i < num_nodes; i++ )
409 tgtConn[( i + 1 ) % num_nodes] };
410 std::vector< EntityHandle > adj_entities;
412 if( rval !=
MB_SUCCESS || adj_entities.size() < 1 )
return rval;
413 zeroh[i] = adj_entities[0];
419 "can't set edge target edge neighbors tag" );
423 double max_length = 0;
425 std::vector< double > coords( 3 *
max_edges_1, 0.0 );
431 while( conn[nnodes - 2] == conn[nnodes - 1] && nnodes > 3 )
434 for(
int j = 0; j < nnodes; j++ )
436 int next = ( j + 1 ) % nnodes;
438 ( coords[3 * j] - coords[3 * next] ) * ( coords[3 * j] - coords[3 * next] ) +
439 ( coords[3 * j + 1] - coords[3 * next + 1] ) * ( coords[3 * j + 1] - coords[3 * next + 1] ) +
440 ( coords[3 * j + 2] - coords[3 * next + 2] ) * ( coords[3 * j + 2] - coords[3 * next + 2] );
444 max_length = std::sqrt( max_length );
449 if( max_length < 1. )
452 tolerance = 1. - sqrt( 1 - max_length * max_length / 4 );
459 std::cout <<
" max edge length: " << max_length <<
" tolerance for kd tree: " <<
tolerance <<
"\n";
460 std::cout <<
" box overlap tolerance: " <<
box_error <<
"\n";
466 if(
nullptr != parcomm ) MPI_Allreduce( &
box_error, &min_box_eps, 1, MPI_DOUBLE, MPI_MIN, parcomm->comm() );
472 FileOptions kdOpts(
"PLANE_SET=1;SPLITS_PER_DIR=2;SPHERICAL;RADIUS=1.0;" );
490 std::vector< double > positions;
491 positions.resize( nnodes * 3 );
496 for(
int k = 0; k < nnodes; k++ )
498 int ik = ( k + 1 ) % nnodes;
500 for(
int j = 0; j < 3; j++ )
502 double len2 = positions[3 * k + j] - positions[3 * ik + j];
505 av_len += sqrt( len1 );
507 if( nnodes > 0 ) av_len /= nnodes;
510 Range close_source_cells;
511 std::vector< EntityHandle > leaves;
512 for(
int i = 0; i < nnodes; i++ )
516 "can't search for leaves" );
518 for( std::vector< EntityHandle >::iterator j = leaves.begin(); j != leaves.end(); ++j )
527 if( close_source_cells.
empty() )
529 std::cout <<
" there are no close source cells to target cell " << tcell
545 "can't compute intersection between target and source" );
554 <<
" g:" << global_id_ent(
mb, startSrc,
gid ) <<
" counting: " <<
counting <<
"\n";
568 if(
nullptr != parcomm )
570 MB_CHK_SET_ERR( resolve_intersection_sharing(),
"can't resolve intersection sharing (correct position)" );
586 std::stringstream ffs, fft;
587 ffs <<
"source_rank0" <<
my_rank <<
".vtk";
589 fft <<
"target_rank0" <<
my_rank <<
".vtk";
617 FileOptions kdOpts(
"PLANE_SET=1;SPLITS_PER_DIR=2;SPHERICAL;RADIUS=1.0;" );
624 #if defined( ENABLE_DEBUG )
625 for(
auto it = rs22.
begin(); it != rs22.
end(); ++it )
631 std::cout <<
" cell: \t" <<
" ht:" <<
mb->
id_from_handle( cell ) <<
" nodes: " << nnodes
632 <<
" gt:" << global_id_ent(
mb, cell,
gid ) <<
" stat: " << char_stat_ent(
mb, cell,
TgtFlagTag )
637 while( !rs22.
empty() )
639 #if defined( ENABLE_DEBUG ) || defined( VERBOSE )
642 std::cout <<
" possible not connected arrival mesh; my_rank: " <<
my_rank <<
" counting: " <<
counting
643 <<
" rs22.size():" << rs22.
size() <<
"\n";
644 std::stringstream ffo;
647 for(
auto it = rs22.
begin(); it != rs22.
end(); ++it )
653 std::cout <<
" cell: \t" <<
" ht:" <<
mb->
id_from_handle( cell ) <<
" nodes: " << nnodes
654 <<
" g:" << global_id_ent(
mb, cell,
gid )
655 <<
" stat: " << char_stat_ent(
mb, cell,
TgtFlagTag ) <<
"\n";
659 bool seedFound =
false;
660 Range verified_seeds;
664 unsigned char status = 0;
668 verified_seeds.
insert( startTgt );
677 std::vector< double > positions;
678 positions.resize( nnodes * 3 );
683 Range close_source_cells;
684 std::vector< EntityHandle > leaves;
685 for(
int i = 0; i < nnodes; i++ )
689 "can't search for leaves" );
691 for( std::vector< EntityHandle >::iterator j = leaves.begin(); j != leaves.end(); ++j )
712 "can't compute intersection between target and source" );
726 <<
" g:" << global_id_ent(
mb, startTgt,
gid ) <<
" not intx with any source\n";
728 verified_seeds.
insert( startTgt );
731 rs22 =
subtract( rs22, verified_seeds );
732 if( !seedFound )
continue;
734 std::queue< EntityHandle > srcQueue;
735 srcQueue.push( startSrc );
736 std::queue< EntityHandle > tgtQueue;
737 tgtQueue.push( startTgt );
739 unsigned char used = 1;
742 while( !tgtQueue.empty() )
753 double recoveredArea = 0;
758 "can't get target neighbors" );
762 std::cout <<
"Next: neighbors for current tgt nsidesTgt: " << nsidesTgt <<
" ";
763 for(
int kk = 0; kk < nsidesTgt; kk++ )
765 if( tgtNeighbors[kk] > 0 )
768 std::cout << 0 <<
" ";
770 std::cout << std::endl;
775 for(
int j = 0; j < nsidesTgt; j++ )
778 unsigned char status = 1;
779 if( tgtNeigh == 0 )
continue;
781 "can't get target flag" );
782 if( 1 == status ) tgtNeighbors[j] = 0;
794 Range localSrcAlreadyTested;
795 localSrc.
insert( currentSrc );
803 while( !localSrc.
empty() )
820 nsidesSrc, nsidesTgt ),
821 "can't compute intersection between target and source" );
822 localSrcAlreadyTested.
insert( srcT );
828 <<
" g:" << global_id_ent(
mb, srcT,
gid ) <<
" nsidesSrc:" << nsidesSrc <<
"\n";
830 <<
" g:" << global_id_ent(
mb, currentTgt,
gid )
831 <<
" stat:" << char_stat_ent(
mb, currentTgt,
TgtFlagTag ) <<
" nsidesTgt:" << nsidesTgt
833 unsigned char status = 1;
837 for(
int k = 0; k < nsidesSrc; k++ )
838 std::cout <<
" nb[" << k <<
"]=" << nb[k];
840 for(
int k = 0; k < nsidesTgt; k++ )
841 std::cout <<
" nr[" << k <<
"]=" << nr[k];
850 "failed to get the neighbors for source element " <<
mb->
id_from_handle( srcT ) );
852 Range newPotentialSrc;
854 for(
int nn = 0; nn < nsidesSrc; nn++ )
861 if( localSrcAlreadyTested.
index( neighbor ) < 0 )
863 localSrc.
insert( neighbor );
879 Range adjacentSourceCells1, adjacentSourceCells2;
881 adjacentSourceCells1 =
intersect( adjacentSourceCells1,
rs1 );
883 adjacentSourceCells2 =
intersect( adjacentSourceCells2,
rs1 );
884 adjacentSourceCells1.merge( adjacentSourceCells2 );
885 Range potentialSrc =
subtract( adjacentSourceCells1, localSrcAlreadyTested );
886 newPotentialSrc.
merge( potentialSrc );
891 if( !newPotentialSrc.
empty() )
893 localSrc.
merge( newPotentialSrc );
896 for(
int nn = 0; nn < nsidesTgt; nn++ )
898 if( nr[nn] > 0 && tgtNeighbors[nn] > 0 )
899 nextSrc[nn].
insert( srcT );
905 "can't find nodes" );
907 std::cout <<
" intersect: " <<
" ht:" <<
mb->
id_from_handle( currentTgt ) <<
" "
909 <<
" g:" << global_id_ent(
mb, currentTgt,
gid ) <<
" "
910 <<
" g:" << global_id_ent(
mb, srcT,
gid ) <<
" counting: " <<
counting <<
"\n";
914 recoveredArea += area;
919 std::cout <<
" tgt, src, do not intersect: " <<
"ht:" <<
mb->
id_from_handle( currentTgt ) <<
" "
924 recoveredArea = ( recoveredArea - areaTgtCell ) / areaTgtCell;
925 #if defined( ENABLE_DEBUG ) || defined( VERBOSE )
929 std::cout <<
" tgt area: " << areaTgtCell <<
" recovered :" << recoveredArea * ( 1 + areaTgtCell )
930 <<
" fraction error recovery:" << recoveredArea
932 <<
" countingStart:" << countingStart <<
"\n";
938 rs22.
erase( currentTgt );
941 <<
" g:" << global_id_ent(
mb, currentTgt,
gid ) <<
" rs22.size():" << rs22.
size() <<
"\n";
946 for(
int j = 0; j < nsidesTgt; j++ )
949 if( tgtNeigh == 0 || nextSrc[j].size() == 0 )
967 tgtNeigh, nextB, P, nP, area, nb, nr, nsidesSrc, nsidesTgt2 ),
968 "can't compute intersection between target and source" );
971 unsigned char is_used = 0;
975 tgtQueue.push( tgtNeigh );
976 srcQueue.push( nextB );
979 std::cout <<
"new polys pushed: src, tgt:" <<
" ht:" <<
mb->
id_from_handle( tgtNeigh )
984 "can't set target flag" );
999 MB_CHK_SET_ERR( resolve_intersection_sharing(),
"can't resolve intersection sharing" );
1009 size_t sz = cells.
size();
1010 std::vector< int > masks( sz );
1013 Range cellsToRemove;
1017 if( masks[indx] )
continue;
1018 cellsToRemove.
insert( *eit );
1020 cells =
subtract( cells, cellsToRemove );
1048 int nextIndex = ( i + 1 ) % nP;
1049 if( nodes[i] == nodes[nextIndex] )
1055 std::cout <<
" nodes duplicated in list: ";
1056 for(
int j = 0; j < nP; j++ )
1057 std::cout << nodes[j] <<
" ";
1059 std::cout <<
" node " << nodes[i] <<
" at index " << i <<
" is duplicated" <<
"\n";
1065 for(
int k = i; k < nP - 1; k++ )
1066 nodes[k] = nodes[k + 1];
1076 #ifdef MOAB_HAVE_MPI
1082 if( gnomonic ) gnomonic =
false;
1087 int num_local_verts = (int)local_verts.
size();
ERRORR( rval,
"can't get local vertices" );
1089 assert( parcomm !=
nullptr );
1092 double bmin[3] = { std::numeric_limits< double >::max(), std::numeric_limits< double >::max(),
1093 std::numeric_limits< double >::max() };
1094 double bmax[3] = { -std::numeric_limits< double >::max(), -std::numeric_limits< double >::max(),
1095 -std::numeric_limits< double >::max() };
1097 std::vector< double > coords( 3 * num_local_verts );
1098 rval =
mb->
get_coords( local_verts, &coords[0] );
ERRORR( rval,
"can't get coords of vertices " );
1100 for(
int i = 0; i < num_local_verts; i++ )
1102 for(
int k = 0; k < 3; k++ )
1104 double val = coords[3 * i + k];
1105 if( val < bmin[k] ) bmin[k] = val;
1106 if( val > bmax[k] ) bmax[k] = val;
1109 int numprocs = parcomm->proc_config().proc_size();
1112 my_rank = parcomm->proc_config().proc_rank();
1113 for(
int k = 0; k < 3; k++ )
1121 #if ( MPI_VERSION >= 2 )
1123 mpi_err = MPI_Allgather( MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, &
allBoxes[0], 6, MPI_DOUBLE,
1124 parcomm->proc_config().proc_comm() );
1127 std::vector< double > allBoxes_tmp( 6 * parcomm->proc_config().proc_size() );
1128 mpi_err = MPI_Allgather( &
allBoxes[6 *
my_rank], 6, MPI_DOUBLE, &allBoxes_tmp[0], 6, MPI_DOUBLE,
1129 parcomm->proc_config().proc_comm() );
1133 if( MPI_SUCCESS != mpi_err )
return MB_FAILURE;
1138 std::cout <<
" maximum number of vertices per cell are " <<
max_edges_1 <<
" on first mesh and " <<
max_edges_2
1139 <<
" on second mesh \n";
1140 for(
int i = 0; i < numprocs; i++ )
1142 std::cout <<
"proc: " << i <<
" box min: " <<
allBoxes[6 * i] <<
" " <<
allBoxes[6 * i + 1] <<
" "
1144 std::cout <<
" box max: " <<
allBoxes[6 * i + 3] <<
" " <<
allBoxes[6 * i + 4] <<
" "
1156 assert( parcomm !=
nullptr );
1162 std::string tag_name(
"DP" );
1171 int num_local_verts = (int)local_verts.size();
ERRORR( rval,
"can't get local vertices" );
1173 rval = Intx2Mesh::build_processor_euler_boxes( euler_set, local_verts );
ERRORR( rval,
"can't build processor boxes" );
1175 std::vector< int > gids( num_local_verts );
1179 std::vector< double > dep_points( 3 * num_local_verts );
1180 rval =
mb->
tag_get_data( dpTag, local_verts, (
void*)&dep_points[0] );
ERRORR( rval,
"can't get DP tag values" );
1183 std::map< int, Range > Rto;
1184 int numprocs = parcomm->proc_config().proc_size();
1192 CartVect qbmin( std::numeric_limits< double >::max() );
1193 CartVect qbmax( -std::numeric_limits< double >::max() );
1194 for(
int i = 0; i < num_nodes; i++ )
1197 size_t index = local_verts.find( v ) - local_verts.begin();
1198 CartVect dp( &dep_points[3 *
index] );
1199 for(
int j = 0; j < 3; j++ )
1201 if( qbmin[j] > dp[j] ) qbmin[j] = dp[j];
1202 if( qbmax[j] < dp[j] ) qbmax[j] = dp[j];
1205 for(
int p = 0; p < numprocs; p++ )
1207 CartVect bbmin( &
allBoxes[6 * p] );
1208 CartVect bbmax( &
allBoxes[6 * p + 3] );
1219 for(
int p = 0; p < numprocs; p++ )
1221 if( p == (
int)
my_rank )
continue;
1222 Range& range_to_P = Rto[p];
1224 if( range_to_P.empty() )
continue;
1227 numq = numq + range_to_P.size();
1228 numv = numv + vertsToP.size();
1229 range_to_P.merge( vertsToP );
1233 TLv.initialize( 2, 0, 0, 3, numv );
1234 TLv.enableWriteAccess();
1239 TLq.enableWriteAccess();
1241 std::cout <<
"from proc " <<
my_rank <<
" send " << numv <<
" vertices and " << numq <<
" elements\n";
1243 for(
int to_proc = 0; to_proc < numprocs; to_proc++ )
1245 if( to_proc == (
int)
my_rank )
continue;
1246 Range& range_to_P = Rto[to_proc];
1247 Range V = range_to_P.subset_by_type(
MBVERTEX );
1252 unsigned int index = local_verts.find( v ) - local_verts.begin();
1253 int n = TLv.get_n();
1254 TLv.vi_wr[2 * n] = to_proc;
1255 TLv.vi_wr[2 * n + 1] = gids[
index];
1256 TLv.vr_wr[3 * n] = dep_points[3 *
index];
1257 TLv.vr_wr[3 * n + 1] = dep_points[3 *
index + 1];
1258 TLv.vr_wr[3 * n + 2] = dep_points[3 *
index + 2];
1262 Range Q = range_to_P.subset_by_dimension( 2 );
1268 int n = TLq.get_n();
1269 TLq.vi_wr[sizeTuple * n] = to_proc;
1270 TLq.vi_wr[sizeTuple * n + 1] = global_id;
1275 ERRORR( rval,
"can't get connectivity for cell" );
1276 if( num_nodes >
MAXEDGES )
ERRORR( MB_FAILURE,
"too many nodes in a polygon" );
1277 for(
int i = 0; i < num_nodes; i++ )
1280 unsigned int index = local_verts.find( v ) - local_verts.begin();
1281 TLq.vi_wr[sizeTuple * n + 2 + i] = gids[
index];
1285 TLq.vi_wr[sizeTuple * n + 2 + k] =
1295 ( parcomm->proc_config().crystal_router() )->gs_transfer( 1, TLv, 0 );
1296 ( parcomm->proc_config().crystal_router() )->gs_transfer( 1, TLq, 0 );
1300 std::map< int, EntityHandle > globalID_to_handle;
1302 globalID_to_eh.clear();
1304 int n = TLv.get_n();
1305 for(
int i = 0; i < n; i++ )
1307 int globalId = TLv.vi_rd[2 * i + 1];
1308 if( globalID_to_handle.find( globalId ) == globalID_to_handle.end() )
1311 double dp_pos[3] = { TLv.vr_wr[3 * i], TLv.vr_wr[3 * i + 1], TLv.vr_wr[3 * i + 2] };
1313 globalID_to_handle[globalId] = new_vert;
1321 Range local_q = local.subset_by_dimension( 2 );
1323 for(
Range::iterator it = local_q.begin(); it != local_q.end(); ++it )
1330 for(
int i = 0; i < nnodes; i++ )
1333 unsigned int index = local_verts.find( v1 ) - local_verts.begin();
1334 int globalId = gids[
index];
1335 if( globalID_to_handle.find( globalId ) == globalID_to_handle.end() )
1338 double dp_pos[3] = { dep_points[3 *
index], dep_points[3 *
index + 1], dep_points[3 *
index + 2] };
1341 globalID_to_handle[globalId] = new_vert;
1343 new_conn[i] = globalID_to_handle[gids[
index]];
1347 EntityType entType =
MBQUAD;
1349 if( nnodes < 4 ) entType =
MBTRI;
1351 rval =
mb->
create_element( entType, new_conn, nnodes, new_element );
ERRORR( rval,
"can't create new quad " );
1352 rval =
mb->
add_entities( covering_lagr_set, &new_element, 1 );
ERRORR( rval,
"can't add new element to dep set" );
1356 globalID_to_eh[gid_el] = new_element;
1358 rval =
mb->
tag_set_data( corrTag, &new_element, 1, &q );
ERRORR( rval,
"can't set corr tag on new el" );
1365 remote_cells =
new TupleList();
1366 remote_cells->initialize( 2, 0, 1, 0, n );
1367 remote_cells->enableWriteAccess();
1368 for(
int i = 0; i < n; i++ )
1370 int globalIdEl = TLq.vi_rd[sizeTuple * i + 1];
1371 int from_proc = TLq.vi_wr[sizeTuple * i];
1373 if( globalID_to_eh.find( globalIdEl ) == globalID_to_eh.end() )
1380 int vgid = TLq.vi_rd[sizeTuple * i + 2 + j];
1385 assert( globalID_to_handle.find( vgid ) != globalID_to_handle.end() );
1386 new_conn[j] = globalID_to_handle[vgid];
1392 EntityType entType =
MBQUAD;
1394 if( nnodes < 4 ) entType =
MBTRI;
1395 rval =
mb->
create_element( entType, new_conn, nnodes, new_element );
ERRORR( rval,
"can't create new element " );
1396 globalID_to_eh[globalIdEl] = new_element;
1397 rval =
mb->
add_entities( covering_lagr_set, &new_element, 1 );
ERRORR( rval,
"can't add new element to dep set" );
1399 remote_cells->vi_wr[2 * i] = from_proc;
1400 remote_cells->vi_wr[2 * i + 1] = globalIdEl;
1402 remote_cells->vul_wr[i] = TLq.vul_rd[i];
1403 remote_cells->inc_n();
1405 rval =
mb->
tag_set_data(
gid, &new_element, 1, &globalIdEl );
ERRORR( rval,
"can't set global id tag on new el" );
1411 sort_buffer.buffer_init( n );
1412 remote_cells->sort( 1, &sort_buffer );
1413 sort_buffer.
reset();
1430 assert( parcomm !=
nullptr );
1431 if( 1 == parcomm->proc_config().proc_size() )
1433 covering_set = lagr_set;
1440 int num_local_verts = (int)local_verts.size();
ERRORR( rval,
"can't get local vertices" );
1442 std::vector< int > gids( num_local_verts );
1445 Range localDepCells;
1452 int num_lagr_verts = (int)lagr_verts.size();
ERRORR( rval,
"can't get local lagr vertices" );
1455 std::vector< double > dep_points( 3 * num_lagr_verts );
1456 rval =
mb->
get_coords( lagr_verts, &dep_points[0] );
ERRORR( rval,
"can't get departure points position" );
1459 std::map< int, Range > Rto;
1460 int numprocs = parcomm->proc_config().proc_size();
1462 for(
Range::iterator eit = localDepCells.begin(); eit != localDepCells.end(); ++eit )
1468 CartVect qbmin( std::numeric_limits< double >::max() );
1469 CartVect qbmax( -std::numeric_limits< double >::max() );
1470 for(
int i = 0; i < num_nodes; i++ )
1473 int index = lagr_verts.index( v );
1474 assert( -1 !=
index );
1475 CartVect dp( &dep_points[3 *
index] );
1476 for(
int j = 0; j < 3; j++ )
1478 if( qbmin[j] > dp[j] ) qbmin[j] = dp[j];
1479 if( qbmax[j] < dp[j] ) qbmax[j] = dp[j];
1482 for(
int p = 0; p < numprocs; p++ )
1484 CartVect bbmin( &
allBoxes[6 * p] );
1485 CartVect bbmax( &
allBoxes[6 * p + 3] );
1496 for(
int p = 0; p < numprocs; p++ )
1498 if( p == (
int)
my_rank )
continue;
1499 Range& range_to_P = Rto[p];
1501 if( range_to_P.empty() )
continue;
1504 numq = numq + range_to_P.size();
1505 numv = numv + vertsToP.size();
1506 range_to_P.merge( vertsToP );
1510 TLv.initialize( 2, 0, 0, 3, numv );
1511 TLv.enableWriteAccess();
1517 TLq.enableWriteAccess();
1519 std::cout <<
"from proc " <<
my_rank <<
" send " << numv <<
" vertices and " << numq <<
" elements\n";
1522 for(
int to_proc = 0; to_proc < numprocs; to_proc++ )
1524 if( to_proc == (
int)
my_rank )
continue;
1525 Range& range_to_P = Rto[to_proc];
1526 Range V = range_to_P.subset_by_type(
MBVERTEX );
1531 int index = lagr_verts.index( v );
1532 assert( -1 !=
index );
1533 int n = TLv.get_n();
1534 TLv.vi_wr[2 * n] = to_proc;
1535 TLv.vi_wr[2 * n + 1] = gids[
index];
1536 TLv.vr_wr[3 * n] = dep_points[3 *
index];
1537 TLv.vr_wr[3 * n + 1] = dep_points[3 *
index + 1];
1538 TLv.vr_wr[3 * n + 2] = dep_points[3 *
index + 2];
1542 Range Q = range_to_P.subset_by_dimension( 2 );
1548 int n = TLq.get_n();
1549 TLq.vi_wr[sizeTuple * n] = to_proc;
1550 TLq.vi_wr[sizeTuple * n + 1] = global_id;
1554 q, conn4, num_nodes );
1555 if( num_nodes >
MAXEDGES )
ERRORR( MB_FAILURE,
"too many nodes in a polygon" );
1556 for(
int i = 0; i < num_nodes; i++ )
1559 int index = lagr_verts.index( v );
1560 assert( -1 !=
index );
1561 TLq.vi_wr[sizeTuple * n + 2 + i] = gids[
index];
1565 TLq.vi_wr[sizeTuple * n + 2 + k] =
1569 rval =
mb->
tag_get_data( corrTag, &q, 1, &tgtCell );
ERRORR( rval,
"can't get corresponding tgt cell for dep cell" );
1570 TLq.vul_wr[n] = tgtCell;
1576 ( parcomm->proc_config().crystal_router() )->gs_transfer( 1, TLv, 0 );
1577 ( parcomm->proc_config().crystal_router() )->gs_transfer( 1, TLq, 0 );
1581 std::map< int, EntityHandle > globalID_to_handle;
1585 for(
Range::iterator vit = lagr_verts.begin(); vit != lagr_verts.end(); ++vit, k++ )
1587 globalID_to_handle[gids[k]] = *vit;
1591 globalID_to_eh.clear();
1593 int n = TLv.get_n();
1594 for(
int i = 0; i < n; i++ )
1596 int globalId = TLv.vi_rd[2 * i + 1];
1597 if( globalID_to_handle.find( globalId ) == globalID_to_handle.end() )
1600 double dp_pos[3] = { TLv.vr_wr[3 * i], TLv.vr_wr[3 * i + 1], TLv.vr_wr[3 * i + 2] };
1602 globalID_to_handle[globalId] = new_vert;
1610 Range local_q = local.subset_by_dimension( 2 );
1612 for(
Range::iterator it = local_q.begin(); it != local_q.end(); ++it )
1617 globalID_to_eh[gid_el] = q;
1625 remote_cells =
new TupleList();
1626 remote_cells->initialize( 2, 0, 1, 0, n );
1627 remote_cells->enableWriteAccess();
1628 for(
int i = 0; i < n; i++ )
1630 int globalIdEl = TLq.vi_rd[sizeTuple * i + 1];
1631 int from_proc = TLq.vi_rd[sizeTuple * i];
1633 if( globalID_to_eh.find( globalIdEl ) == globalID_to_eh.end() )
1640 int vgid = TLq.vi_rd[sizeTuple * i + 2 + j];
1645 assert( globalID_to_handle.find( vgid ) != globalID_to_handle.end() );
1646 new_conn[j] = globalID_to_handle[vgid];
1652 EntityType entType =
MBQUAD;
1654 if( nnodes < 4 ) entType =
MBTRI;
1655 rval =
mb->
create_element( entType, new_conn, nnodes, new_element );
ERRORR( rval,
"can't create new element " );
1656 globalID_to_eh[globalIdEl] = new_element;
1657 local_q.insert( new_element );
1660 remote_cells->vi_wr[2 * i] = from_proc;
1661 remote_cells->vi_wr[2 * i + 1] = globalIdEl;
1663 remote_cells->vul_wr[i] = TLq.vul_rd[i];
1664 remote_cells->inc_n();
1668 rval =
mb->
add_entities( covering_set, local_q );
ERRORR( rval,
"can't add entities to new mesh set " );
1672 sort_buffer.buffer_init( n );
1673 remote_cells->sort( 1, &sort_buffer );
1674 sort_buffer.
reset();
1679 ErrorCode Intx2Mesh::resolve_intersection_sharing()
1681 if( parcomm && parcomm->size() > 1 )
1691 Range nonOwnedVerts;
1698 "can't filter pstatus" );
1708 Range vertsCovInterface;
1710 "can't filter pstatus" );
1712 Range nodesToDuplicate =
intersect( vertsCovInterface, nonOwnedVerts );
1715 Range connectedCells;
1718 connectedCells =
intersect( connectedCells, intxCells );
1720 std::map< EntityHandle, EntityHandle > duplicatedVerticesMap;
1721 for(
Range::iterator vit = nodesToDuplicate.begin(); vit != nodesToDuplicate.end(); ++vit )
1728 duplicatedVerticesMap[
vertex] = newVertex;
1732 for(
Range::iterator eit = connectedCells.begin(); eit != connectedCells.end(); ++eit )
1736 std::vector< EntityHandle > connectivity;
1738 for(
size_t i = 0; i < connectivity.size(); i++ )
1741 std::map< EntityHandle, EntityHandle >::iterator mit = duplicatedVerticesMap.find( currentVertex );
1742 if( mit != duplicatedVerticesMap.end() )
1744 connectivity[i] = mit->second;
1747 int nnodes = (int)connectivity.size();