!c Description: 
!c   物理量の配置場所を変更する. 平均化操作
!c
!c Current Code Owner: 
!c   sugiyama@gfd-dennou.org
!c
!c Comment: 
!c   
!c
!c Histry: 
!c   Version    Date          Comment
!c   -------    ----------    --------
!c   1.0        2004-08-11    杉山耕一朗 
!c   1.1        2004-08-24    杉山耕一朗 
!c
!c Copyright (C) SUGIYAMA Ko-ichiro, 2004, All rights reserved

module if_avr

  interface s_avr_u
     function s_avr1d_u(var)
       use gridset
       real(8), intent(in)  :: var(imin:imax)
       real(8)              :: s_avr1d_u(imin:imax)
     end function s_avr1d_u

     function s_avr2d_u(var) 
       use gridset
       real(8), intent(in)  :: var(imin:imax, kmin:kmax)
       real(8)              :: s_avr2d_u(imin:imax, kmin:kmax)
     end function s_avr2d_u
  end interface

  interface s_avr_w
     function s_avr1d_w(var)
       use gridset
       real(8), intent(in)  :: var(kmin:kmax)
       real(8)              :: s_avr1d_w(kmin:kmax)
     end function s_avr1d_w

     function s_avr2d_w(var)
       use gridset
       real(8), intent(in)  :: var(imin:imax, kmin:kmax)
       real(8)              :: s_avr2d_w(imin:imax, kmin:kmax)
     end function s_avr2d_w
  end interface

  interface u_avr_s
     function u_avr1d_s(var)
       use gridset
       real(8), intent(in)  :: var(imin:imax)
       real(8)              :: u_avr1d_s(imin:imax)
     end function u_avr1d_s

     function u_avr2d_s(var) 
       use gridset
       real(8), intent(in)  :: var(imin:imax, kmin:kmax)
       real(8)              :: u_avr2d_s(imin:imax, kmin:kmax)
     end function u_avr2d_s
  end interface

  interface w_avr_s
     function w_avr1d_s(var) 
       use gridset
       real(8), intent(in)  :: var(kmin:kmax)
       real(8)              :: w_avr1d_s(kmin:kmax)
     end function w_avr1d_s

     function w_avr2d_s(var) 
       use gridset
       real(8), intent(in)  :: var(imin:imax, kmin:kmax)
       real(8)              :: w_avr2d_s(imin:imax, kmin:kmax)
     end function w_avr2d_s
  end interface

end module if_avr



!!!
!!!スカラーの位置での平均操作
!!!  
function s_avr1d_u(var)
  use gridset
  use if_boundary

  implicit none 
  
  real(8), intent(in)  :: var(imin:imax)
  real(8)              :: s_avr1d_u(imin:imax)

  s_avr1d_u(imin:imax-1) =          &
       &  (                       &
       &     var(imin+1:imax)     &
       &   + var(imin:imax-1)     &
       &  ) * 5.0d-1

  call boundary(bdc_s, s_avr1d_u)    
end function s_avr1d_u

function s_avr1d_w(var)
  use gridset
  use if_boundary

  implicit none 
  
  real(8), intent(in)  :: var(kmin:kmax)
  real(8)              :: s_avr1d_w(kmin:kmax)
  
  s_avr1d_w(kmin:kmax-1) =          &
       &  (                       &
       &     var(kmin+1:kmax)     &
       &   + var(kmin:kmax-1)     &
       &  ) * 5.0d-1

  call boundary(bdc_s, s_avr1d_w)  
end function s_avr1d_w

function s_avr_s(var)
  use gridset
  use if_boundary

  implicit none
  
  real(8), intent(in)  :: var(imin:imax, kmin:kmax)
  real(8)              :: s_avr_s(imin:imax, kmin:kmax)
  
  s_avr_s = var
end function s_avr_s


function s_avr2d_u(var) 
  use gridset
  use if_boundary

  implicit none
  
  real(8), intent(in)  :: var(imin:imax, kmin:kmax)
  real(8)              :: s_avr2d_u(imin:imax, kmin:kmax)
  
  s_avr2d_u(imin:imax-1,kmin:kmax) =          &
       &  (                                 &
       &     var(imin+1:imax,kmin:kmax)     &
       &   + var(imin:imax-1,kmin:kmax)     &
       &  ) * 5.0d-1
  
  call boundary(bdc_s, s_avr2d_u)
end function s_avr2d_u
  
  
function s_avr2d_w(var)
  use gridset
  use if_boundary

  implicit none
  
  real(8), intent(in)  :: var(imin:imax, kmin:kmax)
  real(8)              :: s_avr2d_w(imin:imax, kmin:kmax)
  
  s_avr2d_w(imin:imax,kmin:kmax-1) =          &
       &  (                                 &
       &     var(imin:imax,kmin+1:kmax)     &
       &   + var(imin:imax,kmin:kmax-1)     &
       &  ) * 5.0d-1
  
  call boundary(bdc_s, s_avr2d_w)
end function s_avr2d_w
  
  
!!!
!!!速度 u の位置での平均操作
!!!  

function u_avr1d_s(var)
  use gridset
  use if_boundary

  implicit none
  
  real(8), intent(in)  :: var(imin:imax)
  real(8)              :: u_avr1d_s(imin:imax)

  u_avr1d_s(imin+1:imax) =        &
       &  (                       &
       &     var(imin+1:imax)     &
       &   + var(imin:imax-1)     &
       &  ) * 5.0d-1

  call boundary(bdc_u, u_avr1d_s)  
end function u_avr1d_s

function u_avr2d_s(var) 
  use gridset
  use if_boundary

  implicit none
  
  real(8), intent(in)  :: var(imin:imax, kmin:kmax)
  real(8)              :: u_avr2d_s(imin:imax, kmin:kmax)
  
  u_avr2d_s(imin+1:imax,kmin:kmax) =         &
       &  (                                &
       &     var(imin+1:imax,kmin:kmax)    &
       &   + var(imin:imax-1,kmin:kmax)    &
       &  ) * 5.0d-1
  
  call boundary(bdc_u, u_avr2d_s)
end function u_avr2d_s


function u_avr_u(var) 
  use gridset
  use if_boundary

  implicit none

  real(8), intent(in)  :: var(imin:imax, kmin:kmax)
  real(8)              :: u_avr_u(imin:imax, kmin:kmax)
  
  u_avr_u = var
end function u_avr_u


function u_avr_w(var) 
  use gridset
  use if_boundary

  implicit none

  real(8), intent(in)  :: var(imin:imax, kmin:kmax)
  real(8)              :: u_avr_w(imin:imax, kmin:kmax)
  
  u_avr_w(imin+1:imax,kmin:kmax-1) =       &
       &  (                                &
       &     var(imin+1:imax,kmin+1:kmax)  &
       &   + var(imin+1:imax,kmin:kmax-1)  &
       &   + var(imin:imax-1,kmin+1:kmax)  &
       &   + var(imin:imax-1,kmin:kmax-1)  &
       &  ) * 2.5d-1
  
  call boundary(bdc_u, u_avr_w)
end function u_avr_w
  
  
!!!
!!!速度 w の位置での平均操作
!!!  
  
function w_avr1d_s(var) 
  use gridset
  use if_boundary

  implicit none

  real(8), intent(in)  :: var(kmin:kmax)
  real(8)              :: w_avr1d_s(kmin:kmax)
  
  w_avr1d_s(kmin+1:kmax) =          &
       &  (                       &
       &     var(kmin+1:kmax)     &
       &   + var(kmin:kmax-1)     &
       &  ) * 5.0d-1

  call boundary(bdc_w, w_avr1d_s)    
end function w_avr1d_s


function w_avr2d_s(var) 
  use gridset
  use if_boundary

  implicit none

  real(8), intent(in)  :: var(imin:imax, kmin:kmax)
  real(8)              :: w_avr2d_s(imin:imax, kmin:kmax)
  
  w_avr2d_s(imin:imax,kmin+1:kmax) =         &
       &  (                                &
       &     var(imin:imax,kmin+1:kmax)    &
       &   + var(imin:imax,kmin:kmax-1)    &
       &  ) * 5.0d-1
  
  call boundary(bdc_w, w_avr2d_s) 
end function w_avr2d_s

  
function w_avr_u(var) 
  use gridset
  use if_boundary

  implicit none

  real(8), intent(in)  :: var(imin:imax, kmin:kmax)
  real(8)              :: w_avr_u(imin:imax, kmin:kmax)
  
  w_avr_u(imin:imax-1,kmin+1:kmax) =       &
       &  (                                &
       &     var(imin+1:imax,kmin+1:kmax)  &
       &   + var(imin+1:imax,kmin:kmax-1)  &
       &   + var(imin:imax-1,kmin+1:kmax)  &
       &   + var(imin:imax-1,kmin:kmax-1)  &
       &  ) * 2.5d-1
  
  call boundary(bdc_w, w_avr_u)
end function w_avr_u


function w_avr_w(var) 
  use gridset
  use if_boundary

  implicit none

  real(8), intent(in)  :: var(imin:imax, kmin:kmax)
  real(8)              :: w_avr_w(imin:imax, kmin:kmax)
  
  w_avr_w = var
end function w_avr_w

