Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
advection.F90
Go to the documentation of this file.
1 ! advection: do a one time step transport, using c binding module
2 ! example of how to do it in parallel in fortran
3 ! This program shows how to load in parallel in moab from Fortran90, and how
4 ! to call the transport wrapper. It is a fortran equivalent of intx_imesh
5 ! driver
6 !
7 ! Usage: advection
8 
9 #define CHECK(a) if (ierr .ne. 0) print *, a
10 program advection
11 
12  use iso_c_binding
13  implicit none
14 
15 #include "moab/MOABConfig.h"
16 #ifdef MOAB_HAVE_MPI
17 # include "mpif.h"
18 # include "iMeshP_f.h"
19 #else
20 # include "iMesh_f.h"
21 #endif
22 
23 ! extern void update_tracer( iMesh_Instance instance, iBase_EntitySetHandle * opEulerSet, int * ierr);
24  INTERFACE
25  SUBROUTINE update_tracer ( instance , opEulerSet, ierr) bind(C)
26  use iso_c_binding
27  implicit none
28  imesh_instance, INTENT(IN) , VALUE :: instance
29  ibase_entitysethandle, INTENT(IN), VALUE :: opeulerset
30  integer(c_int) , INTENT (OUT) :: ierr
31  END SUBROUTINE update_tracer
32  END INTERFACE
33 
34  ! declarations
35  ! imesh is the instance handle
36  imesh_instance imesh
37 
38  ! cells will be storing 2d cells
39  TYPE(c_ptr) cells_ptr
40  ibase_entityhandle, pointer :: cells(:)
41  INTEGER ents_alloc, ents_size
42 
43  ibase_entitysethandle root_set
44  ibase_entitysethandle opeulerset
45  CHARACTER (LEN=200) options
46  CHARACTER (LEN=200) filename
47  CHARACTER (LEN=200) optionswrite
48  CHARACTER (LEN=200) outname
49  ! TYPE(C_PTR) :: vertsPtr, entsPtr
50 
51  integer rank, sz, ierr
52  integer lenopt, lenname
53  integer islist
54 
55 #ifdef MOAB_HAVE_MPI
56  ! local variables for parallel runs
57  imeshp_partitionhandle imeshp
58  ibase_handle_t mpi_comm_c
59 #endif
60 
61  ! init the parallel partition
62  call mpi_init(ierr)
63  check("fail to initialize MPI")
64  call mpi_comm_size(mpi_comm_world, sz, ierr)
65  check("fail to get MPI size")
66  call mpi_comm_rank(mpi_comm_world, rank, ierr)
67  check("fail to get MPI rank")
68 
69  ! now load the mesh; this also initializes parallel sharing
70  imesh = 0
71  imeshp = 0
72  call imesh_newmesh("MOAB", imesh, ierr)
73  check("fail to initialize imesh")
74 
75  call imesh_getrootset(%VAL(imesh), root_set, ierr)
76  check("fail to get root set")
77 
78  call imeshp_getcommunicator(%VAL(imesh), mpi_comm_world, mpi_comm_c, ierr)
79 
80  call imeshp_createpartitionall(%VAL(imesh), %VAL(mpi_comm_c), imeshp, ierr)
81  check("fail to create parallel partition ")
82  options = " moab:PARALLEL=READ_PART moab:PARTITION=PARALLEL_PARTITION" // &
83  " moab:PARALLEL_RESOLVE_SHARED_ENTS moab:PARTITION_DISTRIBUTE "
84 ! " moab:PARALLEL=READ_PART moab:PARTITION=PARALLEL_PARTITION " &
85 ! " moab:PARALLEL_RESOLVE_SHARED_ENTS moab:PARTITION_DISTRIBUTE ", & ! options
86  if (0 .eq. rank) then
87  print *, "load in parallel file HN16DP.h5m"
88  endif
89  lenname = 11;
90  lenopt = 123
91  filename = "HN16DP.h5m"
92  call imeshp_loadall(%VAL(imesh), &
93  %VAL(imeshp), &
94  %VAL(root_set), &
95  filename, & ! filename
96  options, & !options
97  ierr, &
98  %VAL(lenname), & ! strlen(filename),
99  %VAL(lenopt) ) !119) !strlen(options));
100  check("fail to load mesh in parallel ")
101 
102  islist = 0
103  call imesh_createentset(%VAL(imesh), %VAL(islist), opeulerset, ierr)
104  check("fail to create euler set ")
105 
106  ents_alloc = 0
107  ents_size = 0
108 
109  call imesh_getentities(%VAL(imesh),%VAL(root_set), &
110  %VAL(ibase_face), &
111  %VAL(imesh_all_topologies), cells_ptr, &
112  ents_alloc, ents_size, ierr);
113  check("fail to get 2d entities ")
114 
115  call c_f_pointer(cells_ptr, cells, [ents_size])
116 
117  call imesh_addentarrtoset(%VAL(imesh), cells, %VAL(ents_size), &
118  %VAL(opeulerset), ierr)
119 
120  call update_tracer(imesh, opeulerset, ierr)
121  check("fail to update tracer ")
122 
123  outname = "outF.h5m";
124  optionswrite = " moab:PARALLEL=WRITE_PART " ;
125  lenname = 8
126  lenopt = 27
127  call imeshp_saveall( %VAL(imesh), &
128  %VAL(imeshp), &
129  %VAL(opeulerset), &
130  outname, &
131  optionswrite, &
132  ierr, &
133  %VAL(lenname), & ! strlen(filename),
134  %VAL(lenopt) ) !119) !strlen(options));
135  check(" can't save ")
136 
137  if (0==rank) then
138  print *, "Done"
139  endif
140 
141  call mpi_finalize(ierr)
142  stop
143 end program advection
144