massless_merge_fields Subroutine

public pure subroutine massless_merge_fields(h, kc, nz, nzc, u, v, t, s, uc, vc, tc, sc)

Thickness-weighted merged means for u, v, T, S — the solver receives MEANS, not integrals, and must not re-divide. Accumulation runs in the same surface-down k order as massless_build_maps so the column-integral conservation holds to round-off.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: h(NZL)
integer, intent(in) :: kc(NZLI)
integer, intent(in) :: nz
integer, intent(in) :: nzc
real(kind=wp), intent(in) :: u(NZL)
real(kind=wp), intent(in) :: v(NZL)
real(kind=wp), intent(in) :: t(NZL)
real(kind=wp), intent(in) :: s(NZL)
real(kind=wp), intent(out) :: uc(NZL)
real(kind=wp), intent(out) :: vc(NZL)
real(kind=wp), intent(out) :: tc(NZL)
real(kind=wp), intent(out) :: sc(NZL)

Called by

proc~~massless_merge_fields~~CalledByGraph proc~massless_merge_fields massless_merge_fields proc~kappa_shear_column_kernel kappa_shear_column_kernel proc~kappa_shear_column_kernel->proc~massless_merge_fields proc~kappa_shear_vertex_kernel kappa_shear_vertex_kernel proc~kappa_shear_vertex_kernel->proc~massless_merge_fields proc~kappa_shear_compute kappa_shear_compute proc~kappa_shear_compute->proc~kappa_shear_column_kernel proc~kappa_shear_compute->proc~kappa_shear_vertex_kernel proc~vmix_apply_in_stage vmix_apply_in_stage proc~vmix_apply_in_stage->proc~kappa_shear_compute proc~run_stage run_stage proc~run_stage->proc~vmix_apply_in_stage proc~run_stage_split run_stage_split proc~run_stage_split->proc~vmix_apply_in_stage proc~ocean_dyn_step ocean_dyn_step proc~ocean_dyn_step->proc~run_stage proc~ocean_dyn_step_split ocean_dyn_step_split proc~ocean_dyn_step_split->proc~run_stage_split

Variables

Type Visibility Attributes Name Initial
real(kind=wp), private :: denom
real(kind=wp), private :: hc_acc(NZL)
integer, private :: k
integer, private :: kk

Source Code

   pure subroutine massless_merge_fields(h, kc, nz, nzc, &
                                         u, v, t, s, uc, vc, tc, sc)
      !! Thickness-weighted merged means for u, v, T, S — the solver receives
      !! MEANS, not integrals, and must not re-divide. Accumulation runs in the
      !! same surface-down `k` order as `massless_build_maps` so the
      !! column-integral conservation holds to round-off.
      !$acc routine seq
      integer, intent(in) :: nz, nzc
      real(wp), intent(in) :: h(NZL)
      integer, intent(in) :: kc(NZLI)
      real(wp), intent(in) :: u(NZL), v(NZL), t(NZL), s(NZL)
      real(wp), intent(out) :: uc(NZL), vc(NZL), tc(NZL), sc(NZL)

      integer :: k, kk
      real(wp) :: hc_acc(NZL)
      real(wp) :: denom

      do kk = 1, nzc
         hc_acc(kk) = 0.0_wp
         uc(kk) = 0.0_wp
         vc(kk) = 0.0_wp
         tc(kk) = 0.0_wp
         sc(kk) = 0.0_wp
      end do

      do k = 1, nz
         kk = kc(k)
         hc_acc(kk) = hc_acc(kk) + h(k)
         uc(kk) = uc(kk) + u(k)*h(k)
         vc(kk) = vc(kk) + v(k)*h(k)
         tc(kk) = tc(kk) + t(k)*h(k)
         sc(kk) = sc(kk) + s(k)*h(k)
      end do

      ! Finalise means.  hc_acc(kk) > 0 for every kk (a cluster opens only
      ! on a massive layer or holds an absorbed leading run + its first
      ! massive layer), so H_DIV_EPS is armour, not a clamp.
      do kk = 1, nzc
         denom = max(hc_acc(kk), H_DIV_EPS)
         uc(kk) = uc(kk)/denom
         vc(kk) = vc(kk)/denom
         tc(kk) = tc(kk)/denom
         sc(kk) = sc(kk)/denom
      end do
   end subroutine massless_merge_fields