!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2005. All rights reserved.
!---------------------------------------------------------------------
!= Module Turbulence
!
!   * Developer: SUGIYAMA Ko-ichiro
!   * Version: $Id: $
!   * Tag Name: $Name:  $
!   * Change History: 
!
!== Overview
!
!乱流拡散の計算を行うための関数を束ねたモジュール
! 
!== Error Handling
!
!== Bugs
!
!== Note
!
!== Future Plans
!
!

module Turbulence

  interface ss_TurbX_ss_ss
    function ss_TurbX_ss_ss(ss_Scalar, ss_Kh)
      use gridset
      real(8), intent(in) :: ss_Kh(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !乱流拡散係数
      real(8), intent(in) :: ss_Scalar(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !スカラー量
      real(8)             :: ss_TurbX_ss_ss(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !スカラー量の水平乱流拡散
    end function ss_TurbX_ss_ss
  end interface

  interface ss_TurbZ_ss_ss
    function ss_TurbZ_ss_ss(ss_Scalar, ss_Kh)
      use gridset
      real(8), intent(in) :: ss_Kh(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !乱流拡散係数
      real(8), intent(in) :: ss_Scalar(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !スカラー量
      real(8)             :: ss_TurbZ_ss_ss(DimXMin:DimXMax, DimZMin:DimZMax)
    end function ss_TurbZ_ss_ss
  end interface

end module Turbulence



function ss_TurbX_ss_ss(ss_Scalar, ss_Kh)
  !
  ! スカラー量の水平方向の乱流拡散
  !
  use gridset, only: DimXMin, DimXMax, DimZMin, DimZMax
  use average,  only: fs_avr_ss
  use differentiate_center4, only: ss_dx_fs, fs_dx_ss
  implicit none
  
  real(8), intent(in) :: ss_Kh(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !乱流拡散係数
  real(8), intent(in) :: ss_Scalar(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !スカラー量
  real(8)             :: ss_TurbX_ss_ss(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !スカラー量の水平乱流拡散
  
  ss_TurbX_ss_ss = 0.0d0  !初期化
  ss_TurbX_ss_ss = ss_dx_fs(fs_avr_ss(ss_Kh) * fs_dx_ss(ss_Scalar)) 
  
end function ss_TurbX_ss_ss


function ss_TurbZ_ss_ss(ss_Scalar, ss_Kh)
  !
  ! スカラー量の鉛直方向の乱流拡散
  !
  use gridset, only: DimXMin, DimXMax, DimZMin, DimZMax
  use average,  only: sf_avr_ss
  use differentiate_center4, only: ss_dz_sf, sf_dz_ss
  implicit none
  
  real(8), intent(in) :: ss_Kh(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !乱流拡散係数
  real(8), intent(in) :: ss_Scalar(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !スカラー量
  real(8)             :: ss_TurbZ_ss_ss(DimXMin:DimXMax, DimZMin:DimZMax)
                                                    !スカラー量の鉛直乱流拡散
  
  ss_TurbZ_ss_ss = 0.0d0  !初期化
  ss_TurbZ_ss_ss =  ss_dz_sf(sf_avr_ss(ss_Kh) * sf_dz_ss(ss_Scalar))
  
end function ss_TurbZ_ss_ss
