Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
intx_imesh.cpp
Go to the documentation of this file.
1 /*
2  * This program updates a manufactured tracer field from time T0 to time T1, in parallel.
3  * Input: arrival mesh, already distributed on processors, and a departure position for
4  * each vertex, saved in a tag DP
5  */
6 #include <string>
7 #include <iostream>
8 #include "moab/Core.hpp"
11 
12 #include "moab_mpi.h"
13 #include "iMeshP.h"
14 #include "MBiMesh.hpp"
15 
16 #define IMESH_ASSERT( ierr ) \
17  if( ( ierr ) != 0 ) std::cout << "iMesh Assert: \n";
18 #define IMESH_NULL 0
19 
20 extern "C" void update_tracer( iMesh_Instance instance, iBase_EntitySetHandle imesh_euler_set, int* ierr );
21 
22 int main( int argc, char* argv[] )
23 {
24  MPI_Init( &argc, &argv );
25 
26  iMesh_Instance imesh;
27  iMeshP_PartitionHandle partn;
28  int ierr, num_sets;
29 
30  iBase_EntitySetHandle root;
31  imesh = IMESH_NULL;
32  iMesh_newMesh( 0, &imesh, &ierr, 0 );
33  IMESH_ASSERT( ierr );
34  iMesh_getRootSet( imesh, &root, &ierr );
35  IMESH_ASSERT( ierr );
36 
37  iMeshP_createPartitionAll( imesh, MPI_COMM_WORLD, &partn, &ierr );
38  int rank, size;
39  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
40  MPI_Comm_size( MPI_COMM_WORLD, &size );
41  IMESH_ASSERT( ierr );
42 
43  const char options[] = " moab:PARALLEL=READ_PART "
44  " moab:PARTITION=PARALLEL_PARTITION "
45  " moab:PARALLEL_RESOLVE_SHARED_ENTS "
46  " moab:PARTITION_DISTRIBUTE ";
47  const char* filename = "HN16DP.h5m"; // the file should have the dp tag already
48 
49  if( 0 == rank ) std::cout << "Load in parallel the file: " << filename << std::endl;
50  iMeshP_loadAll( imesh, partn, root, filename, options, &ierr, strlen( filename ), strlen( options ) );
51  IMESH_ASSERT( ierr );
52 
53  iMesh_getNumEntSets( imesh, IMESH_NULL, 1, &num_sets, &ierr );
54  IMESH_ASSERT( ierr );
55  std::cout << "There's " << num_sets << " entity sets here on process rank " << rank << std::endl;
56 
57  iBase_EntitySetHandle euler_set;
58 
59  iMesh_createEntSet( imesh, 0, &euler_set, &ierr );
60  IMESH_ASSERT( ierr );
61 
62  iBase_EntityHandle* cells = NULL;
63  int ents_alloc = 0;
64  int ents_size = 0;
65 
66  iMesh_getEntities( imesh, root, iBase_FACE, iMesh_ALL_TOPOLOGIES, &cells, &ents_alloc, &ents_size, &ierr );
67  IMESH_ASSERT( ierr );
68 
69  iMesh_addEntArrToSet( imesh, cells, ents_size, euler_set, &ierr );
70  IMESH_ASSERT( ierr );
71 
72  update_tracer( imesh, euler_set, &ierr );
73  IMESH_ASSERT( ierr );
74 
75  // write everything
76  const char* out_name = "out.h5m";
77  const char optionswrite[] = " moab:PARALLEL=WRITE_PART ";
78  iMeshP_saveAll( imesh, partn, euler_set, out_name, optionswrite, &ierr, strlen( out_name ),
79  strlen( optionswrite ) );
80  IMESH_ASSERT( ierr );
81 
82  if( 0 == rank ) std::cout << "Done\n";
83  MPI_Finalize();
84 
85  return 0;
86 }