pure subroutine remap_y_face_grounded(nx, ny, nz, h_old, h_new, mask, v_face_y)
!! Conservative north-face velocity remap, mirror of the x routine.
integer, intent(in) :: nx, ny, nz
real(wp), intent(in) :: h_old(nx, ny, nz)
real(wp), intent(in) :: h_new(nx, ny, nz)
real(wp), intent(in) :: mask(nx, ny, 1)
real(wp), intent(inout) :: v_face_y(nx, ny + 1, nz)
integer :: i, J, k
real(wp) :: h_old_face(NZ_STACK_MAX), h_new_face(NZ_STACK_MAX)
real(wp) :: v_old(NZ_STACK_MAX), v_new(NZ_STACK_MAX)
real(wp) :: hns, hnn
logical :: active, gs, gn
do concurrent(J=1:ny + 1, i=1:nx) &
local(k, h_old_face, h_new_face, v_old, v_new, active, gs, gn, hns, hnn)
gs = .false.
gn = .false.
if (J >= 2) gs = mask(i, J - 1, 1) > 0.5_wp
if (J <= ny) gn = mask(i, J, 1) > 0.5_wp
active = gs .or. gn
if (active) then
do k = 1, nz
if (J == 1) then
h_old_face(k) = h_old(i, 1, k)
h_new_face(k) = merge(h_new(i, 1, k), h_old(i, 1, k), gn)
else if (J == ny + 1) then
h_old_face(k) = h_old(i, ny, k)
h_new_face(k) = merge(h_new(i, ny, k), h_old(i, ny, k), gs)
else
h_old_face(k) = 0.5_wp*(h_old(i, J - 1, k) + h_old(i, J, k))
hns = merge(h_new(i, J - 1, k), h_old(i, J - 1, k), gs)
hnn = merge(h_new(i, J, k), h_old(i, J, k), gn)
h_new_face(k) = 0.5_wp*(hns + hnn)
end if
v_old(k) = v_face_y(i, J, k)
end do
call remap_column(REMAP_PPM, nz, h_old_face(1:nz), h_new_face(1:nz), &
v_old(1:nz), v_new(1:nz))
do k = 1, nz
v_face_y(i, J, k) = v_new(k)
end do
end if
end do
end subroutine remap_y_face_grounded