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 */910#include"moab/Core.hpp"11#include<iostream>1213usingnamespace moab;
14usingnamespace std;
1516#ifndef MESH_DIR17#define MESH_DIR "."18#endif1920// Note: change the file name below to test a trivial "No such file or directory" error21 string test_file_name = string( MESH_DIR ) + string( "/3k-tri-sphere.vtk" );
2223intmain( int argc, char** argv )
24 {
25// Get MOAB instance26 Interface* mb = new( std::nothrow ) Core;
27if( NULL == mb ) return1;
2829// Need option handling here for input filename30if( argc > 1 )
31 {
32// User has input a mesh file33 test_file_name = argv[1];
34 }
3536// Load the mesh from vtk file37 ErrorCode rval = mb->load_mesh( test_file_name.c_str() );MB_CHK_ERR( rval );
3839// Get verts entities, by type40 Range verts;
41 rval = mb->get_entities_by_type( 0, MBVERTEX, verts );MB_CHK_ERR( rval );
4243// Get edge entities, by type44 Range edges;
45 rval = mb->get_entities_by_type( 0, MBEDGE, edges );MB_CHK_ERR( rval );
4647// Get faces, by dimension, so we stay generic to entity type48 Range faces;
49 rval = mb->get_entities_by_dimension( 0, 2, faces );MB_CHK_ERR( rval );
5051// Get regions, by dimension, so we stay generic to entity type52 Range elems;
53 rval = mb->get_entities_by_dimension( 0, 3, elems );MB_CHK_ERR( rval );
5455// Output the number of entities56 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;
6061delete mb;
6263return0;
64 }