MOAB: Mesh Oriented datABase  (version 5.5.0)
test_adj.cpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 #ifdef WIN32
17 #ifdef _DEBUG
18 // turn off warnings that say they debugging identifier has been truncated
19 // this warning comes up when using some STL containers
20 #pragma warning( disable : 4786 )
21 #endif
22 #endif
23 
24 #include <iostream>
25 #include "moab/Core.hpp"
26 #include "TestUtil.hpp"
27 
28 #ifndef IS_BUILDING_MB
29 #define IS_BUILDING_MB
30 #endif
31 
32 #include "Internals.hpp"
33 #include "TestUtil.hpp"
34 
35 using namespace moab;
36 
37 int main()
38 {
39  Interface* iface = new Core;
40 
41  std::string filename;
42 
43 #ifdef MOAB_HAVE_HDF5
44  filename = TestDir + "unittest/testquad-cyl.h5m";
45 #else
46  filename = TestDir + "unittest/hexes_mixed.vtk";
47 #endif
48 
49  ErrorCode err;
50  err = iface->load_mesh( filename.c_str() );CHECK_ERR( err );
51 
52  Range quads, verts;
53  err = iface->get_entities_by_dimension( 0, 0, verts );CHECK_ERR( err );
54  err = iface->get_entities_by_dimension( 0, 2, quads );CHECK_ERR( err );
55 
56  for( Range::iterator it = verts.begin(); it != verts.end(); it++ )
57  std::cout << "verts[" << ( *it - *verts.begin() ) << "] = " << *it << std::endl;
58 
59  std::vector< EntityHandle > conn;
60  for( Range::iterator it = quads.begin(); it != quads.end(); it++ )
61  {
62  conn.clear();
63  err = iface->get_connectivity( &*it, 1, conn );CHECK_ERR( err );
64  std::cout << "quads[" << ( *it - *quads.begin() ) << "] = " << *it << " :: conn = [" << conn[0] << ", "
65  << conn[1] << ", " << conn[2] << ", " << conn[3] << "]" << std::endl;
66  }
67 
68  std::vector< EntityHandle > nodes;
69  int error;
71  CHECK_EQUAL( 0, error );
72  std::cout << "h = " << h << std::endl;
73 
74  err = iface->get_adjacencies( &h, 1, 0, true, nodes );CHECK_ERR( err );
75 
76  for( int i = 0; i < (int)nodes.size(); i++ )
77  std::cout << "nodes[" << i << "] = " << nodes[i] << " ";
78  std::cout << std::endl;
79 
80  std::vector< EntityHandle > edgs;
81  err = iface->get_adjacencies( &h, 1, 1, true, edgs );CHECK_ERR( err );
82 
83  for( int i = 0; i < (int)edgs.size(); i++ )
84  std::cout << "edgs[" << i << "] = " << edgs[i] << " ";
85  std::cout << std::endl;
86 
87  // faces to nodes
88 
89  for( unsigned int i = 0; i < edgs.size(); i++ )
90  {
91  nodes.clear();
92  err = iface->get_adjacencies( &edgs[i], 1, 0, true, nodes );CHECK_ERR( err );
93  std::cout << "edge " << ID_FROM_HANDLE( edgs[i] ) << std::endl;
94  std::cout << "nodes = ";
95  for( unsigned int j = 0; j < nodes.size(); j++ )
96  std::cout << nodes[j] << " ";
97  std::cout << std::endl;
98  }
99 
100  delete iface;
101 
102  return 0;
103 }