Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
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 \n
00021  *
00022  * <b> To run: </b>
00023  *    -# TestExodusII <mesh-file> \n
00024  *    -# TestExodusII (This uses the default <mesh-file>: MeshFiles/unittest/mbtest2.g)
00025  */
00026 #include <iostream>
00027 
00028 // Include header for MOAB instance and range
00029 #include "moab/Core.hpp"
00030 
00031 using namespace moab;
00032 using namespace std;
00033 
00034 string test_file_name = string( MESH_DIR ) + string( "/mbtest2.g" );
00035 int main( int argc, char** argv )
00036 {
00037 #ifdef MOAB_HAVE_NETCDF
00038     // Get MOAB instance
00039     Interface* mb = new( std::nothrow ) Core;
00040     if( NULL == mb ) return 1;
00041 
00042     // Get the material set tag handle
00043     Tag mtag;
00044     ErrorCode rval;
00045     const char* tag_nms[] = { "MATERIAL_SET", "DIRICHLET_SET", "NEUMANN_SET" };
00046     Range sets, set_ents;
00047 
00048     // Load a file
00049     if( argc == 1 )
00050     {
00051         cout << "Running default case, loading " << test_file_name << endl;
00052         cout << "Usage: " << argv[0] << " <filename>\n" << endl;
00053         rval = mb->load_file( test_file_name.c_str() );MB_CHK_ERR( rval );
00054     }
00055     else
00056     {
00057         rval = mb->load_file( argv[argc - 1] );MB_CHK_ERR( rval );
00058         cout << "Loaded mesh file: " << argv[argc - 1] << endl;
00059     }
00060 
00061     // Loop over set types
00062     for( int i = 0; i < 3; i++ )
00063     {
00064         rval = mb->tag_get_handle( tag_nms[i], 1, MB_TYPE_INTEGER, mtag );MB_CHK_ERR( rval );
00065 
00066         // Get all the sets of that type in the mesh
00067         sets.clear();
00068         rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &mtag, NULL, 1, sets );MB_CHK_ERR( rval );
00069 
00070         // Iterate over each set, getting entities
00071         Range::iterator set_it;
00072         for( set_it = sets.begin(); set_it != sets.end(); ++set_it )
00073         {
00074             EntityHandle this_set = *set_it;
00075 
00076             // Get the id for this set
00077             int set_id;
00078             rval = mb->tag_get_data( mtag, &this_set, 1, &set_id );MB_CHK_ERR( rval );
00079 
00080             // Get the entities in the set, recursively
00081             rval = mb->get_entities_by_handle( this_set, set_ents, true );MB_CHK_ERR( rval );
00082 
00083             cout << tag_nms[i] << " " << set_id << " has " << set_ents.size() << " entities:" << endl;
00084 
00085             // Print the entities contained in this set
00086             set_ents.print( "   " );
00087             set_ents.clear();
00088         }
00089     }
00090 
00091     delete mb;
00092 #else
00093     cout << " This test needs moab configured with netcdf \n";
00094 #endif
00095 
00096     return 0;
00097 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines