10 #define CHECKRC( rc, message ) \
13 printf( "Error: %s.\n", message ); \
17 int main(
int argc,
char* argv[] )
21 int nprocs = 1,
rank = 0;
22 char filen[1024] =
"";
25 int irank = 0, num_tags_to_sync = 1;
31 int compid = 11, compdupid = 12;
33 int num_global_vertices = 0, num_global_elements = 0, num_dimension = 0, num_parts = 0;
34 int nverts[3], nelem[3], nblocks[3], nsbc[3], ndbc[3];
42 const char* read_opts =
"PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS";
43 int num_ghost_layers[1] = { 1 };
45 const char* read_opts =
"";
46 int num_ghost_layers[1] = { 0 };
51 int entTypes[2] = { 0, 1 };
53 int num_components = 1;
56 int vertices_per_element, num_elements_in_block;
57 int conn[27], nv, eindex;
60 double* double_tag_vals;
63 int num_adjacent_elements = 10;
64 iMOAB_LocalID adjacent_element_IDs[10], *element_connectivity, *local_element_ID;
65 int size_conn, *element_ownership;
69 int *vertBC_value, *ref_surf, *bc_value;
71 char *outputFile, *writeOptions;
75 MPI_Init( &argc, &argv );
78 MPI_Comm_size( comm, &nprocs );
79 MPI_Comm_rank( comm, &
rank );
84 strcat( filen,
"unittest/io/p8ex1.h5m" );
87 if( argc > 1 ) strcpy( filen, argv[1] );
89 if( !strlen( filen ) )
91 printf(
"Invalid filename specified at command line.\n" );
99 CHECKRC( rc,
"failed to initialize MOAB" );
107 rc =
iMOAB_ReadHeaderInfo( filen, &num_global_vertices, &num_global_elements, &num_dimension, &num_parts );
108 CHECKRC( rc,
"failed to read header info" );
112 printf(
"file %s has %d vertices, %d elements, %d parts in partition\n", filen, num_global_vertices,
113 num_global_elements, num_parts );
129 CHECKRC( rc,
"failed to register application" );
135 &compdupid, pidDup );
136 CHECKRC( rc,
"failed to register duplicate application" );
146 CHECKRC( rc,
"failed to load mesh" );
148 rc =
iMOAB_LoadMesh( pidDup, filen, read_opts, num_ghost_layers );
149 CHECKRC( rc,
"failed to load mesh" );
152 CHECKRC( rc,
"failed to set global info" );
161 CHECKRC( rc,
"failed to get mesh info" );
170 CHECKRC( rc,
"failed to get vertex id info" );
172 vranks = (
int*)malloc( nverts[2] *
sizeof(
int ) );
182 CHECKRC( rc,
"failed to get vertex ranks" );
184 coords = (
double*)malloc( 3 * nverts[2] *
sizeof(
double ) );
185 size_coords = 3 * nverts[2];
191 CHECKRC( rc,
"failed to get coordinates" );
205 CHECKRC( rc,
"failed to get block info" );
215 CHECKRC( rc,
"failed to get tag INTFIELD " );
217 CHECKRC( rc,
"failed to get tag DFIELD " );
226 CHECKRC( rc,
"failed to sync tag INTFIELD " );
228 for( irank = 0; irank < nprocs; irank++ )
233 printf(
"on rank %d, there are \n"
234 " %3d visible vertices of which %3d local %3d ghost \n"
235 " %3d visible elements of which %3d owned %3d ghost \n"
236 " %3d visible blocks\n"
237 " %3d visible neumann BCs\n"
238 " %3d visible dirichlet BCs\n",
239 rank, nverts[2], nverts[0], nverts[1], nelem[2], nelem[0], nelem[1], nblocks[2], nsbc[2], ndbc[2] );
242 printf(
"on rank %d vertex info:\n",
rank );
243 for( i = 0; i < nverts[2]; i++ )
244 printf(
" vertex local id: %3d, rank ID:%d global ID: %3d coords: %g, %g, %g\n", i, vranks[i],
245 vGlobalID[i], coords[3 * i], coords[3 * i + 1], coords[3 * i + 2] );
249 ranks = (
int*)malloc( nelem[2] *
sizeof(
int ) );
255 CHECKRC( rc,
"failed to get all elem info" );
256 for( i = 0; i < nelem[2]; i++ )
257 printf(
" element local id: %3d, global ID: %3d rank:%d block ID: %2d \n", i, element_global_IDs[i],
258 ranks[i], block_IDs[i] );
259 free( element_global_IDs );
270 CHECKRC( rc,
"failed to get first element connectivity" );
271 printf(
" conn for first element: \n" );
272 for( i = 0; i < nv; i++ )
273 printf(
" %3d", conn[i] );
282 CHECKRC( rc,
"failed to get first element neighbors" );
283 printf(
" neighbors for first element:\n" );
284 for( i = 0; i < num_adjacent_elements; i++ )
286 printf(
" %4d", adjacent_element_IDs[i] );
290 for( i = 0; i < nblocks[2]; i++ )
292 printf(
" block index: %3d, block ID: %3d \n", i, gbIDs[i] );
300 rc =
iMOAB_GetBlockInfo( pid, &gbIDs[i], &vertices_per_element, &num_elements_in_block );
301 CHECKRC( rc,
"failed to elem block info" );
302 printf(
" has %4d elements with %d vertices per element\n", num_elements_in_block,
303 vertices_per_element );
305 size_conn = num_elements_in_block * vertices_per_element;
313 CHECKRC( rc,
"failed to get block elem connectivity" );
314 element_ownership = (
int*)malloc(
sizeof(
int ) * num_elements_in_block );
321 CHECKRC( rc,
"failed to get block elem ownership" );
329 rc =
iMOAB_GetElementID( pid, &gbIDs[i], &num_elements_in_block, global_element_ID, local_element_ID );
330 CHECKRC( rc,
"failed to get block elem IDs" );
331 for( j = 0; j < num_elements_in_block; j++ )
333 printf(
" elem %3d owned by %d gid: %4d lid: %4d -- ", j, element_ownership[j],
334 global_element_ID[j], local_element_ID[j] );
335 for( k = 0; k < vertices_per_element; k++ )
336 printf(
" %5d", element_connectivity[j * vertices_per_element + k] );
339 free( global_element_ID );
340 free( local_element_ID );
341 free( element_connectivity );
342 free( element_ownership );
351 int_tag_vals = (
int*)malloc(
sizeof(
int ) * nverts[2] );
353 CHECKRC( rc,
"failed to get INTFIELD tag" );
354 printf(
"INTFIELD tag values:\n" );
355 for( i = 0; i < nverts[2]; i++ )
357 printf(
" %4d", int_tag_vals[i] );
358 if( i % 20 == 19 ) printf(
"\n" );
361 free( int_tag_vals );
367 double_tag_vals = (
double*)malloc(
sizeof(
double ) * nelem[2] );
369 CHECKRC( rc,
"failed to get DFIELD tag" );
370 printf(
"DFIELD tag values: (not exchanged) \n" );
371 for( i = 0; i < nelem[2]; i++ )
373 printf(
" %f", double_tag_vals[i] );
374 if( i % 8 == 7 ) printf(
"\n" );
377 free( double_tag_vals );
381 ref_surf = (
int*)malloc(
sizeof(
int ) * nsbc[2] );
382 bc_value = (
int*)malloc(
sizeof(
int ) * nsbc[2] );
389 CHECKRC( rc,
"failed to get surf boundary conditions" );
390 printf(
" Surface boundary conditions:\n" );
391 for( i = 0; i < nsbc[2]; i++ )
393 printf(
" elem_localID %4d side:%d BC:%2d\n", surfBC_ID[i], ref_surf[i], bc_value[i] );
401 vertBC_value = (
int*)malloc(
sizeof(
int ) * ndbc[2] );
403 CHECKRC( rc,
"failed to get vertex boundary conditions" );
404 printf(
" Vertex boundary conditions:\n" );
405 for( i = 0; i < ndbc[2]; i++ )
407 printf(
" vertex %4d BC:%2d\n", vertBC_ID[i], vertBC_value[i] );
410 free( vertBC_value );
421 outputFile =
"fnew.h5m";
423 writeOptions =
"PARALLEL=WRITE_PART";
432 CHECKRC( rc,
"failed to write output file" );
439 CHECKRC( rc,
"failed to de-register application" );
442 CHECKRC( rc,
"failed to de-register application" );
448 CHECKRC( rc,
"failed to finalize MOAB" );