MOAB: Mesh Oriented datABase  (version 5.4.1)
imoab_ptest.F
Go to the documentation of this file.
00001 C      push parallel mesh into moab, using iMoab API, F77 version
00002 C
00003 C      This program shows how to push a mesh into MOAB in parallel using iMoab, with sufficient
00004 C      information to resolve boundary sharing and exchange a layer of ghost information.
00005 C
00006 C       After resolving the sharing, mesh is saved to a file, then read back again, in parallel
00007 C        the mesh is a quad mesh, 2x2 on each task,
00008 C       by default, this test is run on 2 processors
00009 
00010 C       Test is similar to itaps/iMeshP_unit_tests.cpp
00011 C
00012 C
00013 C       Create a mesh:
00014 C       Groups of four quads will be arranged into parts as follows:
00015 C       +------+------+------+------+------+-----
00016 C       |             |             |
00017 C       |             |             |
00018 C       +    Part 0   +    Part 2   +    Part 4
00019 C       |             |             |
00020 C       |             |             |
00021 C       +------+------+------+------+------+-----
00022 C       |             |             |
00023 C       |             |             |
00024 C       +    Part 1   +    Part 3   +    Part 5
00025 C       |             |             |
00026 C       |             |             |
00027 C       +------+------+------+------+------+-----
00028 C
00029 C       Vertices will be enumerated as follows:
00030 C       1------6-----11-----16-----21-----26----- > x  x from 0, 1, 2
00031 C       |             |             |
00032 C       |             |             |
00033 C       2      7     12     17     22     27
00034 C       |             |             |
00035 C       |             |             |
00036 C       3------8-----13-----18-----23-----28-----
00037 C       |             |             |
00038 C       |             |             |
00039 C       4      9     14     19     24     29
00040 C       |             |             |
00041 C       |             |             |
00042 C       5-----10-----15-----20-----25-----30-----
00043 C       |
00044 C       y varies from 0 to 4
00045 C
00046 C       Processor 0 will have vertices 1, 2, 3, 6, 7, 8, 11, 12, 13
00047 C         and 4 quads, with ids from 1 to 4, and connectivity
00048 C          1, 2, 7, 6;  2, 3, 8, 7; 6 ,7, 12, 11; 7, 8, 13, 12
00049 C       Processor 1 will have vertices 3, 4, 5, 8, 9, 10, 13, 14, 15
00050 C         and 4 quads, with ids from 5 to 8, and connectivity
00051 C          3, 4, 8, 9;  4, 5, 10, 9; 8, 9, 14, 13; 9, 10, 15, 14,
00052 C       and so on
00053 C
00054 C       Vertex Global IDs will be used to resolve sharing
00055 C
00056 C       Element IDs will be [4*rank+1,4*rank+5]
00057 C  #define ERROR(rval) if (0 .ne. rval) call exit(1)
00058 
00059 
00060       SUBROUTINE errorout(ierr, message)
00061       integer ierr
00062       character*(*) message
00063       if (ierr.ne.0) then
00064         print *, message
00065         call exit (1)
00066       end if
00067       return
00068       end
00069 
00070 #include "moab/MOABConfig.h"
00071       program imoabpar_test
00072 C      implicit none
00073 
00074       use iMOAB
00075 #include "mpif.h"
00076 
00077       integer ierr, my_id, num_procs, pid, i, ix, iy, numv, nume
00078       integer dime, lco, mbtype, blockid, npe
00079       integer compid
00080       character :: appname*10
00081       character :: outfile*100, wopts*100
00082 C coordinates for 9 vertices
00083       double precision  coordinates(27) , coords_core(27), deltax, deltay
00084       integer ids(9)
00085       integer connec(16)
00086 C      used for ghosting
00087       integer dimgh, bridge, num_layers
00088 
00089       data coords_core/ 0., 0., 0.,
00090      &                  0., 1., 0.,
00091      &                  0., 2., 0.,
00092      &                  1., 0., 0.,
00093      &                  1., 1., 0.,
00094      &                  1., 2., 0.,
00095      &                  2., 0., 0.,
00096      &                  2., 1., 0.,
00097      &                  2., 2., 0./
00098       data ids/1, 2, 3, 6, 7, 8, 11, 12, 13/
00099       data connec/ 1, 2, 5, 4,
00100      &             2, 3, 6, 5,
00101      &             4, 5, 8, 7,
00102      &             5, 6, 9, 8/
00103 
00104       call MPI_Init ( ierr )
00105       call errorout(ierr, 'fail to initialize MPI')
00106 
00107       ierr = iMOAB_Initialize()
00108       call errorout(ierr, 'fail to initialize iMOAB')
00109 
00110       call MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr)
00111       call errorout(ierr, 'fail to get MPI rank')
00112 
00113       call MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr)
00114       call errorout(ierr, 'fail to get MPI size')
00115 
00116       ! find out MY process ID, and how many processes were started.
00117       if (my_id .eq. 0) then
00118         print *, " I'm process ", my_id, " out of ", 
00119      &           num_procs, " processes."
00120       end if
00121 
00122       !  give a component id
00123       compid = 7
00124       appname = 'IMTEST'//CHAR(0)
00125       ierr = iMOAB_RegisterApplication(appname, MPI_COMM_WORLD,
00126      & compid, pid)
00127       call errorout(ierr, 'fail to initialize fortran app')
00128 
00129       !  create first 9 vertices,  in a square 3x3;
00130       deltax=(my_id/2) * 2.
00131       deltay = mod(my_id, 2) * 2.
00132       ix = (my_id/2) * 10
00133       iy = mod(my_id,2) * 2
00134       do i=1,9
00135         coordinates( 3*(i-1) + 1 ) = coords_core (3*(i-1)+1) + deltax
00136         coordinates( 3*(i-1) + 2 ) = coords_core (3*(i-1)+2) + deltay
00137         coordinates( 3*(i-1) + 3 ) = coords_core (3*(i-1)+3)
00138 
00139         ! translate the ids too, by multiples of 10 or add 2
00140         ids(i) = ids(i) + ix+iy
00141       enddo
00142       numv = 9
00143       nume = 4
00144       lco = numv*3
00145       dime = 3
00146       ierr = iMOAB_CreateVertices(pid, lco, dime, coordinates);
00147       call errorout(ierr, 'fail to create vertices')
00148 
00149       ! create now 4 quads with those 9 vertices
00150       mbtype = 3
00151       blockid  = 100
00152       npe = 4
00153       ierr = iMOAB_CreateElements(pid, nume, mbtype, npe, 
00154      &                           connec, blockid)
00155       call errorout(ierr, 'fail to create quads')
00156 
00157       ierr = iMOAB_ResolveSharedEntities( pid, numv, ids );
00158       call errorout(ierr, 'fail to resolve shared entities')
00159 
00160       !  see ghost elements
00161       dimgh = 2 ! will ghost quads, topological dim 2
00162       bridge = 0 ! use vertex as bridge
00163       num_layers = 1 ! so far, one layer only
00164       ierr = iMOAB_DetermineGhostEntities( pid, dimgh, num_layers,
00165      & bridge)
00166       call errorout(ierr, 'fail to determine ghosts')
00167 
00168       ! write out the mesh file to disk, in parallel, if h5m
00169 #ifdef MOAB_HAVE_HDF5
00170       outfile = 'wholeF.h5m'//CHAR(0)
00171       wopts   = 'PARALLEL=WRITE_PART'//CHAR(0)
00172       ierr = iMOAB_WriteMesh(pid, outfile, wopts)
00173       call errorout(ierr, 'fail to write the mesh file')
00174 #endif
00175 
00176       !  all done. de-register and finalize
00177       ierr = iMOAB_DeregisterApplication(pid)
00178       call errorout(ierr, 'fail to deregister application')
00179 
00180       ierr = iMOAB_Finalize()
00181       call errorout(ierr, 'fail to finalize iMOAB')
00182 
00183 
00184       call MPI_FINALIZE ( ierr )
00185       call errorout(ierr, 'fail to finalize MPI')
00186 
00187       end
00188 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines