module boundary_condition
  use CalcParameter
  implicit none
contains
  
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  ! duとdTの境界
  subroutine uT_boundary(data,jmax)
    real(8), intent(inout) :: data(-1:,0:)
    integer, intent(in) :: jmax
    ! 水平境界条件
    data(-1,0:jmax)      = data(grd_x-1,0:jmax)
    data(0,0:jmax)       = data(grd_x,0:jmax)
    data(grd_x+1,0:jmax) = data(1,0:jmax)
    data(grd_x+2,0:jmax) = data(2,0:jmax)

    ! 鉛直境界条件
    !    data(-1:grd_x+2,0)      = data(-1:grd_x+2,1)
    data(-1:grd_x+2,0)      = dble(0)
!    data(-1:grd_x+2,jmax-1) = dble(0)
    data(-1:grd_x+2,jmax)   = dble(0)
    
  end subroutine uT_boundary

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
  
  ! dwの境界
  subroutine dw_boundary(data,jmax)
    real(8), intent(inout) :: data(-1:,0:)
    integer, intent(in) :: jmax
    ! 水平境界条件
    data(-1,0:jmax)      = data(grd_x-1,0:jmax)
    data(0,0:jmax)       = data(grd_x,0:jmax)
    data(grd_x+1,0:jmax) = data(1,0:jmax)
    data(grd_x+2,0:jmax) = data(2,0:jmax)

    ! 鉛直境界条件
    data(-1:grd_x+2,0)      = dble(0) 
!    data(-1:grd_x+2,1)      = dble(0)
    data(-1:grd_x+2,jmax-1) = dble(0)
    data(-1:grd_x+2,jmax)   = dble(0)

  end subroutine dw_boundary

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  ! rho,p,Tの境界条件
  subroutine p_boundary(data,jmax)
    real(8), intent(inout) :: data(-1:,0:)
    integer, intent(in) :: jmax
    ! 水平境界条件
    data(-1,0:jmax)      = data(grd_x-1,0:jmax)
    data(0,0:jmax)       = data(grd_x,0:jmax)
    data(grd_x+1,0:jmax) = data(1,0:jmax)
    data(grd_x+2,0:jmax) = data(2,0:jmax)
!   
    ! 鉛直境界条件
    data(-1:grd_x+2,0)    = data(-1:grd_x+2,1)
    data(-1:grd_x+2,jmax) = data(-1:grd_x+2,jmax-1)

  end subroutine p_boundary

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  ! 初期値生成のときに使う境界条件
  subroutine basic_boundary(data)
    real(8), intent(inout) :: data(0:)

    data(0)       = data(1)
    data(grd_z+1) = data(grd_z)

  end subroutine basic_boundary

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  
end module boundary_condition
