Build the thickness-derived interface grids that the iteration reuses: 1/h, the interface 1/dz, the harmonic-mean interface FV cell thicknesses h_Int (Sum h_Int = Sum h), and the inverse boundary length scale squared (design doc section 5.1).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | nz | |||
| real(kind=wp), | intent(in) | :: | lz_rescale | |||
| real(kind=wp), | intent(in) | :: | h_sd(NZL) | |||
| real(kind=wp), | intent(out) | :: | idz_o(NZL) | |||
| real(kind=wp), | intent(out) | :: | idz_int_o(NZLI) | |||
| real(kind=wp), | intent(out) | :: | hint_o(NZLI) | |||
| real(kind=wp), | intent(out) | :: | il2_o(NZLI) |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| real(kind=wp), | private | :: | dbot(NZLI) | ||||
| real(kind=wp), | private | :: | dtop | ||||
| real(kind=wp), | private | :: | hk | ||||
| real(kind=wp), | private | :: | hkm1 | ||||
| real(kind=wp), | private | :: | hkp1 | ||||
| real(kind=wp), | private | :: | i_lz2 | ||||
| integer, | private | :: | k | ||||
| real(kind=wp), | private | :: | norm_l | ||||
| real(kind=wp), | private | :: | wt_a | ||||
| real(kind=wp), | private | :: | wt_b |
pure subroutine ks_precompute(nz, lz_rescale, h_sd, & idz_o, idz_int_o, hint_o, il2_o) !! Build the thickness-derived interface grids that the iteration !! reuses: 1/h, the interface 1/dz, the harmonic-mean interface FV !! cell thicknesses h_Int (Sum h_Int = Sum h), and the inverse !! boundary length scale squared (design doc section 5.1). !$acc routine seq integer, intent(in) :: nz real(wp), intent(in) :: lz_rescale real(wp), intent(in) :: h_sd(NZL) real(wp), intent(out) :: idz_o(NZL), idz_int_o(NZLI) real(wp), intent(out) :: hint_o(NZLI), il2_o(NZLI) integer :: k real(wp) :: hk, hkm1, hkp1, norm_l, wt_a, wt_b, i_lz2, dtop real(wp) :: dbot(NZLI) i_lz2 = 1.0_wp/(lz_rescale*lz_rescale) do k = 1, nz idz_o(k) = 1.0_wp/h_sd(k) end do idz_int_o(1) = 2.0_wp/h_sd(1) do k = 2, nz idz_int_o(k) = 2.0_wp/(h_sd(k - 1) + h_sd(k)) end do idz_int_o(nz + 1) = 2.0_wp/h_sd(nz) hint_o(1) = 0.0_wp if (nz >= 2) then hint_o(2) = h_sd(1) do k = 2, nz - 1 hk = h_sd(k) hkm1 = h_sd(k - 1) hkp1 = h_sd(k + 1) norm_l = 1.0_wp/(hk*(hkm1 + hkp1) + 2.0_wp*hkm1*hkp1) wt_a = (hk + hkp1)*hkm1*norm_l wt_b = (hkm1 + hk)*hkp1*norm_l hint_o(k) = hint_o(k) + hk*wt_a hint_o(k + 1) = hk*wt_b end do hint_o(nz) = hint_o(nz) + h_sd(nz) end if hint_o(nz + 1) = 0.0_wp dbot(nz + 1) = 0.0_wp do k = nz, 1, -1 dbot(k) = dbot(k + 1) + h_sd(k) end do il2_o(1) = 0.0_wp il2_o(nz + 1) = 0.0_wp dtop = 0.0_wp do k = 2, nz dtop = dtop + h_sd(k - 1) if (dtop > 0.0_wp .and. dbot(k) > 0.0_wp) then il2_o(k) = i_lz2*(dtop + dbot(k))**2/((dtop*dbot(k))**2) else il2_o(k) = 0.0_wp end if end do end subroutine ks_precompute