module topbc
use types,only:rprec
use param,only:nz
implicit none
real(kind=rprec),dimension(nz)::sponge

contains
subroutine setsponge()
use param,only:u_star,z_i
implicit none
real(kind=rprec)::factor
integer::k
! sets relaxation term to vertical momentum equation in top quarter
! of domain, relaxation timescale on top is 50s with a factor of 5 if we
! had Nz=40 for the layers 40...31, Nieuwstadt et al. 1991, turbulent shear 
! flows

sponge=0._rprec
factor=9._rprec/dble(nz-3*nz/4+1)
sponge(nz)=z_i/(50._rprec*u_star)
do k=nz-1,3*nz/4+1,-1
   sponge(k)=sponge(k+1)/5._rprec**factor
end do
end subroutine setsponge
end module topbc
