25 : mbImpl( impl ), pcomm( comm ), _rset( rset )
28 assert( NULL != impl );
38 std::cout <<
"Error initializing NestedRefine\n" << std::endl;
79 MB_SET_ERR( MB_FAILURE,
"Not supported 3D entity types: MBPRISM, MBPYRAMID, MBKNIFE, MBPOLYHEDRON" );
116 std::vector< EntityHandle >& level_sets,
119 assert( num_level > 0 );
123 std::vector< moab::EntityHandle > hmsets( num_level );
127 for(
int i = 0; i < num_level; i++ )
129 assert( ( level_degrees[i] == 2 ) || ( level_degrees[i] == 3 ) || ( level_degrees[i] == 5 ) );
135 for(
int i = 0; i < num_level; i++ )
137 assert( ( level_degrees[i] == 2 ) || ( level_degrees[i] == 3 ) );
145 level_sets.resize( num_level + 1 );
146 level_sets[0] =
_rset;
147 for(
int i = 0; i < num_level; i++ )
148 level_sets[i + 1] = hmsets[i];
158 if( !conn.empty() ) conn.clear();
166 conn.push_back(
level_mesh[level - 1].edge_conn[2 * offset] );
167 conn.push_back(
level_mesh[level - 1].edge_conn[2 * offset + 1] );
172 conn.reserve( num_corners );
176 for(
int i = 0; i < num_corners; i++ )
183 conn.reserve( num_corners );
186 for(
int i = 0; i < num_corners; i++ )
190 MB_SET_ERR( MB_FAILURE,
"Requesting connectivity for an unsupported entity type" );
205 for(
int i = 0; i < num_verts; i++ )
224 const unsigned int target_dimension,
225 std::vector< EntityHandle >& target_entities )
236 assert( ( child_level > 0 ) && ( child_level > parent_level ) );
248 MB_SET_ERR( MB_FAILURE,
"Requesting parent for unsupported entity type" );
251 int l = child_level - parent_level;
252 for(
int i = 0; i < l; i++ )
256 child_index = child_index / nch;
258 parent_index = child_index;
262 if( parent_level > 0 )
269 if( parent_level > 0 )
276 if( parent_level > 0 )
288 std::vector< EntityHandle >&
children )
290 assert( ( child_level > 0 ) && ( child_level > parent_level ) );
297 if( parent_level > 0 )
304 if( parent_level > 0 )
311 if( parent_level > 0 )
317 MB_SET_ERR( MB_FAILURE,
"Requesting children for unsupported entity type" );
320 start = end = parent_index;
321 for(
int i = parent_level; i < child_level; i++ )
326 end = end * nch + nch - 1;
329 int num_child = end - start;
332 for(
int i = start; i <= end; i++ )
351 std::vector< EntityHandle >& incident_entities )
353 assert( vert_level > parent_level );
357 std::vector< EntityHandle > inents;
372 for(
int i = 0; i < (int)inents.size(); i++ )
377 incident_entities.push_back( parent );
381 std::sort( incident_entities.begin(), incident_entities.end() );
382 incident_entities.erase( std::unique( incident_entities.begin(), incident_entities.end() ),
383 incident_entities.end() );
391 std::vector< EntityHandle >& incident_entities )
393 assert( vert_level < child_level );
397 std::vector< EntityHandle > inents;
412 std::vector< EntityHandle > childs;
413 for(
int i = 0; i < (int)inents.size(); i++ )
418 for(
int j = 0; j < (int)childs.size(); j++ )
419 incident_entities.push_back( childs[j] );
428 MB_SET_ERR( MB_FAILURE,
"Requesting duplicates for non-coarse vertices" );
437 bool is_border =
false;
449 MB_SET_ERR( MB_FAILURE,
"Requesting boundary information for unsupported entity type" );
469 MB_SET_ERR( MB_FAILURE,
"Requesting ghost layers for a serial mesh" );
474 for(
size_t i = 0; i < lsets.size(); i++ )
479 for(
int gl = 0; gl < num_glayers; gl++ )
485 for(
size_t i = 0; i < lsets.size(); i++ )
498 assert( level > 0 && level <
nlevels + 1 );
501 std::vector< Tag > mtags( 3 );
507 for(
int i = 0; i < 3; i++ )
517 std::vector< EntityHandle > childs;
519 for( set_it = sets.
begin(); set_it != sets.
end(); ++set_it )
533 std::vector< EntityHandle > cents;
536 childs.insert( childs.end(), cents.begin(), cents.end() );
543 std::sort( childs.begin(), childs.end() );
544 childs.erase( std::unique( childs.begin(), childs.end() ), childs.end() );
569 int nverts_prev, nedges_prev, nfaces_prev, ncells_prev;
586 int nedges = 0, nfaces = 0;
591 hmest[0] = nverts_prev + nverts;
597 if( nfaces_prev != 0 )
612 if( ncells_prev != 0 )
728 for(
int l = 0; l < num_level; l++ )
734 int hmest[4] = { 0, 0, 0, 0 };
807 int nverts_prev, nents_prev;
821 std::vector< EntityHandle > vbuffer( vtotal );
823 std::vector< EntityHandle > conn;
825 int count_verts = nverts_prev;
828 for(
int eid = 0; eid < nents_prev; eid++ )
851 for(
int i = 0; i < (int)conn.size(); i++ )
862 for(
int i = 0; i < num_new_verts; i++ )
871 std::vector< EntityHandle > ent_buffer( etotal );
873 for(
int i = 0; i < etotal; i++ )
888 for(
int i = 0; i < num_new_verts; i++ )
904 ( 1 - xi ) *
level_mesh[cur_level].coordinates[0][id1] + xi *
level_mesh[cur_level].coordinates[0][id2];
906 ( 1 - xi ) *
level_mesh[cur_level].coordinates[1][id1] + xi *
level_mesh[cur_level].coordinates[1][id2];
908 ( 1 - xi ) *
level_mesh[cur_level].coordinates[2][id1] + xi *
level_mesh[cur_level].coordinates[2][id2];
920 std::vector< EntityHandle >& trackverts )
934 int ne = 0,
dim = 0, index = 0;
948 std::vector< EntityHandle > vbuffer( vtotal );
949 std::vector< EntityHandle > ent_buffer( etotal );
951 std::vector< EntityHandle > adjents, econn, fconn;
952 std::vector< int > leids;
956 for(
int eid = 0; eid < nedges_prev; eid++ )
962 for(
int i = 0; i < vtotal; i++ )
964 for(
int i = 0; i < etotal; i++ )
975 for(
int i = 0; i < (int)econn.size(); i++ )
983 int fid = -1, lid = -1, idx1 = -1, idx2 = -1;
1012 bool orient =
false;
1013 if( ( fconn[idx1] == econn[0] ) && ( fconn[idx2] == econn[1] ) ) orient =
true;
1017 for(
int j = 0; j < nve; j++ )
1018 vbuffer[j + 2] = trackverts[fid * ne * nve + nve * lid + j];
1022 for(
int j = 0; j < nve; j++ )
1023 vbuffer[( nve - j - 1 ) + 2] = trackverts[fid * ne * nve + nve * lid + j];
1029 for(
int i = 0; i < etotal; i++ )
1051 int nverts_prev, nents_prev;
1067 int findex = ftype - 1;
1071 int vtotal = nepf + tnv;
1072 std::vector< EntityHandle > vbuffer( vtotal );
1074 std::vector< EntityHandle > ent_buffer( etotal );
1077 std::vector< EntityHandle > trackvertsF( nents_prev * nepf * nve, 0 );
1079 std::vector< int > flag_verts( cur_nverts - nverts_prev, 0 );
1081 int count_nverts = nverts_prev;
1082 int count_nents = 0;
1083 std::vector< EntityHandle > conn, cur_conn;
1086 for(
int fid = 0; fid < nents_prev; fid++ )
1090 for(
int i = 0; i < vtotal; i++ )
1092 for(
int i = 0; i < etotal; i++ )
1107 for(
int i = 0; i < (int)conn.size(); i++ )
1114 cur_conn.push_back( vbuffer[i] );
1119 for(
int i = 0; i < nepf; i++ )
1121 for(
int j = 0; j < nve; j++ )
1124 vbuffer[id] = trackvertsF[fid * nve * nepf + nve * i + j];
1129 for(
int i = 0; i < tnv; i++ )
1131 if( !vbuffer[i + nepf] )
1140 for(
int i = 0; i < etotal; i++ )
1142 for(
int k = 0; k < nepf; k++ )
1157 for(
int i = 0; i < nepf; i++ )
1160 for(
int j = 0; j < nve; j++ )
1163 trackvertsF[fid * nepf * nve + nve * i + j] = vbuffer[id];
1166 std::vector< EntityHandle > sibfids;
1167 std::vector< int > sibleids;
1168 std::vector< int > siborient;
1173 if( !sibfids.size() )
continue;
1175 for(
int s = 0; s < (int)sibfids.size(); s++ )
1185 for(
int j = 0; j < nve; j++ )
1188 trackvertsF[sibid * nepf * nve + nve * sibleids[s] + j] = vbuffer[id];
1193 for(
int j = 0; j < nve; j++ )
1196 trackvertsF[sibid * nepf * nve + nve * sibleids[s] + j] = vbuffer[id];
1204 std::vector< double > corner_coords( nepf * 3 );
1226 std::vector< EntityHandle >& trackvertsE,
1227 std::vector< EntityHandle >& trackvertsF )
1231 EntityType ftype =
MBTRI;
1235 int findex = ftype - 1;
1245 int vtotal = nepf + tnv;
1248 std::vector< EntityHandle > vbuffer( vtotal );
1249 std::vector< EntityHandle > ent_buffer( etotal );
1251 std::vector< EntityHandle > adjents, fconn, cconn;
1252 std::vector< int > leids;
1253 int count_nents = 0;
1255 int nents_prev, ecount;
1270 for(
int it = 0; it < nents_prev; it++ )
1276 for(
int i = 0; i < vtotal; i++ )
1278 for(
int i = 0; i < etotal; i++ )
1291 for(
int i = 0; i < (int)fconn.size(); i++ )
1313 std::vector< EntityHandle > fac_conn( nepf );
1314 std::vector< EntityHandle > lfac_conn( nepf );
1315 for(
int j = 0; j < nepf; j++ )
1317 fac_conn[j] = fconn[j];
1319 lfac_conn[j] = cconn[id];
1322 std::vector< int > le_idx, indices;
1327 for(
int j = 0; j < nepf; j++ )
1334 bool eorient =
false;
1338 if( ( fconn[j] == cconn[idx1] ) && ( fconn[fnext] == cconn[idx2] ) ) eorient =
true;
1342 for(
int k = 0; k < nve; k++ )
1345 vbuffer[ind] = trackvertsE[fid * nepc * nve + nve * idx + k];
1350 for(
int k = 0; k < nve; k++ )
1353 vbuffer[ind] = trackvertsE[fid * nepc * nve + nve * idx + k];
1361 for(
int k = 0; k < nvf; k++ )
1364 vbuffer[ind] = trackvertsF[fid * nfpc * nvf + nvf * lid + indices[k] - 1];
1369 for(
int i = 0; i < etotal; i++ )
1371 for(
int k = 0; k < nepf; k++ )
1386 for(
int i = 0; i < ne; i++ )
1424 int nverts_prev, nents_prev;
1437 int cindex = type - 1;
1448 int vtotal = nvpc + nvtotal;
1449 std::vector< EntityHandle > vbuffer( vtotal );
1451 std::vector< EntityHandle > trackvertsC_edg( nepc * ne * nents_prev, 0 );
1452 std::vector< EntityHandle > trackvertsC_face( nfpc * nvf * nents_prev, 0 );
1455 std::vector< int > flag_verts( cur_nverts - nverts_prev, 0 );
1457 int count_nverts = nverts_prev;
1459 std::vector< EntityHandle > conn, cur_conn;
1462 for(
int cid = 0; cid < nents_prev; cid++ )
1466 for(
int i = 0; i < vtotal; i++ )
1481 for(
int i = 0; i < (int)conn.size(); i++ )
1488 cur_conn.push_back( vbuffer[i] );
1492 for(
int i = 0; i < nepc; i++ )
1494 for(
int j = 0; j < ne; j++ )
1497 vbuffer[idx] = trackvertsC_edg[cid * nepc * ne + ne * i + j];
1502 for(
int i = 0; i < nfpc; i++ )
1504 for(
int j = 0; j < nvf; j++ )
1507 vbuffer[idx] = trackvertsC_face[cid * nfpc * nvf + nvf * i + j];
1512 for(
int i = 0; i < nvtotal; i++ )
1514 if( !vbuffer[i + nvpc] )
1524 std::vector< EntityHandle > ent_buffer( etotal );
1526 for(
int i = 0; i < etotal; i++ )
1528 for(
int k = 0; k < nvpc; k++ )
1544 std::vector< double > corner_coords( nvpc * 3 );
1576 int nverts_prev, nents_prev;
1588 EntityType type =
MBTET;
1589 int cindex = type - 1;
1601 int vtotal = nvpc + nvtotal;
1602 std::vector< EntityHandle > vbuffer( vtotal );
1605 std::vector< EntityHandle > trackvertsC_edg( nepc * ne * nents_prev, 0 );
1606 std::vector< EntityHandle > trackvertsC_face( nfpc * nvf * nents_prev, 0 );
1609 std::vector< int > flag_verts( cur_nverts - nverts_prev, 0 );
1610 std::vector< int > cell_patterns( nents_prev, 0 );
1612 int count_nverts = nverts_prev;
1614 std::vector< EntityHandle > conn, cur_conn;
1617 for(
int cid = 0; cid < nents_prev; cid++ )
1621 for(
int i = 0; i < vtotal; i++ )
1636 for(
int i = 0; i < (int)conn.size(); i++ )
1643 cur_conn.push_back( vbuffer[i] );
1647 for(
int i = 0; i < nepc; i++ )
1649 for(
int j = 0; j < ne; j++ )
1652 vbuffer[idx] = trackvertsC_edg[cid * nepc * ne + ne * i + j];
1657 for(
int i = 0; i < nfpc; i++ )
1659 for(
int j = 0; j < nvf; j++ )
1662 vbuffer[idx] = trackvertsC_face[cid * nfpc * nvf + nvf * i + j];
1667 for(
int i = 0; i < nvtotal; i++ )
1669 if( !vbuffer[i + nvpc] )
1677 std::vector< double > corner_coords( nvpc * 3 );
1685 int pat_id = diag + 2;
1686 cell_patterns[cid] = pat_id;
1691 std::vector< EntityHandle > ent_buffer( etotal );
1693 for(
int i = 0; i < etotal; i++ )
1695 for(
int k = 0; k < nvpc; k++ )
1735 double* corner_coords,
1736 std::vector< int >& vflag,
1744 double xi, eta, N[3];
1747 for(
int i = 3; i < vtotal; i++ )
1749 if( vflag[vbuffer[i] - vstart - nverts_prev] )
continue;
1753 N[0] = 1 - xi - eta;
1757 double x = 0, y = 0, z = 0;
1758 for(
int j = 0; j < 3; j++ )
1760 x += N[j] * corner_coords[3 * j];
1761 y += N[j] * corner_coords[3 * j + 1];
1762 z += N[j] * corner_coords[3 * j + 2];
1768 vflag[vbuffer[i] - vstart - nverts_prev] = 1;
1771 else if( type ==
MBQUAD )
1773 double xi, eta, N[4];
1776 for(
int i = 4; i < vtotal; i++ )
1778 if( vflag[vbuffer[i] - vstart - nverts_prev] )
continue;
1782 N[0] = ( 1 - xi ) * ( 1 - eta ) / 4;
1783 N[1] = ( 1 + xi ) * ( 1 - eta ) / 4;
1784 N[2] = ( 1 + xi ) * ( 1 + eta ) / 4, N[3] = ( 1 - xi ) * ( 1 + eta ) / 4;
1786 double x = 0, y = 0, z = 0;
1787 for(
int j = 0; j < 4; j++ )
1789 x += N[j] * corner_coords[3 * j];
1790 y += N[j] * corner_coords[3 * j + 1];
1791 z += N[j] * corner_coords[3 * j + 2];
1797 vflag[vbuffer[i] - vstart - nverts_prev] = 1;
1800 else if( type ==
MBTET )
1802 double xi, eta, mu, N[4];
1805 for(
int i = 4; i < vtotal; i++ )
1807 if( vflag[vbuffer[i] - vstart - nverts_prev] )
continue;
1813 N[0] = 1 - xi - eta - mu;
1815 N[2] = eta, N[3] = mu;
1817 double x = 0, y = 0, z = 0;
1818 for(
int j = 0; j < 4; j++ )
1820 x += N[j] * corner_coords[3 * j];
1821 y += N[j] * corner_coords[3 * j + 1];
1822 z += N[j] * corner_coords[3 * j + 2];
1828 vflag[vbuffer[i] - vstart - nverts_prev] = 1;
1833 double xi, eta, mu, N[6];
1836 for(
int i = 6; i < vtotal; i++ )
1838 if( vflag[vbuffer[i] - vstart - nverts_prev] )
continue;
1844 N[0] = ( 1 - xi - eta ) * ( 1 - mu ), N[1] = xi * ( 1 - mu ), N[2] = eta * ( 1 - mu ),
1845 N[3] = ( 1 - xi - eta ) * ( 1 + mu ), N[4] = xi * ( 1 + mu ), N[5] = eta * ( 1 + mu );
1847 double x = 0, y = 0, z = 0;
1848 for(
int j = 0; j < 6; j++ )
1850 x += N[j] * corner_coords[3 * j];
1851 y += N[j] * corner_coords[3 * j + 1];
1852 z += N[j] * corner_coords[3 * j + 2];
1858 vflag[vbuffer[i] - vstart - nverts_prev] = 1;
1861 else if( type ==
MBHEX )
1863 double xi, eta, mu, N[8];
1864 double d1, d2, d3, s1, s2, s3;
1867 for(
int i = 8; i < vtotal; i++ )
1870 if( vflag[vbuffer[i] - vstart - nverts_prev] )
continue;
1882 N[0] = ( d1 * d2 * d3 ) / 8;
1883 N[1] = ( s1 * d2 * d3 ) / 8;
1884 N[2] = ( s1 * s2 * d3 ) / 8;
1885 N[3] = ( d1 * s2 * d3 ) / 8;
1886 N[4] = ( d1 * d2 * s3 ) / 8;
1887 N[5] = ( s1 * d2 * s3 ) / 8;
1888 N[6] = ( s1 * s2 * s3 ) / 8;
1889 N[7] = ( d1 * s2 * s3 ) / 8;
1891 double x = 0, y = 0, z = 0;
1892 for(
int j = 0; j < 8; j++ )
1894 x += N[j] * corner_coords[3 * j];
1895 y += N[j] * corner_coords[3 * j + 1];
1896 z += N[j] * corner_coords[3 * j + 2];
1903 vflag[vbuffer[i] - vstart - nverts_prev] = 1;
1912 #ifdef MOAB_HAVE_MPI
1954 int partid =
pcomm->
rank(), dum_id = -1;
1969 ParallelMergeMesh pm(
pcomm, 1e-08 );
1986 for(
int i = 0; i < num_levels; i++ )
1989 int partid =
pcomm->
rank(), dum_id = -1;
1999 std::set< unsigned int > shprocs;
2002 std::vector< int > sharedprocs;
2003 for( std::set< unsigned int >::iterator it = shprocs.begin(); it != shprocs.end(); it++ )
2004 sharedprocs.push_back( *it );
2005 int nprocs = sharedprocs.size();
2008 std::vector< std::vector< int > > nsharedEntsperproc( nprocs );
2009 std::vector< std::vector< EntityHandle > > localBuffs( nprocs );
2010 std::vector< std::vector< EntityHandle > > remlocalBuffs( nprocs );
2011 std::vector< std::vector< EntityHandle > > remoteBuffs( nprocs );
2014 Range sharedentities;
2016 for( i = 0; i < nprocs; i++ )
2019 sharedentities.clear();
2027 V0 = allEnts.subset_by_dimension( 0 );
2028 E0 = allEnts.subset_by_dimension( 1 );
2029 F0 = allEnts.subset_by_dimension( 2 );
2049 std::vector< EntityHandle > locFList, remFList;
2050 std::vector< EntityHandle > locEList, remEList;
2051 std::vector< EntityHandle > locVList, remVList;
2072 std::vector< int > msgsz;
2073 msgsz.push_back( F0.size() );
2074 msgsz.push_back( locFList.size() );
2075 msgsz.push_back( E0.size() );
2076 msgsz.push_back( locEList.size() );
2077 msgsz.push_back( V0.size() );
2078 msgsz.push_back( locVList.size() );
2079 nsharedEntsperproc[i].insert( nsharedEntsperproc[i].end(), msgsz.begin(), msgsz.end() );
2083 localBuffs[i].insert( localBuffs[i].end(), locFList.begin(), locFList.end() );
2084 remlocalBuffs[i].insert( remlocalBuffs[i].end(), remFList.begin(), remFList.end() );
2088 localBuffs[i].insert( localBuffs[i].end(), locEList.begin(), locEList.end() );
2089 remlocalBuffs[i].insert( remlocalBuffs[i].end(), remEList.begin(), remEList.end() );
2093 localBuffs[i].insert( localBuffs[i].end(), locVList.begin(), locVList.end() );
2094 remlocalBuffs[i].insert( remlocalBuffs[i].end(), remVList.begin(), remVList.end() );
2102 std::multimap< EntityHandle, int > rprocs;
2103 std::multimap< EntityHandle, EntityHandle > rhandles;
2105 error = decipher_remote_handles( sharedprocs, nsharedEntsperproc, localBuffs, remoteBuffs, rprocs, rhandles );
MB_CHK_ERR(
error );
2113 ErrorCode NestedRefine::collect_shared_entities_by_dimension( Range sharedEnts, Range& allEnts )
2117 Range F0, E0, V0, E0all, V0all;
2118 std::vector< EntityHandle > ents;
2120 F0 = sharedEnts.subset_by_dimension( 2 );
2121 E0all = sharedEnts.subset_by_dimension( 1 );
2122 V0all = sharedEnts.subset_by_dimension( 0 );
2132 std::copy( ents.begin(), ents.end(), range_inserter( edges ) );
2135 std::copy( ents.begin(), ents.end(), range_inserter( verts ) );
2145 std::copy( ents.begin(), ents.end(), range_inserter( verts ) );
2150 else if( !E0all.empty() )
2157 std::copy( ents.begin(), ents.end(), range_inserter( verts ) );
2162 else if( !V0all.empty() )
2167 MB_SET_ERR( MB_FAILURE,
"Trying to pack unsupported sub-entities for shared interface entities" );
2169 if( !F0.empty() ) std::copy( F0.begin(), F0.end(), range_inserter( allEnts ) );
2170 if( !E0.empty() ) std::copy( E0.begin(), E0.end(), range_inserter( allEnts ) );
2171 if( !V0.empty() ) std::copy( V0.begin(), V0.end(), range_inserter( allEnts ) );
2176 ErrorCode NestedRefine::collect_FList(
int to_proc,
2178 std::vector< EntityHandle >& FList,
2179 std::vector< EntityHandle >& RList )
2184 std::vector< EntityHandle >
F, FC, FE, lF, lFC, lFE, rF, rFC, rFE;
2185 std::vector< EntityHandle > childEnts, conn, fedges;
2196 lF.push_back( *it );
2197 lFC.insert( lFC.end(), conn.begin(), conn.end() );
2198 lFE.insert( lFE.end(), fedges.begin(), fedges.end() );
2203 rF.push_back( rval );
2205 for(
int i = 0; i < (int)conn.size(); i++ )
2208 rFC.push_back( rval );
2211 rFE.push_back( rval );
2215 for(
int l = 0; l <
nlevels; l++ )
2222 for(
int i = 0; i < (int)childEnts.size(); i++ )
2229 F.push_back( childEnts[i] );
2230 FC.insert( FC.end(), conn.begin(), conn.end() );
2231 FE.insert( FE.end(), fedges.begin(), fedges.end() );
2236 FList.insert( FList.end(), lF.begin(), lF.end() );
2237 FList.insert( FList.end(),
F.begin(),
F.end() );
2238 FList.insert( FList.end(), lFC.begin(), lFC.end() );
2239 FList.insert( FList.end(), FC.begin(), FC.end() );
2240 FList.insert( FList.end(), lFE.begin(), lFE.end() );
2241 FList.insert( FList.end(), FE.begin(), FE.end() );
2243 RList.insert( RList.end(), rF.begin(), rF.end() );
2244 RList.insert( RList.end(),
F.begin(),
F.end() );
2245 RList.insert( RList.end(), rFC.begin(), rFC.end() );
2246 RList.insert( RList.end(), FC.begin(), FC.end() );
2247 RList.insert( RList.end(), rFE.begin(), rFE.end() );
2248 RList.insert( RList.end(), FE.begin(), FE.end() );
2253 ErrorCode NestedRefine::collect_EList(
int to_proc,
2255 std::vector< EntityHandle >& EList,
2256 std::vector< EntityHandle >& RList )
2260 std::vector< EntityHandle >
E, EC, lE, lEC, rE, rEC;
2261 std::vector< EntityHandle > childEnts, conn;
2271 lE.push_back( edg );
2272 lEC.insert( lEC.end(), conn.begin(), conn.end() );
2277 rE.push_back( rval );
2279 rEC.push_back( rval );
2281 rEC.push_back( rval );
2285 for(
int l = 0; l <
nlevels; l++ )
2292 for(
int i = 0; i < (int)childEnts.size(); i++ )
2296 E.push_back( childEnts[i] );
2297 EC.insert( EC.end(), conn.begin(), conn.end() );
2302 EList.insert( EList.end(), lE.begin(), lE.end() );
2303 EList.insert( EList.end(),
E.begin(),
E.end() );
2304 EList.insert( EList.end(), lEC.begin(), lEC.end() );
2305 EList.insert( EList.end(), EC.begin(), EC.end() );
2307 RList.insert( RList.end(), rE.begin(), rE.end() );
2308 RList.insert( RList.end(),
E.begin(),
E.end() );
2309 RList.insert( RList.end(), rEC.begin(), rEC.end() );
2310 RList.insert( RList.end(), EC.begin(), EC.end() );
2315 ErrorCode NestedRefine::collect_VList(
int to_proc,
2317 std::vector< EntityHandle >& VList,
2318 std::vector< EntityHandle >& RList )
2321 std::vector< EntityHandle > V, lV, rV;
2333 rV.push_back( rval );
2337 for(
int l = 0; l <
nlevels; l++ )
2343 V.push_back( dupvert );
2348 VList.insert( VList.end(), lV.begin(), lV.end() );
2349 VList.insert( VList.end(), V.begin(), V.end() );
2352 RList.insert( RList.end(), rV.begin(), rV.end() );
2353 RList.insert( RList.end(), V.begin(), V.end() );
2358 ErrorCode NestedRefine::decipher_remote_handles( std::vector< int >& sharedprocs,
2359 std::vector< std::vector< int > >& auxinfo,
2360 std::vector< std::vector< EntityHandle > >& localbuffers,
2361 std::vector< std::vector< EntityHandle > >& remotebuffers,
2362 std::multimap< EntityHandle, int >& remProcs,
2363 std::multimap< EntityHandle, EntityHandle >& remHandles )
2368 int nprocs = sharedprocs.size();
2370 for( i = 0; i < nprocs; i++ )
2372 std::vector< int > msgsz;
2373 for(
int j = 0; j < (int)auxinfo[i].
size(); j++ )
2375 msgsz.push_back( auxinfo[i][j] );
2381 std::vector< EntityHandle > LFList, RFList;
2382 LFList.insert( LFList.end(), localbuffers[i].begin(), localbuffers[i].begin() + msgsz[1] );
2383 RFList.insert( RFList.end(), remotebuffers[i].begin(), remotebuffers[i].begin() + msgsz[1] );
2385 error = decipher_remote_handles_face( sharedprocs[i], msgsz[0], LFList, RFList, remProcs, remHandles );
MB_CHK_ERR(
error );
2389 std::vector< EntityHandle > LEList, REList;
2390 LEList.insert( LEList.end(), localbuffers[i].begin() + msgsz[1] + 1,
2391 localbuffers[i].begin() + msgsz[1] + msgsz[3] );
2392 REList.insert( REList.end(), remotebuffers[i].begin() + msgsz[1] + 1,
2393 remotebuffers[i].begin() + msgsz[1] + msgsz[3] );
2395 error = decipher_remote_handles_edge( sharedprocs[i], msgsz[2], LEList, REList, remProcs, remHandles );
MB_CHK_ERR(
error );
2400 std::vector< EntityHandle > LVList, RVList;
2401 LVList.insert( LVList.end(), localbuffers[i].begin() + msgsz[1] + msgsz[3] + 1,
2402 localbuffers[i].begin() + msgsz[1] + msgsz[3] + msgsz[5] );
2403 RVList.insert( RVList.end(), remotebuffers[i].begin() + msgsz[1] + msgsz[3] + 1,
2404 remotebuffers[i].begin() + msgsz[1] + msgsz[3] + msgsz[5] );
2406 error = decipher_remote_handles_vertex( sharedprocs[i], msgsz[4], LVList, RVList, remProcs,
2410 else if( msgsz[4] != 0 )
2413 std::vector< EntityHandle > LVList, RVList;
2414 LVList.insert( LVList.end(), localbuffers[i].begin() + msgsz[1] + 1,
2415 localbuffers[i].begin() + msgsz[1] + msgsz[5] );
2416 RVList.insert( RVList.end(), remotebuffers[i].begin() + msgsz[1] + 1,
2417 remotebuffers[i].begin() + msgsz[1] + msgsz[5] );
2420 decipher_remote_handles_vertex( sharedprocs[i], msgsz[4], LVList, RVList, remProcs, remHandles );
MB_CHK_ERR(
error );
2424 else if( msgsz[2] != 0 )
2427 std::vector< EntityHandle > LEList, REList;
2428 LEList.insert( LEList.end(), localbuffers[i].begin(), localbuffers[i].begin() + msgsz[3] );
2429 REList.insert( REList.end(), remotebuffers[i].begin(), remotebuffers[i].begin() + msgsz[3] );
2431 error = decipher_remote_handles_edge( sharedprocs[i], msgsz[2], LEList, REList, remProcs, remHandles );
MB_CHK_ERR(
error );
2436 std::vector< EntityHandle > LVList, RVList;
2437 LVList.insert( LVList.end(), localbuffers[i].begin() + msgsz[3] + 1,
2438 localbuffers[i].begin() + msgsz[3] + msgsz[5] );
2439 RVList.insert( RVList.end(), remotebuffers[i].begin() + msgsz[3] + 1,
2440 remotebuffers[i].begin() + msgsz[3] + msgsz[5] );
2443 decipher_remote_handles_vertex( sharedprocs[i], msgsz[4], LVList, RVList, remProcs, remHandles );
MB_CHK_ERR(
error );
2447 else if( msgsz[4] != 0 )
2450 std::vector< EntityHandle > LVList, RVList;
2451 LVList.insert( LVList.end(), localbuffers[i].begin(), localbuffers[i].end() );
2452 RVList.insert( RVList.end(), remotebuffers[i].begin(), remotebuffers[i].end() );
2454 error = decipher_remote_handles_vertex( sharedprocs[i], msgsz[4], LVList, RVList, remProcs, remHandles );
MB_CHK_ERR(
error );
2457 MB_SET_ERR( MB_FAILURE,
"Trying to decipher entities other than verts, edges, faces" );
2463 ErrorCode NestedRefine::decipher_remote_handles_face(
int shared_proc,
2465 std::vector< EntityHandle >& localFaceList,
2466 std::vector< EntityHandle >& remFaceList,
2467 std::multimap< EntityHandle, int >& remProcs,
2468 std::multimap< EntityHandle, EntityHandle >& remHandles )
2472 for(
int i = 0; i < numfaces; i++ )
2477 ( std::find( remFaceList.begin(), remFaceList.begin() + numfaces - 1, Lface ) ) - remFaceList.begin();
2480 std::vector< EntityHandle > Lface_conn, Rface_conn;
2481 error = get_data_from_buff( 2, 1, 0, i, numfaces, localFaceList, Lface_conn );
MB_CHK_ERR(
error );
2482 error = get_data_from_buff( 2, 1, 0, Rface_idx, numfaces, remFaceList, Rface_conn );
MB_CHK_ERR(
error );
2485 std::vector< int > cmap;
2487 int nvF = (int)Lface_conn.size();
2491 std::vector< EntityHandle > lchildents, lparents;
2492 std::vector< EntityHandle > lcents, rcents;
2495 for(
int l = 0; l <
nlevels; l++ )
2503 error = get_data_from_buff( 2, 0, l + 1, i, numfaces, localFaceList, lchildents );
MB_CHK_ERR(
error );
2508 lparents.push_back( Lface );
2512 error = get_data_from_buff( 2, 0, l, i, numfaces, localFaceList, lparents );
MB_CHK_ERR(
error );
2519 std::vector< int > fmap;
2523 for(
int j = 0; j < (int)lparents.size(); j++ )
2526 lidx = std::find( localFaceList.begin(), localFaceList.end(), lparents[j] ) - localFaceList.begin();
2527 error = get_data_from_buff( 2, 0, l + 1, lidx, numfaces, localFaceList, lcents );
MB_CHK_ERR(
error );
2531 error = check_for_parallelinfo( lparents[j], shared_proc, remHandles, remProcs, rparent );
MB_CHK_ERR(
error );
2532 ridx = std::find( remFaceList.begin(), remFaceList.end(), rparent ) - remFaceList.begin();
2533 error = get_data_from_buff( 2, 0, l + 1, ridx, numfaces, remFaceList, rcents );
MB_CHK_ERR(
error );
2536 std::vector< EntityHandle > lconn, rconn, ledg, redg;
2537 for(
int k = 0; k < nch; k++ )
2545 bool found = check_for_parallelinfo( lcents[k], shared_proc, remProcs );
2548 remProcs.insert( std::pair< EntityHandle, int >( lcents[k], shared_proc ) );
2549 remHandles.insert( std::pair< EntityHandle, EntityHandle >( lcents[k], rcents[fmap[k]] ) );
2553 lidx = std::find( localFaceList.begin(), localFaceList.end(), lcents[k] ) - localFaceList.begin();
2554 ridx = std::find( remFaceList.begin(), remFaceList.end(), rcents[fmap[k]] ) - remFaceList.begin();
2557 error = get_data_from_buff( 2, 2, l + 1, lidx, numfaces, localFaceList, ledg );
MB_CHK_ERR(
error );
2558 error = get_data_from_buff( 2, 1, l + 1, lidx, numfaces, localFaceList, lconn );
MB_CHK_ERR(
error );
2559 error = get_data_from_buff( 2, 2, l + 1, ridx, numfaces, remFaceList, redg );
MB_CHK_ERR(
error );
2560 error = get_data_from_buff( 2, 1, l + 1, ridx, numfaces, remFaceList, rconn );
MB_CHK_ERR(
error );
2564 for(
int m = 0; m < (int)ledg.size(); m++ )
2566 found = check_for_parallelinfo( ledg[m], shared_proc, remProcs );
2570 remProcs.insert( std::pair< EntityHandle, int >( ledg[m], shared_proc ) );
2571 remHandles.insert( std::pair< EntityHandle, EntityHandle >( ledg[m], redg[cmap[m]] ) );
2574 found = check_for_parallelinfo( lconn[m], shared_proc, remProcs );
2578 remProcs.insert( std::pair< EntityHandle, int >( lconn[m], shared_proc ) );
2579 remHandles.insert( std::pair< EntityHandle, EntityHandle >( lconn[m], rconn[cmap[m]] ) );
2590 ErrorCode NestedRefine::decipher_remote_handles_edge(
int shared_proc,
2592 std::vector< EntityHandle >& localEdgeList,
2593 std::vector< EntityHandle >& remEdgeList,
2594 std::multimap< EntityHandle, int >& remProcs,
2595 std::multimap< EntityHandle, EntityHandle >& remHandles )
2599 for(
int i = 0; i < numedges; i++ )
2603 ( std::find( remEdgeList.begin(), remEdgeList.begin() + numedges - 1, Ledge ) ) - remEdgeList.begin();
2605 std::vector< EntityHandle > Ledge_conn, Redge_conn;
2606 error = get_data_from_buff( 1, 1, 0, i, numedges, localEdgeList, Ledge_conn );
MB_CHK_ERR(
error );
2607 error = get_data_from_buff( 1, 1, 0, Redge_idx, numedges, remEdgeList, Redge_conn );
MB_CHK_ERR(
error );
2610 if( ( Ledge_conn[0] == Redge_conn[1] ) && ( Ledge_conn[1] == Redge_conn[0] ) ) orient =
false;
2612 if( orient ) assert( ( Ledge_conn[0] == Redge_conn[0] ) && ( Ledge_conn[1] == Redge_conn[1] ) );
2614 std::vector< EntityHandle > lchildEdgs, rchildEdgs, lconn, rconn;
2615 for(
int l = 0; l <
nlevels; l++ )
2619 error = get_data_from_buff( 1, 0, l + 1, i, numedges, localEdgeList, lchildEdgs );
MB_CHK_ERR(
error );
2620 error = get_data_from_buff( 1, 0, l + 1, Redge_idx, numedges, remEdgeList, rchildEdgs );
MB_CHK_ERR(
error );
2622 int nchd = lchildEdgs.size();
2625 for(
int j = 0; j < nchd; j++ )
2628 bool found = check_for_parallelinfo( lchildEdgs[j], shared_proc, remProcs );
2631 remProcs.insert( std::pair< EntityHandle, int >( lchildEdgs[j], shared_proc ) );
2632 remHandles.insert( std::pair< EntityHandle, EntityHandle >( lchildEdgs[j], rchildEdgs[j] ) );
2640 std::find( localEdgeList.begin(), localEdgeList.end(), lchildEdgs[j] ) - localEdgeList.begin();
2641 int ridx = std::find( remEdgeList.begin(), remEdgeList.end(), rchildEdgs[j] ) - remEdgeList.begin();
2643 error = get_data_from_buff( 1, 1, l + 1, lidx, numedges, localEdgeList, lconn );
MB_CHK_ERR(
error );
2644 error = get_data_from_buff( 1, 1, l + 1, ridx, numedges, remEdgeList, rconn );
MB_CHK_ERR(
error );
2646 found = check_for_parallelinfo( lconn[0], shared_proc, remProcs );
2649 remProcs.insert( std::pair< EntityHandle, int >( lconn[0], shared_proc ) );
2650 remHandles.insert( std::pair< EntityHandle, EntityHandle >( lconn[0], rconn[0] ) );
2652 found = check_for_parallelinfo( lconn[1], shared_proc, remProcs );
2655 remProcs.insert( std::pair< EntityHandle, int >( lconn[1], shared_proc ) );
2656 remHandles.insert( std::pair< EntityHandle, EntityHandle >( lconn[1], rconn[0] ) );
2663 for(
int j = 0; j < nchd; j++ )
2666 bool found = check_for_parallelinfo( lchildEdgs[j], shared_proc, remProcs );
2670 remProcs.insert( std::pair< EntityHandle, int >( lchildEdgs[j], shared_proc ) );
2672 std::pair< EntityHandle, EntityHandle >( lchildEdgs[j], rchildEdgs[nchd - j - 1] ) );
2680 std::find( localEdgeList.begin(), localEdgeList.end(), lchildEdgs[j] ) - localEdgeList.begin();
2681 int ridx = std::find( remEdgeList.begin(), remEdgeList.end(), rchildEdgs[nchd - j - 1] ) -
2682 remEdgeList.begin();
2684 error = get_data_from_buff( 1, 1, l + 1, lidx, numedges, localEdgeList, lconn );
MB_CHK_ERR(
error );
2685 error = get_data_from_buff( 1, 1, l + 1, ridx, numedges, remEdgeList, rconn );
MB_CHK_ERR(
error );
2686 found = check_for_parallelinfo( lconn[0], shared_proc, remProcs );
2690 remProcs.insert( std::pair< EntityHandle, int >( lconn[0], shared_proc ) );
2691 remHandles.insert( std::pair< EntityHandle, EntityHandle >( lconn[0], rconn[1] ) );
2694 found = check_for_parallelinfo( lconn[1], shared_proc, remProcs );
2697 remProcs.insert( std::pair< EntityHandle, int >( lconn[1], shared_proc ) );
2698 remHandles.insert( std::pair< EntityHandle, EntityHandle >( lconn[1], rconn[1] ) );
2708 ErrorCode NestedRefine::decipher_remote_handles_vertex(
int shared_proc,
2710 std::vector< EntityHandle >& localVertexList,
2711 std::vector< EntityHandle >& remVertexList,
2712 std::multimap< EntityHandle, int >& remProcs,
2713 std::multimap< EntityHandle, EntityHandle >& remHandles )
2721 for(
int i = 0; i < numverts; i++ )
2725 ( std::find( remVertexList.begin(), remVertexList.begin() + numverts - 1, v ) ) - remVertexList.begin();
2727 std::vector< EntityHandle > lverts, rverts;
2728 for(
int l = 0; l <
nlevels; l++ )
2730 error = get_data_from_buff( 0, 0, l + 1, i, numverts, localVertexList, lverts );
MB_CHK_ERR(
error );
2731 error = get_data_from_buff( 0, 0, l + 1, Rvert_idx, numverts, remVertexList, rverts );
MB_CHK_ERR(
error );
2733 bool found = check_for_parallelinfo( lverts[0], shared_proc, remProcs );
2736 remProcs.insert( std::pair< EntityHandle, int >( lverts[0], shared_proc ) );
2737 remHandles.insert( std::pair< EntityHandle, EntityHandle >( lverts[0], rverts[0] ) );
2745 ErrorCode NestedRefine::update_parallel_tags( std::multimap< EntityHandle, int >& remProcs,
2746 std::multimap< EntityHandle, EntityHandle >& remHandles )
2750 std::vector< int > rprocs;
2751 std::vector< EntityHandle > rhandles;
2753 std::multimap< EntityHandle, int >::iterator it;
2754 std::pair< std::multimap< EntityHandle, int >::iterator, std::multimap< EntityHandle, int >::iterator > it_procs;
2755 std::pair< std::multimap< EntityHandle, EntityHandle >::iterator,
2756 std::multimap< EntityHandle, EntityHandle >::iterator >
2759 it = remProcs.begin();
2760 while( it != remProcs.end() )
2766 it_procs = remProcs.equal_range( entity );
2767 it_handles = remHandles.equal_range( entity );
2769 for( std::multimap< EntityHandle, int >::iterator pit = it_procs.first; pit != it_procs.second; pit++ )
2770 rprocs.push_back( pit->second );
2771 for( std::multimap< EntityHandle, EntityHandle >::iterator pit = it_handles.first; pit != it_handles.second;
2773 rhandles.push_back( pit->second );
2777 it = remProcs.upper_bound( it->first );
2783 ErrorCode NestedRefine::get_data_from_buff(
int listtype,
2788 std::vector< EntityHandle >&
buffer,
2789 std::vector< EntityHandle >& data )
2815 int start, end, toadd, prev;
2816 start = end = entity_index;
2817 toadd = prev = nentities;
2818 for(
int i = 0; i < level; i++ )
2822 start = start * nch;
2823 end = end * nch + nch - 1;
2834 int num_child = end - start + 1;
2835 data.reserve( num_child );
2837 for(
int i = start; i <= end; i++ )
2840 data.push_back(
child );
2843 else if( datatype == 1 )
2848 int toadd = nentities, prev = nentities;
2849 for(
int i = 0; i <
nlevels; i++ )
2857 for(
int i = 0; i < nepf; i++ )
2858 data.push_back(
buffer[toadd + nepf * entity_index + i] );
2860 else if( datatype == 2 )
2865 int toadd = nentities, prev = nentities;
2866 for(
int i = 0; i <
nlevels; i++ )
2873 toadd += toadd * nepf;
2875 for(
int i = 0; i < nepf; i++ )
2876 data.push_back(
buffer[toadd + nepf * entity_index + i] );
2879 MB_SET_ERR( MB_FAILURE,
"Requesting invalid info from buffer for faces" );
2881 else if( listtype == 1 )
2886 int start, end, toadd, prev;
2887 start = end = entity_index;
2888 toadd = prev = nentities;
2889 for(
int i = 0; i < level; i++ )
2893 start = start * nch;
2894 end = end * nch + nch - 1;
2906 int num_child = end - start + 1;
2907 data.reserve( num_child );
2909 for(
int i = start; i <= end; i++ )
2912 data.push_back(
child );
2915 else if( datatype == 1 )
2917 int toadd = nentities, prev = nentities;
2918 for(
int i = 0; i <
nlevels; i++ )
2926 data.push_back(
buffer[toadd + 2 * entity_index] );
2927 data.push_back(
buffer[toadd + 2 * entity_index + 1] );
2930 MB_SET_ERR( MB_FAILURE,
"Requesting invalid info from buffer for edges" );
2932 else if( listtype == 0 )
2937 int idx = level * nentities + entity_index;
2938 data.push_back(
buffer[idx] );
2941 MB_SET_ERR( MB_FAILURE,
"Requesting invalid info from buffer for vertices" );
2944 MB_SET_ERR( MB_FAILURE,
"Requesting invalid info from buffer" );
2949 bool NestedRefine::check_for_parallelinfo(
EntityHandle entity,
int proc, std::multimap< EntityHandle, int >& remProcs )
2953 std::pair< std::multimap< EntityHandle, int >::iterator, std::multimap< EntityHandle, int >::iterator > it_hes;
2954 it_hes = remProcs.equal_range( entity );
2956 for( std::multimap< EntityHandle, int >::iterator it = it_hes.first; it != it_hes.second; ++it )
2958 if( it->second == proc )
2970 std::multimap< EntityHandle, EntityHandle >& remHandles,
2971 std::multimap< EntityHandle, int >& remProcs,
2975 std::pair< std::multimap< EntityHandle, int >::iterator, std::multimap< EntityHandle, int >::iterator > it_ps;
2976 it_ps = remProcs.equal_range( entity );
2979 std::pair< std::multimap< EntityHandle, EntityHandle >::iterator,
2980 std::multimap< EntityHandle, EntityHandle >::iterator >
2982 it_hs = remHandles.equal_range( entity );
2984 std::multimap< EntityHandle, int >::iterator itp;
2985 std::multimap< EntityHandle, EntityHandle >::iterator ith;
2987 for( itp = it_ps.first, ith = it_hs.first; itp != it_ps.second; ++itp, ++ith )
2989 if( itp->second == proc )
2991 rhandle = ith->second;
3013 int nhf = 0, nv = 0, total_new_verts = 0;
3037 std::vector< EntityHandle > ent;
3038 std::vector< int > lid;
3041 for(
int i = 0; i < total_new_verts; i++ )
3048 if( ent[0] )
continue;
3051 ent[0] = ent_buffer[id];
3058 for(
int i = 0; i < etotal; i++ )
3060 std::vector< EntityHandle > sib_entids( nhf );
3061 std::vector< int > sib_lids( nhf );
3065 for(
int l = 0; l < nhf; l++ )
3067 if( sib_entids[l] )
continue;
3073 sib_entids[l] = ent_buffer[
id - 1];
3085 for(
int l = 0; l < nhf; l++ )
3107 assert( type !=
MBTET );
3121 assert( pattern_ids == NULL );
3126 assert( pattern_ids == NULL );
3129 else if( type ==
MBHEX )
3131 assert( pattern_ids == NULL );
3134 else if( type ==
MBTET )
3136 assert( pattern_ids != NULL );
3157 int nhf, nchilds, nverts_prev, nents_prev;
3171 std::vector< EntityHandle > inci_ent, child_ents;
3172 std::vector< int > inci_lid, child_lids;
3175 for(
int i = 0; i < nverts_prev; i++ )
3194 int lvid =
get_local_vid( vid, inci_ent[0], cur_level - 1 );
3195 if( lvid < 0 )
MB_SET_ERR( MB_FAILURE,
"did not find local vertex ix " );
3204 int ind = nchilds * pid;
3206 child_ents.push_back(
level_mesh[cur_level].start_edge + ind + chid );
3207 child_lids.push_back(
refTemplates[0][d].v2hf[lvid][1] );
3213 for(
int i = 0; i < nents_prev; i++ )
3221 std::vector< EntityHandle > sib_entids( nhf );
3222 std::vector< int > sib_lids( nhf );
3228 for(
int l = 0; l < nhf; l++ )
3230 if( !sib_entids[l] )
continue;
3239 std::vector< EntityHandle > sib_childs( nhf );
3240 std::vector< int > sib_chlids( nhf );
3245 if( sib_childs[ch_lid] )
continue;
3254 int plid = sib_lids[l];
3257 idx = nchilds * psib;
3260 int psib_chlid = plid;
3263 sib_childs[ch_lid] = psib_child;
3264 sib_chlids[ch_lid] = psib_chlid;
3277 int nhf, nchilds, nents_prev;
3291 std::vector< EntityHandle > conn;
3292 for(
int i = 0; i < nents_prev; i++ )
3304 std::vector< EntityHandle > inci_ent, child_ents;
3305 std::vector< int > inci_lid, child_lids;
3306 for(
int j = 0; j < 2; j++ )
3322 if( inci_ent[0] != 0 )
continue;
3328 int lvid =
get_local_vid( conn[j], inci_ent[0], cur_level - 1 );
3329 if( lvid < 0 )
MB_SET_ERR( MB_FAILURE,
"did not find local vertex ix " );
3338 int ind = nchilds * pid;
3340 child_ents.push_back(
level_mesh[cur_level].start_edge + ind + chid );
3341 child_lids.push_back(
refTemplates[0][d].v2hf[lvid][1] );
3346 std::vector< EntityHandle > sib_entids( nhf );
3347 std::vector< int > sib_lids( nhf );
3353 for(
int l = 0; l < nhf; l++ )
3355 if( !sib_entids[l] )
continue;
3364 std::vector< EntityHandle > sib_childs( nhf );
3365 std::vector< int > sib_chlids( nhf );
3370 if( sib_childs[ch_lid] )
continue;
3379 int plid = sib_lids[l];
3382 idx = nchilds * psib;
3385 int psib_chlid = plid;
3388 sib_childs[ch_lid] = psib_child;
3389 sib_chlids[ch_lid] = psib_chlid;
3413 int nhf, nchilds, nverts_prev, nents_prev;
3430 std::vector< EntityHandle > inci_ent, child_ents;
3431 std::vector< int > inci_lid, child_lids;
3434 for(
int i = 0; i < nverts_prev; i++ )
3453 for(
int j = 0; j < (int)inci_ent.size(); j++ )
3455 int lvid =
get_local_vid( vid, inci_ent[j], cur_level - 1 );
3456 if( lvid < 0 )
MB_SET_ERR( MB_FAILURE,
"did not find local vertex ix " );
3465 int ind = nchilds * pid;
3467 child_ents.push_back(
level_mesh[cur_level].start_face + ind + chid );
3468 child_lids.push_back(
refTemplates[type - 1][d].v2hf[lvid][1] );
3476 for(
int i = 0; i < nents_prev; i++ )
3484 std::vector< EntityHandle > fid_conn;
3488 std::vector< EntityHandle > sib_entids( nhf );
3489 std::vector< int > sib_lids( nhf );
3495 for(
int l = 0; l < nhf; l++ )
3497 if( !sib_entids[l] )
continue;
3500 fedge[0] = fid_conn[l];
3501 fedge[1] = fid_conn[nidx];
3504 int slid = sib_lids[l];
3506 std::vector< EntityHandle > conn;
3512 if( ( fedge[1] == conn[slid] ) && ( fedge[0] == conn[nidx] ) ) orient =
false;
3514 if( orient ) assert( ( fedge[0] == conn[slid] ) && ( fedge[1] == conn[nidx] ) );
3521 for(
int k = 0; k < nch; k++ )
3532 if( child_sibent != 0 )
continue;
3548 int sidx = nchilds * psib;
3551 int psib_chlid = plid;
3567 int nhf, nchilds, nents_prev;
3579 for(
int i = 0; i < nents_prev; i++ )
3587 std::vector< EntityHandle > fid_conn;
3591 std::vector< EntityHandle > inci_ent, child_ents;
3592 std::vector< int > inci_lid, child_lids;
3595 for(
int j = 0; j < nhf; j++ )
3609 if( inci_ent[0] != 0 )
continue;
3615 for(
int k = 0; k < (int)inci_ent.size(); k++ )
3617 int lvid =
get_local_vid( fid_conn[j], inci_ent[k], cur_level - 1 );
3618 if( lvid < 0 )
MB_SET_ERR( MB_FAILURE,
"did not find local vertex ix " );
3627 int ind = nchilds * pid;
3629 child_ents.push_back(
level_mesh[cur_level].start_face + ind + chid );
3630 child_lids.push_back(
refTemplates[type - 1][d].v2hf[lvid][1] );
3637 std::vector< EntityHandle > sib_entids( nhf );
3638 std::vector< int > sib_lids( nhf );
3644 for(
int l = 0; l < nhf; l++ )
3646 if( !sib_entids[l] )
continue;
3649 fedge[0] = fid_conn[l];
3650 fedge[1] = fid_conn[nidx];
3653 int slid = sib_lids[l];
3655 std::vector< EntityHandle > conn;
3658 assert( (
int)conn.size() > nidx && (
int)conn.size() > slid );
3662 if( ( fedge[1] == conn[slid] ) && ( fedge[0] == conn[nidx] ) ) orient =
false;
3664 if( orient ) assert( ( fedge[0] == conn[slid] ) && ( fedge[1] == conn[nidx] ) );
3671 for(
int k = 0; k < nch; k++ )
3682 if( child_sibent != 0 )
continue;
3698 int sidx = nchilds * psib;
3701 int psib_chlid = plid;
3715 int nvpc, ne, nhf, nchilds, nverts_prev, nents_prev;
3737 std::vector< EntityHandle > inci_ent, child_ents;
3738 std::vector< int > inci_lid, child_lids;
3741 for(
int i = 0; i < nverts_prev; i++ )
3760 for(
int j = 0; j < (int)inci_ent.size(); j++ )
3762 int lvid =
get_local_vid( vid, inci_ent[j], cur_level - 1 );
3763 if( lvid < 0 )
MB_SET_ERR( MB_FAILURE,
"did not find local vertex ix " );
3772 int ind = nchilds * pid;
3776 child_ents.push_back(
level_mesh[cur_level].start_cell + ind + chid );
3777 child_lids.push_back(
refTemplates[type - 1][d].v2hf[lvid][1] );
3786 for(
int i = 0; i < nents_prev; i++ )
3794 std::vector< EntityHandle > sib_entids( nhf );
3795 std::vector< int > sib_lids( nhf );
3801 for(
int l = 0; l < nhf; l++ )
3804 if( !sib_entids[l] )
continue;
3809 pat_id = ( *pattern_ids )[i];
3815 std::vector< int > id_sib( nch );
3816 for(
int k = 0; k < nch; k++ )
3828 int plid = sib_lids[l];
3829 int sidx = nchilds * psib;
3832 sibpat_id = ( *pattern_ids )[psib];
3834 sibpat_id = type - 1;
3839 for(
int k = 0; k < nch; k++ )
3850 if( child_sibent != 0 )
continue;
3858 int psib_chlid = plid;
3874 for(
int l = 0; l < ne; l++ )
3881 bool visited =
false;
3883 std::vector< EntityHandle > inci_ent1, inci_ent2;
3884 std::vector< int > inci_lid1, inci_lid2;
3888 if( inci_ent1.size() > 1 && inci_ent2.size() > 1 )
3890 std::vector< EntityHandle > cell_comps;
3891 std::vector< int > leid_comps;
3895 int ncomps = cell_comps.size();
3896 std::vector< EntityHandle > edgverts;
3897 std::vector< EntityHandle > compchildents( nv * ncomps );
3898 std::vector< int > compchildlfids( nv * ncomps );
3900 for(
int s = 0; s < nv * ncomps; s++ )
3902 compchildents[s] = 0;
3903 compchildlfids[s] = 0;
3906 for(
int j = 0; j < (int)cell_comps.size(); j++ )
3914 for(
int k = 0; k < nv; k++ )
3933 if( edgverts.empty() )
3935 edgverts.push_back( vert );
3936 compchildents[0] = childcell;
3937 compchildlfids[0] = lfid;
3941 std::vector< EntityHandle >::iterator it;
3942 it = find( edgverts.begin(), edgverts.end(), vert );
3943 int indx = it - edgverts.begin();
3945 if( it == edgverts.end() )
3947 edgverts.push_back( vert );
3948 compchildents[k * ncomps] = childcell;
3949 compchildlfids[k * ncomps] = lfid;
3953 compchildents[indx * ncomps + j] = childcell;
3954 compchildlfids[indx * ncomps + j] = lfid;
3966 for(
int k = 0; k < nv; k++ )
3968 std::vector< EntityHandle > set_childents;
3969 std::vector< int > set_childlfids;
3970 for(
int j = 0; j < ncomps; j++ )
3972 set_childents.push_back( compchildents[k * ncomps + j] );
3973 set_childlfids.push_back( compchildlfids[k * ncomps + j] );
3989 std::vector< int >& child_ids,
3990 std::vector< int >& child_lvids )
4002 for(
int i = 0; i < nch; i++ )
4005 for(
int j = 0; j < nvpc; j++ )
4008 for(
int k = 0; k < nv; k++ )
4010 if( lv ==
refTemplates[type - 1][d].vert_on_edges[leid][k] )
4012 child_ids.push_back(
id );
4013 child_lvids.push_back( j );
4031 std::vector< EntityHandle > ent;
4032 std::vector< int > lid;
4045 MB_SET_ERR( MB_FAILURE,
"Requesting vertex boundary information for an unsupported entity type" );
4050 return ( sibents[lid[0]] == 0 );
4056 bool is_border =
false;
4062 for(
int i = 0; i < 2; i++ )
4064 if( sibents[i] == 0 )
4073 std::vector< EntityHandle > adjents;
4075 if( adjents.size() == 1 ) is_border =
true;
4079 std::vector< EntityHandle > adjents;
4080 std::vector< int > leids;
4082 assert( !adjents.empty() );
4087 for(
int i = 0; i < (int)adjents.size(); i++ )
4092 for(
int k = 0; k < 2; k++ )
4095 if( sibents[hf] == 0 )
4109 bool is_border =
false;
4112 MB_SET_ERR( MB_FAILURE,
"Requesting boundary information for a face entity type on a curve mesh" );
4120 for(
int i = 0; i < nepf; i++ )
4122 if( sibents[i] == 0 )
4131 std::vector< EntityHandle > adjents;
4133 if( adjents.size() == 1 ) is_border =
true;
4141 MB_SET_ERR( MB_FAILURE,
"Requesting boundary information for a cell entity type on a curve or surface mesh" );
4143 bool is_border =
false;
4151 for(
int i = 0; i < nfpc; i++ )
4153 if( sibents[i] == 0 )
4172 for(
int i = 0; i < nverts_prev; i++ )
4182 std::vector< double > vcoords( 3 * nverts_in );
4185 for(
int i = 0; i < nverts_in; i++ )
4199 std::vector< EntityHandle >& trackvertsC_edg,
4200 std::vector< EntityHandle >& trackvertsC_face,
4214 int cindex = cell_type - 1;
4225 for(
int i = 0; i < nepc; i++ )
4228 for(
int j = 0; j < nve; j++ )
4231 int idx = cid - cstart_prev;
4232 int aid = idx * nve * nepc + nve * i + j;
4234 if( !trackvertsC_edg[aid] ) trackvertsC_edg[aid] = vbuffer[id];
4238 std::vector< EntityHandle > inc_cids;
4239 std::vector< int > inc_leids, inc_orient;
4243 if( inc_cids.size() == 1 )
continue;
4246 for(
int k = 0; k < (int)inc_cids.size(); k++ )
4248 if( inc_cids[k] == cid )
continue;
4250 int idx = inc_cids[k] - cstart_prev;
4254 for(
int j = 0; j < nve; j++ )
4257 int aid = idx * nve * nepc + nve * inc_leids[k] + j;
4259 if( !trackvertsC_edg[aid] ) trackvertsC_edg[aid] = vbuffer[id];
4264 for(
int j = 0; j < nve; j++ )
4267 int aid = idx * nve * nepc + nve * inc_leids[k] + j;
4269 if( !trackvertsC_edg[aid] ) trackvertsC_edg[aid] = vbuffer[id];
4279 for(
int i = 0; i < nfpc; i++ )
4282 std::vector< EntityHandle > face_vbuf( nvf, 0 );
4283 for(
int j = 0; j < nvf; j++ )
4286 int idx = cid - cstart_prev;
4287 int aid = idx * nvf * nfpc + nvf * i + j;
4289 if( !trackvertsC_face[aid] ) trackvertsC_face[aid] = vbuffer[id];
4291 face_vbuf[j] = vbuffer[id];
4295 std::vector< EntityHandle > sib_cids;
4296 std::vector< int > sib_lfids;
4299 if( sib_cids.size() == 1 )
continue;
4302 std::vector< int > id_sib( nvf );
4303 for(
int k = 0; k < nvf; k++ )
4310 for(
int j = 0; j < nvf; j++ )
4312 int idx = sib_cids[1] - cstart_prev;
4313 int aid = idx * nvf * nfpc + nvf * sib_lfids[1] + j;
4315 if( !trackvertsC_face[aid] ) trackvertsC_face[aid] = face_vbuf[id_sib[j] - 1];
4335 assert( deg == 2 || deg == 3 );
4342 if( !index && ( ( nvF == 3 && deg == 3 ) || ( nvF == 4 && deg == 2 ) ) )
4349 std::vector< EntityHandle > conn, sib_conn;
4355 std::vector< EntityHandle > lface( nvF );
4356 std::vector< EntityHandle > lface_sib( nvF );
4357 for(
int i = 0; i < nvF; i++ )
4360 lface[i] = conn[id];
4363 lface_sib[i] = sib_conn[id];
4368 for(
int i = 0; i < nco; i++ )
4371 for(
int j = 0; j < nvF; j++ )
4374 if( lface[j] == lface_sib[
id] ) count += 1;
4384 if( c > nco )
MB_SET_ERR( MB_FAILURE,
"Getting a combination number more than currently supported" );
4387 if( ( ( !index ) && ( nvF == 4 ) && ( deg == 3 ) ) || ( deg == 2 ) )
4389 for(
int i = 0; i < 4; i++ )
4394 for(
int i = 0; i < 9; i++ )
4406 std::vector< int >& lemap,
4407 std::vector< int >& vidx,
4414 for(
int i = 0; i < nco; i++ )
4417 for(
int j = 0; j < nvF; j++ )
4420 if( face1_conn[j] == face2_conn[
id] ) count += 1;
4430 if( c > nco )
MB_SET_ERR( MB_FAILURE,
"Getting a combination number more than currently supported" );
4433 lemap.reserve( nvF );
4434 for(
int i = 0; i < nvF; i++ )
4436 lemap.push_back(
permutation[nvF - 3].lemap[c][i] );
4440 if( nvF == 3 && deg == 2 )
return MB_SUCCESS;
4442 if( ( nvF == 3 && deg == 3 ) || ( nvF == 4 && deg == 2 ) )
4444 vidx.push_back( 1 );
4446 else if( nvF == 4 && deg == 3 )
4448 for(
int i = 0; i < 4; i++ )
4460 assert( deg == 2 || deg == 3 );
4465 for(
int i = 0; i < 4; i++ )
4466 childfid_map[i] =
permutation[nvF - 3].porder2[comb][i];
4470 for(
int i = 0; i < 9; i++ )
4471 childfid_map[i] =
permutation[nvF - 3].porder3[comb][i];
4490 for(
int i = 0; i < nco; i++ )
4493 for(
int j = 0; j < nvF; j++ )
4496 if( face1_conn[j] == face2_conn[
id] ) count += 1;
4506 if( c > nco )
MB_SET_ERR( MB_FAILURE,
"Getting a combination number more than currently supported" );
4512 for(
int j = 0; j < nvF; j++ )
4524 if( cur_level >= 0 )
4526 Range edges, faces, cells;
4546 int lid[6] = { 0, 0, 0, 0, 0, 0 };
4569 for(
int i = 0; i < 6; i++ )
4587 int diag_map[6] = { 1, 3, 2, 4, 5, 0 };
4588 double length = std::numeric_limits< double >::max();
4594 for(
int d = 0; d < 3; d++ )
4596 int id1 = diag_map[2 * d];
4597 int id2 = diag_map[2 * d + 1];
4598 x = coords[3 * id1] - coords[3 * id2];
4599 y = coords[3 * id1 + 1] - coords[3 * id2 + 1];
4600 z = coords[3 * id1 + 2] - coords[3 * id2 + 2];
4601 double dlen = sqrt( x * x + y * y + z * z );
4616 std::vector< EntityHandle > conn;
4622 for(
int i = 0; i < (int)conn.size(); i++ )
4624 if( conn[i] == vid )
4630 if( lid < 0 )
MB_SET_ERR( MB_FAILURE,
"Error in getting local vertex id in the given entity" );
4636 int d =
deg_index.find( degree )->second;