MOAB: Mesh Oriented datABase  (version 5.4.1)
dual_test.cpp
Go to the documentation of this file.
00001 // tests dual construction code
00002 
00003 #include "moab/Core.hpp"
00004 #include "moab/Range.hpp"
00005 #include "moab/MeshTopoUtil.hpp"
00006 #include "moab/DualTool.hpp"
00007 #include "../TestUtil.hpp"
00008 #include <iostream>
00009 #include <string>
00010 
00011 using namespace moab;
00012 
00013 std::string default_input   = TestDir + "unittest/hex01.vtk";
00014 const char default_output[] = "dual.vtk";
00015 
00016 Interface* gMB;
00017 
00018 int main( int argc, char* argv[] )
00019 {
00020     const char* f1 = default_input.c_str();
00021     const char* f2 = default_output;
00022     if( argc <= 2 )
00023     {
00024         std::cout << "Usage: dual_test <mesh_file_name> <out file>" << std::endl;
00025         std::cout << "using default input : " << default_input << " and output " << default_output << "\n";
00026     }
00027     else
00028     {
00029         f1 = argv[1];
00030         f2 = argv[2];
00031     }
00032 
00033     gMB = new Core();
00034 
00035     // read the mesh file
00036     ErrorCode result = gMB->load_mesh( f1 );
00037     if( MB_SUCCESS != result )
00038     {
00039         std::cout << "Problems reading file " << argv[1] << "." << std::endl;
00040         delete gMB;
00041         return 1;
00042     }
00043 
00044     // make sure aentities are created
00045     Range all_verts;
00046     result = gMB->get_entities_by_dimension( 0, 0, all_verts );
00047     if( MB_SUCCESS != result ) std::cout << "Problem getting vertices." << std::endl;
00048 
00049     MeshTopoUtil( gMB ).construct_aentities( all_verts );
00050 
00051     // get counts before constructing dual
00052     int num_edges;
00053     result = gMB->get_number_entities_by_dimension( 0, 1, num_edges );
00054     if( MB_SUCCESS != result ) std::cout << "Problem getting number of edges." << std::endl;
00055 
00056     // see if it's all-hex or all-quad, and construct hex/quad dual if so
00057     int num_hex, num_quad, num_3d, num_2d;
00058     result = gMB->get_number_entities_by_dimension( 0, 2, num_2d );
00059     if( MB_SUCCESS != result ) return 0;
00060     result = gMB->get_number_entities_by_dimension( 0, 3, num_3d );
00061     if( MB_SUCCESS != result ) return 0;
00062     result = gMB->get_number_entities_by_type( 0, MBQUAD, num_quad );
00063     if( MB_SUCCESS != result ) return 0;
00064     result = gMB->get_number_entities_by_type( 0, MBHEX, num_hex );
00065     if( MB_SUCCESS != result ) return 0;
00066 
00067     // construct the dual for this mesh
00068     DualTool dt( gMB );
00069     if( num_quad == num_2d && num_hex == num_3d )
00070         result = dt.construct_hex_dual( 0, 0 );
00071     else
00072         result = dt.construct_dual( 0, 0 );
00073     if( MB_SUCCESS != result )
00074     {
00075         std::cout << "Problems constructing dual." << std::endl;
00076         return 0;
00077     }
00078 
00079     // print information about the dual
00080     Range dual_cells, dual_faces;
00081     result = dt.get_dual_entities( 0, 0, 2, dual_faces );
00082     if( MB_SUCCESS != result )
00083         std::cout << "Problem getting dual faces." << std::endl;
00084     else
00085         std::cout << "Found " << dual_faces.size() << "/" << num_edges << " dual faces." << std::endl;
00086 
00087     result = dt.get_dual_entities( 0, 0, 3, dual_cells );
00088     if( MB_SUCCESS != result )
00089         std::cout << "Problem getting dual cells." << std::endl;
00090     else
00091         std::cout << "Found " << dual_cells.size() << "/" << all_verts.size() << " dual cells." << std::endl;
00092 
00093     // print information about dual hyperplanes, if any
00094     Tag hp_tag;
00095     Range hp_sets;
00096     if( num_2d == num_quad )
00097     {
00098         // get sets with the right tag
00099         result = gMB->tag_get_handle( DualTool::DUAL_CURVE_TAG_NAME, 1, MB_TYPE_HANDLE, hp_tag );
00100         if( MB_SUCCESS == result )
00101         {
00102             result = gMB->get_entities_by_type_and_tag( 0, MBENTITYSET, &hp_tag, NULL, 1, hp_sets );
00103             if( MB_SUCCESS == result && !hp_sets.empty() )
00104                 std::cout << "Found " << hp_sets.size() << " 1d dual hyperplanes (chords)." << std::endl;
00105         }
00106     }
00107 
00108     if( num_3d == num_hex )
00109     {
00110         // get sets with the right tag
00111         result = gMB->tag_get_handle( DualTool::DUAL_SURFACE_TAG_NAME, 1, MB_TYPE_HANDLE, hp_tag );
00112         if( MB_SUCCESS == result )
00113         {
00114             hp_sets.clear();
00115             result = gMB->get_entities_by_type_and_tag( 0, MBENTITYSET, &hp_tag, NULL, 1, hp_sets );
00116             if( MB_SUCCESS == result && !hp_sets.empty() )
00117                 std::cout << "Found " << hp_sets.size() << " 2d dual hyperplanes (sheets)." << std::endl;
00118         }
00119     }
00120 
00121     // write GMV file
00122     gMB->write_file( f2 );
00123     delete gMB;
00124 
00125     return 0;
00126 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines