moab
intx_imesh.cpp
Go to the documentation of this file.
00001 
00002 /*
00003  *  This program updates a manufactured tracer field from time T0 to time T1, in parallel.
00004  *  Input: arrival mesh, already distributed on processors, and a departure position for
00005  *  each vertex, saved in a tag DP
00006  */
00007 #include <stdio.h>
00008 #include <string.h>
00009 #include "moab_mpi.h"
00010 #include "iMeshP.h"
00011 
00012 
00013 #define IMESH_ASSERT(ierr) if (ierr!=0) printf("imesh assert\n");
00014 #define IMESH_NULL 0
00015 
00016 #ifdef __cplusplus
00017 extern "C" {
00018 #endif
00019  void update_tracer( iMesh_Instance instance,  iBase_EntitySetHandle eulerSet, int * ierr);
00020 
00021 #ifdef __cplusplus
00022 } // extern "C"
00023 #endif
00024 
00025 
00026 int main(int argc, char* argv[]){
00027   MPI_Init(&argc, &argv);
00028 
00029   iMesh_Instance imesh;
00030   iMeshP_PartitionHandle partn;
00031   int ierr, num_sets;
00032 
00033   iBase_EntitySetHandle root;
00034   imesh = IMESH_NULL;
00035   iMesh_newMesh(0, &imesh, &ierr, 0);
00036   IMESH_ASSERT(ierr);
00037   iMesh_getRootSet( imesh, &root, &ierr );
00038   IMESH_ASSERT(ierr);
00039 
00040   iMeshP_createPartitionAll(imesh, MPI_COMM_WORLD, &partn, &ierr);
00041   int rank, size;
00042   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00043   MPI_Comm_size(MPI_COMM_WORLD, &size);
00044   IMESH_ASSERT(ierr);
00045 
00046   const char options[] = " moab:PARALLEL=READ_PART "
00047                          " moab:PARTITION=PARALLEL_PARTITION "
00048                          " moab:PARALLEL_RESOLVE_SHARED_ENTS "
00049                          " moab:PARTITION_DISTRIBUTE ";
00050   const char * filename = "HN16DP.h5m"; // the file should have the dp tag already
00051 
00052   if (0==rank)
00053     printf("load in parallel the file: %s \n", filename);
00054   iMeshP_loadAll(imesh,
00055               partn,
00056               root,
00057               filename,
00058               options,
00059               &ierr,
00060               strlen(filename),
00061               strlen(options));
00062   IMESH_ASSERT(ierr);
00063 
00064 
00065   iMesh_getNumEntSets(imesh,
00066                       IMESH_NULL,
00067                       1,
00068                       &num_sets,
00069                       &ierr);
00070   IMESH_ASSERT(ierr);
00071   printf("There's %d entity sets here on process rank %d \n", num_sets, rank);
00072 
00073   iBase_EntitySetHandle euler_set;
00074 
00075   iMesh_createEntSet(imesh, 0, &euler_set, &ierr);
00076   IMESH_ASSERT(ierr);
00077 
00078   iBase_EntityHandle *cells = NULL;
00079   int ents_alloc = 0;
00080   int ents_size = 0;
00081 
00082   iMesh_getEntities(imesh, root, iBase_FACE, iMesh_ALL_TOPOLOGIES, &cells,
00083       &ents_alloc, &ents_size, &ierr);
00084   IMESH_ASSERT(ierr);
00085 
00086   iMesh_addEntArrToSet(imesh, cells, ents_size, euler_set, &ierr);
00087 
00088   IMESH_ASSERT(ierr);
00089 
00090   update_tracer( imesh, euler_set, &ierr);
00091   IMESH_ASSERT(ierr);
00092 
00093   // write everything
00094   const char * out_name = "out.h5m";
00095   const char optionswrite[] = " moab:PARALLEL=WRITE_PART " ;
00096   iMeshP_saveAll( imesh, partn, euler_set,
00097                      out_name,
00098                      optionswrite,
00099                      &ierr,
00100                      strlen(out_name),
00101                      strlen(optionswrite));
00102   IMESH_ASSERT(ierr);
00103 
00104   if (0==rank)
00105     printf("Done\n");
00106   MPI_Finalize(); //probably the 4th time this is called.. no big deal
00107 
00108 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines