configure_ocean_tidal_mixing Subroutine

private subroutine configure_ocean_tidal_mixing(cfg, ocean_state, compute_rank, ierr)

Copy the &ocean_tidal_mixing_nml knobs onto the tidal-mixing slot — every field, end to end (no dead-config gaps). Seeds the prescribed bottom energy field e_in (v1 uniform path), copies the shared EOS hookup for the N^2 buoyancy derivatives, and validates. No mutual exclusion: tidal mixing is an interior closure that coexists with KPP / EPBL / PP81 / kappa-shear.

Arguments

Type IntentOptional Attributes Name
type(config_t), intent(in) :: cfg
type(ocean_state_t), intent(inout) :: ocean_state
integer, intent(in) :: compute_rank
integer, intent(out), optional :: ierr

Non-zero on a tidal-mixing configuration conflict when present; absent behaves as today (error stop).


Calls

proc~~configure_ocean_tidal_mixing~~CallsGraph proc~configure_ocean_tidal_mixing configure_ocean_tidal_mixing info info proc~configure_ocean_tidal_mixing->info proc~fail fail proc~configure_ocean_tidal_mixing->proc~fail proc~ocean_tidal_mixing_set_e_uniform ocean_tidal_mixing_t%ocean_tidal_mixing_set_e_uniform proc~configure_ocean_tidal_mixing->proc~ocean_tidal_mixing_set_e_uniform to_string to_string proc~configure_ocean_tidal_mixing->to_string error error proc~fail->error proc~error_ring_push error_ring_push proc~fail->proc~error_ring_push

Called by

proc~~configure_ocean_tidal_mixing~~CalledByGraph proc~configure_ocean_tidal_mixing configure_ocean_tidal_mixing proc~configure_ocean_lateral configure_ocean_lateral proc~configure_ocean_lateral->proc~configure_ocean_tidal_mixing 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

Source Code

   subroutine configure_ocean_tidal_mixing(cfg, ocean_state, compute_rank, ierr)
      !! Copy the `&ocean_tidal_mixing_nml` knobs onto the tidal-mixing
      !! slot — every field, end to end (no dead-config gaps).  Seeds the
      !! prescribed bottom energy field `e_in` (v1 uniform path), copies
      !! the shared EOS hookup for the N^2 buoyancy derivatives, and
      !! validates.  No mutual exclusion: tidal mixing is an interior
      !! closure that coexists with KPP / EPBL / PP81 / kappa-shear.
      type(config_t), intent(in) :: cfg
      type(ocean_state_t), intent(inout) :: ocean_state
      integer, intent(in) :: compute_rank
      integer, intent(out), optional :: ierr
         !! Non-zero on a tidal-mixing configuration conflict when present;
         !! absent behaves as today (`error stop`).

      associate (tm => ocean_state%vmix_tidal, tcfg => cfg%ocean%tidal_mixing)
         ! `enable` is flipped LAST, only once every validation below has
         ! passed (P0.1 review F9 — `configure_ocean_porous` is the
         ! pattern): setting it up front left a half-configured slot
         ! flagged enabled on any of this routine's failure returns.
         if (.not. tcfg%enable) then
            tm%enable = .false.
            if (present(ierr)) ierr = OCEAN_STATUS_OK
            return
         end if

         ! Every St-Laurent/Simmons knob (no dead-config gaps).
         tm%gamma = tcfg%gamma
         tm%mu = tcfg%mu
         tm%zeta = tcfg%zeta
         tm%kd_max = tcfg%kd_max
         tm%prandtl_tidal = tcfg%prandtl_tidal
         tm%min_zbot = tcfg%min_zbot
         tm%e_uniform = tcfg%e_uniform
         tm%e_compute = tcfg%e_compute
         tm%kappa_itides = tcfg%kappa_itides
         tm%kappa_h2 = tcfg%kappa_h2
         tm%utide = tcfg%utide
         tm%h2_rough = tcfg%h2_rough
         tm%frac_rough = tcfg%frac_rough
         tm%e_max = tcfg%e_max

         ! EOS hookup: the buoyancy derivatives use the SAME EOS handle
         ! the dyn-core runs (shared flat-POD copy — one source of truth).
         tm%eos = ocean_state%eos
         tm%rho0 = ocean_state%eos%rho0

         ! Seed the prescribed bottom energy field (v1 uniform path).
         call tm%set_e_uniform(tm%e_uniform)

         ! Validation.
         if (.not. cfg%ocean%vmix%use_closure) then
            call fail("ocean_tidal_mixing_nml: enable=.true. requires "// &
                      "ocean_vmix_nml use_closure=.true. (tidal mixing "// &
                      "folds into the interior closure's kv/kt)", ierr, OCEAN_STATUS_ERR_SETUP)
            return
         end if
         if (.not. cfg%ocean%thermo%enable_thermodynamics) then
            call fail("ocean_tidal_mixing_nml: enable=.true. requires "// &
                      "active thermodynamics (tidal mixing reads T, S for N^2)", ierr, OCEAN_STATUS_ERR_SETUP)
            return
         end if
         if (tm%zeta <= 0.0_wp) then
            call fail("ocean_tidal_mixing_nml: zeta must be > 0", ierr, OCEAN_STATUS_ERR_SETUP)
            return
         end if
         if (tm%prandtl_tidal <= 0.0_wp) then
            call fail("ocean_tidal_mixing_nml: prandtl_tidal must be > 0", ierr, OCEAN_STATUS_ERR_SETUP)
            return
         end if

         if (compute_rank == 0) then
            call logger%info("Tidal mixing:     interior closure enabled "// &
                             "(zeta="//to_string(tcfg%zeta)//" m  "// &
                             "E="//to_string(tcfg%e_uniform)//" W/m^2)")
         end if
         tm%enable = .true.
      end associate
      if (present(ierr)) ierr = OCEAN_STATUS_OK
   end subroutine configure_ocean_tidal_mixing