MOAB: Mesh Oriented datABase  (version 5.4.1)
imoab_testF.F90
Go to the documentation of this file.
00001 
00002 SUBROUTINE errorout(ierr, message)
00003 integer ierr
00004 character*(*) message
00005 if (ierr.ne.0) then
00006       print *, message
00007       call exit (1)
00008 end if
00009 return
00010 end
00011 
00012 program fdriver
00013 
00014 use iso_c_binding
00015 use iMOAB
00016 
00017 #include "moab/MOABConfig.h"
00018 #ifdef MOAB_HAVE_MPI
00019 include 'mpif.h'
00020 #endif
00021 
00022 #ifndef MOAB_MESH_DIR
00023 #error Specify MOAB_MESH_DIR path
00024 #endif
00025 
00026       integer ierr, num_procs, my_id
00027       integer pid
00028       integer compid
00029       character :: appname*32
00030       character :: filename*1024
00031       character :: fname*1024
00032       character :: readopts*1024
00033       integer ngv, nge, ndim, nparts
00034       integer nghlay
00035       integer nverts(3), nelem(3), nblocks(3), nsbc(3), ndbc(3)
00036       !      large enough work arrays
00037       integer iwork(100000)
00038       double precision  dwork(100000)
00039       !      indices in work arrays for vertex ids, ranks, coordinates
00040       integer vID, vRA, vCO
00041       !
00042       !      indices for free memory (index in integer or double work arrays)
00043       integer ifree, dfree
00044       !      size of coordinates array
00045       integer  nCO
00046       integer  bID
00047       !     for some tags in the file
00048       character :: tagname1*128, tagname2*128
00049       integer      tagtype(2), enttype(2), num_co
00050       integer      tagindex(2)
00051       integer      ntsync
00052 
00053       integer      eRA, beID, eID
00054       !     vertices per element, number of elements in block
00055       integer  vpere, nebl, blockID
00056       !      iWORK(eCO) start for connectivity
00057       integer    sizeconn, eCO
00058       !      IWORK(egID) , IWORK(elID) starts for global el ID, local elem ID
00059       integer    egID, elID, eOWN
00060       integer    iTAG, dTAG
00061 
00062       !       indices for surface BC element, reference surf BC, value
00063       integer    isBC, irBC, ivBC
00064 
00065       character outfile*1024, wopts*1024
00066       my_id = 0
00067       fname = 'unittest/io/p8ex1.h5m'//C_NULL_CHAR
00068 
00069 #ifdef MOAB_HAVE_MPI
00070       call MPI_INIT ( ierr )
00071       call errorout(ierr, 'fail to initialize MPI')
00072 
00073       !     find out MY process ID, and how many processes were started.
00074 
00075       call MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr)
00076       call errorout(ierr, 'fail to get MPI rank')
00077 
00078       call MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr)
00079       call errorout(ierr, 'fail to get MPI size')
00080 
00081       if (my_id .eq. 0) then
00082             print *, " I'm process ", my_id, " out of ", num_procs, " processes."
00083       end if
00084 #endif
00085 
00086       ierr = iMOAB_Initialize()
00087       call errorout(ierr, 'fail to initialize iMOAB')
00088 
00089       appname = 'PROTEUS'//C_NULL_CHAR
00090       ! give a unique external id; here we just use 8?
00091       compid = 8
00092       !  number of ghost layers needed by application
00093       nghlay = 0
00094 
00095 
00096 #ifdef MOAB_HAVE_MPI
00097       ierr = iMOAB_RegisterApplication(appname, MPI_COMM_WORLD, compid, pid)
00098 #else
00099       ierr = iMOAB_RegisterApplication(appname, compid, pid)
00100 #endif
00101       call errorout(ierr, 'fail to register application')
00102 
00103       filename = MOAB_MESH_DIR//fname
00104       ierr = iMOAB_ReadHeaderInfo ( filename, ngv, nge, ndim, nparts)
00105       call errorout(ierr, 'fail to read header info')
00106 
00107       if (0.eq.my_id) then
00108             print *, filename, ' has ', nparts, ' parts in partition', ngv, ' vertices ', nge, ' elements of dimension ', ndim
00109       endif
00110 #ifdef MOAB_HAVE_MPI
00111       nghlay = 1
00112       readopts='PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;'// &
00113        'PARALLEL_RESOLVE_SHARED_ENTS'//C_NULL_CHAR
00114 #else
00115       readopts=C_NULL_CHAR
00116 #endif
00117 
00118       !  now let us load the mesh in parallel
00119       ierr = iMOAB_LoadMesh(pid, filename, readopts, nghlay)
00120       call errorout(ierr, 'fail to read file in parallel')
00121 
00122       !  number of vertices/elements/blocks/sidesets in the mesh
00123       ierr = iMOAB_GetMeshInfo(pid, nverts, nelem, nblocks, nsbc, ndbc)
00124       call errorout(ierr, 'fail to get mesh info')
00125 
00126       vID = 1
00127       ierr = iMOAB_GetVertexID(pid, nverts(3), IWORK(vID) )
00128       call errorout(ierr, 'failed to get vertex id info')
00129 
00130       vRA = vID + nverts(3)
00131       ierr = iMOAB_GetVertexOwnership(pid, nverts(3), IWORK(vRA) )
00132       call errorout(ierr, 'failed to get vertex owner ranks')
00133 
00134       ifree = vRA + nverts(3)
00135 
00136       !  double * coords = (double*) malloc(3*nverts[2]*sizeof(double));
00137       vCO = 1
00138       nCO = 3 * nverts(3)
00139 
00140       ierr = iMOAB_GetVisibleVerticesCoordinates(pid, nCO, DWORK(vCO))
00141       print *,  'nCO = ', nCO
00142       print *, 'ierr = ', ierr
00143       call errorout(ierr, 'failed to get coordinates')
00144       dfree = vCO + 3 * nverts(3)
00145 
00146       bID = ifree
00147       ierr = iMOAB_GetBlockID(pid, nblocks(3), IWORK(bID))
00148       call errorout(ierr, 'failed to get block info')
00149       ifree = ifree + nblocks(3)
00150 
00151       !      the 2 tags used in this example exist in the file, already
00152       ! first tag, INTFIELD is on vertices, integer
00153       ! second tag DFIELD is on elements, double
00154       tagtype(1)=0                                  !dense, int
00155       tagtype(2)=1                                  !dense, double
00156       enttype(1)=0                                  ! on verts
00157       enttype(2)=1                                  ! on elem
00158       num_co = 1
00159       tagname1 ='INTFIELD'//C_NULL_CHAR
00160       ierr = iMOAB_DefineTagStorage(pid, tagname1, tagtype(1), num_co, tagindex(1) )
00161       call errorout(ierr, 'failed to get tag INTFIELD')
00162 
00163       tagname2 ='DFIELD'//C_NULL_CHAR
00164       ierr = iMOAB_DefineTagStorage(pid, tagname2, tagtype(2), num_co, tagindex(2) )
00165       call errorout(ierr, 'failed to get tag DFIELD')
00166 
00167       ! synchronize one of the tags only, just to see what happens
00168       ! put in the sync array just first tag index (INTFIELD)
00169       ntsync =2
00170 
00171       ierr = iMOAB_SynchronizeTags(pid, ntsync, tagIndex, tagType )
00172       call errorout(ierr, 'failed to sync tag INTFIELD')
00173 
00174       !  start printing some information, retrieved from each task
00175       do irk=0, num_procs-1
00176             if (irk .eq. my_id) then
00177 
00178             ! printf some of the block info */
00179             print *, 'on rank ', my_id, ' there are '
00180             print *, nverts(3), ' visible vertices of which ',nverts(1), ' local ', nverts(2), ' ghost'
00181             print *,  nblocks(3), ' visible blocks'
00182             print *,  nsbc(3), ' visible Neumann BCs'
00183             print *,   ndbc(3), ' visible dirichlet BCs'
00184 
00185             print *, 'on rank ', my_id, ' vertex info:'
00186             do i=1,nverts(3)
00187             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)
00188 100         FORMAT(' vertex local id ', I3, ' rank ID', I3, ' global ID:', I3, '  coords:',  3F11.3)
00189       enddo
00190 
00191       eID = ifree
00192       beID = eID + nelem(3)
00193       eRA = beID + nelem(3)
00194       ierr = iMOAB_GetVisibleElementsInfo(pid, nelem(3),IWORK(eID), IWORK(eRA), IWORK(beID) )
00195       call errorout(ierr, 'failed to get all elem info')
00196       ifree = eRA + nelem(3)
00197       do i=1, nelem(3)
00198           write(*, 101) IWORK(eID+i-1), IWORK(eRA+i-1), IWORK(beID+i-1)
00199 101       FORMAT( ' global ID ', I5, ' rank: ', I3, ' block ID: ', I4)
00200       enddo
00201 
00202       do  i=1,nblocks(3)
00203 
00204             print *,' block index:', i, ' block ID ', IWORK(bID+i-1)
00205             blockID = IWORK(bID+i-1)
00206             ierr = iMOAB_GetBlockInfo(pid, blockID , vpere, nebl)
00207             call errorout(ierr, 'failed to elem block info')
00208             print *, '  has' , nebl, ' elements with ', vpere, 'verts'
00209 
00210             sizeconn = nebl * vpere
00211             eCO = ifree
00212             ierr = iMOAB_GetBlockElementConnectivities(pid, blockID, sizeconn, IWORK(eCO) )
00213             print *, ierr
00214             call errorout(ierr, 'failed to get block elem connectivity')
00215 
00216             ifree = ifree + sizeconn
00217             eOWN = ifree
00218             ierr = iMOAB_GetElementOwnership(pid, blockID, nebl, IWORK(eOWN))
00219             call errorout(ierr, 'failed to get block elem ownership')
00220             ifree = ifree+nebl
00221 
00222             egID = ifree
00223             elID = ifree + nebl
00224             ierr = iMOAB_GetElementID(pid, blockID, nebl, IWORK(egID), IWORK(elID)  )
00225             call errorout(ierr, 'failed to get block elem IDs')
00226             ifree = elID + nebl
00227 
00228             do j=1, nebl
00229                   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)
00230 102               FORMAT(' elem ', I3, ' owned by', I3, ' gid:', I3, ' lid:', I3, ' : ', 10I5)
00231             enddo
00232       enddo
00233 
00234       ! query int tag values on vertices
00235       iTAG= ifree
00236 
00237       ierr = iMOAB_GetIntTagStorage(pid, tagname1, nverts(3), enttype(1), IWORK(iTAG) )
00238       call errorout(ierr, 'failed to get INTFIELD tag')
00239       ifree = iTAG + nverts(3)
00240       print * , 'INTFIELD tag values'
00241       write(*, 103) (IWORK(iTAG+k-1), k=1,nverts(3) )
00242 103     FORMAT (10I8)
00243 
00244       dTAG = dfree
00245       ! query double tag values on elements
00246 
00247       ierr = iMOAB_GetDoubleTagStorage(pid, tagname2, nelem(3), entType(2), DWORK(dTAG) )
00248       call errorout(ierr, 'failed to get DFIELD tag')
00249       dfree = dTAG + nelem(3)
00250       print *, 'DFIELD tag values: (not exchanged) '
00251       write (*, 104) (DWORK(dTAG+k-1), k=1,nelem(3) )
00252 104     FORMAT ( 10F7.2 )
00253 
00254       !  query surface BCs
00255       isBC = ifree
00256       irBC = isBC + nsbc(3)
00257       ivBC = irBC + nsbc(3)
00258 
00259       ierr = iMOAB_GetPointerToSurfaceBC(pid, nsbc(3), IWORK(isBC),IWORK(irBC), IWORK(ivBC))
00260       call errorout(ierr, 'failed to get surf boundary conditions')
00261       ifree = ivBC + nsbc(3)
00262       print * , 'Surface boundary conditions '
00263       write (*, 105) (IWORK(isBC+k-1),IWORK(irBC+k-1), IWORK(ivBC+k-1), k=1, nsbc(3))
00264 105     FORMAT (' elem localID: ', I3, ' side:', I1, ' val:', I4)
00265 
00266       ! query vertex BCs
00267       iveBC = ifree
00268       ivaBC = iveBC + ndbc(3)
00269 
00270       ierr = iMOAB_GetPointerToVertexBC(pid, ndbc(3), IWORK(iveBC),IWORK(ivaBC))
00271       call errorout(ierr, 'failed to get vertex boundary conditions')
00272       ifree = ivaBC + ndbc(3)
00273 
00274       print *, '  Vertex boundary conditions:'
00275       write (*, 106) (IWORK(iveBC+k-1),IWORK(ivaBC+k-1), k=1, ndbc(3))
00276 106     FORMAT (' vertex: ', I3, ' BC:', I6 )
00277 
00278       endif
00279 
00280 #ifdef MOAB_HAVE_MPI
00281       call MPI_Barrier(MPI_COMM_WORLD, ierr)
00282 #endif
00283       call errorout(ierr, 'fail at barrier')
00284 enddo
00285 
00286       outfile = 'fnew2.h5m'//C_NULL_CHAR
00287 #ifdef MOAB_HAVE_MPI
00288       wopts   = 'PARALLEL=WRITE_PART'//C_NULL_CHAR
00289 #else
00290       wopts=C_NULL_CHAR
00291 #endif
00292 
00293       !     write out the mesh file to disk
00294       ierr = iMOAB_WriteMesh(pid, outfile, wopts)
00295       call errorout(ierr, 'fail to write the mesh file')
00296 
00297       !     all done. de-register and finalize
00298       ierr = iMOAB_DeregisterApplication(pid)
00299       call errorout(ierr, 'fail to deregister application')
00300 
00301       ierr = iMOAB_Finalize()
00302       call errorout(ierr, 'fail to finalize iMOAB')
00303 
00304 #ifdef MOAB_HAVE_MPI
00305       call MPI_FINALIZE ( ierr )
00306 #endif
00307       call errorout(ierr, 'fail to finalize MPI')
00308 
00309       stop
00310 end   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines