Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
proj1.cpp
Go to the documentation of this file.
1 /*
2  * proj1.cpp
3  *
4  * project on a sphere of radius R, delete sets if needed, and delete edges between parts
5  * (created by resolve shared ents)
6  */
7 
8 #include "moab/Core.hpp"
9 #include "moab/Interface.hpp"
10 #include <iostream>
11 #include <cmath>
12 
14 #include <cassert>
15 using namespace moab;
16 
17 double radius = 1.; // in m: 6371220.
18 
19 int main( int argc, char** argv )
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 }