MOAB: Mesh Oriented datABase  (version 5.4.1)
TestExodusII.cpp
Go to the documentation of this file.
00001 /** @example TestExodusII.cpp
00002  * This example demonstrates how to retrieve material, dirichlet and neumann sets
00003  * from an ExodusII file. \n
00004  * Sets in MOAB contain entities and have a tag on them to give meaning to the entities.
00005  * Tag names: MATERIAL_SET", "DIRICHLET_SET" and "NEUMANN_SET" are reserved and
00006  * are associated with their corresponding entity sets.
00007  * Sets are traversed to find out the type number of entities contained in each set. \n
00008  *
00009  * <b>Steps in this example </b>:
00010  *    -# Instantiate MOAB
00011  *    -# Get input mesh file name and load it.
00012  *    -# Loop over the three sets: material, dirichlet and neumann
00013  *      -# Get TagHandle and EntitySet(corresponding to the TagHandle)
00014  *      -# Loop thru all the EntitySet's
00015  *        -# Get the set id and entities in this set
00016  *    -# Destroy the MOAB instance
00017  *
00018  *
00019  * <b> To compile: </b>
00020  *    make TestExodusII MOAB_DIR=<installdir> \n
00021  *
00022  * <b> To run: </b>
00023  *    -# TestExodusII <mesh-file> \n
00024  *    -# TestExodusII (This uses the default <mesh-file>:
00025  * <MOAB_SRC_DIR>/MeshFiles/unittest/mbtest2.g)
00026  */
00027 #include <iostream>
00028 
00029 // Include header for MOAB instance and range
00030 #include "moab/Core.hpp"
00031 
00032 using namespace moab;
00033 using namespace std;
00034 
00035 string test_file_name = string( MESH_DIR ) + string( "/mbtest2.g" );
00036 int main( int argc, char** argv )
00037 {
00038 #ifdef MOAB_HAVE_NETCDF
00039     // Get MOAB instance
00040     Interface* mb = new( std::nothrow ) Core;
00041     if( NULL == mb ) return 1;
00042 
00043     // Get the material set tag handle
00044     Tag mtag;
00045     ErrorCode rval;
00046     const char* tag_nms[] = { "MATERIAL_SET", "DIRICHLET_SET", "NEUMANN_SET" };
00047     Range sets, set_ents;
00048 
00049     // Load a file
00050     if( argc == 1 )
00051     {
00052         cout << "Running default case, loading " << test_file_name << endl;
00053         cout << "Usage: " << argv[0] << " <filename>\n" << endl;
00054         rval = mb->load_file( test_file_name.c_str() );MB_CHK_ERR( rval );
00055     }
00056     else
00057     {
00058         rval = mb->load_file( argv[argc - 1] );MB_CHK_ERR( rval );
00059         cout << "Loaded mesh file: " << argv[argc - 1] << endl;
00060     }
00061 
00062     // Loop over set types
00063     for( int i = 0; i < 3; i++ )
00064     {
00065         rval = mb->tag_get_handle( tag_nms[i], 1, MB_TYPE_INTEGER, mtag );MB_CHK_ERR( rval );
00066 
00067         // Get all the sets of that type in the mesh
00068         sets.clear();
00069         rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &mtag, NULL, 1, sets );MB_CHK_ERR( rval );
00070 
00071         // Iterate over each set, getting entities
00072         Range::iterator set_it;
00073         for( set_it = sets.begin(); set_it != sets.end(); ++set_it )
00074         {
00075             EntityHandle this_set = *set_it;
00076 
00077             // Get the id for this set
00078             int set_id;
00079             rval = mb->tag_get_data( mtag, &this_set, 1, &set_id );MB_CHK_ERR( rval );
00080 
00081             // Get the entities in the set, recursively
00082             rval = mb->get_entities_by_handle( this_set, set_ents, true );MB_CHK_ERR( rval );
00083 
00084             cout << tag_nms[i] << " " << set_id << " has " << set_ents.size() << " entities:" << endl;
00085 
00086             // Print the entities contained in this set
00087             set_ents.print( "   " );
00088             set_ents.clear();
00089         }
00090     }
00091 
00092     delete mb;
00093 #else
00094     cout << " This test needs moab configured with netcdf \n";
00095 #endif
00096 
00097     return 0;
00098 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines