Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
depth.cpp File Reference
#include "moab/Range.hpp"
#include "moab/Core.hpp"
#include "moab/Skinner.hpp"
#include <iostream>
#include <cstdlib>
+ Include dependency graph for depth.cpp:

Go to the source code of this file.

Enumerations

enum  { NO_ERROR = 0 , SYNTAX_ERROR = 1 , FILE_IO_ERROR = 2 , INTERNAL_ERROR = 3 }
 

Functions

static void usage (const char *argv0)
 
static void check (ErrorCode rval)
 
static void tag_depth (Interface &moab, Tag tag)
 
int main (int argc, char *argv[])
 
static ErrorCode get_adjacent_elems (Interface &mb, const Range &verts, Range &elems)
 

Variables

const char * DEFAULT_TAG_NAME = "depth"
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NO_ERROR 
SYNTAX_ERROR 
FILE_IO_ERROR 
INTERNAL_ERROR 

Definition at line 9 of file depth.cpp.

10 {
11  NO_ERROR = 0,
12  SYNTAX_ERROR = 1,
13  FILE_IO_ERROR = 2,
14  INTERNAL_ERROR = 3
15 };

Function Documentation

◆ check()

static void check ( ErrorCode  rval)
static

Definition at line 26 of file depth.cpp.

27 {
28  if( MB_SUCCESS != rval )
29  {
30  std::cerr << "Internal error. Aborting." << std::endl;
31  exit( INTERNAL_ERROR );
32  }
33 }

References INTERNAL_ERROR, and MB_SUCCESS.

Referenced by create_mesh_no_holes(), directaccessnoholesf90(), main(), tag_depth(), and moab::ParallelMergeMesh::TupleGreaterThan().

◆ get_adjacent_elems()

static ErrorCode get_adjacent_elems ( Interface mb,
const Range verts,
Range elems 
)
static

Definition at line 117 of file depth.cpp.

118 {
119  elems.clear();
120  ErrorCode rval;
121  for( int dim = 3; dim > 0; --dim )
122  {
123  rval = mb.get_adjacencies( verts, dim, false, elems, Interface::UNION );
124  if( MB_SUCCESS != rval ) break;
125  }
126  return rval;
127 }

References moab::Range::clear(), dim, ErrorCode, moab::Core::get_adjacencies(), mb, MB_SUCCESS, and moab::Interface::UNION.

Referenced by tag_depth().

◆ main()

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

Definition at line 37 of file depth.cpp.

38 {
39  const char *input = 0, *output = 0, *tagname = DEFAULT_TAG_NAME;
40  bool expect_tag_name = false;
41  for( int i = 1; i < argc; ++i )
42  {
43  if( expect_tag_name )
44  {
45  tagname = argv[i];
46  expect_tag_name = false;
47  }
48  else if( !strcmp( "-t", argv[i] ) )
49  expect_tag_name = true;
50  else if( input == 0 )
51  input = argv[i];
52  else if( output == 0 )
53  output = argv[i];
54  else
55  {
56  std::cerr << "Unexpected argument: '" << argv[i] << "'" << std::endl;
57  usage( argv[0] );
58  }
59  }
60 
61  if( expect_tag_name )
62  {
63  std::cerr << "Expected argument following '-t'" << std::endl;
64  usage( argv[0] );
65  }
66  if( !input )
67  {
68  std::cerr << "No input file" << std::endl;
69  usage( argv[0] );
70  }
71  if( !output )
72  {
73  std::cerr << "No output file" << std::endl;
74  usage( argv[0] );
75  }
76 
77  Core moab;
78  Interface& mb = moab;
79 
80  EntityHandle file;
81  ErrorCode rval;
82  rval = mb.create_meshset( MESHSET_SET, file );
83  check( rval );
84  rval = mb.load_file( input, &file );
85  if( MB_SUCCESS != rval )
86  {
87  std::cerr << "Failed to load file: " << input << std::endl;
88  return FILE_IO_ERROR;
89  }
90 
91  int init_val = -1;
92  Tag tag;
93  bool created;
94  rval = mb.tag_get_handle( tagname, 1, MB_TYPE_INTEGER, tag, MB_TAG_DENSE | MB_TAG_CREAT, &init_val, &created );
95  if( !created )
96  {
97  rval = mb.tag_delete( tag );
98  check( rval );
99  rval = mb.tag_get_handle( tagname, 1, MB_TYPE_INTEGER, tag, MB_TAG_DENSE | MB_TAG_CREAT, &init_val, &created );
100  check( rval );
101  }
102 
103  tag_depth( mb, tag );
104 
105  rval = mb.write_file( output, 0, 0, &file, 1 );
106  if( rval == MB_SUCCESS )
107  std::cout << "Wrote file: " << output << std::endl;
108  else
109  {
110  std::cerr << "Failed to write file: " << output << std::endl;
111  return FILE_IO_ERROR;
112  }
113 
114  return NO_ERROR;
115 }

References check(), moab::Core::create_meshset(), moab::DEFAULT_TAG_NAME, ErrorCode, FILE_IO_ERROR, moab::Core::load_file(), mb, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, MESHSET_SET, NO_ERROR, output, moab::Core::tag_delete(), tag_depth(), moab::Core::tag_get_handle(), usage(), and moab::Core::write_file().

◆ tag_depth()

void tag_depth ( Interface moab,
Tag  tag 
)
static

Definition at line 129 of file depth.cpp.

130 {
131  ErrorCode rval;
132  int dim;
133 
134  Skinner tool( &mb );
135  Range verts, elems;
136  dim = 3;
137  while( elems.empty() )
138  {
139  rval = mb.get_entities_by_dimension( 0, dim, elems );
140  check( rval );
141  if( --dim == 0 ) return; // no elements
142  }
143  rval = tool.find_skin( 0, elems, 0, verts );
144  check( rval );
145  rval = get_adjacent_elems( mb, verts, elems );
146  check( rval );
147 
148  std::vector< int > data;
149  int val, depth = 0;
150  while( !elems.empty() )
151  {
152  data.clear();
153  data.resize( elems.size(), depth++ );
154  rval = mb.tag_set_data( tag, elems, &data[0] );
155  check( rval );
156 
157  verts.clear();
158  rval = mb.get_adjacencies( elems, 0, false, verts, Interface::UNION );
159  check( rval );
160 
161  Range tmp;
162  rval = get_adjacent_elems( mb, verts, tmp );
163  check( rval );
164  elems.clear();
165  for( Range::reverse_iterator i = tmp.rbegin(); i != tmp.rend(); ++i )
166  {
167  rval = mb.tag_get_data( tag, &*i, 1, &val );
168  check( rval );
169  if( val == -1 ) elems.insert( *i );
170  }
171  }
172 
173  std::cout << "Maximum depth: " << depth << std::endl;
174 }

References check(), moab::Range::clear(), dim, moab::Range::empty(), ErrorCode, moab::Skinner::find_skin(), moab::Core::get_adjacencies(), get_adjacent_elems(), moab::Core::get_entities_by_dimension(), moab::Range::insert(), mb, moab::Range::rbegin(), moab::Range::rend(), moab::Range::size(), moab::Core::tag_get_data(), moab::Core::tag_set_data(), and moab::Interface::UNION.

Referenced by main().

◆ usage()

static void usage ( const char *  argv0)
static

Definition at line 19 of file depth.cpp.

20 {
21  std::cerr << "Usage: " << argv0 << "[-t <tag name] <input_file> <output_file>" << std::endl
22  << argv0 << "-h" << std::endl;
23  exit( SYNTAX_ERROR );
24 }

References SYNTAX_ERROR.

Referenced by main().

Variable Documentation

◆ DEFAULT_TAG_NAME

const char* DEFAULT_TAG_NAME = "depth"

Definition at line 17 of file depth.cpp.