MOAB: Mesh Oriented datABase  (version 5.5.0)
dual_test.cpp
Go to the documentation of this file.
1 // tests dual construction code
2 
3 #include "moab/Core.hpp"
4 #include "moab/Range.hpp"
5 #include "moab/MeshTopoUtil.hpp"
6 #include "moab/DualTool.hpp"
7 #include "../TestUtil.hpp"
8 #include <iostream>
9 #include <string>
10 
11 using namespace moab;
12 
13 std::string default_input = TestDir + "unittest/hex01.vtk";
14 const char default_output[] = "dual.vtk";
15 
17 
18 int main( int argc, char* argv[] )
19 {
20  const char* f1 = default_input.c_str();
21  const char* f2 = default_output;
22  if( argc <= 2 )
23  {
24  std::cout << "Usage: dual_test <mesh_file_name> <out file>" << std::endl;
25  std::cout << "using default input : " << default_input << " and output " << default_output << "\n";
26  }
27  else
28  {
29  f1 = argv[1];
30  f2 = argv[2];
31  }
32 
33  gMB = new Core();
34 
35  // read the mesh file
36  ErrorCode result = gMB->load_mesh( f1 );
37  if( MB_SUCCESS != result )
38  {
39  std::cout << "Problems reading file " << argv[1] << "." << std::endl;
40  delete gMB;
41  return 1;
42  }
43 
44  // make sure aentities are created
45  Range all_verts;
46  result = gMB->get_entities_by_dimension( 0, 0, all_verts );
47  if( MB_SUCCESS != result ) std::cout << "Problem getting vertices." << std::endl;
48 
49  MeshTopoUtil( gMB ).construct_aentities( all_verts );
50 
51  // get counts before constructing dual
52  int num_edges;
53  result = gMB->get_number_entities_by_dimension( 0, 1, num_edges );
54  if( MB_SUCCESS != result ) std::cout << "Problem getting number of edges." << std::endl;
55 
56  // see if it's all-hex or all-quad, and construct hex/quad dual if so
57  int num_hex, num_quad, num_3d, num_2d;
58  result = gMB->get_number_entities_by_dimension( 0, 2, num_2d );
59  if( MB_SUCCESS != result ) return 0;
60  result = gMB->get_number_entities_by_dimension( 0, 3, num_3d );
61  if( MB_SUCCESS != result ) return 0;
62  result = gMB->get_number_entities_by_type( 0, MBQUAD, num_quad );
63  if( MB_SUCCESS != result ) return 0;
64  result = gMB->get_number_entities_by_type( 0, MBHEX, num_hex );
65  if( MB_SUCCESS != result ) return 0;
66 
67  // construct the dual for this mesh
68  DualTool dt( gMB );
69  if( num_quad == num_2d && num_hex == num_3d )
70  result = dt.construct_hex_dual( 0, 0 );
71  else
72  result = dt.construct_dual( 0, 0 );
73  if( MB_SUCCESS != result )
74  {
75  std::cout << "Problems constructing dual." << std::endl;
76  return 0;
77  }
78 
79  // print information about the dual
80  Range dual_cells, dual_faces;
81  result = dt.get_dual_entities( 0, 0, 2, dual_faces );
82  if( MB_SUCCESS != result )
83  std::cout << "Problem getting dual faces." << std::endl;
84  else
85  std::cout << "Found " << dual_faces.size() << "/" << num_edges << " dual faces." << std::endl;
86 
87  result = dt.get_dual_entities( 0, 0, 3, dual_cells );
88  if( MB_SUCCESS != result )
89  std::cout << "Problem getting dual cells." << std::endl;
90  else
91  std::cout << "Found " << dual_cells.size() << "/" << all_verts.size() << " dual cells." << std::endl;
92 
93  // print information about dual hyperplanes, if any
94  Tag hp_tag;
95  Range hp_sets;
96  if( num_2d == num_quad )
97  {
98  // get sets with the right tag
100  if( MB_SUCCESS == result )
101  {
102  result = gMB->get_entities_by_type_and_tag( 0, MBENTITYSET, &hp_tag, NULL, 1, hp_sets );
103  if( MB_SUCCESS == result && !hp_sets.empty() )
104  std::cout << "Found " << hp_sets.size() << " 1d dual hyperplanes (chords)." << std::endl;
105  }
106  }
107 
108  if( num_3d == num_hex )
109  {
110  // get sets with the right tag
112  if( MB_SUCCESS == result )
113  {
114  hp_sets.clear();
115  result = gMB->get_entities_by_type_and_tag( 0, MBENTITYSET, &hp_tag, NULL, 1, hp_sets );
116  if( MB_SUCCESS == result && !hp_sets.empty() )
117  std::cout << "Found " << hp_sets.size() << " 2d dual hyperplanes (sheets)." << std::endl;
118  }
119  }
120 
121  // write GMV file
122  gMB->write_file( f2 );
123  delete gMB;
124 
125  return 0;
126 }