Description: read a 2d mesh in plane, extrude to form layers of prisms (polyhedra)
To run: ./ExtrudePoly [meshfile] [outfile] [nlayers] [thickness_layer]
#include <iostream>
using namespace std;
#ifndef MESH_DIR
#define MESH_DIR "."
#endif
#define MAXEDGES 20
string output = string(
"polyhedra.vtk" );
int main(
int argc,
char** argv )
{
Interface*
mb =
new( std::nothrow ) Core;
if( NULL ==
mb )
return 1;
if( argc > 1 )
{
}
if( argc > 2 )
output = argv[2];
if( argc > 3 )
layers = atoi( argv[3] );
<< "\n";
Range verts;
Range faces;
rval =
mb->get_entities_by_dimension( 0, 2, faces );
MB_CHK_ERR( rval );
cout << "Number of vertices is " << verts.size() << endl;
cout << "Number of faces is " << faces.size() << endl;
Range edges;
cout << "Number of edges is " << edges.size() << endl;
std::vector< double > coords;
int nvPerLayer = (int)verts.size();
coords.resize( 3 * nvPerLayer );
rval =
mb->get_coords( verts, &coords[0] );
MB_CHK_ERR( rval );
Range* newVerts =
new Range[
layers + 1];
newVerts[0] = verts;
for(
int ii = 0; ii <
layers; ii++ )
{
for( int i = 0; i < nvPerLayer; i++ )
rval =
mb->create_vertices( &coords[0], nvPerLayer, newVerts[ii + 1] );
MB_CHK_ERR( rval );
}
int nquads = edges.size() *
layers;
ReadUtilIface* read_iface;
rval =
mb->query_interface( read_iface );
MB_CHK_SET_ERR( rval,
"Error in query_interface" );
rval = read_iface->get_element_connect( nquads, 4,
MBQUAD, 0, start_elem, connect );
MB_CHK_SET_ERR( rval,
"Error in get_element_connect" );
int nedges = (int)edges.size();
int indexConn = 0;
for( int j = 0; j < nedges; j++ )
{
int num_nodes;
int i0 = verts.index( conn2[0] );
int i1 = verts.index( conn2[1] );
for(
int ii = 0; ii <
layers; ii++ )
{
connect[indexConn++] = newVerts[ii][i0];
connect[indexConn++] = newVerts[ii][i1];
connect[indexConn++] = newVerts[ii + 1][i1];
connect[indexConn++] = newVerts[ii + 1][i0];
}
}
int nfaces = (int)faces.size();
for( int i = 0; i < nfaces; i++ )
allPolygons[i] = faces[i];
for( int j = 0; j < nfaces; j++ )
{
int num_nodes;
rval =
mb->get_connectivity( polyg, connp, num_nodes );
MB_CHK_ERR( rval );
for( int i = 0; i < num_nodes; i++ )
{
indexVerts[i] = verts.index( connp[i] );
int i1 = ( i + 1 ) % num_nodes;
Range adjEdges;
rval =
mb->get_adjacencies( edgeVerts, 2, 1,
false, adjEdges );
MB_CHK_ERR( rval );
if( adjEdges.size() < 1 )
MB_CHK_SET_ERR( MB_FAILURE,
" did not find edge " );
indexEdges[i] = edges.index( adjEdges[0] );
if( indexEdges[i] < 0 )
MB_CHK_SET_ERR( MB_FAILURE,
"did not find edge in range" );
}
for(
int ii = 0; ii <
layers; ii++ )
{
for( int i = 0; i < num_nodes; i++ )
newConn[i] = newVerts[ii + 1][indexVerts[i]];
rval =
mb->create_element(
MBPOLYGON, newConn, num_nodes, allPolygons[nfaces * ( ii + 1 ) + j] );
MB_CHK_ERR( rval );
polyhedronConn[0] = allPolygons[nfaces * ii + j];
polyhedronConn[1] = allPolygons[nfaces * ( ii + 1 ) + j];
for( int i = 0; i < num_nodes; i++ )
{
polyhedronConn[2 + i] = start_elem + ii +
layers * indexEdges[i];
}
}
}
return 0;
}