ITM Grid Service Library: Fortran 90

src/service/itm_grid_access.f90

Go to the documentation of this file.
00001 module itm_grid_access
00002 
00003   use itm_types , ITM_R8 => R8, ITM_R4 => R4
00004   use itm_assert
00005   use euITM_schemas ! IGNORE
00006 
00007   implicit none
00008 
00009   ! TODO: getSpaceNodeCount to replace size( node_value )
00010 
00011 contains
00012 
00013   !> Return the UID number of this grid
00014   pure integer function gridUid( grid )
00015     type(type_complexgrid), intent(in) :: grid
00016 
00017     gridUid = grid%uid
00018   end function gridUid
00019 
00020   !> Return the ID string of this grid
00021   character(132) function gridId(grid) 
00022     type(type_complexgrid), intent(in) :: grid
00023 
00024     gridId = repeat(' ', 132)
00025     if (associated( grid%id )) then
00026         if (len(grid%id) > 0) then
00027             gridId = grid%id(1)
00028         end if
00029     end if
00030   end function gridId
00031 
00032   !> Return total dimension of the grid described by a given grid descriptor.
00033   pure integer function gridNDim( grid )
00034     type(type_complexgrid), intent(in) :: grid
00035 
00036     ! internal
00037     integer :: i
00038 
00039     gridNDim = 0
00040     do i = 1, size( grid % spaces ) 
00041             gridNDim = gridNDim + size( grid % spaces( i ) % coordtype )
00042     end do
00043 
00044   end function gridNDim
00045 
00046 
00047   !> Return the number of spaces in a grid description.
00048   pure integer function gridNSpace( grid )
00049     type(type_complexgrid), intent(in) :: grid
00050     
00051     gridNSpace = size( grid % spaces ) 
00052   end function gridNSpace
00053 
00054 
00055   !> Return the dimension of an individual space.
00056   pure integer function gridSpaceNDim( space )
00057     type(type_complexgrid_space), intent(in) :: space
00058 
00059     gridSpaceNDim = size( space % coordtype )
00060   end function gridSpaceNDim
00061 
00062 
00063   !> Returns the dimension of all individual spaces
00064   pure function gridSpaceNDims( grid ) result( dims )
00065     type(type_complexgrid), intent(in) :: grid
00066     integer, dimension( size( grid % spaces ) ) :: dims
00067 
00068     ! internal
00069     integer :: i
00070 
00071     do i = 1, size( grid % spaces ) 
00072             dims( i ) = gridSpaceNDim( grid % spaces( i ) ) 
00073     end do
00074 
00075   end function gridSpaceNDims
00076 
00077   !> Returns the highest dimension for which objects are defined in the space
00078   pure function gridSpaceMaxObjDim( space ) result( dim )
00079     type(type_complexgrid_space), intent(in) :: space
00080     integer :: dim
00081    
00082     dim = 0
00083     if (associated(space%objects)) dim = size(space%objects) - 1
00084   end function gridSpaceMaxObjDim
00085 
00086   !> Return number of nodes (0d-objects) in the space.
00087   pure integer function gridSpaceNNodes( space )
00088     type(type_complexgrid_space), intent(in) :: space
00089 
00090     gridSpaceNNodes = 0
00091     if (associated( space % objects(1) % geo )) gridSpaceNNodes = size( space % objects(1) % geo, 1 )
00092   end function gridSpaceNNodes  
00093 
00094 
00095   !> Get the total number of objects 
00096   !> of the given dimension in the given space
00097   integer function gridSpaceNObject( space, dim ) result( objcount )
00098     type(type_complexgrid_space), intent(in) :: space
00099     integer, intent(in) :: dim
00100 
00101     call assert( ( dim >= 0 ) .and. ( dim <= gridSpaceNdim( space ) ), &
00102          & "gridSpaceNObject: dim out of bounds" )
00103 
00104     if ( dim == 0 ) then
00105         objcount = gridSpaceNNodes( space )
00106     else
00107         objcount = 0
00108         if (associated(space%objects)) then
00109             if ( dim <= size(space%objects) ) then
00110                 objcount = size( space % objects(dim+1) % boundary, 1 )
00111             end if
00112         end if
00113     end if
00114   end function gridSpaceNObject
00115 
00116 
00117   !> Return maximum number of boundaries an object of dimension dim can have in the space.
00118   integer function gridSpaceMaxNBoundaries( space, dim ) 
00119     type(type_complexgrid_space), intent(in) :: space
00120     integer, intent(in) :: dim
00121 
00122     gridSpaceMaxNBoundaries = size( space % objects(dim+1) % boundary, 2 )
00123   end function gridSpaceMaxNBoundaries
00124 
00125 
00126   !> Returns the coordinate types for the individual dimensions of the grid
00127   !> @note Can be made pure by replacing gridSpaceNDim
00128   function gridCoordTypes( grid ) result( coordtype ) 
00129     type(type_complexgrid), intent(in) :: grid
00130     integer, dimension( gridNDim( grid ) ) :: coordtype
00131 
00132     ! internal
00133     integer :: is, ic, sdim
00134 
00135     ic = 0
00136     do is = 1, gridNSpace( grid )
00137        sdim = gridSpaceNDim( grid % spaces(is) )
00138        ! TODO: add treatement of multiple geometries here 
00139        coordtype( ic + 1 : ic + sdim ) &
00140             & = grid % spaces(is) % coordtype( 1 : sdim, 1 )
00141        ic = ic + sdim
00142     end do
00143 
00144   end function gridCoordTypes
00145 
00146 
00147   !> Returns index of a node according to the implicit ordering rules for the grid descriptor
00148   integer function gridNodeIndex( grid, nodeind ) result( index )
00149     type(type_complexgrid), intent(in) :: grid
00150     integer, dimension(:), intent(in) :: nodeind
00151     
00152     ! internal
00153     integer :: i, s
00154 
00155     call assert( size( nodeind ) == size( grid % spaces ), &
00156          & "gridNodeIndex: size of nodeind does not match the grid description" )
00157     
00158     index = nodeind(1)
00159     s = gridSpaceNNodes( grid % spaces(1) )
00160 
00161     do i = 2, size( grid % spaces )
00162             index = index + s * ( nodeind( i ) - 1 )
00163             s = s * gridSpaceNNodes( grid % spaces(i) ) 
00164     end do
00165     
00166   end function gridNodeIndex
00167 
00168 
00169   !> Get the coordinates of a node according to it's index tuple (assuming
00170   !> the default geometry representation.
00171   function gridNodeCoord( grid, nodeind ) result ( coord )
00172     type(type_complexgrid), intent(in) :: grid
00173     integer, dimension(gridNSpace(grid)), intent(in) :: nodeind
00174     real(ITM_R8), dimension( gridNDim( grid ) ) :: coord
00175     
00176     ! internal   
00177     integer :: is, id, nd
00178 
00179     call assert( size( nodeind ) == size( grid % spaces ), &
00180          & "gridNodeCoord: size of nodeind does not match the grid description" )
00181 
00182     ! FIXME: add test for default geometry representation.
00183 
00184     coord = 0.0_ITM_R8
00185 
00186     id = 0 ! coordinate counter
00187     do is = 1, gridNSpace( grid )
00188             ! get dimension of current space
00189             nd = gridSpaceNDim( grid % spaces(is) )
00190             ! copy coordinates
00191             ! TODO: add handling of multiple geometries here
00192             coord(id + 1 : id + nd ) = grid % spaces( is ) % objects(1) % geo( nodeind( is ), 1:nd, 1, 1 )
00193             ! increase coordinate counter
00194             id = id + nd
00195     end do
00196 
00197   end function gridNodeCoord
00198 
00199 end module itm_grid_access
 All Classes Namespaces Files Functions Variables