MOAB: Mesh Oriented datABase  (version 5.5.0)
parmerge_test.cpp File Reference
#include "moab/ParallelComm.hpp"
#include "moab/Core.hpp"
#include "moab_mpi.h"
#include "moab/ParallelMergeMesh.hpp"
#include "MBParallelConventions.h"
#include "TestUtil.hpp"
#include <iostream>
+ Include dependency graph for parmerge_test.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 11 of file parmerge_test.cpp.

12 {
13  MPI_Init( &argc, &argv );
14  int nproc, rank;
15  MPI_Comm_size( MPI_COMM_WORLD, &nproc );
16  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
17 
18  std::string filename0 = TestDir + "unittest/brick1.vtk";
19  std::string filename1 = TestDir + "unittest/brick2.vtk";
20 
21  moab::Core* mb = new moab::Core();
23  ErrorCode rval = MB_SUCCESS;
24 
25  if( 0 == rank % 2 )
26  rval = mb->load_file( filename0.c_str() );
27  else
28  rval = mb->load_file( filename1.c_str() );
29 
30  if( rval != MB_SUCCESS )
31  {
32  std::cout << "fail to load file\n";
33  delete pc;
34  delete mb;
35  MPI_Finalize();
36  return 1;
37  }
38  // if rank > 2, translate in z direction, with the distance ( (rank)/2 ) * 10
39  if( rank >= 2 )
40  {
41  Range verts;
42  rval = mb->get_entities_by_type( 0, MBVERTEX, verts );MB_CHK_ERR( rval );
43  int num_verts = (int)verts.size();
44  std::vector< double > coords;
45  coords.resize( num_verts * 3 );
46  rval = mb->get_coords( verts, &coords[0] );MB_CHK_ERR( rval );
47  int steps = rank / 2;
48  double z_translate = steps * 10.; // the 2 bricks are size 10
49  for( int i = 0; i < num_verts; i++ )
50  coords[3 * i + 2] += z_translate;
51  rval = mb->set_coords( verts, &coords[0] );MB_CHK_ERR( rval );
52  }
53 
54  ParallelMergeMesh pm( pc, 0.001 );
55  rval = pm.merge();
56  if( rval != MB_SUCCESS )
57  {
58  std::cout << "fail to merge in parallel \n";
59  delete pc;
60  delete mb;
61  MPI_Finalize();
62  return 1;
63  }
64  if( nproc == 2 )
65  {
66  // check number of shared entities
67  Range shared_ents;
68  // Get entities shared with all other processors
69  rval = pc->get_shared_entities( -1, shared_ents );
70  if( rval != MB_SUCCESS )
71  {
72  delete pc;
73  delete mb;
74  MPI_Finalize();
75  return 1;
76  }
77  // there should be exactly 9 vertices, 12 edges, 4 faces
78  unsigned numV = shared_ents.num_of_dimension( 0 );
79  unsigned numE = shared_ents.num_of_dimension( 1 );
80  unsigned numF = shared_ents.num_of_dimension( 2 );
81 
82  if( numV != 9 || numE != 12 || numF != 4 )
83  {
84  std::cout << " wrong number of shared entities on proc " << rank << " v:" << numV << " e:" << numE
85  << " f:" << numF << "\n";
86  delete pc;
87  delete mb;
88  MPI_Finalize();
89  return 1;
90  }
91  }
92  Range verts, verts_owned;
93  rval = mb->get_entities_by_type( 0, MBVERTEX, verts );MB_CHK_ERR( rval );
94 
95  // Get local owned vertices
96  rval = pc->filter_pstatus( verts, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &verts_owned );MB_CHK_ERR( rval );
97  int num_owned_verts = (int)verts_owned.size();
98 
99  int num_total_verts = 0;
100  MPI_Reduce( &num_owned_verts, &num_total_verts, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD );
101 
102  if( 0 == rank ) std::cout << "total vertex number: " << num_total_verts << "\n";
103 
104  // each brick has 27 vertices;
105  // first 2 share 9, total number of vertices should be 27*2 -9 = 45
106  // for each additional row of 2 bricks, we will have 3*5* 2 = 30 more vertices
107  int correct = 45 + ( nproc / 2 - 1 ) * 30;
108  if( nproc % 2 == 1 ) correct += 18; // odd cases have extra 18 nodes (3 * 3 * 2)
109  if( nproc >= 2 && 0 == rank )
110  {
111  if( correct != num_total_verts )
112  {
113  std::cout << "incorrect number of vertices, expected: " << correct << "\n";
114  delete pc;
115  delete mb;
116  MPI_Finalize();
117  return 1;
118  }
119  }
120 
121  rval = mb->write_file( "testpm.h5m", 0, "PARALLEL=WRITE_PART" );MB_CHK_ERR( rval );
122  if( rval != MB_SUCCESS )
123  {
124  std::cout << "fail to write output file \n";
125  delete pc;
126  delete mb;
127  MPI_Finalize();
128  return 1;
129  }
130 
131  delete pc;
132  delete mb;
133 
134  MPI_Finalize();
135  return 0;
136 }

References ErrorCode, moab::ParallelComm::filter_pstatus(), moab::Core::get_coords(), moab::Core::get_entities_by_type(), moab::ParallelComm::get_shared_entities(), moab::Core::load_file(), mb, MB_CHK_ERR, MB_SUCCESS, MBVERTEX, moab::ParallelMergeMesh::merge(), MPI_COMM_WORLD, moab::Range::num_of_dimension(), PSTATUS_NOT, PSTATUS_NOT_OWNED, rank, moab::Core::set_coords(), moab::Range::size(), and moab::Core::write_file().