wall_dist Function

private function wall_dist(grid, celli, cellj, cellk, pos, dir, ldir) result(res)

funtion that returns distant to nearest wall and which wall that is (x, y, or z)

Arguments

Type IntentOptional Attributes Name
type(cart_grid), intent(in) :: grid
integer, intent(inout) :: celli
integer, intent(inout) :: cellj
integer, intent(inout) :: cellk
type(vector), intent(in) :: pos
type(vector), intent(in) :: dir
logical, intent(inout) :: ldir(:)

Return Value real(kind=wp)


Source Code

    function wall_dist(grid, celli, cellj, cellk, pos, dir, ldir) result(res)
    !! funtion that returns distant to nearest wall and which wall that is (x, y, or z)
    
        use vector_class
        use gridMod

        type(cart_grid), intent(IN)    :: grid
        type(vector),    intent(IN)    :: pos, dir
        logical,         intent(INOUT) :: ldir(:)
        integer,         intent(INOUT) :: celli, cellj, cellk
        real(kind=wp) :: res

        real(kind=wp) :: dx, dy, dz

        dx = -999._wp
        dy = -999._wp
        dz = -999._wp

        if(dir%x > 0._wp)then
            dx = (grid%xface(celli+1) - pos%x)/dir%x
        elseif(dir%x < 0._wp)then
            dx = (grid%xface(celli) - pos%x)/dir%x
        elseif(dir%x == 0._wp)then
            dx = 100000._wp
        end if

        if(dir%y > 0._wp)then
            dy = (grid%yface(cellj+1) - pos%y)/dir%y
        elseif(dir%y < 0._wp)then
            dy = (grid%yface(cellj) - pos%y)/dir%y
        elseif(dir%y == 0._wp)then
            dy = 100000._wp
        end if

        if(dir%z > 0._wp)then
            dz = (grid%zface(cellk+1) - pos%z)/dir%z
        elseif(dir%z < 0._wp)then
            dz = (grid%zface(cellk) - pos%z)/dir%z
        elseif(dir%z == 0._wp)then
            dz = 100000._wp
        end if

        res = min(dx, dy, dz)
        if(res < 0._wp)then
            print*,'dcell < 0.0 warning! ',res
            print*,dx,dy,dz
            print*,dir
            print*,celli,cellj,cellk
            error stop 1
        end if

        ldir = [res == dx, res==dy, res==dz]
        if(.not.ldir(1) .and. .not.ldir(2) .and. .not.ldir(3))print*,'Error in dir flag'
      
   end function wall_dist