!c Description: 
!c   X $BJ}8~$N1?F0J}Dx<0$K$*$$$FD9$$;~4V%9%F%C%W$GI>2A$9$k9`$N7W;;(B
!c
!c Current Code Owner: 
!c   sugiyama@gfd-dennou.org
!c
!c Copyright (C) SUGIYAMA Ko-ichiro, 2004, All rights reserved

subroutine DiffuseX(fs_VelX_B, sf_VelZ_B, fs_DiffuseX_B)
  
  !--- $B%b%8%e!<%k$NFI$_9~$_(B
  use gridset,  only: DimXMin, DimXMax, DimZMin, DimZMax, DelXZ
  use bcset,    only: fs_Bc
  use if_diff,  only: fs_dx_ss, fs_dz_ss, ss_dx_sf, ss_dx_fs, ss_dz_fs
  use arareprm, only: Cm
  use if_boundary
  
  !--- $B0EL[$N7?@k8@6X;_(B
  implicit none
  
  !--- $BF~=PNOJQ?t(B
  real(8), intent(in)    :: fs_VelX_B(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(in)    :: sf_VelZ_B(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)   :: fs_DiffuseX_B(DimXMin:DimXMax, DimZMin:DimZMax)

  !--- $BFbItJQ?t(B
  real(8)   :: ss_Km_B(DimXMin:DimXMax, DimZMin:DimZMax)


  !--- $B12G4@-78?t(B, $BMpN.:.9g5wN%$r7h$a$k(B
  call TurbStab(fs_VelX_B, sf_VelZ_B, ss_Km_B)
  
  !--- $B3H;69`(B ($BMpN.%(%M%k%.!<(B E $B$ODj>o$J>l9g(B)
  fs_DiffuseX_B = &
       &   2.0d0 * fs_dx_ss( ss_Km_B * ss_dx_fs( fs_VelX_B ) )  &
       & + 2.0d0 * fs_dz_ss(  &
       &           ss_Km_B * ss_dz_fs( fs_VelX_B )    &
       &         + ss_Km_B * ss_dx_sf( sf_VelZ_B ) )  &
       & - 2.0d0 * fs_dx_ss( ( ss_Km_B ** 2.0d0 ) ) &
       &         / ( 3.0d0 * ( Cm ** 2.0d0 ) * ( DelXZ ** 2.0d0 ) )

  write(*,*) "Dx ", maxval( abs( fs_DiffuseX_B ) )

  !--- $B3H;69`(B ($B3H;6$J$7$N>l9g(B)
  fs_DiffuseX_B = 0.0d0  
  
  !--- $B6-3&>r7o(B
  call boundary(fs_Bc, fs_DiffuseX_B)
  
end subroutine DiffuseX
