!c Description: 
!c   仮温位の数値積分 (Eular 法)
!c
!c Current Code Owner: 
!c   sugiyama@gfd-dennou.org
!c
!c Copyright (C) SUGIYAMA Ko-ichiro, 2004, All rights reserved

subroutine ThetaEular(fs_VelX_B, sf_VelZ_B, ss_Theta_B, ss_Theta_A)

  !--- モジュールの読み込み
  use gridset,  only: DimXMin, DimXMax, DimZMin, DimZMax
  use bcset,    only: ss_Bc
  use timeset,  only: DelTLong
  use if_avr,   only: ss_avr_fs, ss_avr_sf
  use if_diff,  only: ss_dx_ss, ss_dz_ss
  use if_boundary
  
  !--- 暗黙の型宣言禁止
  implicit none
  
  !--- 入出力変数
  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(in)     :: ss_Theta_B(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8), intent(out)    :: ss_Theta_A(DimXMin:DimXMax, DimZMin:DimZMax)

  !--- 内部変数
  real(8)       :: ss_AdvTheta_B(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8)       :: ss_DiffuseTheta_B(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8)       :: ss_Km_B(DimXMin:DimXMax, DimZMin:DimZMax)
  real(8)       :: ss_Kh_B(DimXMin:DimXMax, DimZMin:DimZMax)

  !--- 温位の移流
  ss_AdvTheta_B = &
       &   ss_avr_fs( fs_VelX_B ) * ss_dx_ss( ss_Theta_B ) &
       & + ss_avr_sf( sf_VelZ_B ) * ss_dz_ss( ss_Theta_B ) 
  
  !--- 渦粘性係数, 乱流混合距離を決める
  call TurbStab(fs_VelX_B, sf_VelZ_B, ss_Km_B)
  
  !--- 渦拡散係数を決める
  ss_Kh_B = 3.0d0 * ss_Km_B 

  !--- 温位の拡散
  ss_DiffuseTheta_B = &
       & - ss_dx_ss( ss_Kh_B * ss_dx_ss( ss_Theta_B ) ) &
       & - ss_dz_ss( ss_Kh_B * ss_dz_ss( ss_Theta_B ) ) 

  !--- 温位の拡散 (拡散なし)
  ss_DiffuseTheta_B = 0.0d0
  
  !--- 温位の積分
  ss_Theta_A = &
       & ss_Theta_B &
       &  + DelTLong * ( - ss_AdvTheta_B + ss_DiffuseTheta_B )
  
  !--- 境界条件
  call boundary(ss_Bc, ss_Theta_A)
  
end subroutine ThetaEular

  
