30 rval =
mb->get_connectivity( cells, verts );
MB_CHK_SET_ERR( rval,
"Failed to get connectivity" );
36 std::vector< double* > ccenters;
37 rval =
iface->get_node_coords( 3, cells.
size(), 0, startv, ccenters );
MB_CHK_SET_ERR( rval,
"Can't get node coords" );
41 std::vector< int > gids( cells.
size() );
42 rval =
mb->get_coords( cells, ccenters[0], ccenters[1], ccenters[2] );
MB_CHK_SET_ERR( rval,
"Failed to get coordinates" );
43 rval =
mb->tag_get_data( gidTag, cells, &gids[0] );
MB_CHK_SET_ERR( rval,
"Can't set global_id tag" );
46 rval =
mb->add_entities( dual_set, dualverts );
MB_CHK_SET_ERR( rval,
"Can't add entities" );
47 rval =
mb->tag_set_data( gidTag, dualverts, &gids[0] );
MB_CHK_SET_ERR( rval,
"Can't set global_id tag" );
49 #define CC( ind ) moab::CartVect( ccenters[0][ind], ccenters[1][ind], ccenters[2][ind] )
50 #define CCXMY( ind, cv ) \
51 moab::CartVect( ccenters[0][ind] - ( cv )[0], ccenters[1][ind] - ( cv )[1], ccenters[2][ind] - ( cv )[2] )
57 std::map< size_t, std::vector< moab::EntityHandle > > polygonConn;
63 std::vector< moab::EntityHandle > adjs;
65 rval =
mb->get_adjacencies( &vtx, 1, 2,
true, adjs );
MB_CHK_SET_ERR( rval,
"Failed to get adjacencies" );
66 const size_t nEdges = adjs.size();
69 rval =
mb->get_coords( &vtx, 1, vxyz );
MB_CHK_SET_ERR( rval,
"Failed to get coordinates" );
75 double dNode0Mag = node0.
length();
80 std::vector< double > dAngles;
81 dAngles.resize( nEdges );
84 for(
size_t j = 1; j < nEdges; j++ )
87 double dNodeDiffMag = nodeDiff.
length();
89 double dSide = nodeCross % nodeDiff;
90 double dDotNorm = ( node0 % nodeDiff ) / ( dNode0Mag * dNodeDiffMag );
98 dAngles[j] = acos( dDotNorm );
102 dAngles[j] = -dAngles[j] + 2.0 * M_PI;
106 std::vector< moab::EntityHandle >&
face = polygonConn[nEdges];
107 if(
face.size() == 0 )
face.reserve( nEdges * verts.
size() / 4 );
108 face.push_back( dualverts[adjs[0] - svtx] );
111 double dCurrentAngle = 0.0;
112 for(
size_t j = 1; j < nEdges; j++ )
115 double dNextAngle = 2.0 * M_PI;
117 for(
size_t k = 1; k < nEdges; k++ )
119 if( ( dAngles[k] > dCurrentAngle ) && ( dAngles[k] < dNextAngle ) )
122 dNextAngle = dAngles[k];
126 face.push_back( dualverts[adjs[ixNextNode] - svtx] );
127 dCurrentAngle = dNextAngle;
131 std::map< size_t, std::vector< moab::EntityHandle > >::iterator eit;
132 for( eit = polygonConn.begin(); eit != polygonConn.end(); ++eit )
134 const size_t nVPerE = eit->first;
135 const size_t nElePerType =
static_cast< int >( eit->second.size() / nVPerE );
143 std::copy( eit->second.begin(), eit->second.end(), conn );
147 moab::Range mbcells( starte, starte + nElePerType - 1 );
148 dualcells.
merge( mbcells );
152 rval =
mb->add_entities( dual_set, dualcells );
MB_CHK_SET_ERR( rval,
"Can't add polygonal entities" );
155 assert( dualcells.
size() == verts.
size() );
156 gids.resize( verts.
size() );
157 rval =
mb->tag_get_data( gidTag, verts, &gids[0] );
MB_CHK_SET_ERR( rval,
"Can't set global_id tag" );
158 if( gids[0] == gids[1] && gids[0] < 0 )
163 rval = pcomm.assign_global_ids( dual_set, 2, 1,
false,
true,
true );
MB_CHK_SET_ERR( rval,
"Can't assign global_ids" );
167 for(
size_t ix = 0; ix < gids.size(); ++ix )
171 rval =
mb->tag_set_data( gidTag, dualcells, &gids[0] );
MB_CHK_SET_ERR( rval,
"Can't set global_id tag" );
172 std::cout <<
"GIDs: " << gids[0] <<
" " << gids[1] <<
" " << gids[2] <<
" " << gids[3] <<
" " << gids[4] <<
" "
179 rval =
mb->delete_entities( cells );
MB_CHK_SET_ERR( rval,
"Can't remove entities" );
180 rval =
mb->delete_entities( verts );
MB_CHK_SET_ERR( rval,
"Can't remove entities" );