MOAB: Mesh Oriented datABase  (version 5.5.0)
dual_test.cpp File Reference
#include "moab/Core.hpp"
#include "moab/Range.hpp"
#include "moab/MeshTopoUtil.hpp"
#include "moab/DualTool.hpp"
#include "../TestUtil.hpp"
#include <iostream>
#include <string>
+ Include dependency graph for dual_test.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

std::string default_input = TestDir + "unittest/hex01.vtk"
 
const char default_output [] = "dual.vtk"
 
InterfacegMB
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 18 of file dual_test.cpp.

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
99  result = gMB->tag_get_handle( DualTool::DUAL_CURVE_TAG_NAME, 1, MB_TYPE_HANDLE, hp_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
111  result = gMB->tag_get_handle( DualTool::DUAL_SURFACE_TAG_NAME, 1, MB_TYPE_HANDLE, hp_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 }

References moab::Range::clear(), moab::MeshTopoUtil::construct_aentities(), moab::DualTool::construct_dual(), moab::DualTool::construct_hex_dual(), default_input, default_output, moab::DualTool::DUAL_CURVE_TAG_NAME, moab::DualTool::DUAL_SURFACE_TAG_NAME, moab::Range::empty(), ErrorCode, moab::DualTool::get_dual_entities(), moab::Interface::get_entities_by_dimension(), moab::Interface::get_entities_by_type_and_tag(), moab::Interface::get_number_entities_by_dimension(), moab::Interface::get_number_entities_by_type(), gMB, moab::Interface::load_mesh(), MB_SUCCESS, MB_TYPE_HANDLE, MBENTITYSET, MBHEX, MBQUAD, moab::Range::size(), moab::Interface::tag_get_handle(), and moab::Interface::write_file().

Variable Documentation

◆ default_input

std::string default_input = TestDir + "unittest/hex01.vtk"

Definition at line 13 of file dual_test.cpp.

Referenced by main().

◆ default_output

const char default_output[] = "dual.vtk"

Definition at line 14 of file dual_test.cpp.

Referenced by main().

◆ gMB

Interface* gMB

Definition at line 16 of file dual_test.cpp.

Referenced by main().