Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
FindAdjacencyF90.F90
Go to the documentation of this file.
00001 ! FindAdjacency: Interacting with iMesh
00002 ! 
00003 ! This program shows how to get more information about a mesh, by
00004 ! getting connectivity two different ways (as connectivity and as
00005 ! adjacent 0-dimensional entities).
00006   
00007 ! Usage: FindAdjacency
00008 #define CHECK(a) \
00009   if (ierr .ne. 0) print *, a
00010 
00011 program findadjacency
00012   implicit none
00013 #include "iMesh_f.h"
00014 
00015   ! declarations
00016   iMesh_Instance mesh
00017   IBASE_HANDLE_T rpents, rpverts, rpallverts, ipoffsets
00018   integer ioffsets
00019   IBASE_HANDLE_T ents, verts, allverts, verths
00020   pointer (rpents, ents(0:*))
00021   pointer (rpverts, verts(0:*))
00022   pointer (rpallverts, allverts(0:*))
00023   pointer (ipoffsets, ioffsets(0:*))
00024 !  for all vertices in one call
00025   iBase_EntityHandle verth
00026   pointer (verths, verth(0:*))
00027   integer ierr, ents_alloc, ents_size
00028   integer iverts_alloc, iverts_size
00029   integer allverts_alloc, allverts_size
00030   integer offsets_alloc, offsets_size, coords_alloc, coords_size
00031   iBase_EntitySetHandle root_set
00032   integer vert_uses, i, num_ents
00033   real*8 coords
00034   pointer (pcoord, coords(0:*))
00035 !
00036   iBase_EntitySetHandle :: sethand
00037 
00038   ! create the Mesh instance
00039   call iMesh_newMesh("", mesh, ierr)
00040   CHECK("Problems instantiating interface.")
00041 
00042   ! load the mesh
00043   call iMesh_getRootSet(%VAL(mesh), root_set, ierr)
00044   CHECK("Problems getting root set")
00045 
00046   call iMesh_load(%VAL(mesh), %VAL(root_set), &
00047        "../../MeshFiles/unittest/125hex.g", "", ierr)
00048   CHECK("Load failed")
00049 
00050   ! get all 3d elements
00051   ents_alloc = 0
00052   call iMesh_getEntities(%VAL(mesh), %VAL(root_set), %VAL(iBase_REGION), &
00053        %VAL(iMesh_ALL_TOPOLOGIES), rpents, ents_alloc, ents_size, &
00054        ierr)
00055   CHECK("Couldn't get entities")
00056 
00057   vert_uses = 0
00058 
00059   ! iterate through them; 
00060   do i = 0, ents_size-1
00061      ! get connectivity
00062      iverts_alloc = 0
00063      call iMesh_getEntAdj(%VAL(mesh), %VAL(ents(i)), &
00064           %VAL(iBase_VERTEX), &
00065           rpverts, iverts_alloc, iverts_size, &
00066           ierr)
00067      CHECK("Failure in getEntAdj")
00068      ! sum number of vertex uses
00069 
00070      vert_uses = vert_uses + iverts_size
00071 
00072      if (iverts_size .ne. 0) call iMesh_freeMemory(%VAL(mesh), rpverts)
00073   end do
00074 
00075   ! now get adjacencies in one big block
00076   allverts_alloc = 0
00077   offsets_alloc = 0
00078   call iMesh_getEntArrAdj(%VAL(mesh), %VAL(rpents), &
00079        %VAL(ents_size), %VAL(iBase_VERTEX), rpallverts,  &
00080        allverts_alloc, allverts_size, ipoffsets, offsets_alloc, &
00081        offsets_size, ierr)
00082   CHECK("Failure in getEntArrAdj")
00083 
00084   if (allverts_size .ne. 0) call iMesh_freeMemory(%VAL(mesh), rpallverts);
00085   if (offsets_size .ne. 0) call iMesh_freeMemory(%VAL(mesh), ipoffsets);
00086   if (ents_size .ne. 0) call iMesh_freeMemory(%VAL(mesh), rpents);
00087 
00088   ! compare results of two calling methods
00089   if (allverts_size .ne. vert_uses) then
00090      write(*,'("Sizes didn''t agree!")')
00091   else 
00092      write(*, *)"Sizes did agree: ", vert_uses
00093   endif
00094 ! get all vertices , and then their coordinates
00095   ents_alloc = 0
00096   call iMesh_getEntities(%VAL(mesh), %VAL(root_set), %VAL(iBase_VERTEX), &
00097        %VAL(iMesh_ALL_TOPOLOGIES), verths, ents_alloc, ents_size, &
00098        ierr)
00099   write (*, *) "number of vertices: " , ents_size
00100   print *, "few vertex handles: ", (verth(i), i=0,ents_size/10)
00101 
00102 ! set creation
00103   call iMesh_createEntSet(%VAL(mesh), %VAL(1), &
00104         sethand,ierr)
00105   write(0,*) "createset",ierr,sethand 
00106 
00107 ! we should have 
00108   call iMesh_addEntArrToSet(%VAL(mesh),verth,%VAL(ents_size), &
00109       %VAL(sethand),ierr)
00110   write(0,*) "add Ent Arr to Set",ierr,sethand 
00111 
00112   call iMesh_getNumOfType(%VAL(mesh), %VAL(sethand),  &
00113    %VAL(iBase_VERTEX), num_ents, ierr)
00114   write(0,*) "num verts retrieved from set", num_ents
00115 
00116   ents_alloc = 0;
00117   call iMesh_getVtxArrCoords(%VAL(mesh), verth, %VAL(ents_size), &
00118     %VAL(iBase_INTERLEAVED), pcoord, ents_alloc , ents_size, ierr)
00119 !
00120   write(*, *) "num coords: ", ents_size, " few coords: ", (coords(i), i=0, ents_size/100)  
00121 
00122   call iMesh_freeMemory(%VAL(mesh), verths);
00123   call iMesh_freeMemory(%VAL(mesh), pcoord);
00124 
00125   call iMesh_dtor(%VAL(mesh), ierr)
00126   CHECK("Failed to destroy interface")
00127 
00128 end program findadjacency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines