MOAB: Mesh Oriented datABase  (version 5.4.1)
SetsNTags.cpp
Go to the documentation of this file.
00001 /** @example SetsNTags.cpp
00002  * Description: Get the sets representing materials and Dirichlet/Neumann boundary conditions and
00003  * list their contents.\n This example shows how to get entity sets, and tags on those sets.
00004  *
00005  * To run: ./SetsNTags [meshfile]\n
00006  * (default values can run if users don't specify a mesh file)
00007  */
00008 
00009 #include "moab/Core.hpp"
00010 #include "moab/Interface.hpp"
00011 #include "moab/Range.hpp"
00012 #include "MBTagConventions.hpp"
00013 
00014 #include <iostream>
00015 
00016 using namespace moab;
00017 using namespace std;
00018 
00019 #ifndef MESH_DIR
00020 #define MESH_DIR "."
00021 #endif
00022 
00023 string test_file_name = string( MESH_DIR ) + string( "/hex01.vtk" );
00024 
00025 // Tag names for these conventional tags come from MBTagConventions.hpp
00026 const char* tag_nms[] = { MATERIAL_SET_TAG_NAME, DIRICHLET_SET_TAG_NAME, NEUMANN_SET_TAG_NAME };
00027 
00028 int main( int argc, char** argv )
00029 {
00030     // Get the material set tag handle
00031     Tag mtag;
00032     ErrorCode rval;
00033     Range sets, set_ents;
00034 
00035     // Get MOAB instance
00036     Interface* mb = new( std::nothrow ) Core;
00037     if( NULL == mb ) return 1;
00038 
00039     // Need option handling here for input filename
00040     if( argc > 1 )
00041     {
00042         // User has input a mesh file
00043         test_file_name = argv[1];
00044     }
00045 
00046     // Load a file
00047     rval = mb->load_file( test_file_name.c_str() );MB_CHK_ERR( rval );
00048 
00049     // Loop over set types
00050     for( int i = 0; i < 3; i++ )
00051     {
00052         // Get the tag handle for this tag name; tag should already exist (it was created during
00053         // file read)
00054         rval = mb->tag_get_handle( tag_nms[i], 1, MB_TYPE_INTEGER, mtag );MB_CHK_ERR( rval );
00055 
00056         // Get all the sets having that tag (with any value for that tag)
00057         sets.clear();
00058         rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &mtag, NULL, 1, sets );MB_CHK_ERR( rval );
00059 
00060         // Iterate over each set, getting the entities and printing them
00061         Range::iterator set_it;
00062         for( set_it = sets.begin(); set_it != sets.end(); ++set_it )
00063         {
00064             // Get the id for this set
00065             int set_id;
00066             rval = mb->tag_get_data( mtag, &( *set_it ), 1, &set_id );MB_CHK_ERR( rval );
00067 
00068             // Get the entities in the set, recursively
00069             rval = mb->get_entities_by_handle( *set_it, set_ents, true );MB_CHK_ERR( rval );
00070 
00071             cout << tag_nms[i] << " " << set_id << " has " << set_ents.size() << " entities:" << endl;
00072             set_ents.print( "   " );
00073             set_ents.clear();
00074         }
00075     }
00076 
00077     delete mb;
00078 
00079     return 0;
00080 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines