MOAB: Mesh Oriented datABase  (version 5.2.1)
parmerge_test.cpp
Go to the documentation of this file.
00001 #include "moab/ParallelComm.hpp"
00002 #include "moab/Core.hpp"
00003 #include "moab_mpi.h"
00004 #include "moab/ParallelMergeMesh.hpp"
00005 #include "TestUtil.hpp"
00006 #include <iostream>
00007 
00008 using namespace moab;
00009 
00010 int main( int argc, char* argv[] )
00011 {
00012     MPI_Init( &argc, &argv );
00013     int nproc, rank;
00014     MPI_Comm_size( MPI_COMM_WORLD, &nproc );
00015     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00016 
00017     if( nproc != 2 )
00018     {
00019         std::cout << " run this test on 2 tasks\n";
00020         MPI_Finalize();
00021         return 1;
00022     }
00023 
00024     std::string filename0 = TestDir + "/brick1.vtk";
00025     std::string filename1 = TestDir + "/brick2.vtk";
00026 
00027     moab::Core* mb         = new moab::Core();
00028     moab::ParallelComm* pc = new moab::ParallelComm( mb, MPI_COMM_WORLD );
00029     ErrorCode rval         = MB_SUCCESS;
00030 
00031     if( 0 == rank )
00032         rval = mb->load_file( filename0.c_str() );
00033     else
00034         rval = mb->load_file( filename1.c_str() );
00035 
00036     if( rval != MB_SUCCESS )
00037     {
00038         std::cout << "fail to load file\n";
00039         delete pc;
00040         delete mb;
00041         MPI_Finalize();
00042         return 1;
00043     }
00044     ParallelMergeMesh pm( pc, 0.001 );
00045     rval = pm.merge();
00046     if( rval != MB_SUCCESS )
00047     {
00048         std::cout << "fail to merge in parallel \n";
00049         delete pc;
00050         delete mb;
00051         MPI_Finalize();
00052         return 1;
00053     }
00054     // check number of shared entities
00055     Range shared_ents;
00056     // Get entities shared with all other processors
00057     rval = pc->get_shared_entities( -1, shared_ents );
00058     if( rval != MB_SUCCESS )
00059     {
00060         delete pc;
00061         delete mb;
00062         MPI_Finalize();
00063         return 1;
00064     }
00065     // there should be exactly 9 vertices, 12 edges, 4 faces
00066     unsigned numV = shared_ents.num_of_dimension( 0 );
00067     unsigned numE = shared_ents.num_of_dimension( 1 );
00068     unsigned numF = shared_ents.num_of_dimension( 2 );
00069 
00070     if( numV != 9 || numE != 12 || numF != 4 )
00071     {
00072         std::cout << " wrong number of shared entities on proc " << rank << " v:" << numV << " e:" << numE
00073                   << " f:" << numF << "\n";
00074         delete pc;
00075         delete mb;
00076         MPI_Finalize();
00077         return 1;
00078     }
00079 
00080     rval = mb->write_file( "testpm.h5m", 0, "PARALLEL=WRITE_PART" );
00081     if( rval != MB_SUCCESS )
00082     {
00083         std::cout << "fail to write output file \n";
00084         delete pc;
00085         delete mb;
00086         MPI_Finalize();
00087         return 1;
00088     }
00089 
00090     delete pc;
00091     delete mb;
00092 
00093     MPI_Finalize();
00094     return 0;
00095 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines