!---------------------------------------------------------------------
!     Copyright (C) GFD Dennou Club, 2004. All rights reserved.
!---------------------------------------------------------------------
                                                                 !=begin
!= Subroutine SubGridShear
!
!   * Developer: SUGIYAMA Ko-ichiro (sugiyama@gfd-dennou.org)
!   * Version: $Id: subgridshear.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 SubGridShear( fs_VelX_n, sf_VelZ_n, ss_DivVel_n, ss_Km_n, &
     &                   ss_ShearKm_n )
                                                                 !=begin  
  !== Dependency 
  use dc_trace,       only: BeginSub, EndSub
  use gridset,        only: DimXMin, DimXMax, DimZMin, DimZMax, DelXZ
  use differentiate_center2,  only: ss_dx_fs, ss_dz_sf, ff_dz_fs, ff_dx_sf 
  use average,        only: ss_avr_ff
  use arareprm,       only: Cm

                                                                 !=end  
  !--- 暗黙の型宣言禁止
  implicit none
                                                                 !=begin    
  !== Input 
  real(8), intent(in) :: fs_VelX_n(DimXMin:DimXMax, DimZMin:DimZMax) !速度 u  
  real(8), intent(in) :: sf_VelZ_n(DimXMin:DimXMax, DimZMin:DimZMax) !速度 w
  real(8), intent(in) :: ss_DivVel_n(DimXMin:DimXMax, DimZMin:DimZMax) !速度の収束
  real(8), intent(in) :: ss_Km_n(DimXMin:DimXMax, DimZMin:DimZMax) !渦粘性係数
  
  !== Output
  real(8), intent(out) :: ss_ShearKm_n(DimXMin:DimXMax, DimZMin:DimZMax) !シアーよる乱流エネルギー生成
                                                                 !=end
  call BeginSub("SubGridShear", &
&              fmt="%c",       &
&              c1="Calculate subgrid terbulent energy for shear (ss_ShearKm).")


  !-- 速度シアーによる乱流エネルギー生成
  ss_ShearKm_n = &
       &  ( Cm ** 2.0d0 ) * ( DelXZ ** 2.0d0 )               &
       &    * (                                              &
       &          ( ss_dx_fs( fs_VelX_n ) ) ** 2.0d0        &
       &       + ( ss_dz_sf( sf_VelZ_n ) ) ** 2.0d0         &
       &       + ( (   ss_avr_ff( ff_dz_fs( fs_VelX_n ) )   &
       &             + ss_avr_ff( ff_dx_sf( sf_VelZ_n ) )   &
       &           ) ** 2.0d0 ) / 2.0d0                      &
       &      )                                              &
       & - ss_Km_n * ss_DivVel_n / 3.0d0
  
  call EndSub("SubGridShear")
  
end subroutine SubGridShear
