Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestExodusII.cpp
Go to the documentation of this file.
1 /** @example TestExodusII.cpp 2  * This example demonstrates how to retrieve material, dirichlet and neumann sets 3  * from an ExodusII file. \n 4  * Sets in MOAB contain entities and have a tag on them to give meaning to the entities. 5  * Tag names: MATERIAL_SET", "DIRICHLET_SET" and "NEUMANN_SET" are reserved and 6  * are associated with their corresponding entity sets. 7  * Sets are traversed to find out the type number of entities contained in each set. \n 8  * 9  * <b>Steps in this example </b>: 10  * -# Instantiate MOAB 11  * -# Get input mesh file name and load it. 12  * -# Loop over the three sets: material, dirichlet and neumann 13  * -# Get TagHandle and EntitySet(corresponding to the TagHandle) 14  * -# Loop thru all the EntitySet's 15  * -# Get the set id and entities in this set 16  * -# Destroy the MOAB instance 17  * 18  * 19  * <b> To compile: </b> 20  * make TestExodusII \n 21  * 22  * <b> To run: </b> 23  * -# TestExodusII <mesh-file> \n 24  * -# TestExodusII (This uses the default <mesh-file>: MeshFiles/unittest/mbtest2.g) 25  */ 26 #include <iostream> 27  28 // Include header for MOAB instance and range 29 #include "moab/Core.hpp" 30  31 using namespace moab; 32 using namespace std; 33  34 string test_file_name = string( MESH_DIR ) + string( "/mbtest2.g" ); 35 int main( int argc, char** argv ) 36 { 37 #ifdef MOAB_HAVE_NETCDF 38  // Get MOAB instance 39  Interface* mb = new( std::nothrow ) Core; 40  if( NULL == mb ) return 1; 41  42  // Get the material set tag handle 43  Tag mtag; 44  ErrorCode rval; 45  const char* tag_nms[] = { "MATERIAL_SET", "DIRICHLET_SET", "NEUMANN_SET" }; 46  Range sets, set_ents; 47  48  // Load a file 49  if( argc == 1 ) 50  { 51  cout << "Running default case, loading " << test_file_name << endl; 52  cout << "Usage: " << argv[0] << " <filename>\n" << endl; 53  rval = mb->load_file( test_file_name.c_str() );MB_CHK_ERR( rval ); 54  } 55  else 56  { 57  rval = mb->load_file( argv[argc - 1] );MB_CHK_ERR( rval ); 58  cout << "Loaded mesh file: " << argv[argc - 1] << endl; 59  } 60  61  // Loop over set types 62  for( int i = 0; i < 3; i++ ) 63  { 64  rval = mb->tag_get_handle( tag_nms[i], 1, MB_TYPE_INTEGER, mtag );MB_CHK_ERR( rval ); 65  66  // Get all the sets of that type in the mesh 67  sets.clear(); 68  rval = mb->get_entities_by_type_and_tag( 0, MBENTITYSET, &mtag, NULL, 1, sets );MB_CHK_ERR( rval ); 69  70  // Iterate over each set, getting entities 71  Range::iterator set_it; 72  for( set_it = sets.begin(); set_it != sets.end(); ++set_it ) 73  { 74  EntityHandle this_set = *set_it; 75  76  // Get the id for this set 77  int set_id; 78  rval = mb->tag_get_data( mtag, &this_set, 1, &set_id );MB_CHK_ERR( rval ); 79  80  // Get the entities in the set, recursively 81  rval = mb->get_entities_by_handle( this_set, set_ents, true );MB_CHK_ERR( rval ); 82  83  cout << tag_nms[i] << " " << set_id << " has " << set_ents.size() << " entities:" << endl; 84  85  // Print the entities contained in this set 86  set_ents.print( " " ); 87  set_ents.clear(); 88  } 89  } 90  91  delete mb; 92 #else 93  cout << " This test needs moab configured with netcdf \n"; 94 #endif 95  96  return 0; 97 }