pure subroutine mask_time_mean_velocities(metrics, ms)
!! Apply the land contract of `mask_layer_velocities` — static
!! `wet_u`/`wet_v`, times the z-level `open_u`/`open_v` when
!! `zfixed_closed_faces` is on — to the `pred_corr` time-mean
!! velocities `u_av`/`v_av`. Called once, on the step-0 seed: the
!! renormaliser's `u_cor`, their only other writer, never writes a
!! masked face, so what the seed leaves there is what every later
!! step reads. (Wet/dry is refused under `pred_corr`, so its
!! dynamic mask has no branch here.) All-wet, knob off ⇒ products
!! with exactly 1, i.e. byte-identical.
type(ocean_metrics_t), intent(in) :: metrics
type(multilayer_state_t), intent(inout) :: ms
integer :: i, j, k, nz, nx_face, ny_uface, nx_vface, ny_face
nz = ms%nz_ml
nx_face = size(ms%u_av_layer, 1)
ny_uface = size(ms%u_av_layer, 2)
nx_vface = size(ms%v_av_layer, 1)
ny_face = size(ms%v_av_layer, 2)
do concurrent(k=1:nz, j=1:ny_uface, i=1:nx_face)
ms%u_av_layer(i, j, k) = metrics%wet_u(i, j)*ms%u_av_layer(i, j, k)
end do
do concurrent(k=1:nz, j=1:ny_face, i=1:nx_vface)
ms%v_av_layer(i, j, k) = metrics%wet_v(i, j)*ms%v_av_layer(i, j, k)
end do
if (metrics%use_closed_faces) then
do concurrent(k=1:nz, j=1:ny_uface, i=1:nx_face)
ms%u_av_layer(i, j, k) = metrics%open_u(i, j, k)*ms%u_av_layer(i, j, k)
end do
do concurrent(k=1:nz, j=1:ny_face, i=1:nx_vface)
ms%v_av_layer(i, j, k) = metrics%open_v(i, j, k)*ms%v_av_layer(i, j, k)
end do
end if
end subroutine mask_time_mean_velocities