probe_h_vs_eta_residual Subroutine

private subroutine probe_h_vs_eta_residual(grid, ms, bt_work, stage, outer_step)

Debug probe: print max|sum_k(h_layer) - (H_ref + bt_eta_end)| over interior cells. In Eulerian-z this is forced to zero by apply_bt_correction’s h-rescale. In Lagrangian mode the rescale is skipped, so this residual is what the slow continuity actually drifts to (expected to be FP). Watching how it grows over time across many outer steps is what pins down whether the long-run momentum NaN is FP accumulation in sum_k(h_layer) - H - bt_eta_end.

Arguments

Type IntentOptional Attributes Name
type(hgrid_t), intent(in) :: grid
type(multilayer_state_t), intent(inout) :: ms
type(barotropic_workstate_t), intent(in) :: bt_work
integer, intent(in) :: stage
integer, intent(in) :: outer_step

Called by

proc~~probe_h_vs_eta_residual~~CalledByGraph proc~probe_h_vs_eta_residual probe_h_vs_eta_residual proc~run_stage_split run_stage_split proc~run_stage_split->proc~probe_h_vs_eta_residual 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_split proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_step proc~rdb_ocean_step rdb_ocean_step proc~rdb_ocean_step->proc~engine_step proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean

Variables

Type Visibility Attributes Name Initial
integer, private :: i
integer, private :: i0
integer, private :: i1
integer, private :: ig
integer, private :: j
integer, private :: j0
integer, private :: j1
integer, private :: k
real(kind=wp), private :: max_res
real(kind=wp), private :: res
real(kind=wp), private :: sum_h
real(kind=wp), private :: target_h

Source Code

   subroutine probe_h_vs_eta_residual(grid, ms, bt_work, stage, outer_step)
      !! Debug probe: print max|sum_k(h_layer) - (H_ref + bt_eta_end)|
      !! over interior cells.  In Eulerian-z this is forced to zero
      !! by `apply_bt_correction`'s h-rescale.  In Lagrangian mode
      !! the rescale is skipped, so this residual is what the slow
      !! continuity actually drifts to (expected to be FP).  Watching
      !! how it grows over time across many outer steps is what
      !! pins down whether the long-run momentum NaN is FP
      !! accumulation in `sum_k(h_layer) - H - bt_eta_end`.
      type(hgrid_t), intent(in) :: grid
      type(multilayer_state_t), intent(inout) :: ms
      type(barotropic_workstate_t), intent(in) :: bt_work
      integer, intent(in) :: stage, outer_step

      integer :: i, j, k, i0, i1, j0, j1, ig
      real(wp) :: max_res, sum_h, target_h, res

      if (.not. bcdiag_enabled) return
      if (outer_step > bcdiag_step_limit) return

      !$acc update self(ms%h_layer, bt_work%bt_eta_end, bt_work%bt_H_ref)

      ig = grid%nghost
      i0 = ig + 1
      i1 = grid%nx_total - ig
      j0 = ig + 1
      j1 = grid%ny_total - ig

      max_res = 0.0_wp
      do j = j0, j1
         do i = i0, i1
            sum_h = 0.0_wp
            do k = 1, ms%nz_ml
               sum_h = sum_h + ms%h_layer(i, j, k)
            end do
            target_h = bt_work%bt_H_ref(i, j) + bt_work%bt_eta_end(i, j)
            res = abs(sum_h - target_h)
            if (res > max_res) max_res = res
         end do
      end do

      write (output_unit, &
             '("[bcdiag] step=", i0, " stage=", i0, " ", a40, " max|h_sum - (H+eta_end)|=", es12.4)') &
         outer_step, stage, "h_vs_eta_residual", max_res
      flush (output_unit)
   end subroutine probe_h_vs_eta_residual