vmix_smooth_121_impl Subroutine

private pure subroutine vmix_smooth_121_impl(nx, ny, nzp1, fld, scratch, wet_mask)

One in-plane 1-2-1 horizontal smoothing pass on interior interfaces k = 2..nzp1-1. Wet-mask aware: contributions from dry neighbours (wet_mask == 0) are excluded and the 9-point stencil weight is renormalised over the wet cells only. A dry centre column (wet_mask(i,j) == 0) is left unchanged — no leakage into or out of dry cells.

Reads fld into scratch, then writes the smoothed result back to fld. Interior (i,j) only (i = 2..nx-1, j = 2..ny-1) — edge columns are left unchanged so closed-wall ghost rows don’t bleed into the smoothed field.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: nx
integer, intent(in) :: ny
integer, intent(in) :: nzp1
real(kind=wp), intent(inout) :: fld(nx,ny,nzp1)
real(kind=wp), intent(inout) :: scratch(nx,ny,nzp1)
real(kind=wp), intent(in) :: wet_mask(nx,ny)

1 = wet, 0 = dry. Shape (nx, ny).


Calls

proc~~vmix_smooth_121_impl~~CallsGraph proc~vmix_smooth_121_impl vmix_smooth_121_impl local local proc~vmix_smooth_121_impl->local

Called by

proc~~vmix_smooth_121_impl~~CalledByGraph proc~vmix_smooth_121_impl vmix_smooth_121_impl proc~vmix_assemble vmix_assemble proc~vmix_assemble->proc~vmix_smooth_121_impl proc~vmix_apply_in_stage vmix_apply_in_stage proc~vmix_apply_in_stage->proc~vmix_assemble 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 proc~engine_step engine_step proc~engine_step->proc~ocean_dyn_step proc~engine_step->proc~ocean_dyn_step_split

Variables

Type Visibility Attributes Name Initial
integer, private :: i
integer, private :: j
integer, private :: k
real(kind=wp), private :: w_c
real(kind=wp), private :: w_e
real(kind=wp), private :: w_n
real(kind=wp), private :: w_ne
real(kind=wp), private :: w_nw
real(kind=wp), private :: w_s_pt
real(kind=wp), private :: w_se
real(kind=wp), private :: w_sw
real(kind=wp), private :: w_w
real(kind=wp), private :: wsum

Source Code

   pure subroutine vmix_smooth_121_impl(nx, ny, nzp1, fld, scratch, wet_mask)
      !! One in-plane 1-2-1 horizontal smoothing pass on interior
      !! interfaces k = 2..nzp1-1.  Wet-mask aware: contributions from
      !! dry neighbours (wet_mask == 0) are excluded and the 9-point
      !! stencil weight is renormalised over the wet cells only.  A dry
      !! centre column (wet_mask(i,j) == 0) is left unchanged — no
      !! leakage into or out of dry cells.
      !!
      !! Reads `fld` into `scratch`, then writes the smoothed result back
      !! to `fld`.  Interior (i,j) only (i = 2..nx-1, j = 2..ny-1) —
      !! edge columns are left unchanged so closed-wall ghost rows don't
      !! bleed into the smoothed field.
      integer, intent(in) :: nx, ny, nzp1
      real(wp), intent(inout) :: fld(nx, ny, nzp1)
      real(wp), intent(inout) :: scratch(nx, ny, nzp1)
      real(wp), intent(in) :: wet_mask(nx, ny)
         !! 1 = wet, 0 = dry.  Shape (nx, ny).

      integer :: i, j, k
      real(wp) :: w_c, w_e, w_n, w_w, w_s_pt, w_ne, w_nw, w_se, w_sw, wsum

      do concurrent(k=1:nzp1, j=1:ny, i=1:nx)
         scratch(i, j, k) = fld(i, j, k)
      end do
      do concurrent(k=2:nzp1 - 1, j=2:ny - 1, i=2:nx - 1) &
         local(w_c, w_e, w_n, w_w, w_s_pt, w_ne, w_nw, w_se, w_sw, wsum)
         ! Standard 9-point [[1,2,1],[2,4,2],[1,2,1]]/16 weights, masked.
         w_c = 4.0_wp*wet_mask(i, j)
         w_e = 2.0_wp*wet_mask(i + 1, j)
         w_w = 2.0_wp*wet_mask(i - 1, j)
         w_n = 2.0_wp*wet_mask(i, j + 1)
         w_s_pt = 2.0_wp*wet_mask(i, j - 1)
         w_ne = wet_mask(i + 1, j + 1)
         w_nw = wet_mask(i - 1, j + 1)
         w_se = wet_mask(i + 1, j - 1)
         w_sw = wet_mask(i - 1, j - 1)
         wsum = w_c + w_e + w_w + w_n + w_s_pt + w_ne + w_nw + w_se + w_sw
         if (wsum <= 0.0_wp .or. wet_mask(i, j) == 0.0_wp) then
            ! Dry centre or fully isolated cell: leave unchanged.
            fld(i, j, k) = scratch(i, j, k)
         else
            fld(i, j, k) = (w_c*scratch(i, j, k) &
                            + w_e*scratch(i + 1, j, k) + w_w*scratch(i - 1, j, k) &
                            + w_n*scratch(i, j + 1, k) + w_s_pt*scratch(i, j - 1, k) &
                            + w_ne*scratch(i + 1, j + 1, k) + w_nw*scratch(i - 1, j + 1, k) &
                            + w_se*scratch(i + 1, j - 1, k) + w_sw*scratch(i - 1, j - 1, k)) &
                           /wsum
         end if
      end do
   end subroutine vmix_smooth_121_impl