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
HelloMOAB.cpp
Go to the documentation of this file.
1 /** @example HelloMOAB.cpp 2  * Description: read a mesh, get the entities.\n 3  * HelloMOAB is a simple test file which is used to read meshes from VTK file and test how many 4  * entities there are.\n 5  * 6  * To run: ./HelloMOAB [meshfile]\n 7  * (default values can run if users don't specify a mesh file) 8  */ 9  10 #include "moab/Core.hpp" 11 #include <iostream> 12  13 using namespace moab; 14 using namespace std; 15  16 #ifndef MESH_DIR 17 #define MESH_DIR "." 18 #endif 19  20 // Note: change the file name below to test a trivial "No such file or directory" error 21 string test_file_name = string( MESH_DIR ) + string( "/3k-tri-sphere.vtk" ); 22  23 int main( int argc, char** argv ) 24 { 25  // Get MOAB instance 26  Interface* mb = new( std::nothrow ) Core; 27  if( NULL == mb ) return 1; 28  29  // Need option handling here for input filename 30  if( argc > 1 ) 31  { 32  // User has input a mesh file 33  test_file_name = argv[1]; 34  } 35  36  // Load the mesh from vtk file 37  ErrorCode rval = mb->load_mesh( test_file_name.c_str() );MB_CHK_ERR( rval ); 38  39  // Get verts entities, by type 40  Range verts; 41  rval = mb->get_entities_by_type( 0, MBVERTEX, verts );MB_CHK_ERR( rval ); 42  43  // Get edge entities, by type 44  Range edges; 45  rval = mb->get_entities_by_type( 0, MBEDGE, edges );MB_CHK_ERR( rval ); 46  47  // Get faces, by dimension, so we stay generic to entity type 48  Range faces; 49  rval = mb->get_entities_by_dimension( 0, 2, faces );MB_CHK_ERR( rval ); 50  51  // Get regions, by dimension, so we stay generic to entity type 52  Range elems; 53  rval = mb->get_entities_by_dimension( 0, 3, elems );MB_CHK_ERR( rval ); 54  55  // Output the number of entities 56  cout << "Number of vertices is " << verts.size() << endl; 57  cout << "Number of edges is " << edges.size() << endl; 58  cout << "Number of faces is " << faces.size() << endl; 59  cout << "Number of elements is " << elems.size() << endl; 60  61  delete mb; 62  63  return 0; 64 }