subroutine accel_visc_rem_reweight(n1, n2, n3, snap, rem, vel)
!! accel_visc_rem post-apply reweight:
!! `vel = snap + rem·(vel − snap)` — the whole explicit-tendency
!! sum accumulated since the snapshot is attenuated by the
!! per-layer viscous remnant (linearity ⇒ identical to weighting
!! each tendency individually, MOM6 `u = u_init + dt·visc_rem·
!! (CAu + PFu + diffu)`). Faces with `rem == 1` (the unconditioned
!! `source=1.0` init, and every face before the first vdiff fills
!! the producer) are SKIPPED, not rewritten — `snap + 1·(vel−snap)`
!! is not an FP identity, and the skip keeps rem≡1 bitwise inert.
!! Friction-dominated near-massless layers (`rem → 0`) keep their
!! entry velocity. Public only for the unit-test suite. Under
!! `mem:separate` this `do concurrent` runs on the device-resident
!! arrays in production (all mapped on the ocean state); unit tests
!! must map their own arrays explicitly. The masked write stays
!! inside the `do concurrent` body (legal — no cross-iteration dep).
integer, intent(in) :: n1, n2, n3
real(wp), intent(in) :: snap(n1, n2, n3)
real(wp), intent(in) :: rem(n1, n2, n3)
real(wp), intent(inout) :: vel(n1, n2, n3)
integer :: i, j, k
do concurrent(k=1:n3, j=1:n2, i=1:n1)
if (rem(i, j, k) /= 1.0_wp) then
vel(i, j, k) = snap(i, j, k) &
+ rem(i, j, k)*(vel(i, j, k) - snap(i, j, k))
end if
end do
end subroutine accel_visc_rem_reweight