MOAB: Mesh Oriented datABase  (version 5.5.0)
scdtest.cpp File Reference
#include <string>
#include <iomanip>
#include <iostream>
#include <cassert>
#include "moab/Core.hpp"
#include "moab/ParallelComm.hpp"
#include "moab/HomXform.hpp"
#include "MBParallelConventions.h"
#include "MBTagConventions.hpp"
+ Include dependency graph for scdtest.cpp:

Go to the source code of this file.

Functions

void set_local_domain_bounds ()
 
void create_hexes_and_verts ()
 
void resolve_and_exchange ()
 
void error (ErrorCode err)
 
int main (int argc, char *argv[])
 

Variables

const int NI = 2
 
const int NJ = 2
 
const int NK = 1
 
Interfacembint = NULL
 
ParallelCommmbpc = NULL
 
int is
 
int js
 
int ks
 
int ie
 
int je
 
int ke
 
int rank
 
int size
 

Function Documentation

◆ create_hexes_and_verts()

void create_hexes_and_verts ( )

Definition at line 140 of file scdtest.cpp.

141 {
142  Core* mbcore = dynamic_cast< Core* >( mbint );
143  HomCoord coord_min( 0, 0, 0 );
144  HomCoord coord_max( ie - is, je - js, ke - ks );
145  EntitySequence* vertex_seq = NULL;
146  EntitySequence* cell_seq = NULL;
147  EntityHandle vs, cs;
148 
149  error( mbcore->create_scd_sequence( coord_min, coord_max, MBVERTEX, 1, vs, vertex_seq ) );
150  error( mbcore->create_scd_sequence( coord_min, coord_max, MBHEX, 1, cs, cell_seq ) );
151 
152  HomCoord p1( 0, 0, 0 );
153  HomCoord p2( 1, 0, 0 );
154  HomCoord p3( 0, 1, 0 );
155 
156  error( mbcore->add_vsequence( vertex_seq, cell_seq, p1, p1, p2, p2, p3, p3 ) );
157 
158  // Set global id's:
159  int gid;
160  Tag global_id_tag = mbint->globalId_tag();
161  EntityHandle handle = vs;
162  int i, j, k;
163 
164  ErrorCode err;
165 
166  for( k = ks; k < ke + 1; k++ )
167  for( j = js; j < je + 1; j++ )
168  for( i = is; i < ie + 1; i++ )
169  {
170  gid = 1 + i + j * ( NI + 1 ) + k * ( NI + 1 ) * ( NJ + 1 );
171  err = mbint->tag_set_data( global_id_tag, &handle, 1, &gid );
172  if( err != MB_SUCCESS )
173  {
174  exit( 1 );
175  }
176  handle++;
177  }
178 
179  handle = cs;
180  for( k = ks; k < ke; k++ )
181  for( j = js; j < je; j++ )
182  for( i = is; i < ie; i++ )
183  {
184  gid = 1 + i + j * NI + k * NI * NJ;
185  error( mbint->tag_set_data( global_id_tag, &handle, 1, &gid ) );
186  handle++;
187  }
188 }

References moab::Core::add_vsequence(), moab::Core::create_scd_sequence(), moab::error(), ErrorCode, moab::Interface::globalId_tag(), ie, is, je, js, ke, ks, MB_SUCCESS, mbcore, MBHEX, mbint, MBVERTEX, NI, NJ, and moab::Interface::tag_set_data().

Referenced by main().

◆ error()

void error ( ErrorCode  err)

Definition at line 219 of file scdtest.cpp.

220 {
221  if( err != MB_SUCCESS )
222  {
223  std::cerr << "Error: MOAB function failed\n";
224  assert( 0 );
225  }
226 }

References MB_SUCCESS.

◆ main()

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

Definition at line 44 of file scdtest.cpp.

45 {
46  MPI_Init( &argc, &argv );
47  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
48  MPI_Comm_size( MPI_COMM_WORLD, &size );
49  if( size != 4 && size != 2 )
50  {
51  std::cerr << "Run this with 2 or 4 processes\n";
52  MPI_Finalize();
53  exit( 1 );
54  }
55 
56  mbint = new Core();
58 
62 
63  delete mbpc; // ParallelComm instance should be deleted before MOAB instance is deleted
64  delete mbint;
65 
66  MPI_Finalize();
67  return 0;
68 }

References create_hexes_and_verts(), mbint, mbpc, MPI_COMM_WORLD, rank, resolve_and_exchange(), set_local_domain_bounds(), and size.

◆ resolve_and_exchange()

void resolve_and_exchange ( )

Definition at line 190 of file scdtest.cpp.

191 {
192  EntityHandle entity_set;
193 
194  // Create the entity set:
195  error( mbint->create_meshset( MESHSET_SET, entity_set ) );
196 
197  // Get a list of hexes:
198  Range range;
199  error( mbint->get_entities_by_type( 0, MBHEX, range ) );
200 
201  // Add entities to the entity set:
202  error( mbint->add_entities( entity_set, range ) );
203 
204  // Add the MATERIAL_SET tag to the entity set:
205  Tag tag;
207  error( mbint->tag_set_data( tag, &entity_set, 1, &rank ) );
208 
209  // Set up partition sets. This is where MOAB is actually told what
210  // entities each process owns:
212 
213  // Finally, determine which entites are shared and exchange the
214  // ghosted entities:
215  error( mbpc->resolve_shared_ents( 0, -1, -1 ) );
216  error( mbpc->exchange_ghost_cells( -1, 0, 1, 0, true ) );
217 }

References moab::Interface::add_entities(), moab::Interface::create_meshset(), moab::error(), moab::ParallelComm::exchange_ghost_cells(), moab::Interface::get_entities_by_type(), moab::Interface::get_entities_by_type_and_tag(), MATERIAL_SET_TAG_NAME, MB_TYPE_INTEGER, MBENTITYSET, MBHEX, mbint, mbpc, MESHSET_SET, moab::ParallelComm::partition_sets(), rank, moab::ParallelComm::resolve_shared_ents(), moab::Interface::tag_get_handle(), and moab::Interface::tag_set_data().

Referenced by main().

◆ set_local_domain_bounds()

void set_local_domain_bounds ( )

Definition at line 70 of file scdtest.cpp.

71 {
72  switch( size )
73  {
74  case 2:
75  switch( rank )
76  {
77  case 0:
78  is = 0;
79  ie = NI / 2;
80  js = 0;
81  je = NJ;
82  ks = 0;
83  ke = NK;
84  break;
85  case 1:
86  is = NI / 2;
87  ie = NI;
88  js = 0;
89  je = NJ;
90  ks = 0;
91  ke = NK;
92  break;
93  }
94  break;
95 
96  case 4:
97  switch( rank )
98  {
99  case 0:
100  is = 0;
101  ie = NI / 2;
102  js = 0;
103  je = NJ / 2;
104  ks = 0;
105  ke = NK;
106  break;
107  case 1:
108  is = NI / 2;
109  ie = NI;
110  js = 0;
111  je = NJ / 2;
112  ks = 0;
113  ke = NK;
114  break;
115  case 2:
116  is = 0;
117  ie = NI / 2;
118  js = NJ / 2;
119  je = NJ;
120  ks = 0;
121  ke = NK;
122  break;
123  case 3:
124  is = NI / 2;
125  ie = NI;
126  js = NJ / 2;
127  je = NJ;
128  ks = 0;
129  ke = NK;
130  break;
131  }
132  break;
133 
134  default:
135  std::cerr << "Run this with 4 processes\n";
136  exit( 1 );
137  }
138 }

References ie, is, je, js, ke, ks, NI, NJ, NK, rank, and size.

Referenced by main().

Variable Documentation

◆ ie

◆ is

int is

Definition at line 32 of file scdtest.cpp.

Referenced by create_hexes_and_verts(), get_vartag_data(), and set_local_domain_bounds().

◆ je

int je

Definition at line 33 of file scdtest.cpp.

Referenced by create_hexes_and_verts(), and set_local_domain_bounds().

◆ js

int js

Definition at line 32 of file scdtest.cpp.

Referenced by create_hexes_and_verts(), and set_local_domain_bounds().

◆ ke

int ke

Definition at line 33 of file scdtest.cpp.

Referenced by create_hexes_and_verts(), and set_local_domain_bounds().

◆ ks

int ks

Definition at line 32 of file scdtest.cpp.

Referenced by create_hexes_and_verts(), and set_local_domain_bounds().

◆ mbint

Interface* mbint = NULL

◆ mbpc

◆ NI

const int NI = 2

Definition at line 17 of file scdtest.cpp.

Referenced by create_hexes_and_verts(), main(), and set_local_domain_bounds().

◆ NJ

const int NJ = 2

Definition at line 18 of file scdtest.cpp.

Referenced by create_hexes_and_verts(), main(), and set_local_domain_bounds().

◆ NK

const int NK = 1

Definition at line 19 of file scdtest.cpp.

Referenced by set_local_domain_bounds().

◆ rank

int rank

Definition at line 36 of file scdtest.cpp.

Referenced by main(), resolve_and_exchange(), and set_local_domain_bounds().

◆ size

int size

Definition at line 37 of file scdtest.cpp.

Referenced by main(), and set_local_domain_bounds().