Skip to content

Commit

Permalink
Obc setup plus segment update period (#198)
Browse files Browse the repository at this point in the history
* Setup OBC segments for COBALT/OBGC tracers

    - These are updates required to setup OBC segments for OBGC tracers.
    - Since COBALT package has more than 50 tracers using the MOM6 table
      mechanism for setting up OBC segments is not feasible. Rather, this
      update delegates such setup to mechanims used in ocean_BGS tracers
      leaving MOM6 mechanism for native tracers intact.
    - Fixed issues caught by MOM6 githubCI

* Add capability to change obc segment update period

- COBALT tracers do not need as frequent segment bc updates and can
  use a larger update period to speed up the model.
  This commit introduces a new parameter DT_OBC_SEG_UPDATE_OBGC
  that can be adjusted for obc segment update period.
- This commit applies the change only to BGC tracers but can easily
  be changed to apply for all.

* Insert missing US%T_to_sec

- The unit conversion factor was missing causing a crash in a newer test.

* Updates from Andrew Ross

- Avoid low initial values in the tracer reservoirs

* Per Andrew Ross review

* corrected indentation per review

* Avoid using module vars per review request

- Reviewer asked to avoid using module variables with "save" attributes.
- This commit hides the module variables inside the existing OBC type.

* Coding style corrections per review

* Modification per review: do_not_log if .not.associated(CS%OBC)

Co-authored-by: Robert Hallberg <[email protected]>
  • Loading branch information
nikizadehgfdl and Hallberg-NOAA authored Nov 10, 2022
1 parent 522e7aa commit 9d5a320
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 22 deletions.
14 changes: 14 additions & 0 deletions config_src/external/GFDL_ocean_BGC/generic_tracer_utils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module g_tracer_utils
character(len=fm_string_len) :: src_var_name !< Tracer source variable name
character(len=fm_string_len) :: src_var_unit !< Tracer source variable units
character(len=fm_string_len) :: src_var_gridspec !< Tracer source grid file name
character(len=fm_string_len) :: obc_src_file_name !< Boundary condition tracer source filename
character(len=fm_string_len) :: obc_src_field_name !< Boundary condition tracer source fieldname
integer :: src_var_record !< Unknown
logical :: requires_src_info = .false. !< Unknown
real :: src_var_unit_conversion = 1.0 !< This factor depends on the tracer. Ask Jasmin
Expand Down Expand Up @@ -61,6 +63,7 @@ module g_tracer_utils
public :: g_tracer_get_next
public :: g_tracer_is_prog
public :: g_diag_type
public :: g_tracer_get_obc_segment_props

!> Set the values of various (array) members of the tracer node g_tracer_type
!!
Expand Down Expand Up @@ -284,6 +287,17 @@ subroutine g_tracer_get_next(g_tracer,g_tracer_next)
type(g_tracer_type), pointer :: g_tracer_next !< Pointer to the next tracer node in the list
end subroutine g_tracer_get_next

!> get obc segment properties for each tracer
subroutine g_tracer_get_obc_segment_props(g_tracer_list, name, obc_has, src_file, src_var_name,lfac_in,lfac_out)
type(g_tracer_type), pointer :: g_tracer_list !< pointer to the head of the generic tracer list
character(len=*), intent(in) :: name !< tracer name
logical, intent(out):: obc_has !< .true. if This tracer has OBC
real, optional,intent(out):: lfac_in !< OBC reservoir inverse lengthscale factor
real, optional,intent(out):: lfac_out !< OBC reservoir inverse lengthscale factor
character(len=*),optional,intent(out):: src_file !< OBC source file
character(len=*),optional,intent(out):: src_var_name !< OBC source variable in file
end subroutine g_tracer_get_obc_segment_props

!>Vertical Diffusion of a tracer node
!!
!! This subroutine solves a tridiagonal equation to find and set values of vertically diffused field
Expand Down
34 changes: 32 additions & 2 deletions src/core/MOM.F90
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module MOM
use MOM_tracer_registry, only : lock_tracer_registry, tracer_registry_end
use MOM_tracer_flow_control, only : call_tracer_register, tracer_flow_control_CS
use MOM_tracer_flow_control, only : tracer_flow_control_init, call_tracer_surface_state
use MOM_tracer_flow_control, only : tracer_flow_control_end
use MOM_tracer_flow_control, only : tracer_flow_control_end, call_tracer_register_obc_segments
use MOM_transcribe_grid, only : copy_dyngrid_to_MOM_grid, copy_MOM_grid_to_dyngrid
use MOM_unit_scaling, only : unit_scale_type, unit_scaling_init
use MOM_unit_scaling, only : unit_scaling_end, fix_restart_unit_scaling
Expand Down Expand Up @@ -294,7 +294,11 @@ module MOM
!! barotropic time step [s]. If this is negative dtbt is never
!! calculated, and if it is 0, dtbt is calculated every step.
type(time_type) :: dtbt_reset_interval !< A time_time representation of dtbt_reset_period.
type(time_type) :: dtbt_reset_time !< The next time DTBT should be calculated.
type(time_type) :: dtbt_reset_time !< The next time DTBT should be calculated.
real :: dt_obc_seg_period !< The time interval between OBC segment updates for OBGC tracers
type(time_type) :: dt_obc_seg_interval !< A time_time representation of dt_obc_seg_period.
type(time_type) :: dt_obc_seg_time !< The next time OBC segment update is applied to OBGC tracers.

real, dimension(:,:), pointer :: frac_shelf_h => NULL() !< fraction of total area occupied
!! by ice shelf [nondim]
real, dimension(:,:), pointer :: mass_shelf => NULL() !< Mass of ice shelf [R Z ~> kg m-2]
Expand Down Expand Up @@ -1132,6 +1136,17 @@ subroutine step_MOM_dynamics(forces, p_surf_begin, p_surf_end, dt, dt_thermo, &
call disable_averaging(CS%diag)
endif

!OBC segment data update for some fields can be less frequent than others
if(associated(CS%OBC)) then
CS%OBC%update_OBC_seg_data = .false.
if (CS%dt_obc_seg_period == 0.0) CS%OBC%update_OBC_seg_data = .true.
if (CS%dt_obc_seg_period > 0.0) then
if (Time_local >= CS%dt_obc_seg_time) then
CS%OBC%update_OBC_seg_data = .true.
CS%dt_obc_seg_time = CS%dt_obc_seg_time + CS%dt_obc_seg_interval
endif
endif
endif

if (CS%do_dynamics .and. CS%split) then !--------------------------- start SPLIT
! This section uses a split time stepping scheme for the dynamic equations,
Expand Down Expand Up @@ -2152,6 +2167,13 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
units="s", default=default_val, do_not_read=(dtbt > 0.0))
endif

CS%dt_obc_seg_period = -1.0
call get_param(param_file, "MOM", "DT_OBC_SEG_UPDATE_OBGC", CS%dt_obc_seg_period, &
"The time between OBC segment data updates for OBGC tracers. "//&
"This must be an integer multiple of DT and DT_THERM. "//&
"The default is set to DT.", &
units="s", default=US%T_to_s*CS%dt, do_not_log=.not.associated(CS%OBC))

! This is here in case these values are used inappropriately.
use_frazil = .false. ; bound_salinity = .false.
CS%tv%P_Ref = 2.0e7*US%kg_m3_to_R*US%m_s_to_L_T**2
Expand Down Expand Up @@ -2627,6 +2649,8 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
! could occur with the call to update_OBC_data or after the main initialization.
if (use_temperature) &
call register_temp_salt_segments(GV, US, CS%OBC, CS%tracer_Reg, param_file)
!This is the equivalent call to register_temp_salt_segments for external tracers with OBC
call call_tracer_register_obc_segments(GV, param_file, CS%tracer_flow_CSp, CS%tracer_Reg, CS%OBC)

! This needs the number of tracers and to have called any code that sets whether
! reservoirs are used.
Expand Down Expand Up @@ -2962,6 +2986,12 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
CS%ntrunc, cont_stencil=CS%cont_stencil)
endif

!Set OBC segment data update period
if (associated(CS%OBC) .and. CS%dt_obc_seg_period > 0.0) then
CS%dt_obc_seg_interval = real_to_time(US%T_to_s*CS%dt_obc_seg_period)
CS%dt_obc_seg_time = Time + CS%dt_obc_seg_interval
endif

call callTree_waypoint("dynamics initialized (initialize_MOM)")

CS%mixedlayer_restrat = mixedlayer_restrat_init(Time, G, GV, US, param_file, diag, &
Expand Down
Loading

0 comments on commit 9d5a320

Please sign in to comment.