pure function corner_abs_vort(ic, jc, k, nx, ny, nz, q_val, h, wet_T, areaT, &
use_mom6_ch) result(av)
!$acc routine seq
!! BOUND_CORIOLIS abs_vort recovery: return `(f+ζ)` at corner `(ic,jc)`
!! by multiplying the PV `q_val` back by the corner thickness Pass 2
!! divided abs_vort by — recovering `(f+ζ)` to round-off. Recomputes
!! the SAME wet-area-weighted 4-cell `hm_num`/`hm_den`, then reconstructs
!! the effective corner thickness with the SAME formula (and floors) the
!! active `corner_h` variant used in Pass 2:
!! `cell_mean` (default): h_corner = max(hm_num/max(hm_den,H_DIV_EPS),
!! CORIOLIS_H_MIN_PV); av = q·h_corner.
!! `mom6_area` (`use_mom6_ch`): Pass 2 formed q = abs_vort·hm_den/
!! (hm_num + PV_VOL_NEGLECT), so the consistent inverse is
!! av = q·(hm_num + PV_VOL_NEGLECT)/hm_den (hm_den guarded by
!! H_DIV_EPS for the fully-land corner, where q≡0 ⇒ av≡0 anyway).
!! Without matching the variant the recovered abs_vort would be slightly
!! inconsistent with how q was made whenever BOTH bound_coriolis and
!! corner_h="mom6_area" are on — visible only in the truly-vanishing-
!! thickness limit. Chosen over a persistent abs_vort buffer so the
!! default-off knob costs ZERO memory.
integer, intent(in) :: ic, jc, k, nx, ny, nz
real(wp), intent(in) :: q_val
real(wp), intent(in) :: h(nx, ny, nz)
real(wp), intent(in) :: wet_T(nx, ny), areaT(nx, ny)
logical, intent(in) :: use_mom6_ch
real(wp) :: av
integer :: iw, ie, js, jn
real(wp) :: aSW, aSE, aNW, aNE, hm_num, hm_den, h_corner
iw = max(1, ic - 1)
ie = min(nx, ic)
js = max(1, jc - 1)
jn = min(ny, jc)
aSW = wet_T(iw, js)*areaT(iw, js)
aSE = wet_T(ie, js)*areaT(ie, js)
aNW = wet_T(iw, jn)*areaT(iw, jn)
aNE = wet_T(ie, jn)*areaT(ie, jn)
hm_num = aSW*h(iw, js, k) + aSE*h(ie, js, k) + &
aNW*h(iw, jn, k) + aNE*h(ie, jn, k)
hm_den = aSW + aSE + aNW + aNE
if (use_mom6_ch) then
! Algebraic inverse of Pass 2's mom6_area form (no thickness cap;
! PV_VOL_NEGLECT is the same 1/0 armor Pass 2 added to hm_num).
h_corner = (hm_num + PV_VOL_NEGLECT)/max(hm_den, H_DIV_EPS)
else
h_corner = hm_num/max(hm_den, H_DIV_EPS)
h_corner = max(h_corner, CORIOLIS_H_MIN_PV)
end if
av = q_val*h_corner
end function corner_abs_vort