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 )
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" );
187 int main(
int argc,
char** argv )
194 if( NULL ==
mb )
return 1;
196 std::string inputFile = std::string(
MESH_DIR ) +
"/globalmpas_deltri.h5m";
197 opts.
addOpt< std::string >(
"inFile,i",
"Specify the input file name string ", &inputFile );
198 #ifdef MOAB_HAVE_HDF5
199 std::string outputFile =
"outDualMesh.h5m";
201 std::string outputFile =
"outDualMesh.vtk";
203 opts.
addOpt< std::string >(
"outFile,o",
"Specify the input file name string ", &outputFile );
212 const char* readopts =
"";
213 rval =
mb->load_file( inputFile.c_str(), &triangle_set, readopts );
MB_CHK_SET_ERR( rval,
"Failed to read" );
217 rval =
mb->get_entities_by_dimension( triangle_set, 2, cells );
MB_CHK_SET_ERR( rval,
"Failed to get cells" );
219 std::cout <<
"Original number of triangular cells : " << cells.
size() <<
"\n";
225 rval =
mb->write_file( outputFile.c_str() );
MB_CHK_SET_ERR( rval,
"Failed to write new file" );
228 rval =
mb->get_entities_by_dimension( dual_set, 2, cells );
MB_CHK_SET_ERR( rval,
"Failed to get cells" );
229 std::cout <<
"Wrote the dual mesh: " << outputFile <<
" containing " << cells.
size() <<
" polygonal cells\n";