pure subroutine bt_rem_wave_drag_open_impl(nx, ny, nz, h_layer, open_u, open_v, &
lwd_u, lwd_v, dt_inner, bt_rem_u, bt_rem_v)
!! `compute_bt_rem_wave_drag` under `&vcoord_nml zfixed_closed_faces`:
!! MULTIPLIES `H/(H + r_H·dt_inner)` into `bt_rem` with the OPEN-column
!! face depth `H = Σ_k h_face·open` (the `bt_rem_open_impl` depth).
!! `H <= 0` (every layer closed) ⇒ unmodified, MOM6's guard.
integer, intent(in) :: nx, ny, nz
real(wp), intent(in) :: h_layer(nx, ny, nz)
real(wp), intent(in) :: open_u(nx + 1, ny, nz), open_v(nx, ny + 1, nz)
real(wp), intent(in) :: lwd_u(nx + 1, ny), lwd_v(nx, ny + 1)
real(wp), intent(in) :: dt_inner
real(wp), intent(inout) :: bt_rem_u(nx + 1, ny), bt_rem_v(nx, ny + 1)
integer :: i, j, k
real(wp) :: htot_face
do concurrent(j=1:ny, i=2:nx) local(k, htot_face)
htot_face = 0.0_wp
do k = 1, nz
htot_face = htot_face + &
0.5_wp*(h_layer(i - 1, j, k) + h_layer(i, j, k))*open_u(i, j, k)
end do
if (htot_face > 0.0_wp) then
bt_rem_u(i, j) = bt_rem_u(i, j)*(htot_face/(htot_face + lwd_u(i, j)*dt_inner))
end if
end do
do concurrent(j=2:ny, i=1:nx) local(k, htot_face)
htot_face = 0.0_wp
do k = 1, nz
htot_face = htot_face + &
0.5_wp*(h_layer(i, j - 1, k) + h_layer(i, j, k))*open_v(i, j, k)
end do
if (htot_face > 0.0_wp) then
bt_rem_v(i, j) = bt_rem_v(i, j)*(htot_face/(htot_face + lwd_v(i, j)*dt_inner))
end if
end do
end subroutine bt_rem_wave_drag_open_impl