ocean_wave_speed_build_static Subroutine

private subroutine ocean_wave_speed_build_static(this, grid, metrics, f_centre)

Copy a pre-filled cell-centre Coriolis magnitude |f| (1/s) onto the slot (mirror of ocean_meke_set_f_centre — the caller builds f_centre via fill_coriolis_centre / metrics_fill_coriolis, which handles beta-plane AND planetary/spherical), and fill the static beta_centre = |grad f| field with the SAME centred-difference stencil meke_length_scales uses (edge rows/columns left at 0 -> the extratropical Rd = cg1/|f| branch there).

Divergence note (documented, not fixed here): this takes the gradient of f_centre, which is |f| (matching the VarMix / MEKE house idiom) rather than the signed Coriolis field, so |grad|f|| has a kink at the equator where |grad f| would be smooth. Shared pre-existing divergence with VarMix/MEKE — not fixed by this PR (see docs/CLOSURE_MATRIX.md).

Host loops only — these are static (functions of geometry + planetary f) and never change with time. Call after init, AFTER the metrics are filled + finalized, BEFORE enter_data.

Type Bound

ocean_wave_speed_t

Arguments

Type IntentOptional Attributes Name
class(ocean_wave_speed_t), intent(inout) :: this
type(hgrid_t), intent(in) :: grid
type(ocean_metrics_t), intent(in) :: metrics
real(kind=wp), intent(in) :: f_centre(grid%nx_total,grid%ny_total)

Called by

proc~~ocean_wave_speed_build_static~~CalledByGraph proc~ocean_wave_speed_build_static ocean_wave_speed_t%ocean_wave_speed_build_static proc~configure_ocean_wavespeed configure_ocean_wavespeed proc~configure_ocean_wavespeed->proc~ocean_wave_speed_build_static proc~configure_ocean_lateral configure_ocean_lateral proc~configure_ocean_lateral->proc~configure_ocean_wavespeed proc~engine_setup engine_setup proc~engine_setup->proc~configure_ocean_lateral proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_setup proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_setup proc~driver_validate driver_validate proc~driver_validate->proc~engine_setup proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean proc~rdb_ocean_create_finalize rdb_ocean_create_finalize proc~rdb_ocean_create_finalize->proc~complete_ocean_create proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~complete_ocean_create

Variables

Type Visibility Attributes Name Initial
real(kind=wp), private :: dfdx
real(kind=wp), private :: dfdy
integer, private :: i
integer, private :: j
integer, private :: nx
integer, private :: ny

Source Code

   subroutine ocean_wave_speed_build_static(this, grid, metrics, f_centre)
      !! Copy a pre-filled cell-centre Coriolis magnitude |f| (1/s) onto
      !! the slot (mirror of `ocean_meke_set_f_centre` — the caller
      !! builds `f_centre` via `fill_coriolis_centre` /
      !! `metrics_fill_coriolis`, which handles beta-plane AND
      !! planetary/spherical), and fill the static `beta_centre =
      !! |grad f|` field with the SAME centred-difference stencil
      !! `meke_length_scales` uses (edge rows/columns left at 0 -> the
      !! extratropical `Rd = cg1/|f|` branch there).
      !!
      !! Divergence note (documented, not fixed here): this takes the
      !! gradient of `f_centre`, which is `|f|` (matching the VarMix /
      !! MEKE house idiom) rather than the signed Coriolis field, so
      !! `|grad|f||` has a kink at the equator where `|grad f|` would be
      !! smooth.  Shared pre-existing divergence with VarMix/MEKE — not
      !! fixed by this PR (see docs/CLOSURE_MATRIX.md).
      !!
      !! Host loops only — these are static (functions of geometry +
      !! planetary f) and never change with time.  Call after `init`,
      !! AFTER the metrics are filled + finalized, BEFORE `enter_data`.
      class(ocean_wave_speed_t), intent(inout) :: this
      type(hgrid_t), intent(in) :: grid
      type(ocean_metrics_t), intent(in) :: metrics
      real(wp), intent(in) :: f_centre(grid%nx_total, grid%ny_total)
      integer :: i, j, nx, ny
      real(wp) :: dfdx, dfdy

      if (.not. allocated(this%f_centre)) return
      nx = grid%nx_total
      ny = grid%ny_total
      do j = 1, ny
         do i = 1, nx
            this%f_centre(i, j) = f_centre(i, j)
         end do
      end do

      do j = 1, ny
         do i = 1, nx
            dfdx = 0.0_wp
            dfdy = 0.0_wp
            if (i > 1 .and. i < nx) then
               dfdx = 0.5_wp*(f_centre(i + 1, j) - f_centre(i - 1, j))*metrics%idxT(i, j)
            end if
            if (j > 1 .and. j < ny) then
               dfdy = 0.5_wp*(f_centre(i, j + 1) - f_centre(i, j - 1))*metrics%idyT(i, j)
            end if
            this%beta_centre(i, j) = sqrt(dfdx*dfdx + dfdy*dfdy)
         end do
      end do
   end subroutine ocean_wave_speed_build_static