![]() |
Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 ! advection: do a one time step transport, using c binding module
00002 ! example of how to do it in parallel in fortran
00003 ! This program shows how to load in parallel in moab from Fortran90, and how
00004 ! to call the transport wrapper. It is a fortran equivalent of intx_imesh
00005 ! driver
00006 !
00007 ! Usage: advection
00008
00009 #define CHECK(a) if (ierr .ne. 0) print *, a
00010 program advection
00011
00012 use ISO_C_BINDING
00013 implicit none
00014
00015 #include "moab/MOABConfig.h"
00016 #ifdef MOAB_HAVE_MPI
00017 # include "mpif.h"
00018 # include "iMeshP_f.h"
00019 #else
00020 # include "iMesh_f.h"
00021 #endif
00022
00023 ! extern void update_tracer( iMesh_Instance instance, iBase_EntitySetHandle * opEulerSet, int * ierr);
00024 INTERFACE
00025 SUBROUTINE update_tracer ( instance , opEulerSet, ierr) bind(C)
00026 use ISO_C_BINDING
00027 implicit none
00028 iMesh_Instance, INTENT(IN) , VALUE :: instance
00029 iBase_EntitySetHandle, INTENT(IN), VALUE :: opEulerSet
00030 integer(c_int) , INTENT (OUT) :: ierr
00031 END SUBROUTINE update_tracer
00032 END INTERFACE
00033
00034 ! declarations
00035 ! imesh is the instance handle
00036 iMesh_Instance imesh
00037
00038 ! cells will be storing 2d cells
00039 TYPE(C_PTR) cells_ptr
00040 iBase_EntityHandle, pointer :: cells(:)
00041 INTEGER ents_alloc, ents_size
00042
00043 iBase_EntitySetHandle root_set
00044 iBase_EntitySetHandle opEulerSet
00045 CHARACTER (LEN=200) options
00046 CHARACTER (LEN=200) filename
00047 CHARACTER (LEN=200) optionswrite
00048 CHARACTER (LEN=200) outname
00049 ! TYPE(C_PTR) :: vertsPtr, entsPtr
00050
00051 integer rank, sz, ierr
00052 integer lenopt, lenname
00053 integer isList
00054
00055 #ifdef MOAB_HAVE_MPI
00056 ! local variables for parallel runs
00057 iMeshP_PartitionHandle imeshp
00058 IBASE_HANDLE_T mpi_comm_c
00059 #endif
00060
00061 ! init the parallel partition
00062 call MPI_INIT(ierr)
00063 CHECK("fail to initialize MPI")
00064 call MPI_COMM_SIZE(MPI_COMM_WORLD, sz, ierr)
00065 CHECK("fail to get MPI size")
00066 call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
00067 CHECK("fail to get MPI rank")
00068
00069 ! now load the mesh; this also initializes parallel sharing
00070 imesh = 0
00071 imeshp = 0
00072 call iMesh_newMesh("MOAB", imesh, ierr)
00073 CHECK("fail to initialize imesh")
00074
00075 call iMesh_getRootSet(%VAL(imesh), root_set, ierr)
00076 CHECK("fail to get root set")
00077
00078 call iMeshP_getCommunicator(%VAL(imesh), MPI_COMM_WORLD, mpi_comm_c, ierr)
00079
00080 call iMeshP_createPartitionAll(%VAL(imesh), %VAL(mpi_comm_c), imeshp, ierr)
00081 CHECK("fail to create parallel partition ")
00082 options = " moab:PARALLEL=READ_PART moab:PARTITION=PARALLEL_PARTITION" // &
00083 " moab:PARALLEL_RESOLVE_SHARED_ENTS moab:PARTITION_DISTRIBUTE "
00084 ! " moab:PARALLEL=READ_PART moab:PARTITION=PARALLEL_PARTITION " &
00085 ! " moab:PARALLEL_RESOLVE_SHARED_ENTS moab:PARTITION_DISTRIBUTE ", & ! options
00086 if (0 .eq. rank) then
00087 print *, "load in parallel file HN16DP.h5m"
00088 endif
00089 lenname = 11;
00090 lenopt = 123
00091 filename = "HN16DP.h5m"
00092 call iMeshP_loadAll(%VAL(imesh), &
00093 %VAL(imeshp), &
00094 %VAL(root_set), &
00095 filename, & ! filename
00096 options, & !options
00097 ierr, &
00098 %VAL(lenname), & ! strlen(filename),
00099 %VAL(lenopt) ) !119) !strlen(options));
00100 CHECK("fail to load mesh in parallel ")
00101
00102 isList = 0
00103 call iMesh_createEntSet(%VAL(imesh), %VAL(isList), opEulerSet, ierr)
00104 CHECK("fail to create euler set ")
00105
00106 ents_alloc = 0
00107 ents_size = 0
00108
00109 call iMesh_getEntities(%VAL(imesh),%VAL(root_set), &
00110 %VAL(iBase_FACE), &
00111 %VAL(iMesh_ALL_TOPOLOGIES), cells_ptr, &
00112 ents_alloc, ents_size, ierr);
00113 CHECK("fail to get 2d entities ")
00114
00115 call c_f_pointer(cells_ptr, cells, [ents_size])
00116
00117 call iMesh_addEntArrToSet(%VAL(imesh), cells, %VAL(ents_size), &
00118 %VAL(opEulerSet), ierr)
00119
00120 call update_tracer(imesh, opEulerSet, ierr)
00121 CHECK("fail to update tracer ")
00122
00123 outname = "outF.h5m";
00124 optionswrite = " moab:PARALLEL=WRITE_PART " ;
00125 lenname = 8
00126 lenopt = 27
00127 call iMeshP_saveAll( %VAL(imesh), &
00128 %VAL(imeshp), &
00129 %VAL(opEulerSet), &
00130 outname, &
00131 optionswrite, &
00132 ierr, &
00133 %VAL(lenname), & ! strlen(filename),
00134 %VAL(lenopt) ) !119) !strlen(options));
00135 CHECK(" can't save ")
00136
00137 if (0==rank) then
00138 print *, "Done"
00139 endif
00140
00141 call MPI_FINALIZE(ierr)
00142 stop
00143 end program advection
00144