This example demonstrates how to retrieve material, dirichlet and neumann sets from an ExodusII file.
Sets in MOAB contain entities and have a tag on them to give meaning to the entities. Tag names: MATERIAL_SET", "DIRICHLET_SET" and "NEUMANN_SET" are reserved and are associated with their corresponding entity sets. Sets are traversed to find out the type number of entities contained in each set.
Steps in this example :
- Instantiate MOAB
- Get input mesh file name and load it.
- Loop over the three sets: material, dirichlet and neumann
- Get TagHandle and EntitySet(corresponding to the TagHandle)
- Loop thru all the EntitySet's
- Get the set id and entities in this set
- Destroy the MOAB instance
To compile: make TestExodusII
To run:
- TestExodusII <mesh-file>
- TestExodusII (This uses the default <mesh-file>: MeshFiles/unittest/mbtest2.g)
#include <iostream>
using namespace std;
int main(
int argc,
char** argv )
{
#ifdef MOAB_HAVE_NETCDF
Interface*
mb =
new( std::nothrow ) Core;
if( NULL ==
mb )
return 1;
const char*
tag_nms[] = {
"MATERIAL_SET",
"DIRICHLET_SET",
"NEUMANN_SET" };
Range sets, set_ents;
if( argc == 1 )
{
cout << "Usage: " << argv[0] << " <filename>\n" << endl;
}
else
{
cout << "Loaded mesh file: " << argv[argc - 1] << endl;
}
for( int i = 0; i < 3; i++ )
{
sets.clear();
for( set_it = sets.begin(); set_it != sets.end(); ++set_it )
{
int set_id;
rval =
mb->tag_get_data( mtag, &this_set, 1, &set_id );
MB_CHK_ERR( rval );
rval =
mb->get_entities_by_handle( this_set, set_ents,
true );
MB_CHK_ERR( rval );
cout <<
tag_nms[i] <<
" " << set_id <<
" has " << set_ents.size() <<
" entities:" << endl;
set_ents.print( " " );
set_ents.clear();
}
}
#else
cout << " This test needs moab configured with netcdf \n";
#endif
return 0;
}