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 entities there are.\n
4 *
5 * To run: ./HelloMOAB [meshfile]\n
6 * (default values can run if users don't specify a mesh file)
7 */
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
main(int argc,char ** argv)23 int main(int argc, char **argv)
24 {
25 // Get MOAB instance
26 Interface* mb = new (std::nothrow) Core;
27 if (NULL == mb)
28 return 1;
29
30 // Need option handling here for input filename
31 if (argc > 1) {
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 }
65