Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made MOM_control_struct opaque #701

Merged
merged 14 commits into from
Feb 3, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 103 additions & 174 deletions config_src/coupled_driver/ocean_model_MOM.F90

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions config_src/ice_solo_driver/ice_shelf_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,14 @@ program SHELF_main
call log_param(param_file, mdl, "ELAPSED TIME AS MASTER", elapsed_time_master)

! i don't think we'll use this...
! call MOM_sum_output_init(grid, param_file, dirs%output_directory, &
! MOM_CSp%ntrunc, Start_time, sum_output_CSp)
call MOM_write_cputime_init(param_file, dirs%output_directory, Start_time, &
write_CPU_CSp)
call MOM_mesg("Done MOM_write_cputime_init.", 5)


! Close the param_file. No further parsing of input is possible after this.
call close_param_file(param_file)
call diag_mediator_close_registration(MOM_CSp%diag)
! call diag_mediator_close_registration(diag)

! Write out a time stamp file.
call open_file(unit, 'time_stamp.out', form=ASCII_FILE, action=APPEND_FILE, &
Expand Down
125 changes: 50 additions & 75 deletions config_src/mct_driver/ocn_comp_mct.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module ocn_comp_mct
use MOM_coms, only : reproducing_sum
use MOM_cpu_clock, only : cpu_clock_id, cpu_clock_begin, cpu_clock_end
use MOM_cpu_clock, only : CLOCK_SUBCOMPONENT
use MOM, only: initialize_MOM, step_MOM, MOM_control_struct, MOM_end
use MOM, only: initialize_MOM, step_MOM, MOM_control_struct, MOM_state_type, MOM_end
use MOM, only: calculate_surface_state, allocate_surface_state
use MOM, only: finish_MOM_initialization, step_offline
use MOM_forcing_type, only: forcing, forcing_diags, register_forcing_type_diags
Expand All @@ -57,8 +57,6 @@ module ocn_comp_mct
use MOM_diag_mediator, only: safe_alloc_ptr
use MOM_ice_shelf, only: initialize_ice_shelf, shelf_calc_flux, ice_shelf_CS
use MOM_ice_shelf, only: ice_shelf_end, ice_shelf_save_restart
use MOM_sum_output, only: MOM_sum_output_init, sum_output_CS
use MOM_sum_output, only: write_energy, accumulate_net_input
use MOM_string_functions, only: uppercase
use MOM_constants, only: CELSIUS_KELVIN_OFFSET, hlf, hlv
use MOM_EOS, only: gsw_sp_from_sr, gsw_pt_from_ct
Expand Down Expand Up @@ -297,9 +295,6 @@ module ocn_comp_mct
!! files and +2 (bit 1) for time-stamped files. A
!! restart file is saved at the end of a run segment
!! unless Restart_control is negative.
type(time_type) :: energysavedays !< The interval between writing the energies
!! and other integral quantities of the run.
type(time_type) :: write_energy_time !< The next time to write to the energy file.
integer :: nstep = 0 !< The number of calls to update_ocean.
logical :: use_ice_shelf !< If true, the ice shelf model is enabled.
logical :: icebergs_apply_rigid_boundary !< If true, the icebergs can change ocean bd condition.
Expand All @@ -317,6 +312,13 @@ module ocn_comp_mct
real :: press_to_z !< A conversion factor between pressure and ocean
!! depth in m, usually 1/(rho_0*g), in m Pa-1.
real :: C_p !< The heat capacity of seawater, in J K-1 kg-1.
logical :: offline_tracer_mode = .false. !< If false, use the model in prognostic mode
!! with the barotropic and baroclinic dynamics, thermodynamics,
!! etc. stepped forward integrated in time.
!! If true, all of the above are bypassed with all
!! fields necessary to integrate only the tracer advection
!! and diffusion equation read in from files stored from
!! a previous integration of the prognostic model.
type(directories) :: dirs !< A structure containing several relevant directory paths.
type(forcing) :: fluxes !< A structure containing pointers to
!! the ocean forcing fields.
Expand All @@ -330,8 +332,13 @@ module ocn_comp_mct
type(verticalGrid_type), pointer :: GV => NULL() !< A pointer to a vertical grid
!! structure containing metrics and related information.
type(MOM_control_struct), pointer :: MOM_CSp => NULL()
type(MOM_state_type), pointer :: MSp => NULL()
type(surface_forcing_CS), pointer :: forcing_CSp => NULL()
type(sum_output_CS), pointer :: sum_output_CSp => NULL()
type(MOM_restart_CS), pointer :: &
restart_CSp => NULL() !< A pointer set to the restart control structure
!! that will be used for MOM restart files.
type(diag_ctrl), pointer :: &
diag => NULL() !< A pointer to the diagnostic regulatory structure
end type ocean_state_type

!> Control structure for this module
Expand Down Expand Up @@ -802,7 +809,6 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
! Because of the way that indicies and domains are handled, Ocean_sfc must have
! been used in a previous call to initialize_ocean_type.

real :: Time_unit !< The time unit in seconds for ENERGYSAVEDAYS.
real :: Rho0 !< The Boussinesq ocean density, in kg m-3.
real :: G_Earth !< The gravitational acceleration in m s-2.
!! This include declares and sets the variable "version".
Expand All @@ -811,7 +817,6 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
character(len=48) :: stagger
integer :: secs, days
type(param_file_type) :: param_file !< A structure to parse for run-time parameters
logical :: offline_tracer_mode

call callTree_enter("ocean_model_init(), ocn_comp_mct.F90")
if (associated(OS)) then
Expand All @@ -825,11 +830,14 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
if (.not.OS%is_ocean_pe) return

OS%Time = Time_in
call initialize_MOM(OS%Time, param_file, OS%dirs, OS%MOM_CSp, Time_in, &
offline_tracer_mode=offline_tracer_mode, input_restart_file=input_restart_file)
OS%grid => OS%MOM_CSp%G ; OS%GV => OS%MOM_CSp%GV
OS%C_p = OS%MOM_CSp%tv%C_p
OS%fluxes%C_p = OS%MOM_CSp%tv%C_p
call initialize_MOM(OS%Time, Time_init, param_file, OS%dirs, OS%MSp, OS%MOM_CSp, &
OS%restart_CSp, Time_in, offline_tracer_mode=OS%offline_tracer_mode, &
input_restart_file=input_restart_file, diag_ptr=OS%diag, &
count_calls=.true.)
OS%grid => OS%MSp%G ; OS%GV => OS%MSp%GV
OS%C_p = OS%MSp%tv%C_p
OS%fluxes%C_p = OS%MSp%tv%C_p
use_temperature = ASSOCIATED(OS%MSp%tv%T)

! Read all relevant parameters and write them to the model log.
call log_version(param_file, mdl, version, "")
Expand All @@ -839,14 +847,6 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
"(bit 0) for a non-time-stamped file. A restart file \n"//&
"will be saved at the end of the run segment for any \n"//&
"non-negative value.", default=1)
call get_param(param_file, mdl, "TIMEUNIT", Time_unit, &
"The time unit for ENERGYSAVEDAYS.", &
units="s", default=86400.0)
call get_param(param_file, mdl, "ENERGYSAVEDAYS",OS%energysavedays, &
"The interval in units of TIMEUNIT between saves of the \n"//&
"energies of the run and other globally summed diagnostics.", &
default=set_time(0,days=1), timeunit=Time_unit)

call get_param(param_file, mdl, "OCEAN_SURFACE_STAGGER", stagger, &
"A case-insensitive character string to indicate the \n"//&
"staggering of the surface velocity field that is \n"//&
Expand Down Expand Up @@ -899,54 +899,43 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i

! Consider using a run-time flag to determine whether to do the diagnostic
! vertical integrals, since the related 3-d sums are not negligible in cost.
call allocate_surface_state(OS%state, OS%grid, OS%MOM_CSp%use_temperature, &
call allocate_surface_state(OS%state, OS%grid, use_temperature, &
do_integrals=.true., gas_fields_ocn=gas_fields_ocn)

call surface_forcing_init(Time_in, OS%grid, param_file, OS%MOM_CSp%diag, &
call surface_forcing_init(Time_in, OS%grid, param_file, OS%diag, &
OS%forcing_CSp, OS%restore_salinity, OS%restore_temp)

if (OS%use_ice_shelf) then
call initialize_ice_shelf(param_file, OS%grid, OS%Time, OS%ice_shelf_CSp, &
OS%MOM_CSp%diag, OS%fluxes)
OS%diag, OS%fluxes)
endif
if (OS%icebergs_apply_rigid_boundary) then
!call allocate_forcing_type(OS%grid, OS%fluxes, iceberg=.true.)
!This assumes that the iceshelf and ocean are on the same grid. I hope this is true
if (.not. OS%use_ice_shelf) call allocate_forcing_type(OS%grid, OS%fluxes, ustar=.true., shelf=.true.)
endif

call MOM_sum_output_init(OS%grid, param_file, OS%dirs%output_directory, &
OS%MOM_CSp%ntrunc, Time_init, OS%sum_output_CSp)

! This call has been moved into the first call to update_ocean_model.
! call write_energy(OS%MOM_CSp%u, OS%MOM_CSp%v, OS%MOM_CSp%h, OS%MOM_CSp%tv, &
! OS%Time, 0, OS%grid, OS%GV, OS%sum_output_CSp, OS%MOM_CSp%tracer_flow_CSp)

! write_energy_time is the next integral multiple of energysavedays.
OS%write_energy_time = Time_init + OS%energysavedays * &
(1 + (OS%Time - Time_init) / OS%energysavedays)

if (ASSOCIATED(OS%grid%Domain%maskmap)) then
call initialize_ocean_public_type(OS%grid%Domain%mpp_domain, Ocean_sfc, &
OS%MOM_CSp%diag, maskmap=OS%grid%Domain%maskmap, &
OS%diag, maskmap=OS%grid%Domain%maskmap, &
gas_fields_ocn=gas_fields_ocn)
else
call initialize_ocean_public_type(OS%grid%Domain%mpp_domain, Ocean_sfc, &
OS%MOM_CSp%diag, gas_fields_ocn=gas_fields_ocn)
OS%diag, gas_fields_ocn=gas_fields_ocn)
endif

! This call can only occur here if the coupler_bc_type variables have been
! initialized already using the information from gas_fields_ocn.
if (present(gas_fields_ocn)) then
call calculate_surface_state(OS%state, OS%MOM_CSp%u, &
OS%MOM_CSp%v, OS%MOM_CSp%h, OS%MOM_CSp%ave_ssh,&
OS%grid, OS%GV, OS%MOM_CSp)
call calculate_surface_state(OS%state, OS%MSp%u, &
OS%MSp%v, OS%MSp%h, OS%MSp%ave_ssh,&
OS%grid, OS%GV, OS%MSp, OS%MOM_CSp)

call convert_state_to_ocean_type(OS%state, Ocean_sfc, OS%grid)
endif

call close_param_file(param_file)
call diag_mediator_close_registration(OS%MOM_CSp%diag)
call diag_mediator_close_registration(OS%diag)

if (is_root_pe()) &
write(glb%stdout,'(/12x,a/)') '======== COMPLETED MOM INITIALIZATION ========'
Expand All @@ -968,9 +957,9 @@ subroutine ocean_model_init_sfc(OS, Ocean_sfc)
call coupler_type_spawn(Ocean_sfc%fields, OS%state%tr_fields, &
(/is,is,ie,ie/), (/js,js,je,je/), as_needed=.true.)

call calculate_surface_state(OS%state, OS%MOM_CSp%u, &
OS%MOM_CSp%v, OS%MOM_CSp%h, OS%MOM_CSp%ave_ssh,&
OS%grid, OS%GV, OS%MOM_CSp)
call calculate_surface_state(OS%state, OS%MSp%u, &
OS%MSp%v, OS%MSp%h, OS%MSp%ave_ssh,&
OS%grid, OS%GV, OS%Msp, OS%MOM_CSp)

call convert_state_to_ocean_type(OS%state, Ocean_sfc, OS%grid)

Expand Down Expand Up @@ -1621,7 +1610,7 @@ subroutine ocn_run_mct( EClock, cdata_o, x2o_o, o2x_o)
write(restartname,'(A,".mom6.r.",I4.4,"-",I2.2,"-",I2.2,"-",I5.5)') trim(runid), year, month, day, seconds

call save_restart(glb%ocn_state%dirs%restart_output_dir, glb%ocn_state%Time, glb%grid, &
glb%ocn_state%MOM_CSp%restart_CSp, .false., filename=restartname,GV=glb%ocn_state%GV)
glb%ocn_state%restart_CSp, .false., filename=restartname,GV=glb%ocn_state%GV)

! write name of restart file in the rpointer file
nu = shr_file_getUnit()
Expand Down Expand Up @@ -1730,7 +1719,7 @@ subroutine update_ocean_model(OS, Ocean_sfc, time_start_update, &

if (OS%fluxes%fluxes_used) then
! GMM, is enable_averaging needed now?
call enable_averaging(time_step, OS%Time + Ocean_coupling_time_step, OS%MOM_CSp%diag)
call enable_averaging(time_step, OS%Time + Ocean_coupling_time_step, OS%diag)
call ocn_import(OS%fluxes, OS%Time, OS%grid, OS%forcing_CSp, OS%state, x2o_o, ind, sw_decomp, &
c1, c2, c3, c4, OS%restore_salinity,OS%restore_temp)
#ifdef _USE_GENERIC_TRACER
Expand Down Expand Up @@ -1776,46 +1765,32 @@ subroutine update_ocean_model(OS, Ocean_sfc, time_start_update, &
endif

if (OS%nstep==0) then
call finish_MOM_initialization(OS%Time, OS%dirs, OS%MOM_CSp, OS%fluxes)

call write_energy(OS%MOM_CSp%u, OS%MOM_CSp%v, OS%MOM_CSp%h, OS%MOM_CSp%tv, &
OS%Time, 0, OS%grid, OS%GV, OS%sum_output_CSp, &
OS%MOM_CSp%tracer_flow_CSp)
call finish_MOM_initialization(OS%Time, OS%dirs, OS%MSp, OS%MOM_CSp, OS%fluxes, &
OS%restart_CSp)
endif

call disable_averaging(OS%MOM_CSp%diag)
call disable_averaging(OS%diag)
Master_time = OS%Time ; Time1 = OS%Time

if(OS%MOM_Csp%offline_tracer_mode) then
call step_offline(OS%fluxes, OS%state, Time1, time_step, OS%MOM_CSp)
if(OS%offline_tracer_mode) then
call step_offline(OS%fluxes, OS%state, Time1, time_step, OS%MSp, OS%MOM_CSp)
else
call step_MOM(OS%fluxes, OS%state, Time1, time_step, OS%MOM_CSp)
call step_MOM(OS%fluxes, OS%state, Time1, time_step, OS%MSp, OS%MOM_CSp)
endif

OS%Time = Master_time + Ocean_coupling_time_step
OS%nstep = OS%nstep + 1

call enable_averaging(time_step, OS%Time, OS%MOM_CSp%diag)
call enable_averaging(time_step, OS%Time, OS%diag)
call mech_forcing_diags(OS%fluxes, time_step, OS%grid, &
OS%MOM_CSp%diag, OS%forcing_CSp%handles)
call disable_averaging(OS%MOM_CSp%diag)
OS%diag, OS%forcing_CSp%handles)
call disable_averaging(OS%diag)

if (OS%fluxes%fluxes_used) then
call enable_averaging(OS%fluxes%dt_buoy_accum, OS%Time, OS%MOM_CSp%diag)
call enable_averaging(OS%fluxes%dt_buoy_accum, OS%Time, OS%diag)
call forcing_diagnostics(OS%fluxes, OS%state, OS%fluxes%dt_buoy_accum, &
OS%grid, OS%MOM_CSp%diag, OS%forcing_CSp%handles)
call accumulate_net_input(OS%fluxes, OS%state, OS%fluxes%dt_buoy_accum, &
OS%grid, OS%sum_output_CSp)
call disable_averaging(OS%MOM_CSp%diag)
endif

! See if it is time to write out the energy.
if ((OS%Time + ((Ocean_coupling_time_step)/2) > OS%write_energy_time) .and. &
(OS%MOM_CSp%t_dyn_rel_adv==0.0)) then
call write_energy(OS%MOM_CSp%u, OS%MOM_CSp%v, OS%MOM_CSp%h, OS%MOM_CSp%tv, &
OS%Time, OS%nstep, OS%grid, OS%GV, OS%sum_output_CSp, &
OS%MOM_CSp%tracer_flow_CSp)
OS%write_energy_time = OS%write_energy_time + OS%energysavedays
OS%grid, OS%diag, OS%forcing_CSp%handles)
call disable_averaging(OS%diag)
endif

! Translate state into Ocean.
Expand Down Expand Up @@ -2453,8 +2428,8 @@ subroutine ocean_model_end(Ocean_sfc, Ocean_state, Time)

!if (debug .and. is_root_pe()) write(glb%stdout,*)'Here 1'
!GMM call save_restart(Ocean_state, Time)
call diag_mediator_end(Time, Ocean_state%MOM_CSp%diag)
call MOM_end(Ocean_state%MOM_CSp)
call diag_mediator_end(Time, Ocean_state%diag)
call MOM_end(Ocean_state%MSp, Ocean_state%MOM_CSp)
if (Ocean_state%use_ice_shelf) call ice_shelf_end(Ocean_state%Ice_shelf_CSp)
!if (debug .and. is_root_pe()) write(glb%stdout,*)'Here 2'

Expand Down
Loading