!= Module DynFunc_3D
!
! Authors::   SUGIYAMA Ko-ichiro, ODAKA Masatsugu
! Version::   $Id: dynfunc_3d.f90,v 1.5 2008-06-26 09:24:27 odakker2 Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2007. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]
!
!== Overview
!
!繝｢繝�Ν縺ｮ蜉帛ｭｦ驕守ｨ九ｒ險育ｮ励☆繧九◆繧√↓蠢�ｦ√→縺ｪ繧矩未謨ｰ鄒､繧呈據縺ｭ縺溘Δ繧ｸ繝･繝ｼ繝ｫ
!蜈ｷ菴鍋噪縺ｫ縺ｯ莉･荳九�鬆�ｒ險育ｮ励☆繧九◆繧√�髢｢謨ｰ繧呈�ｼ邏阪☆繧�.
!  * 遘ｻ豬���
!  * 豬ｮ蜉幃��
!  * 豌怜悸蛯ｾ蠎ｦ蜉幃��
!
!== Error Handling
!
!== Known Bugs
!
!== Note
!
!  * 繧ｨ繧ｯ繧ｹ繝翫�髢｢謨ｰ縺ｮ遨ｺ髢捺婿蜷代�髮｢謨｣蛹悶↓縺翫＞縺ｦ, 2 谺｡邊ｾ蠎ｦ縺ｮ髮｢謨｣蛹悶ｒ髯ｽ縺ｫ蛻ｩ逕ｨ縺励※縺�ｋ縺溘ａ,
!    豌怜悸蛯ｾ蠎ｦ蜉幃���險育ｮ励�繝ｭ繧ｰ繝ｩ繝�縺ｫ縺翫＞縺ｦ differentiate_center4 繝｢繧ｸ繝･繝ｼ繝ｫ繧呈欠螳壹☆繧�
!    縺薙→縺ｯ縺ｧ縺阪↑縺��縺ｧ豕ｨ諢�.
!
!== Future Plans
!

module DynFunc_3d
  !
  !髯ｽ髢区叛繧堤畑縺�◆蜉帛ｭｦ驕守ｨ九�蜷����險育ｮ励Δ繧ｸ繝･繝ｼ繝ｫ.
  !蜈ｷ菴鍋噪縺ｫ縺ｯ莉･荳九�鬆�ｒ險育ｮ励☆繧九◆繧√�髢｢謨ｰ繧呈�ｼ邏阪☆繧�.
  !  * 遘ｻ豬���
  !  * 豬ｮ蜉幃��
  !  * 豌怜悸蛯ｾ蠎ｦ蜉幃��
  !

  !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
  use dc_types, only: DP

  use gridset, only:  DimXMin,           &! x 譁ｹ蜷代�驟榊�縺ｮ荳矩剞
    &                 DimXMax,           &! x 譁ｹ蜷代�驟榊�縺ｮ荳企剞
    &                 DimYMin,           &! y 譁ｹ蜷代�驟榊�縺ｮ荳矩剞
    &                 DimYMax,           &! y 譁ｹ蜷代�驟榊�縺ｮ荳企剞
    &                 DimZMin,           &! z 譁ｹ蜷代�驟榊�縺ｮ荳矩剞
    &                 DimZMax,           &! z 譁ｹ蜷代�驟榊�縺ｮ荳企剞
    &                 SpcNum              !
  use damping_3d_v2,  only: DampSound           !髻ｳ豕｢縺ｮ貂幄｡ｰ菫よ焚
  use basicset_3d, only: xyz_EffMolWtBasicZ, &
    &                    xyz_PotTempBasicZ   !蝓ｺ譛ｬ蝣ｴ縺ｮ貂ｩ菴�
  use constants, only: CpDry,             &!荵ｾ辯･謌仙�縺ｮ豈皮�
    &                  Grav                !驥榊鴨蜉�騾溷ｺｦ
  use xyz_base_module, only: &
    &                xyz_avr_pyz, xyr_avr_pyr, xqz_avr_pqz, &
    &                pyz_avr_xyz, pyr_avr_xyr, pqz_avr_xqz, &
    &                xyz_avr_xqz, pyz_avr_pqz, xyr_avr_xqr, &
    &                xqz_avr_xyz, pqz_avr_pyz, xqr_avr_xyr, &
    &                xyz_avr_xyr, pyz_avr_pyr, xqz_avr_xqr, &
    &                xyr_avr_xyz, pyr_avr_pyz, xqr_avr_xqz
!  use StorePotTemp_3d,  only: StorePotTempAdv
!  use StoreMixRt_3d,    only: StoreMixRtAdv

  !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
  implicit none

  !螻樊ｧ縺ｮ謖�ｮ�
  private

  !遘ｻ豬���ｨ育ｮ励�縺溘ａ縺ｮ髢｢謨ｰ繧� public 縺ｫ縺吶ｋ
  public xyz_AdvScalar
  public xyz_AdvKm
  public xyza_AdvScalar
  public pyz_AdvVelX
  public xqz_AdvVelY
  public xyr_AdvVelZ

  !豬ｮ蜉幃��ｨ育ｮ励�縺溘ａ縺ｮ髢｢謨ｰ繧� public 縺ｫ縺吶ｋ
  public xyr_Buoy

  !豌怜悸蛯ｾ蠎ｦ蜉帙�險育ｮ励�縺溘ａ縺ｮ髢｢謨ｰ繧� public 縺ｫ縺吶ｋ
  public pyz_GradPi
  public xqz_GradPi

contains

!!!------------------------------------------------------------------------!!!
  function xyz_AdvScalar(xyz_Var, pyz_VelX, xqz_VelY, xyr_VelZ)
    !
    ! x, z 譁ｹ蜷代↓蜊頑�ｼ蟄舌★繧後◆轤ｹ縺ｫ縺翫￠繧狗ｧｻ豬√ｒ險育ｮ�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use xyz_deriv_c4_module, only: pyz_dx_xyz, xqz_dy_xyz, xyr_dz_xyz

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: pyz_VelX &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xqz_VelY &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xyr_VelZ &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !驩帷峩鬚ｨ騾�
    real(DP), intent(in) :: xyz_Var &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !繧ｹ繧ｫ繝ｩ繝ｼ驥�
    real(DP)             :: xyz_AdvScalar &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !繧ｹ繧ｫ繝ｩ繝ｼ驥上�豌ｴ蟷ｳ遘ｻ豬�

    xyz_AdvScalar =                                    &
      & - xyz_avr_pyz(pyz_VelX * pyz_dx_xyz(xyz_Var))  &
      & - xyz_avr_xqz(xqz_VelY * xqz_dy_xyz(xyz_Var))  &
      & - xyz_avr_xyr(xyr_VelZ * xyr_dz_xyz(xyz_Var))

!    call StorePotTempAdv( xyz_AdvScalar )

  end function xyz_AdvScalar

!!!------------------------------------------------------------------------!!!
  function xyz_AdvKm(xyz_Var, pyz_VelX, xqz_VelY, xyr_VelZ)
    !
    ! x, z 譁ｹ蜷代↓蜊頑�ｼ蟄舌★繧後◆轤ｹ縺ｫ縺翫￠繧狗ｧｻ豬√ｒ險育ｮ�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use xyz_deriv_c4_module, only: pyz_dx_xyz, xqz_dy_xyz, xyr_dz_xyz

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: pyz_VelX &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xqz_VelY &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xyr_VelZ &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !驩帷峩鬚ｨ騾�
    real(DP), intent(in) :: xyz_Var &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !繧ｹ繧ｫ繝ｩ繝ｼ驥�
    real(DP)             :: xyz_AdvKm &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !繧ｹ繧ｫ繝ｩ繝ｼ驥上�豌ｴ蟷ｳ遘ｻ豬�

    xyz_AdvKm =                               &
      & - xyz_avr_pyz(pyz_VelX * pyz_dx_xyz(xyz_Var))  &
      & - xyz_avr_xqz(xqz_VelY * xqz_dy_xyz(xyz_Var))  &
      & - xyz_avr_xyr(xyr_VelZ * xyr_dz_xyz(xyz_Var))

  end function xyz_AdvKm

!!!------------------------------------------------------------------------!!!
  function xyza_AdvScalar(xyza_Var, pyz_VelX, xqz_VelY, xyr_VelZ)
    !
    ! x, z 譁ｹ蜷代↓蜊頑�ｼ蟄舌★繧後◆轤ｹ縺ｫ縺翫￠繧狗ｧｻ豬√ｒ險育ｮ�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use xyz_deriv_c4_module, only: pyz_dx_xyz, xqz_dy_xyz, xyr_dz_xyz
!    use xyz_deriv_module, only: pyz_dx_xyz, xqz_dy_xyz, xyr_dz_xyz

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: pyz_VelX &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xqz_VelY &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xyr_VelZ &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !驩帷峩鬚ｨ騾�
    real(DP), intent(in) :: xyza_Var &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax,SpcNum)
                                                        !繧ｹ繧ｫ繝ｩ繝ｼ驥�
    real(DP)             :: xyza_AdvScalar &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax,SpcNum)
                                                        !繧ｹ繧ｫ繝ｩ繝ｼ驥上�豌ｴ蟷ｳ遘ｻ豬�
    integer :: s ! 繝ｫ繝ｼ繝怜､画焚

    do s = 1, SpcNum
      xyza_AdvScalar(:,:,:,s) =                                  &
        & - xyz_avr_pyz(pyz_VelX * pyz_dx_xyz(xyza_Var(:,:,:,s))) &
        & - xyz_avr_xqz(xqz_VelY * xqz_dy_xyz(xyza_Var(:,:,:,s))) &
        & - xyz_avr_xyr(xyr_VelZ * xyr_dz_xyz(xyza_Var(:,:,:,s)))
    end do

!    call StoreMixRtAdv( xyza_AdvScalar )

  end function xyza_AdvScalar
!!!------------------------------------------------------------------------!!!
  function pyz_AdvVelX(pyz_VelX, xqz_VelY, xyr_VelZ)
    !
    ! z 譁ｹ蜷代↓蜊頑�ｼ蟄舌★繧後◆轤ｹ縺ｫ縺翫￠繧狗ｧｻ豬√ｒ險育ｮ�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use xyz_deriv_c4_module, only: xyz_dx_pyz, pqz_dy_pyz, pyr_dz_pyz

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: pyz_VelX &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xqz_VelY &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xyr_VelZ &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !驩帷峩鬚ｨ騾�
    real(DP)             :: pyz_AdvVelX(DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ縺ｮ遘ｻ豬�

!    pz_AdvVelX = 0.0d0  !蛻晄悄蛹�

    pyz_AdvVelX =                                                 &
      & - pyz_VelX * pyz_avr_xyz( xyz_dx_pyz( pyz_VelX ) )        &
      & - pyz_avr_pqz( pqz_avr_xqz( xqz_VelY ) * pqz_dy_pyz( pyz_VelX ) ) &
      & - pyz_avr_pyr( pyr_avr_xyr( xyr_VelZ ) * pyr_dz_pyz( pyz_VelX ) )

  end function pyz_AdvVelX

!!!------------------------------------------------------------------------!!!
  function xyr_AdvVelZ(pyz_VelX, xqz_VelY, xyr_VelZ)
    !
    ! x 譁ｹ蜷代↓蜊頑�ｼ蟄舌★繧後◆轤ｹ縺ｫ縺翫￠繧狗ｧｻ豬√ｒ險育ｮ�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use xyz_deriv_c4_module, only: pyr_dx_xyr, xqr_dy_xyr, xyz_dz_xyr

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: pyz_VelX &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xqz_VelY &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xyr_VelZ &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !驩帷峩鬚ｨ騾�
    real(DP)             :: xyr_AdvVelZ &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !驩帷峩鬚ｨ縺ｮ遘ｻ豬�

!    xr_AdvVelZ = 0.0d0  !蛻晄悄蛹�
    xyr_AdvVelZ =                                                 &
      & - xyr_avr_pyr( pyr_avr_pyz( pyz_VelX ) * pyr_dx_xyr( xyr_VelZ ) ) &
      & - xyr_avr_xqr( xqr_avr_xqz( xqz_VelY ) * xqr_dy_xyr( xyr_VelZ ) ) &
      & - xyr_VelZ * xyr_avr_xyz( xyz_dz_xyr( xyr_VelZ ) )

  end function xyr_AdvVelZ

!!!------------------------------------------------------------------------!!!
  function xqz_AdvVelY(pyz_VelX, xqz_VelY, xyr_VelZ)
    !
    ! x 譁ｹ蜷代↓蜊頑�ｼ蟄舌★繧後◆轤ｹ縺ｫ縺翫￠繧狗ｧｻ豬√ｒ險育ｮ�
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ
    use xyz_deriv_c4_module, only: pqz_dx_xqz, xyz_dy_xqz, xqr_dz_xqz

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: pyz_VelX &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xqz_VelY &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !豌ｴ蟷ｳ鬚ｨ騾�
    real(DP), intent(in) :: xyr_VelZ &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !驩帷峩鬚ｨ騾�
    real(DP)             :: xqz_AdvVelY &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                                        !驩帷峩鬚ｨ縺ｮ遘ｻ豬�

!    xr_AdvVelZ = 0.0d0  !蛻晄悄蛹�
    xqz_AdvVelY =                                                 &
      & - xqz_avr_pqz( pqz_avr_pyz( pyz_VelX ) * pqz_dx_xqz( xqz_VelY ) ) &
      & - xqz_VelY * xqz_avr_xyz( xyz_dy_xqz( xqz_VelY ) ) &
      & - xqz_avr_xqr( xqr_avr_xyr( xyr_VelZ ) * xqr_dz_xqz( xqz_VelY ) )

  end function xqz_AdvVelY

!!!------------------------------------------------------------------------!!!
  function xyr_Buoy(xyz_PotTemp)
    !
    ! 驩帷峩譁ｹ蜷代�驕句虚譁ｹ遞句ｼ上↓迴ｾ繧後ｋ豬ｮ蜉幃��ｒ險育ｮ�

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in)  :: xyz_PotTemp(DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !貂ｩ菴肴得荵ｱ
    real(DP)              :: xyr_Buoy &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !豬ｮ蜉幃��

!    !蛻晄悄蛹�
!    xr_Buoy = 0.0d0

    !豬ｮ蜉幃���險育ｮ�
    xyr_Buoy = Grav * xyr_avr_xyz(xyz_PotTemp / xyz_PotTempBasicZ)

  end function xyr_Buoy

!!!------------------------------------------------------------------------!!!
  function pyz_GradPi(xyz_Exner, pyz_VelX, xqz_VelY, xyr_VelZ)
    !
    ! z 譁ｹ蜷代↓蜊頑�ｼ蟄舌★繧後◆轤ｹ縺ｧ縺ｮ蝨ｧ蜉帛だ蠎ｦ蜉幃���險育ｮ�.
    ! 髻ｳ豕｢貂幄｡ｰ鬆�ｒ蜷ｫ繧√◆蠖｢蠑上〒螳壼ｼ丞喧縺励※縺ゅｋ縺薙→縺ｫ豕ｨ諢�.
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ

    use xyz_deriv_module, only: xyz_dx_pyz, xyz_dy_xqz, xyz_dz_xyr, pyz_dx_xyz

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in) :: xyz_Exner &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !繧ｨ繧ｯ繧ｹ繝翫�髢｢謨ｰ縺ｮ謫ｾ荵ｱ
    real(DP), intent(in) :: pyz_VelX &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !豌ｴ蟷ｳ騾溷ｺｦ
    real(DP), intent(in) :: xqz_VelY &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !豌ｴ蟷ｳ騾溷ｺｦ
    real(DP), intent(in) :: xyr_VelZ &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !驩帷峩騾溷ｺｦ
    real(DP)             :: pyz_GradPi &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !蝨ｧ蜉帛だ蠎ｦ蜉�
    real(DP)             :: xyz_DivVel &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !騾溷ｺｦ縺ｮ蜿取據

    !騾溷ｺｦ縺ｮ蜿取據
    xyz_DivVel = xyz_dx_pyz( pyz_VelX ) + xyz_dy_xqz( xqz_VelY ) &
      &          + xyz_dz_xyr( xyr_VelZ )

    !蝨ｧ蜉帛だ蠎ｦ
!    pyz_GradPi = 0.0d0
    pyz_GradPi =  &
      & + pyz_avr_xyz( CpDry * xyz_PotTempBasicZ / xyz_EffMolWtBasicZ )    &
      &   * pyz_dx_xyz( xyz_Exner ) &
      & - pyz_dx_xyz( DampSound * xyz_DivVel )

  end function pyz_GradPi

!!!------------------------------------------------------------------------!!!
  function xqz_GradPi(xyz_Exner, pyz_VelX, xqz_VelY, xyr_VelZ)
    !
    ! y 譁ｹ蜷代↓蜊頑�ｼ蟄舌★繧後◆轤ｹ縺ｧ縺ｮ蝨ｧ蜉帛だ蠎ｦ蜉幃���險育ｮ�.
    ! 髻ｳ豕｢貂幄｡ｰ鬆�ｒ蜷ｫ繧√◆蠖｢蠑上〒螳壼ｼ丞喧縺励※縺ゅｋ縺薙→縺ｫ豕ｨ諢�.
    !

    !繝｢繧ｸ繝･繝ｼ繝ｫ隱ｭ縺ｿ霎ｼ縺ｿ

    use xyz_deriv_module, only: xyz_dx_pyz, xyz_dy_xqz, xyz_dz_xyr, xqz_dy_xyz

    !證鈴ｻ吶�蝙句ｮ｣險遖∵ｭ｢
    implicit none

    !螟画焚螳夂ｾｩ
    real(DP), intent(in)  :: xyz_Exner &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !繧ｨ繧ｯ繧ｹ繝翫�髢｢謨ｰ縺ｮ謫ｾ荵ｱ
    real(DP), intent(in)  :: pyz_VelX &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !豌ｴ蟷ｳ騾溷ｺｦ
    real(DP), intent(in)  :: xqz_VelY &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !豌ｴ蟷ｳ騾溷ｺｦ
    real(DP), intent(in)  :: xyr_VelZ &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !驩帷峩騾溷ｺｦ
    real(DP)              :: xqz_GradPi &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !蝨ｧ蜉帛だ蠎ｦ蜉�
    real(DP)              :: xyz_DivVel &
      &                    (DimXMin:DimXMax,DimYMin:DimYMax,DimZMin:DimZMax)
                                               !騾溷ｺｦ縺ｮ蜿取據

    !騾溷ｺｦ縺ｮ蜿取據
    xyz_DivVel = xyz_dx_pyz( pyz_VelX ) + xyz_dy_xqz( xqz_VelY ) &
      &          + xyz_dz_xyr( xyr_VelZ )

    !蝨ｧ蜉帛だ蠎ｦ
!    xqz_GradPi = 0.0d0
    xqz_GradPi =  &
      & + xqz_avr_xyz( CpDry * xyz_PotTempBasicZ / xyz_EffMolWtBasicZ )    &
      &   * xqz_dy_xyz( xyz_Exner )               &
      & - xqz_dy_xyz( DampSound * xyz_DivVel )

  end function xqz_GradPi

end module DynFunc_3d