ocean_sponge_apply_maps Subroutine

public subroutine ocean_sponge_apply_maps(grid, sp, ms, dt)

Map-driven sponge dispatch (&ocean_sponge_nml enable=.true.). Relaxes momentum toward u_ref/v_ref (when relax_uv) and every registered tracer toward ref_tracer (when relax_tracers), mirroring the S/T tracer relaxation into ms%salt_budget_sponge / ms%heat_budget_sponge so the console salt/heat budget can close with the sponge on (rdb_ocean_console_stats::ocean_heat_src_sum / ocean_salt_src_sum). No-op when .not. sp%is_init .or. .not. sp%enable. Run from the same slot as the legacy path — see rdb_ocean_dyn::run_stage_split’s dispatch (exactly one of the legacy band / map-driven path runs).

Arguments

Type IntentOptional Attributes Name
type(hgrid_t), intent(in) :: grid
type(ocean_sponge_t), intent(in) :: sp
type(multilayer_state_t), intent(inout) :: ms
real(kind=wp), intent(in) :: dt

Calls

proc~~ocean_sponge_apply_maps~~CallsGraph proc~ocean_sponge_apply_maps ocean_sponge_apply_maps proc~relax_map_tracer_budget_impl relax_map_tracer_budget_impl proc~ocean_sponge_apply_maps->proc~relax_map_tracer_budget_impl proc~relax_map_tracer_impl relax_map_tracer_impl proc~ocean_sponge_apply_maps->proc~relax_map_tracer_impl proc~relax_map_u_impl relax_map_u_impl proc~ocean_sponge_apply_maps->proc~relax_map_u_impl proc~relax_map_v_impl relax_map_v_impl proc~ocean_sponge_apply_maps->proc~relax_map_v_impl local local proc~relax_map_tracer_budget_impl->local proc~relax_map_tracer_impl->local proc~relax_toward relax_toward proc~relax_map_tracer_impl->proc~relax_toward proc~relax_map_u_impl->local proc~relax_map_u_impl->proc~relax_toward proc~relax_map_v_impl->local proc~relax_map_v_impl->proc~relax_toward

Called by

proc~~ocean_sponge_apply_maps~~CalledByGraph proc~ocean_sponge_apply_maps ocean_sponge_apply_maps proc~run_stage_split run_stage_split proc~run_stage_split->proc~ocean_sponge_apply_maps 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 :: it
integer, private :: nx
integer, private :: ny
integer, private :: nz

Source Code

   subroutine ocean_sponge_apply_maps(grid, sp, ms, dt)
      !! Map-driven sponge dispatch (`&ocean_sponge_nml enable=.true.`).
      !! Relaxes momentum toward `u_ref`/`v_ref` (when `relax_uv`) and every
      !! registered tracer toward `ref_tracer` (when `relax_tracers`),
      !! mirroring the S/T tracer relaxation into `ms%salt_budget_sponge` /
      !! `ms%heat_budget_sponge` so the console salt/heat budget can close
      !! with the sponge on (`rdb_ocean_console_stats::ocean_heat_src_sum` /
      !! `ocean_salt_src_sum`). No-op when `.not. sp%is_init .or. .not.
      !! sp%enable`. Run from the same slot as the legacy path — see
      !! `rdb_ocean_dyn::run_stage_split`'s dispatch (exactly one of the
      !! legacy band / map-driven path runs).
      type(hgrid_t), intent(in) :: grid
      type(ocean_sponge_t), intent(in) :: sp
      type(multilayer_state_t), intent(inout) :: ms
      real(wp), intent(in) :: dt

      integer :: nx, ny, nz, it

      if (.not. sp%is_init .or. .not. sp%enable) return

      nx = grid%nx_total
      ny = grid%ny_total
      nz = ms%nz_ml

      if (sp%relax_uv) then
         call relax_map_u_impl(ms%u_face_x_layer, sp%u_ref, sp%idamp_u, nx + 1, ny, nz, dt)
         call relax_map_v_impl(ms%v_face_y_layer, sp%v_ref, sp%idamp_v, nx, ny + 1, nz, dt)
      end if

      if (sp%relax_tracers .and. allocated(ms%tracers)) then
         ! Outer-shim: the per-tracer `it` loop stays outside the `do
         ! concurrent` kernels (§6.4 of the plan) — `ms%tracers(it)%hTr` is
         ! dereferenced here on the host, never inside the device loop.
         do it = 1, min(size(ms%tracers), sp%n_tracers)
            if (.not. allocated(ms%tracers(it)%hTr)) cycle
            if (it == ms%idx_salinity) then
               call relax_map_tracer_budget_impl(ms%tracers(it)%hTr, ms%h_layer, &
                                                 sp%ref_tracer, it, sp%n_tracers, &
                                                 sp%idamp_h, ms%salt_budget_sponge, &
                                                 nx, ny, nz, dt)
            else if (it == ms%idx_temperature) then
               call relax_map_tracer_budget_impl(ms%tracers(it)%hTr, ms%h_layer, &
                                                 sp%ref_tracer, it, sp%n_tracers, &
                                                 sp%idamp_h, ms%heat_budget_sponge, &
                                                 nx, ny, nz, dt)
            else
               call relax_map_tracer_impl(ms%tracers(it)%hTr, ms%h_layer, &
                                          sp%ref_tracer, it, sp%n_tracers, &
                                          sp%idamp_h, nx, ny, nz, dt)
            end if
         end do
      end if
   end subroutine ocean_sponge_apply_maps