MOAB: Mesh Oriented datABase  (version 5.4.1)
mergemesh_test.cpp
Go to the documentation of this file.
00001 #include "moab/Core.hpp"
00002 #include "moab/Range.hpp"
00003 #include "moab/MergeMesh.hpp"
00004 #include <iostream>
00005 #include "TestUtil.hpp"
00006 
00007 #ifdef MOAB_HAVE_MPI
00008 #include "moab_mpi.h"
00009 #endif
00010 
00011 #ifndef MOAB_HAVE_HDF5
00012 #error This test requires HDF5 support
00013 #endif
00014 
00015 using namespace moab;
00016 
00017 std::string meshfile  = TestDir + "unittest/16_unmerged_hex.h5m";
00018 std::string meshfile2 = TestDir + "unittest/merge_with_tag.h5m";
00019 std::string meshfile3 = TestDir + "unittest/triangles.h5m";
00020 std::string outfile   = "mm_out.h5m";
00021 
00022 void mergesimple_test();
00023 void merge_with_tag_test();
00024 void merge_all_test();
00025 
00026 #ifdef MOAB_HAVE_MPI
00027 int main( int argc, char** argv )
00028 #else
00029 int main()
00030 #endif
00031 {
00032 #ifdef MOAB_HAVE_MPI
00033     MPI_Init( &argc, &argv );
00034 #endif
00035     int result = 0;
00036 
00037     result += RUN_TEST( mergesimple_test );
00038     result += RUN_TEST( merge_with_tag_test );
00039     result += RUN_TEST( merge_all_test );
00040 
00041 #ifdef MOAB_HAVE_MPI
00042     MPI_Finalize();
00043 #endif
00044     return result;
00045 }
00046 
00047 void mergesimple_test()
00048 {
00049     ErrorCode rval;
00050     Core mb;
00051     Interface* iface = &mb;
00052     // can be generalized to load user defined input/output file
00053 
00054     rval = iface->load_mesh( meshfile.c_str() );CHECK_ERR( rval );
00055     int dim = 3;
00056     moab::Range ents;
00057     iface->get_entities_by_dimension( 0, dim, ents );
00058 
00059     MergeMesh mm( iface );
00060     double merge_tol = 1e-3;
00061 
00062     rval = mm.merge_entities( ents, merge_tol );CHECK_ERR( rval );
00063 
00064     // Fixed for now
00065 
00066     rval = iface->write_file( outfile.c_str() );CHECK_ERR( rval );
00067 
00068     return;
00069 }
00070 
00071 void merge_with_tag_test()
00072 {
00073     ErrorCode rval;
00074     Core mb;
00075     Interface* iface = &mb;
00076     // can be generalized to load user defined input/output file
00077 
00078     rval = iface->load_mesh( meshfile2.c_str() );CHECK_ERR( rval );
00079     int dim = 0;
00080     moab::Range verts;
00081     iface->get_entities_by_dimension( 0, dim, verts );
00082     Tag tag_for_merge;
00083     rval = iface->tag_get_handle( "IDFTAG", tag_for_merge );CHECK_ERR( rval );
00084 
00085     MergeMesh mm( iface );
00086     rval = mm.merge_using_integer_tag( verts, tag_for_merge );CHECK_ERR( rval );
00087     rval = iface->write_file( outfile.c_str() );CHECK_ERR( rval );
00088 
00089     verts.clear();
00090     iface->get_entities_by_dimension( 0, dim, verts );
00091     CHECK_EQUAL( 405, (int)verts.size() );
00092 
00093     return;
00094 }
00095 
00096 void merge_all_test()
00097 {
00098     ErrorCode rval;
00099     Core mb;
00100     Interface* iface = &mb;
00101 
00102     rval = iface->load_mesh( meshfile3.c_str() );CHECK_ERR( rval );
00103 
00104     MergeMesh mm( iface );
00105     double merge_tol = 1e-3;
00106     rval             = mm.merge_all( 0, merge_tol );  // root set
00107     CHECK_ERR( rval );
00108     rval = iface->write_file( outfile.c_str() );CHECK_ERR( rval );
00109 
00110     return;
00111 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines