Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
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 )
00078         {
00079             tmp_result = make_atomic_pillow();
00080         }
00081         else if( *vit == FACE_OPEN_COLLAPSE )
00082         {
00083             tmp_result = make_face_open_collapse();
00084         }
00085         else if( *vit == CHORD_PUSH )
00086         {
00087             tmp_result = make_chord_push();
00088         }
00089         else if( *vit == MBTRIPLE_CHORD_PUSH )
00090         {
00091             tmp_result = make_triple_chord_push();
00092         }
00093 
00094         else if( *vit == MBTRIPLE_HEX_PUSH )
00095         {
00096             tmp_result = make_triple_hex_push();
00097         }
00098         else if( *vit == FACE_SHRINK )
00099         {
00100             tmp_result = make_face_shrink();
00101         }
00102         else
00103         {
00104             std::cout << "Operation undefined." << std::endl;
00105             return 1;
00106         }
00107         if( MB_SUCCESS != tmp_result ) result = tmp_result;
00108 
00109         // now write to a file
00110         std::string filename( OperationNames[*vit] );
00111         filename.append( extensions[file_exten] );
00112         tmp_result = gMB->write_mesh( filename.c_str() );
00113         if( MB_SUCCESS != tmp_result ) result = tmp_result;
00114     }
00115 
00116     return ( result == MB_SUCCESS ? 0 : 1 );
00117 }
00118 
00119 ErrorCode make_atomic_pillow()
00120 {
00121     // make atomic pillow configuration
00122     // make all vertices
00123     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,
00124                            .75, .75, 1.0, .75, .25, 1.0, .25, .25, 1.0, .25, .75, 1.0 };
00125 
00126     int connect[] = { 0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3 };
00127 
00128     ErrorCode result;
00129     EntityHandle vtx_handles[8];
00130 
00131     for( int i = 0; i < 8; i++ )
00132     {
00133         result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
00134     }
00135 
00136     EntityHandle conn[8], elems[4];
00137 
00138     // make the two hexes
00139     for( int i = 0; i < 8; i++ )
00140         conn[i] = vtx_handles[connect[i]];
00141     result = gMB->create_element( MBHEX, conn, 8, elems[0] );MB_CHK_ERR( result );
00142 
00143     for( int i = 0; i < 8; i++ )
00144         conn[i] = vtx_handles[connect[8 + i]];
00145     result = gMB->create_element( MBHEX, conn, 8, elems[1] );MB_CHK_ERR( result );
00146 
00147     // make one of the end quads explicitly and bind to the first hex
00148     for( int i = 0; i < 4; i++ )
00149         conn[i] = vtx_handles[connect[i]];
00150     result = gMB->create_element( MBQUAD, conn, 4, elems[2] );MB_CHK_ERR( result );
00151 
00152     result = gMB->add_adjacencies( elems[2], elems, 1, false );MB_CHK_ERR( result );
00153 
00154     // now the other one
00155     result = gMB->create_element( MBQUAD, conn, 4, elems[3] );MB_CHK_ERR( result );
00156 
00157     result = gMB->add_adjacencies( elems[3], &elems[1], 1, false );MB_CHK_ERR( result );
00158 
00159     return MB_SUCCESS;
00160 }
00161 
00162 ErrorCode make_face_shrink()
00163 {
00164     // make face shrink configuration
00165     // make all vertices
00166     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,
00167                            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,
00168                            2.0, 0.0, 1.0, 2.0, .75, .75, 1.0, .75, .25, 1.0, .25, .25, 1.0, .25, .75, 1.0 };
00169 
00170     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,
00171                       2, 6, 10, 14, 3, 7, 11, 15, 0, 3, 2, 1,  12, 15, 14, 13, 12, 15, 14, 13, 8, 11, 10, 9 };
00172 
00173     ErrorCode result;
00174     EntityHandle vtx_handles[16];
00175 
00176     for( int i = 0; i < 16; i++ )
00177     {
00178         result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
00179     }
00180 
00181     // make all elements at once
00182     EntityHandle conn[8], elems[6];
00183 
00184     for( int j = 0; j < 6; j++ )
00185     {
00186         for( int i = 0; i < 8; i++ )
00187             conn[i] = vtx_handles[connect[j * 8 + i]];
00188 
00189         result = gMB->create_element( MBHEX, conn, 8, elems[j] );MB_CHK_ERR( result );
00190     }
00191 
00192     return MB_SUCCESS;
00193 }
00194 
00195 ErrorCode make_face_open_collapse()
00196 {
00197     return MB_FAILURE;
00198 }
00199 
00200 ErrorCode make_chord_push()
00201 {
00202     // make chord push configuration
00203     // make all vertices
00204     double vtx_coord[] = { // first layer
00205                            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,
00206                            0.0, 1.0, 0.5, 0.0,
00207                            // second layer
00208                            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,
00209                            -0.5, -1.0, 1.0, 0.5, -1.0,
00210                            // 2 extra vertices for chord push
00211                            0.0, -.333, 0.05, 0.0, -.667, 0.10 };
00212 
00213     int connect[] = { // 3 "normal" hexes first
00214                       // top hex
00215                       0, 2, 1, 6, 7, 9, 8, 13,
00216                       // bottom left
00217                       0, 4, 3, 2, 7, 11, 10, 9,
00218                       // bottom right
00219                       6, 5, 4, 0, 13, 12, 11, 7,
00220                       // front chord push hex
00221                       2, 0, 4, 3, 14, 6, 5, 15,
00222                       // back chord push hex
00223                       2, 14, 15, 3, 0, 6, 5, 4,
00224                       // front/rear quads a, b
00225                       2, 0, 4, 3, 6, 5, 4, 0,
00226                       // duplicate edges from chord push
00227                       0, 4,
00228                       // face between bottom 2 normal hexes (needed for explicit
00229                       // adjacency)
00230                       0, 4, 11, 7 };
00231 
00232     ErrorCode result;
00233     EntityHandle vtx_handles[16];
00234 
00235     for( int i = 0; i < 16; i++ )
00236     {
00237         result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
00238     }
00239 
00240     EntityHandle conn[8], elems[12];
00241 
00242     // make the five hexes
00243     for( int i = 0; i < 5; i++ )
00244     {
00245         for( int j = 0; j < 8; j++ )
00246             conn[j] = vtx_handles[connect[8 * i + j]];
00247         result = gMB->create_element( MBHEX, conn, 8, elems[i] );MB_CHK_ERR( result );
00248     }
00249 
00250     // make the frontmost pair of quads and bind to the front degen hex
00251     for( int i = 0; i < 2; i++ )
00252     {
00253         for( int j = 0; j < 4; j++ )
00254             conn[j] = vtx_handles[connect[40 + 4 * i + j]];
00255         result = gMB->create_element( MBQUAD, conn, 4, elems[5 + i] );MB_CHK_ERR( result );
00256     }
00257 
00258     // now the back pair
00259     for( int i = 0; i < 2; i++ )
00260     {
00261         for( int j = 0; j < 4; j++ )
00262             conn[j] = vtx_handles[connect[40 + 4 * i + j]];
00263         result = gMB->create_element( MBQUAD, conn, 4, elems[7 + i] );MB_CHK_ERR( result );
00264     }
00265 
00266     // make the duplicated edges explicitly too
00267     for( int i = 0; i < 2; i++ )
00268     {
00269         for( int j = 0; j < 2; j++ )
00270             conn[j] = vtx_handles[connect[48 + j]];
00271         result = gMB->create_element( MBEDGE, conn, 2, elems[9 + i] );MB_CHK_ERR( result );
00272     }
00273 
00274     // now the quad between the lower pair of hexes
00275     for( int j = 0; j < 4; j++ )
00276         conn[j] = vtx_handles[connect[50 + j]];
00277     result = gMB->create_element( MBQUAD, conn, 4, elems[11] );MB_CHK_ERR( result );
00278 
00279     // now set adjacencies explicitly
00280     // front/rear duplicated edge to front/rear pair of quads
00281     result = gMB->add_adjacencies( elems[9], &elems[5], 2, false );MB_CHK_ERR( result );
00282     result = gMB->add_adjacencies( elems[10], &elems[7], 2, false );MB_CHK_ERR( result );
00283 
00284     // rear duplicated edge to quad between lower pair of normal hexes
00285     result = gMB->add_adjacencies( elems[10], &elems[11], 1, false );MB_CHK_ERR( result );
00286 
00287     // front/rear duplicated edge to front/rear degen hex
00288     result = gMB->add_adjacencies( elems[9], &elems[3], 1, false );MB_CHK_ERR( result );
00289     result = gMB->add_adjacencies( elems[10], &elems[4], 1, false );MB_CHK_ERR( result );
00290 
00291     // rear duplicated edge to normal hexes behind it
00292     result = gMB->add_adjacencies( elems[10], &elems[1], 2, false );MB_CHK_ERR( result );
00293 
00294     // front pair of quads to front degen hex
00295     result = gMB->add_adjacencies( elems[5], &elems[3], 1, false );MB_CHK_ERR( result );
00296     result = gMB->add_adjacencies( elems[6], &elems[3], 1, false );MB_CHK_ERR( result );
00297 
00298     // rear pair of quads to rear degen hex
00299     result = gMB->add_adjacencies( elems[7], &elems[4], 1, false );MB_CHK_ERR( result );
00300     result = gMB->add_adjacencies( elems[8], &elems[4], 1, false );MB_CHK_ERR( result );
00301 
00302     // rear pair of quads to normal hexes behind them
00303     result = gMB->add_adjacencies( elems[7], &elems[1], 1, false );MB_CHK_ERR( result );
00304     result = gMB->add_adjacencies( elems[8], &elems[2], 1, false );MB_CHK_ERR( result );
00305 
00306     return MB_SUCCESS;
00307 }
00308 
00309 ErrorCode make_triple_chord_push()
00310 {
00311     // make chord push configuration
00312     // make all vertices
00313     double vtx_coord[] = { // first layer
00314                            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,
00315                            0.0, 1.0, 0.5, 0.0,
00316                            // second layer
00317                            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,
00318                            -0.5, -1.0, 1.0, 0.5, -1.0,
00319                            // 2 extra vertices in middle
00320                            0.0, 0.0, -0.25, 0.0, 0.0, 0.0 };
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     ErrorCode result;
00335     EntityHandle vtx_handles[16];
00336 
00337     for( int i = 0; i < 16; i++ )
00338     {
00339         result = gMB->create_vertex( &vtx_coord[3 * i], vtx_handles[i] );MB_CHK_ERR( result );
00340     }
00341 
00342     EntityHandle conn[8], elems[12];
00343 
00344     // make the five hexes
00345     for( int i = 0; i < 5; i++ )
00346     {
00347         for( int j = 0; j < 8; j++ )
00348             conn[j] = vtx_handles[connect[8 * i + j]];
00349         result = gMB->create_element( MBHEX, conn, 8, elems[i] );MB_CHK_ERR( result );
00350     }
00351 
00352     return MB_SUCCESS;
00353 }
00354 
00355 ErrorCode make_triple_hex_push()
00356 {
00357     return MB_FAILURE;
00358 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines