pure subroutine fill_tracer_ghosts_meridional(hTr, h_layer, v_layer, &
nx_total, ny_total, nz, &
i_w, i_e, j_s, j_n, nghost, &
bc_s, bc_n, &
clamped_tr_s, clamped_tr_n)
!! Upwind-aware tracer ghost fill for south and north open edges.
integer, intent(in) :: nx_total, ny_total, nz, nghost
real(wp), intent(inout) :: hTr(nx_total, ny_total, nz)
real(wp), intent(in) :: h_layer(nx_total, ny_total, nz)
real(wp), intent(in) :: v_layer(nx_total, ny_total + 1, nz)
integer, intent(in) :: i_w, i_e, j_s, j_n
integer, intent(in) :: bc_s, bc_n
real(wp), intent(in) :: clamped_tr_s, clamped_tr_n
integer :: i, k, g
real(wp) :: hTr_bc, hTr_int
! South ghosts
if (is_open_ish(bc_s)) then
do concurrent(k=1:nz, i=i_w:i_e, g=1:nghost) local(hTr_bc, hTr_int)
! South inflow = v > 0 (northward into domain).
if (v_layer(i, j_s, k) > 0.0_wp) then
hTr_bc = clamped_tr_s*h_layer(i, g, k)
hTr(i, g, k) = hTr_bc
else
hTr_int = hTr(i, j_s, k)
hTr(i, g, k) = hTr_int
end if
end do
end if
! North ghosts
if (is_open_ish(bc_n)) then
do concurrent(k=1:nz, i=i_w:i_e, g=1:nghost) local(hTr_bc, hTr_int)
! North inflow = v < 0 (southward into domain from north).
if (v_layer(i, j_n + 1, k) < 0.0_wp) then
hTr_bc = clamped_tr_n*h_layer(i, ny_total - g + 1, k)
hTr(i, ny_total - g + 1, k) = hTr_bc
else
hTr_int = hTr(i, j_n, k)
hTr(i, ny_total - g + 1, k) = hTr_int
end if
end do
end if
end subroutine fill_tracer_ghosts_meridional