MOAB: Mesh Oriented datABase  (version 5.2.1)
makeops.cpp
Go to the documentation of this file.
00001 /*
00002  * Program to make hex modification operation meshes
00003  *
00004  */
00005 
00006 #include "moab/Core.hpp"
00007 #include "moab/Range.hpp"
00008 #include <iostream>
00009 
00010 using namespace moab;
00011 
00012 Interface* gMB = NULL;
00013 
00014 static ErrorCode make_atomic_pillow();
00015 static ErrorCode make_face_shrink();
00016 static ErrorCode make_face_open_collapse();
00017 static ErrorCode make_chord_push();
00018 static ErrorCode make_triple_chord_push();
00019 static ErrorCode make_triple_hex_push();
00020 
00021 enum OperationType
00022 {
00023     ATOMIC_PILLOW = 0,
00024     FACE_OPEN_COLLAPSE,
00025     FACE_SHRINK,
00026     CHORD_PUSH,
00027     MBTRIPLE_CHORD_PUSH,
00028     MBTRIPLE_HEX_PUSH,
00029     UNDEFINED
00030 };
00031 
00032 const char* OperationNames[] = { "atomic_pillow",     "face_open_collapse", "face_shrink", "chord_push",
00033                                  "triple_chord_push", "triple_hex_push",    "undefined" };
00034 
00035 int main( int argc, char** argv )
00036 {
00037     gMB                      = new Core();
00038     const char* extensions[] = { ".g", ".h5m", ".vtk" };
00039     int file_exten           = 1;
00040 
00041     std::vector< OperationType > op_types;
00042 
00043     if( argc < 2 )
00044     {
00045         std::cout << "Usage: " << argv[0] << " [-h5m] [-vtk] {-ap | -foc | -fs | -cp | -tcp | -thp}" << std::endl;
00046         return 1;
00047     }
00048 
00049     int current_arg = 1;
00050     while( current_arg < argc )
00051     {
00052         if( !strcmp( "-g", argv[current_arg] ) )
00053             file_exten = 0;
00054         else if( !strcmp( "-h5m", argv[current_arg] ) )
00055             file_exten = 1;
00056         else if( !strcmp( "-vtk", argv[current_arg] ) )
00057             file_exten = 2;
00058         else if( !strcmp( "-ap", argv[current_arg] ) )
00059             op_types.push_back( ATOMIC_PILLOW );
00060         else if( !strcmp( "-foc", argv[current_arg] ) )
00061             op_types.push_back( FACE_OPEN_COLLAPSE );
00062         else if( !strcmp( "-fs", argv[current_arg] ) )
00063             op_types.push_back( FACE_SHRINK );
00064         else if( !strcmp( "-cp", argv[current_arg] ) )
00065             op_types.push_back( CHORD_PUSH );
00066         else if( !strcmp( "-tcp", argv[current_arg] ) )
00067             op_types.push_back( MBTRIPLE_CHORD_PUSH );
00068         else if( !strcmp( "-thp", argv[current_arg] ) )
00069             op_types.push_back( MBTRIPLE_HEX_PUSH );
00070         current_arg++;
00071     }
00072 
00073     ErrorCode result = MB_SUCCESS, tmp_result = MB_FAILURE;
00074 
00075     for( std::vector< OperationType >::iterator vit = op_types.begin(); vit != op_types.end(); ++vit )
00076     {
00077         if( *vit == ATOMIC_PILLOW ) { tmp_result = make_atomic_pillow(); }
00078         else if( *vit == FACE_OPEN_COLLAPSE )
00079         {
00080             tmp_result = make_face_open_collapse();
00081         }
00082         else if( *vit == CHORD_PUSH )
00083         {
00084             tmp_result = make_chord_push();
00085         }
00086         else if( *vit == MBTRIPLE_CHORD_PUSH )
00087         {
00088             tmp_result = make_triple_chord_push();
00089         }
00090 
00091         else if( *vit == MBTRIPLE_HEX_PUSH )
00092         {
00093             tmp_result = make_triple_hex_push();
00094         }
00095         else if( *vit == FACE_SHRINK )
00096         {
00097             tmp_result = make_face_shrink();
00098         }
00099         else
00100         {
00101             std::cout << "Operation undefined." << std::endl;
00102             return 1;
00103         }
00104         if( MB_SUCCESS != tmp_result ) result = tmp_result;
00105 
00106         // now write to a file
00107         std::string filename( OperationNames[*vit] );
00108         filename.append( extensions[file_exten] );
00109         tmp_result = gMB->write_mesh( filename.c_str() );
00110         if( MB_SUCCESS != tmp_result ) result = tmp_result;
00111     }
00112 
00113     return ( result == MB_SUCCESS ? 0 : 1 );
00114 }
00115 
00116 ErrorCode make_atomic_pillow()
00117 {
00118     // make atomic pillow configuration
00119     // make all vertices
00120     double vtx_coord[] = { 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
00121                            .75, .75, 1.0, .75, .25, 1.0, .25, .25, 1.0, .25, .75, 1.0 };
00122 
00123     int connect[] = { 0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3 };
00124 
00125     ErrorCode result;
00126     EntityHandle vtx_handles[8];
00127 
00128     for( int i = 0; i < 8; i++ )
00129     {
00130         result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
00131     }
00132 
00133     EntityHandle conn[8], elems[4];
00134 
00135     // make the two hexes
00136     for( int i = 0; i < 8; i++ )
00137         conn[i] = vtx_handles[connect[i]];
00138     result = gMB->create_element( MBHEX, conn, 8, elems[0] );MB_CHK_ERR( result );
00139 
00140     for( int i = 0; i < 8; i++ )
00141         conn[i] = vtx_handles[connect[8 + i]];
00142     result = gMB->create_element( MBHEX, conn, 8, elems[1] );MB_CHK_ERR( result );
00143 
00144     // make one of the end quads explicitly and bind to the first hex
00145     for( int i = 0; i < 4; i++ )
00146         conn[i] = vtx_handles[connect[i]];
00147     result = gMB->create_element( MBQUAD, conn, 4, elems[2] );MB_CHK_ERR( result );
00148 
00149     result = gMB->add_adjacencies( elems[2], elems, 1, false );MB_CHK_ERR( result );
00150 
00151     // now the other one
00152     result = gMB->create_element( MBQUAD, conn, 4, elems[3] );MB_CHK_ERR( result );
00153 
00154     result = gMB->add_adjacencies( elems[3], &elems[1], 1, false );MB_CHK_ERR( result );
00155 
00156     return MB_SUCCESS;
00157 }
00158 
00159 ErrorCode make_face_shrink()
00160 {
00161     // make face shrink configuration
00162     // make all vertices
00163     double vtx_coord[] = { 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0,
00164                            0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 0.0, 2.0, 0.0, 0.0,
00165                            2.0, 0.0, 1.0, 2.0, .75, .75, 1.0, .75, .25, 1.0, .25, .25, 1.0, .25, .75, 1.0 };
00166 
00167     int connect[] = { 3, 7, 11, 15, 0, 4, 8,  12, 0, 4, 8, 12, 1,  5,  9,  13, 1,  5,  9,  13, 2, 6,  10, 14,
00168                       2, 6, 10, 14, 3, 7, 11, 15, 0, 3, 2, 1,  12, 15, 14, 13, 12, 15, 14, 13, 8, 11, 10, 9 };
00169 
00170     ErrorCode result;
00171     EntityHandle vtx_handles[16];
00172 
00173     for( int i = 0; i < 16; i++ )
00174     {
00175         result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
00176     }
00177 
00178     // make all elements at once
00179     EntityHandle conn[8], elems[6];
00180 
00181     for( int j = 0; j < 6; j++ )
00182     {
00183         for( int i = 0; i < 8; i++ )
00184             conn[i] = vtx_handles[connect[j * 8 + i]];
00185 
00186         result = gMB->create_element( MBHEX, conn, 8, elems[j] );MB_CHK_ERR( result );
00187     }
00188 
00189     return MB_SUCCESS;
00190 }
00191 
00192 ErrorCode make_face_open_collapse()
00193 {
00194     return MB_FAILURE;
00195 }
00196 
00197 ErrorCode make_chord_push()
00198 {
00199     // make chord push configuration
00200     // make all vertices
00201     double vtx_coord[] = { // first layer
00202                            0.0, 0.0, 0.5, 0.0, 1.0, 0.0, -1.0, 0.5, 0.0, -1.0, -0.5, 0.0, 0.0, -1.0, 0.0, 1.0, -0.5,
00203                            0.0, 1.0, 0.5, 0.0,
00204                            // second layer
00205                            0.0, 0.0, -1.5, 0.0, 1.0, -1.0, -1.0, 0.5, -1.0, -1.0, -0.5, -1.0, 0.0, -1.0, -1.0, 1.0,
00206                            -0.5, -1.0, 1.0, 0.5, -1.0,
00207                            // 2 extra vertices for chord push
00208                            0.0, -.333, 0.05, 0.0, -.667, 0.10
00209     };
00210 
00211     int connect[] = { // 3 "normal" hexes first
00212                       // top hex
00213                       0, 2, 1, 6, 7, 9, 8, 13,
00214                       // bottom left
00215                       0, 4, 3, 2, 7, 11, 10, 9,
00216                       // bottom right
00217                       6, 5, 4, 0, 13, 12, 11, 7,
00218                       // front chord push hex
00219                       2, 0, 4, 3, 14, 6, 5, 15,
00220                       // back chord push hex
00221                       2, 14, 15, 3, 0, 6, 5, 4,
00222                       // front/rear quads a, b
00223                       2, 0, 4, 3, 6, 5, 4, 0,
00224                       // duplicate edges from chord push
00225                       0, 4,
00226                       // face between bottom 2 normal hexes (needed for explicit
00227                       // adjacency)
00228                       0, 4, 11, 7
00229     };
00230 
00231     ErrorCode result;
00232     EntityHandle vtx_handles[16];
00233 
00234     for( int i = 0; i < 16; i++ )
00235     {
00236         result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
00237     }
00238 
00239     EntityHandle conn[8], elems[12];
00240 
00241     // make the five hexes
00242     for( int i = 0; i < 5; i++ )
00243     {
00244         for( int j = 0; j < 8; j++ )
00245             conn[j] = vtx_handles[connect[8 * i + j]];
00246         result = gMB->create_element( MBHEX, conn, 8, elems[i] );MB_CHK_ERR( result );
00247     }
00248 
00249     // make the frontmost pair of quads and bind to the front degen hex
00250     for( int i = 0; i < 2; i++ )
00251     {
00252         for( int j = 0; j < 4; j++ )
00253             conn[j] = vtx_handles[connect[40 + 4 * i + j]];
00254         result = gMB->create_element( MBQUAD, conn, 4, elems[5 + i] );MB_CHK_ERR( result );
00255     }
00256 
00257     // now the back pair
00258     for( int i = 0; i < 2; i++ )
00259     {
00260         for( int j = 0; j < 4; j++ )
00261             conn[j] = vtx_handles[connect[40 + 4 * i + j]];
00262         result = gMB->create_element( MBQUAD, conn, 4, elems[7 + i] );MB_CHK_ERR( result );
00263     }
00264 
00265     // make the duplicated edges explicitly too
00266     for( int i = 0; i < 2; i++ )
00267     {
00268         for( int j = 0; j < 2; j++ )
00269             conn[j] = vtx_handles[connect[48 + j]];
00270         result = gMB->create_element( MBEDGE, conn, 2, elems[9 + i] );MB_CHK_ERR( result );
00271     }
00272 
00273     // now the quad between the lower pair of hexes
00274     for( int j = 0; j < 4; j++ )
00275         conn[j] = vtx_handles[connect[50 + j]];
00276     result = gMB->create_element( MBQUAD, conn, 4, elems[11] );MB_CHK_ERR( result );
00277 
00278     // now set adjacencies explicitly
00279     // front/rear duplicated edge to front/rear pair of quads
00280     result = gMB->add_adjacencies( elems[9], &elems[5], 2, false );MB_CHK_ERR( result );
00281     result = gMB->add_adjacencies( elems[10], &elems[7], 2, false );MB_CHK_ERR( result );
00282 
00283     // rear duplicated edge to quad between lower pair of normal hexes
00284     result = gMB->add_adjacencies( elems[10], &elems[11], 1, false );MB_CHK_ERR( result );
00285 
00286     // front/rear duplicated edge to front/rear degen hex
00287     result = gMB->add_adjacencies( elems[9], &elems[3], 1, false );MB_CHK_ERR( result );
00288     result = gMB->add_adjacencies( elems[10], &elems[4], 1, false );MB_CHK_ERR( result );
00289 
00290     // rear duplicated edge to normal hexes behind it
00291     result = gMB->add_adjacencies( elems[10], &elems[1], 2, false );MB_CHK_ERR( result );
00292 
00293     // front pair of quads to front degen hex
00294     result = gMB->add_adjacencies( elems[5], &elems[3], 1, false );MB_CHK_ERR( result );
00295     result = gMB->add_adjacencies( elems[6], &elems[3], 1, false );MB_CHK_ERR( result );
00296 
00297     // rear pair of quads to rear degen hex
00298     result = gMB->add_adjacencies( elems[7], &elems[4], 1, false );MB_CHK_ERR( result );
00299     result = gMB->add_adjacencies( elems[8], &elems[4], 1, false );MB_CHK_ERR( result );
00300 
00301     // rear pair of quads to normal hexes behind them
00302     result = gMB->add_adjacencies( elems[7], &elems[1], 1, false );MB_CHK_ERR( result );
00303     result = gMB->add_adjacencies( elems[8], &elems[2], 1, false );MB_CHK_ERR( result );
00304 
00305     return MB_SUCCESS;
00306 }
00307 
00308 ErrorCode make_triple_chord_push()
00309 {
00310     // make chord push configuration
00311     // make all vertices
00312     double vtx_coord[] = { // first layer
00313                            0.0, 0.0, 0.5, 0.0, 1.0, 0.0, -1.0, 0.5, 0.0, -1.0, -0.5, 0.0, 0.0, -1.0, 0.0, 1.0, -0.5,
00314                            0.0, 1.0, 0.5, 0.0,
00315                            // second layer
00316                            0.0, 0.0, -1.5, 0.0, 1.0, -1.0, -1.0, 0.5, -1.0, -1.0, -0.5, -1.0, 0.0, -1.0, -1.0, 1.0,
00317                            -0.5, -1.0, 1.0, 0.5, -1.0,
00318                            // 2 extra vertices in middle
00319                            0.0, 0.0, -0.25, 0.0, 0.0, 0.0
00320     };
00321 
00322     int connect[] = { // 3 "normal" hexes first
00323                       // top hex
00324                       14, 2, 1, 6, 7, 9, 8, 13,
00325                       // bottom left
00326                       14, 4, 3, 2, 7, 11, 10, 9,
00327                       // bottom right
00328                       6, 5, 4, 14, 13, 12, 11, 7,
00329                       // front triple chord push hex
00330                       0, 4, 3, 2, 6, 5, 15, 1,
00331                       // back triple chord push hex
00332                       2, 1, 15, 3, 14, 6, 5, 4
00333     };
00334 
00335     ErrorCode result;
00336     EntityHandle vtx_handles[16];
00337 
00338     for( int i = 0; i < 16; i++ )
00339     {
00340         result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
00341     }
00342 
00343     EntityHandle conn[8], elems[12];
00344 
00345     // make the five hexes
00346     for( int i = 0; i < 5; i++ )
00347     {
00348         for( int j = 0; j < 8; j++ )
00349             conn[j] = vtx_handles[connect[8 * i + j]];
00350         result = gMB->create_element( MBHEX, conn, 8, elems[i] );MB_CHK_ERR( result );
00351     }
00352 
00353     return MB_SUCCESS;
00354 }
00355 
00356 ErrorCode make_triple_hex_push()
00357 {
00358     return MB_FAILURE;
00359 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines