!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Subroutine SubGridDiff
!
!   * Developer: SUGIYAMA Ko-ichiro (sugiyama@gfd-dennou.org)
!   * Version: $Id: subgriddiff.f90,v 1.1 2005/02/07 10:31:21 sugiyama Exp $ 
!   * Tag Name: $Name:  $
!   * Change History: 
!
!== Overview 
!
!CReSS, Klemp and Wilhelmson (1978) で用いられている 1.5 次の
!クロージャーによって, サブグリッドスケールの
!乱流エネルギーの拡散を評価する. 
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!== Future Plans
!
                                                                 !=end


subroutine SubGridDiff( ss_Km_n, ss_DiffKm_n )
                                                                 !=begin  
  !== Dependency 
  use dc_trace,       only: BeginSub, EndSub
  use gridset,        only: DimXMin, DimXMax, DimZMin, DimZMax
  use differentiate_center4,  only: ss_dx_fs,  ss_dz_sf, fs_dx_ss, sf_dz_ss
  use average,        only: ss_avr_fs, ss_avr_sf

                                                                 !=end  
  !--- 暗黙の型宣言禁止
  implicit none
                                                                 !=begin    
  !== Input 
  real(8), intent(in) :: ss_Km_n(DimXMin:DimXMax, DimZMin:DimZMax) !渦粘性係数
  
  !== Output
  real(8), intent(out) :: ss_DiffKm_n(DimXMin:DimXMax, DimZMin:DimZMax) !乱流エネルギーの拡散
                                                                 !=end
  call BeginSub("SubGridDiff", &
&              fmt="%c",       &
&              c1="Calculate subgrid diffusion (ss_DiffKm).")


  !-- 乱流エネルギーの拡散
  ss_DiffKm_n =              &
       &     ss_dx_fs( fs_dx_ss( ss_Km_n ) ) / 2.0d0    &
       &   + ss_dz_sf( sf_dz_ss( ss_Km_n ) ) / 2.0d0    &
       &   + ( ss_avr_fs( fs_dx_ss( ss_Km_n ) ) ) ** 2.0d0 &
       &   + ( ss_avr_sf( sf_dz_ss( ss_Km_n ) ) ) ** 2.0d0
  
  call EndSub("SubGridDiff")
  
end subroutine SubGridDiff
