Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ReadPartFile.cpp File Reference
#include "moab/Core.hpp"
#include <iostream>
#include <fstream>
+ Include dependency graph for ReadPartFile.cpp:

Go to the source code of this file.

Macros

#define MESH_DIR   "."
 

Functions

int main (int argc, char **argv)
 

Variables

string test_file_name = string( MESH_DIR ) + string( "/3k-tri-sphere.vtk" )
 
string part_file_name
 
int nparts
 

Macro Definition Documentation

◆ MESH_DIR

#define MESH_DIR   "."
Examples
ReadPartFile.cpp.

Definition at line 15 of file ReadPartFile.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
Examples
ReadPartFile.cpp.

Definition at line 22 of file ReadPartFile.cpp.

23 {
24  // Get MOAB instance
25  Interface* mb = new( std::nothrow ) Core;
26  if( NULL == mb ) return 1;
27 
28  // Need option handling here for input filename
29  if( argc > 4 )
30  {
31  // User has input a mesh file
32  test_file_name = argv[1];
33  part_file_name = argv[2];
34  nparts = atoi( argv[3] );
35  }
36  else
37  {
38  cerr << " usage is " << argv[0] << " <input file> <part file> <#parts> <output file> \n";
39  exit( 0 );
40  }
41  ifstream inFile;
42  inFile.open( part_file_name.c_str() );
43  if( !inFile )
44  {
45  cerr << "Unable to open file " << part_file_name << "\n";
46  exit( 1 ); // call system to stop
47  }
48  // Load the mesh from file
49  ErrorCode rval = mb->load_mesh( test_file_name.c_str() );MB_CHK_ERR( rval );
50 
51  // Get sets entities, by type
52  Range sets;
53  rval = mb->get_entities_by_type( 0, MBENTITYSET, sets );MB_CHK_ERR( rval );
54 
55  // Output the number of sets
56  cout << "Number of sets is " << sets.size() << endl;
57  // remove the sets that have a PARALLEL_PARTITION tag
58 
59  Tag tag;
60  rval = mb->tag_get_handle( "PARALLEL_PARTITION", tag );MB_CHK_ERR( rval );
61 
62  int i = 0;
63  int num_deleted_sets = 0;
64  for( Range::iterator it = sets.begin(); it != sets.end(); it++, i++ )
65  {
66  EntityHandle eh = *it;
67  // cout << " set :" << mb->id_from_handle(eh) <<"\n";
68  int val = -1;
69  rval = mb->tag_get_data( tag, &eh, 1, &val );
70  if( val != -1 )
71  {
72  num_deleted_sets++;
73  rval = mb->delete_entities( &eh, 1 ); // delete the set, we will have a new partition soon
74  }
75  }
76  if( num_deleted_sets ) cout << "delete " << num_deleted_sets << " existing partition sets, and create new ones \n";
77  Range cells; // get them by dimension 2!
78  rval = mb->get_entities_by_dimension( 0, 2, cells );MB_CHK_ERR( rval );
79  EntityHandle* psets = new EntityHandle[nparts];
80  for( int i = 0; i < nparts; i++ )
81  {
82  rval = mb->create_meshset( MESHSET_SET, psets[i] );MB_CHK_ERR( rval );
83  rval = mb->tag_set_data( tag, &( psets[i] ), 1, &i );MB_CHK_ERR( rval );
84  }
85 
86  for( Range::iterator it = cells.begin(); it != cells.end(); it++ )
87  {
88  int part;
89  EntityHandle eh = *it;
90  inFile >> part;
91  rval = mb->add_entities( psets[part], &eh, 1 );MB_CHK_ERR( rval );
92  }
93  mb->write_file( argv[4] );
94 
95  delete mb;
96 
97  return 0;
98 }

References moab::Core::add_entities(), moab::Range::begin(), moab::Core::create_meshset(), moab::Core::delete_entities(), moab::Range::end(), ErrorCode, moab::Core::get_entities_by_dimension(), moab::Core::get_entities_by_type(), moab::Core::load_mesh(), mb, MB_CHK_ERR, MBENTITYSET, MESHSET_SET, nparts, part_file_name, moab::Range::size(), moab::Core::tag_get_data(), moab::Core::tag_get_handle(), moab::Core::tag_set_data(), test_file_name, and moab::Core::write_file().

Variable Documentation

◆ nparts

◆ part_file_name

string part_file_name
Examples
ReadPartFile.cpp.

Definition at line 20 of file ReadPartFile.cpp.

Referenced by main().

◆ test_file_name

string test_file_name = string( MESH_DIR ) + string( "/3k-tri-sphere.vtk" )
Examples
ReadPartFile.cpp.

Definition at line 19 of file ReadPartFile.cpp.

Referenced by main().