Mesh Oriented datABase
(version 5.5.1)
An array-based unstructured mesh library
ReadPartFile.cpp
Go to the documentation of this file.
1
/** @example ReadPartFile.cpp
2
*
3
* read partition file created by a Zoltan process, that used the global ids for
4
* identification of entities
5
*/
6
7
#include "
moab/Core.hpp
"
8
#include <iostream>
9
#include <fstream>
10
11
using namespace
moab
;
12
using namespace
std;
13
14
#ifndef MESH_DIR
15
#define MESH_DIR "."
16
#endif
17
18
// Note: change the file name below to test a trivial "No such file or directory" error
19
string
test_file_name
= string(
MESH_DIR
) + string(
"/3k-tri-sphere.vtk"
);
20
string
part_file_name
;
21
int
nparts
;
22
int
main
(
int
argc,
char
** argv )
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
}
examples
basic
ReadPartFile.cpp
Generated on Tue Oct 29 2024 02:05:48 for Mesh Oriented datABase by
1.9.1.