Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
proj1.cpp File Reference
#include "moab/Core.hpp"
#include "moab/Interface.hpp"
#include <iostream>
#include <cmath>
#include "moab/IntxMesh/IntxUtils.hpp"
#include <cassert>
+ Include dependency graph for proj1.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Variables

double radius = 1.
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 19 of file proj1.cpp.

20 {
21 
22  bool delete_partition_sets = false;
23 
24  if( argc < 3 ) return 1;
25 
26  int index = 1;
27  char* input_mesh1 = argv[1];
28  char* output = argv[2];
29  while( index < argc )
30  {
31  if( !strcmp( argv[index], "-R" ) ) // this is for radius to project
32  {
33  radius = atof( argv[++index] );
34  }
35  if( !strcmp( argv[index], "-DS" ) ) // delete partition sets
36  {
37  delete_partition_sets = true;
38  }
39 
40  if( !strcmp( argv[index], "-h" ) )
41  {
42  std::cout << " usage: proj1 <input> <output> -R <value> -DS (delete partition sets)\n";
43  return 1;
44  }
45  index++;
46  }
47 
48  Core moab;
49  Interface& mb = moab;
50 
51  ErrorCode rval = mb.load_mesh( input_mesh1 );
52 
53  std::cout << " -R " << radius << " input: " << input_mesh1 << " output: " << output << "\n";
54 
55  Range verts;
56  rval = mb.get_entities_by_dimension( 0, 0, verts );
57  if( MB_SUCCESS != rval ) return 1;
58 
59  double *x_ptr, *y_ptr, *z_ptr;
60  int count;
61  rval = mb.coords_iterate( verts.begin(), verts.end(), x_ptr, y_ptr, z_ptr, count );
62  if( MB_SUCCESS != rval ) return 1;
63  assert( count == (int)verts.size() ); // should end up with just one contiguous chunk of vertices
64 
65  for( int v = 0; v < count; v++ )
66  {
67  // EntityHandle v = verts[v];
68  CartVect pos( x_ptr[v], y_ptr[v], z_ptr[v] );
69  pos = pos / pos.length();
70  pos = radius * pos;
71  x_ptr[v] = pos[0];
72  y_ptr[v] = pos[1];
73  z_ptr[v] = pos[2];
74  }
75 
76  Range edges;
77  rval = mb.get_entities_by_dimension( 0, 1, edges );
78  if( MB_SUCCESS != rval ) return 1;
79  // write edges to a new set, and after that, write the set, delete the edges and the set
80  EntityHandle sf1;
81  rval = mb.create_meshset( MESHSET_SET, sf1 );
82  if( MB_SUCCESS != rval ) return 1;
83  rval = mb.add_entities( sf1, edges );
84  if( MB_SUCCESS != rval ) return 1;
85  rval = mb.write_mesh( "edgesOnly.h5m", &sf1, 1 );
86  if( MB_SUCCESS != rval ) return 1;
87  rval = mb.delete_entities( &sf1, 1 );
88  if( MB_SUCCESS != rval ) return 1;
89  mb.delete_entities( edges );
90  mb.write_file( output );
91 
92  if( delete_partition_sets )
93  {
94  Tag par_tag;
95  rval = mb.tag_get_handle( "PARALLEL_PARTITION", par_tag );
96  if( MB_SUCCESS == rval )
97 
98  {
99  Range par_sets;
100  rval =
101  mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &par_tag, NULL, 1, par_sets, moab::Interface::UNION );
102  if( !par_sets.empty() ) mb.delete_entities( par_sets );
103  mb.tag_delete( par_tag );
104  }
105  }
106 
107  return 0;
108 }

References moab::Core::add_entities(), moab::Range::begin(), moab::Core::coords_iterate(), moab::Core::create_meshset(), moab::Core::delete_entities(), moab::Range::empty(), moab::Range::end(), ErrorCode, moab::Core::get_entities_by_dimension(), moab::Core::get_entities_by_type_and_tag(), moab::CartVect::length(), moab::Core::load_mesh(), mb, MB_SUCCESS, MBENTITYSET, MESHSET_SET, output, radius, moab::Range::size(), moab::Core::tag_delete(), moab::Core::tag_get_handle(), moab::Interface::UNION, moab::Core::write_file(), and moab::Core::write_mesh().

Variable Documentation

◆ radius

double radius = 1.

Definition at line 17 of file proj1.cpp.

Referenced by main().