MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #include "moab/ParallelComm.hpp" 00002 #include "moab/Core.hpp" 00003 #include "moab_mpi.h" 00004 #include "moab/ParallelMergeMesh.hpp" 00005 #include "MBParallelConventions.h" 00006 #include "TestUtil.hpp" 00007 #include <iostream> 00008 00009 using namespace moab; 00010 00011 int main( int argc, char* argv[] ) 00012 { 00013 MPI_Init( &argc, &argv ); 00014 int nproc, rank; 00015 MPI_Comm_size( MPI_COMM_WORLD, &nproc ); 00016 MPI_Comm_rank( MPI_COMM_WORLD, &rank ); 00017 00018 std::string filename0 = TestDir + "unittest/brick1.vtk"; 00019 std::string filename1 = TestDir + "unittest/brick2.vtk"; 00020 00021 moab::Core* mb = new moab::Core(); 00022 moab::ParallelComm* pc = new moab::ParallelComm( mb, MPI_COMM_WORLD ); 00023 ErrorCode rval = MB_SUCCESS; 00024 00025 if( 0 == rank%2 ) 00026 rval = mb->load_file( filename0.c_str() ); 00027 else 00028 rval = mb->load_file( filename1.c_str() ); 00029 00030 if( rval != MB_SUCCESS ) 00031 { 00032 std::cout << "fail to load file\n"; 00033 delete pc; 00034 delete mb; 00035 MPI_Finalize(); 00036 return 1; 00037 } 00038 // if rank > 2, translate in z direction, with the distance ( (rank)/2 ) * 10 00039 if (rank >= 2) 00040 { 00041 Range verts; 00042 rval = mb->get_entities_by_type(0, MBVERTEX, verts);MB_CHK_ERR( rval ); 00043 int num_verts=(int)verts.size(); 00044 std::vector<double> coords; 00045 coords.resize(num_verts*3); 00046 rval = mb->get_coords(verts, &coords[0]);MB_CHK_ERR( rval ); 00047 int steps=rank/2; 00048 double z_translate = steps*10.;// the 2 bricks are size 10 00049 for (int i=0; i<num_verts; i++) 00050 coords[3*i+2] += z_translate; 00051 rval = mb->set_coords(verts, &coords[0]);MB_CHK_ERR( rval ); 00052 } 00053 00054 00055 ParallelMergeMesh pm( pc, 0.001 ); 00056 rval = pm.merge(); 00057 if( rval != MB_SUCCESS ) 00058 { 00059 std::cout << "fail to merge in parallel \n"; 00060 delete pc; 00061 delete mb; 00062 MPI_Finalize(); 00063 return 1; 00064 } 00065 if (nproc == 2) 00066 { 00067 // check number of shared entities 00068 Range shared_ents; 00069 // Get entities shared with all other processors 00070 rval = pc->get_shared_entities( -1, shared_ents ); 00071 if( rval != MB_SUCCESS ) 00072 { 00073 delete pc; 00074 delete mb; 00075 MPI_Finalize(); 00076 return 1; 00077 } 00078 // there should be exactly 9 vertices, 12 edges, 4 faces 00079 unsigned numV = shared_ents.num_of_dimension( 0 ); 00080 unsigned numE = shared_ents.num_of_dimension( 1 ); 00081 unsigned numF = shared_ents.num_of_dimension( 2 ); 00082 00083 if( numV != 9 || numE != 12 || numF != 4 ) 00084 { 00085 std::cout << " wrong number of shared entities on proc " << rank << " v:" << numV << " e:" << numE 00086 << " f:" << numF << "\n"; 00087 delete pc; 00088 delete mb; 00089 MPI_Finalize(); 00090 return 1; 00091 } 00092 } 00093 Range verts, verts_owned; 00094 rval = mb->get_entities_by_type( 0, MBVERTEX, verts );MB_CHK_ERR( rval ); 00095 00096 // Get local owned vertices 00097 rval = pc->filter_pstatus( verts, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &verts_owned );MB_CHK_ERR( rval ); 00098 int num_owned_verts = (int) verts_owned.size(); 00099 00100 int num_total_verts = 0; 00101 MPI_Reduce(&num_owned_verts, &num_total_verts, 1, MPI_INT, MPI_SUM, 0, 00102 MPI_COMM_WORLD); 00103 00104 if (0==rank) 00105 std::cout << "total vertex number: " << num_total_verts << "\n"; 00106 00107 // each brick has 27 vertices; 00108 // first 2 share 9, total number of vertices should be 27*2 -9 = 45 00109 // for each additional row of 2 bricks, we will have 3*5* 2 = 30 more vertices 00110 int correct = 45 + (nproc/2 - 1) * 30; 00111 if (nproc%2 == 1) 00112 correct += 18; // odd cases have extra 18 nodes (3 * 3 * 2) 00113 if (nproc >= 2 && 0==rank) 00114 { 00115 if (correct != num_total_verts) 00116 { 00117 std::cout << "incorrect number of vertices, expected: " << correct << "\n"; 00118 delete pc; 00119 delete mb; 00120 MPI_Finalize(); 00121 return 1; 00122 } 00123 } 00124 00125 rval = mb->write_file( "testpm.h5m", 0, "PARALLEL=WRITE_PART" );MB_CHK_ERR( rval ); 00126 if( rval != MB_SUCCESS ) 00127 { 00128 std::cout << "fail to write output file \n"; 00129 delete pc; 00130 delete mb; 00131 MPI_Finalize(); 00132 return 1; 00133 } 00134 00135 delete pc; 00136 delete mb; 00137 00138 MPI_Finalize(); 00139 return 0; 00140 }