MOAB: Mesh Oriented datABase  (version 5.5.0)
imoab_testF.F90
Go to the documentation of this file.
1 
2 SUBROUTINE errorout(ierr, message)
3 integer ierr
4 character*(*) message
5 if (ierr.ne.0) then
6  print *, message
7  call exit (1)
8 end if
9 return
10 end
11 
12 program fdriver
13 
14 use iso_c_binding
15 use imoab
16 
17 #include "moab/MOABConfig.h"
18 #ifdef MOAB_HAVE_MPI
19 include 'mpif.h'
20 #endif
21 
22 #ifndef MOAB_MESH_DIR
23 #error Specify MOAB_MESH_DIR path
24 #endif
25 
26  integer ierr, num_procs, my_id
27  integer pid
28  integer compid
29  character :: appname*32
30  character :: filename*1024
31  character :: fname*1024
32  character :: readopts*1024
33  integer ngv, nge, ndim, nparts
34  integer nghlay
35  integer nverts(3), nelem(3), nblocks(3), nsbc(3), ndbc(3)
36  ! large enough work arrays
37  integer iwork(100000)
38  double precision dwork(100000)
39  ! indices in work arrays for vertex ids, ranks, coordinates
40  integer vid, vra, vco
41  !
42  ! indices for free memory (index in integer or double work arrays)
43  integer ifree, dfree
44  ! size of coordinates array
45  integer nco
46  integer bid
47  ! for some tags in the file
48  character :: tagname1*128, tagname2*128
49  integer tagtype(2), enttype(2), num_co
50  integer tagindex(2)
51  integer ntsync
52 
53  integer era, beid, eid
54  ! vertices per element, number of elements in block
55  integer vpere, nebl, blockid
56  ! iWORK(eCO) start for connectivity
57  integer sizeconn, eco
58  ! IWORK(egID) , IWORK(elID) starts for global el ID, local elem ID
59  integer egid, elid, eown
60  integer itag, dtag
61 
62  ! indices for surface BC element, reference surf BC, value
63  integer isbc, irbc, ivbc
64 
65  character outfile*1024, wopts*1024
66  my_id = 0
67  fname = 'unittest/io/p8ex1.h5m'//c_null_char
68 
69 #ifdef MOAB_HAVE_MPI
70  call mpi_init ( ierr )
71  call errorout(ierr, 'fail to initialize MPI')
72 
73  ! find out MY process ID, and how many processes were started.
74 
75  call mpi_comm_rank (mpi_comm_world, my_id, ierr)
76  call errorout(ierr, 'fail to get MPI rank')
77 
78  call mpi_comm_size (mpi_comm_world, num_procs, ierr)
79  call errorout(ierr, 'fail to get MPI size')
80 
81  if (my_id .eq. 0) then
82  print *, " I'm process ", my_id, " out of ", num_procs, " processes."
83  end if
84 #endif
85 
86  ierr = imoab_initialize()
87  call errorout(ierr, 'fail to initialize iMOAB')
88 
89  appname = 'PROTEUS'//c_null_char
90  ! give a unique external id; here we just use 8?
91  compid = 8
92  ! number of ghost layers needed by application
93  nghlay = 0
94 
95 
96 #ifdef MOAB_HAVE_MPI
97  ierr = imoab_registerapplication(appname, mpi_comm_world, compid, pid)
98 #else
99  ierr = imoab_registerapplication(appname, compid, pid)
100 #endif
101  call errorout(ierr, 'fail to register application')
102 
103  filename = moab_mesh_dir//fname
104  ierr = imoab_readheaderinfo( filename, ngv, nge, ndim, nparts)
105  call errorout(ierr, 'fail to read header info')
106 
107  if (0.eq.my_id) then
108  print *, filename, ' has ', nparts, ' parts in partition', ngv, ' vertices ', nge, ' elements of dimension ', ndim
109  endif
110 #ifdef MOAB_HAVE_MPI
111  nghlay = 1
112  readopts='PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;'// &
113  'PARALLEL_RESOLVE_SHARED_ENTS'//c_null_char
114 #else
115  readopts=c_null_char
116 #endif
117 
118  ! now let us load the mesh in parallel
119  ierr = imoab_loadmesh(pid, filename, readopts, nghlay)
120  call errorout(ierr, 'fail to read file in parallel')
121 
122  ! number of vertices/elements/blocks/sidesets in the mesh
123  ierr = imoab_getmeshinfo(pid, nverts, nelem, nblocks, nsbc, ndbc)
124  call errorout(ierr, 'fail to get mesh info')
125 
126  vid = 1
127  ierr = imoab_getvertexid(pid, nverts(3), iwork(vid) )
128  call errorout(ierr, 'failed to get vertex id info')
129 
130  vra = vid + nverts(3)
131  ierr = imoab_getvertexownership(pid, nverts(3), iwork(vra) )
132  call errorout(ierr, 'failed to get vertex owner ranks')
133 
134  ifree = vra + nverts(3)
135 
136  ! double * coords = (double*) malloc(3*nverts[2]*sizeof(double));
137  vco = 1
138  nco = 3 * nverts(3)
139 
140  ierr = imoab_getvisibleverticescoordinates(pid, nco, dwork(vco))
141  print *, 'nCO = ', nco
142  print *, 'ierr = ', ierr
143  call errorout(ierr, 'failed to get coordinates')
144  dfree = vco + 3 * nverts(3)
145 
146  bid = ifree
147  ierr = imoab_getblockid(pid, nblocks(3), iwork(bid))
148  call errorout(ierr, 'failed to get block info')
149  ifree = ifree + nblocks(3)
150 
151  ! the 2 tags used in this example exist in the file, already
152  ! first tag, INTFIELD is on vertices, integer
153  ! second tag DFIELD is on elements, double
154  tagtype(1)=0 !dense, int
155  tagtype(2)=1 !dense, double
156  enttype(1)=0 ! on verts
157  enttype(2)=1 ! on elem
158  num_co = 1
159  tagname1 ='INTFIELD'//c_null_char
160  ierr = imoab_definetagstorage(pid, tagname1, tagtype(1), num_co, tagindex(1) )
161  call errorout(ierr, 'failed to get tag INTFIELD')
162 
163  tagname2 ='DFIELD'//c_null_char
164  ierr = imoab_definetagstorage(pid, tagname2, tagtype(2), num_co, tagindex(2) )
165  call errorout(ierr, 'failed to get tag DFIELD')
166 
167  ! synchronize one of the tags only, just to see what happens
168  ! put in the sync array just first tag index (INTFIELD)
169  ntsync =2
170 
171  ierr = imoab_synchronizetags(pid, ntsync, tagindex, tagtype )
172  call errorout(ierr, 'failed to sync tag INTFIELD')
173 
174  ! start printing some information, retrieved from each task
175  do irk=0, num_procs-1
176  if (irk .eq. my_id) then
177 
178  ! printf some of the block info */
179  print *, 'on rank ', my_id, ' there are '
180  print *, nverts(3), ' visible vertices of which ',nverts(1), ' local ', nverts(2), ' ghost'
181  print *, nblocks(3), ' visible blocks'
182  print *, nsbc(3), ' visible Neumann BCs'
183  print *, ndbc(3), ' visible dirichlet BCs'
184 
185  print *, 'on rank ', my_id, ' vertex info:'
186  do i=1,nverts(3)
187  write(*, 100) i, iwork(vra+i-1), iwork( vid+i-1), dwork(vco+3*i-3), dwork(vco+3*i-2), dwork(vco+3*i-1)
188 100 FORMAT(' vertex local id ', i3, ' rank ID', i3, ' global ID:', i3, ' coords:', 3f11.3)
189  enddo
190 
191  eid = ifree
192  beid = eid + nelem(3)
193  era = beid + nelem(3)
194  ierr = imoab_getvisibleelementsinfo(pid, nelem(3),iwork(eid), iwork(era), iwork(beid) )
195  call errorout(ierr, 'failed to get all elem info')
196  ifree = era + nelem(3)
197  do i=1, nelem(3)
198  write(*, 101) iwork(eid+i-1), iwork(era+i-1), iwork(beid+i-1)
199 101 FORMAT( ' global ID ', i5, ' rank: ', i3, ' block ID: ', i4)
200  enddo
201 
202  do i=1,nblocks(3)
203 
204  print *,' block index:', i, ' block ID ', iwork(bid+i-1)
205  blockid = iwork(bid+i-1)
206  ierr = imoab_getblockinfo(pid, blockid , vpere, nebl)
207  call errorout(ierr, 'failed to elem block info')
208  print *, ' has' , nebl, ' elements with ', vpere, 'verts'
209 
210  sizeconn = nebl * vpere
211  eco = ifree
212  ierr = imoab_getblockelementconnectivities(pid, blockid, sizeconn, iwork(eco) )
213  print *, ierr
214  call errorout(ierr, 'failed to get block elem connectivity')
215 
216  ifree = ifree + sizeconn
217  eown = ifree
218  ierr = imoab_getelementownership(pid, blockid, nebl, iwork(eown))
219  call errorout(ierr, 'failed to get block elem ownership')
220  ifree = ifree+nebl
221 
222  egid = ifree
223  elid = ifree + nebl
224  ierr = imoab_getelementid(pid, blockid, nebl, iwork(egid), iwork(elid) )
225  call errorout(ierr, 'failed to get block elem IDs')
226  ifree = elid + nebl
227 
228  do j=1, nebl
229  write (*, 102) j, iwork(eown+j-1),iwork(egid+j-1), iwork(elid+j-1), (iwork(eco-1+(j-1)*vpere+k), k=1,vpere)
230 102 FORMAT(' elem ', i3, ' owned by', i3, ' gid:', i3, ' lid:', i3, ' : ', 10i5)
231  enddo
232  enddo
233 
234  ! query int tag values on vertices
235  itag= ifree
236 
237  ierr = imoab_getinttagstorage(pid, tagname1, nverts(3), enttype(1), iwork(itag) )
238  call errorout(ierr, 'failed to get INTFIELD tag')
239  ifree = itag + nverts(3)
240  print * , 'INTFIELD tag values'
241  write(*, 103) (iwork(itag+k-1), k=1,nverts(3) )
242 103 FORMAT (10i8)
243 
244  dtag = dfree
245  ! query double tag values on elements
246 
247  ierr = imoab_getdoubletagstorage(pid, tagname2, nelem(3), enttype(2), dwork(dtag) )
248  call errorout(ierr, 'failed to get DFIELD tag')
249  dfree = dtag + nelem(3)
250  print *, 'DFIELD tag values: (not exchanged) '
251  write (*, 104) (dwork(dtag+k-1), k=1,nelem(3) )
252 104 FORMAT ( 10f7.2 )
253 
254  ! query surface BCs
255  isbc = ifree
256  irbc = isbc + nsbc(3)
257  ivbc = irbc + nsbc(3)
258 
259  ierr = imoab_getpointertosurfacebc(pid, nsbc(3), iwork(isbc),iwork(irbc), iwork(ivbc))
260  call errorout(ierr, 'failed to get surf boundary conditions')
261  ifree = ivbc + nsbc(3)
262  print * , 'Surface boundary conditions '
263  write (*, 105) (iwork(isbc+k-1),iwork(irbc+k-1), iwork(ivbc+k-1), k=1, nsbc(3))
264 105 FORMAT (' elem localID: ', i3, ' side:', i1, ' val:', i4)
265 
266  ! query vertex BCs
267  ivebc = ifree
268  ivabc = ivebc + ndbc(3)
269 
270  ierr = imoab_getpointertovertexbc(pid, ndbc(3), iwork(ivebc),iwork(ivabc))
271  call errorout(ierr, 'failed to get vertex boundary conditions')
272  ifree = ivabc + ndbc(3)
273 
274  print *, ' Vertex boundary conditions:'
275  write (*, 106) (iwork(ivebc+k-1),iwork(ivabc+k-1), k=1, ndbc(3))
276 106 FORMAT (' vertex: ', i3, ' BC:', i6 )
277 
278  endif
279 
280 #ifdef MOAB_HAVE_MPI
281  call mpi_barrier(mpi_comm_world, ierr)
282 #endif
283  call errorout(ierr, 'fail at barrier')
284 enddo
285 
286  outfile = 'fnew2.h5m'//c_null_char
287 #ifdef MOAB_HAVE_MPI
288  wopts = 'PARALLEL=WRITE_PART'//c_null_char
289 #else
290  wopts=c_null_char
291 #endif
292 
293  ! write out the mesh file to disk
294  ierr = imoab_writemesh(pid, outfile, wopts)
295  call errorout(ierr, 'fail to write the mesh file')
296 
297  ! all done. de-register and finalize
298  ierr = imoab_deregisterapplication(pid)
299  call errorout(ierr, 'fail to deregister application')
300 
301  ierr = imoab_finalize()
302  call errorout(ierr, 'fail to finalize iMOAB')
303 
304 #ifdef MOAB_HAVE_MPI
305  call mpi_finalize ( ierr )
306 #endif
307  call errorout(ierr, 'fail to finalize MPI')
308 
309  stop
310 end