massless_build_maps Subroutine

public pure subroutine massless_build_maps(h, nz, h_min, nzc, hc, kc, kf)

Build the merged massive-layer grid and the maps kc, kf. kc(k) (k=1..nz) = merged-layer index original layer k folds into; kc(nz+1) = nzc+1 is the bed sentinel. kf(K) = fractional position of original interface K inside merged layer kc(K) (0 = coincides with a merged interface -> pure lookup; (0,1) = interior -> linear blend in massless_interp_back). Identity case (no layer < h_min): nzc==nz, kc(k)==k, kf(k)==0, hc==h bit-for-bit.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: h(NZL)

Local surface-down layer thicknesses (m), >= 0.

integer, intent(in) :: nz
real(kind=wp), intent(in) :: h_min

Merge threshold (H_VANISHED).

integer, intent(out) :: nzc

Number of merged massive layers (<= nz).

real(kind=wp), intent(out) :: hc(NZL)

Merged thicknesses (m), valid 1..nzc.

integer, intent(out) :: kc(NZLI)

Layer/interface -> merged index, valid 1..nz+1 (sentinel at nz+1).

real(kind=wp), intent(out) :: kf(NZLI)

Fractional interface weight, valid 1..nz+1.


Called by

proc~~massless_build_maps~~CalledByGraph proc~massless_build_maps massless_build_maps proc~kappa_shear_column_kernel kappa_shear_column_kernel proc~kappa_shear_column_kernel->proc~massless_build_maps proc~kappa_shear_vertex_kernel kappa_shear_vertex_kernel proc~kappa_shear_vertex_kernel->proc~massless_build_maps 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 :: dz_in
integer, private :: k

Source Code

   pure subroutine massless_build_maps(h, nz, h_min, nzc, hc, kc, kf)
      !! Build the merged massive-layer grid and the maps `kc`, `kf`.
      !! `kc(k)` (k=1..nz) = merged-layer index original layer `k` folds into;
      !! `kc(nz+1) = nzc+1` is the bed sentinel. `kf(K)` = fractional position
      !! of original interface `K` inside merged layer `kc(K)` (0 = coincides
      !! with a merged interface -> pure lookup; (0,1) = interior -> linear
      !! blend in `massless_interp_back`).
      !! Identity case (no layer < h_min): `nzc==nz`, `kc(k)==k`, `kf(k)==0`,
      !! `hc==h` bit-for-bit.
      !$acc routine seq
      integer, intent(in) :: nz
      real(wp), intent(in) :: h(NZL)
         !! Local surface-down layer thicknesses (m), >= 0.
      real(wp), intent(in) :: h_min
         !! Merge threshold (H_VANISHED).
      integer, intent(out) :: nzc
         !! Number of merged massive layers (<= nz).
      real(wp), intent(out) :: hc(NZL)
         !! Merged thicknesses (m), valid 1..nzc.
      integer, intent(out) :: kc(NZLI)
         !! Layer/interface -> merged index, valid 1..nz+1 (sentinel at nz+1).
      real(wp), intent(out) :: kf(NZLI)
         !! Fractional interface weight, valid 1..nz+1.

      integer :: k
      real(wp) :: dz_in

      ! Build loop (surface-down, 1-based).
      nzc = 1
      hc(1) = 0.0_wp
      do k = 1, nz
         ! Open a new merged layer iff the current cluster has mass AND
         ! this layer is massive.
         if (hc(nzc) > 0.0_wp .and. h(k) > h_min) then
            nzc = nzc + 1
            hc(nzc) = 0.0_wp
         end if
         kc(k) = nzc
         hc(nzc) = hc(nzc) + h(k)
      end do
      kc(nz + 1) = nzc + 1   ! bed-interface sentinel

      ! --- kf: interface interpolation weights ---
      kf(1) = 0.0_wp
      dz_in = h(1)
      do k = 2, nz
         if (kc(k) > kc(k - 1)) then
            ! Interface k sits ON a merged interface.
            kf(k) = 0.0_wp
            dz_in = h(k)
         else
            ! Interface k is interior to merged layer kc(k).
            kf(k) = dz_in/max(hc(kc(k)), H_DIV_EPS)
            dz_in = dz_in + h(k)
         end if
      end do
      kf(nz + 1) = 0.0_wp
   end subroutine massless_build_maps