Skip to content

Commit

Permalink
Merge branch 'origin/offline_tracers' of github.com:ashao/MOM6 into d…
Browse files Browse the repository at this point in the history
…ev/offline_tracers
  • Loading branch information
Andrew Shao committed Oct 14, 2016
2 parents 6e6ab58 + f837dc5 commit 56a7685
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 77 deletions.
41 changes: 17 additions & 24 deletions config_src/solo_driver/MOM_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ program MOM_main
logical :: do_online ! If true, use the model in prognostic mode where
! the barotropic and baroclinic dynamics, thermodynamics,
! etc. are stepped forward integrated in time.
! If false, the all of the above are bypassed with all
! If false, then all of the above are bypassed with all
! fields necessary to integrate only the tracer advection
! and diffusion equation are read in from files stored from
! a previous integration of the prognostic model
Expand Down Expand Up @@ -260,17 +260,18 @@ program MOM_main
else
Start_time = set_time(0,days=0)
endif

if (sum(date) >= 0) then
! In this case, the segment starts at a time fixed by ocean_solo.res
segment_start_time = set_date(date(1),date(2),date(3),date(4),date(5),date(6))
Time = segment_start_time
call initialize_MOM(Time, param_file, dirs, MOM_CSp, segment_start_time)
! Note the not before CS%d
call initialize_MOM(Time, param_file, dirs, MOM_CSp, segment_start_time, do_online_out = do_online)
else
! In this case, the segment starts at a time read from the MOM restart file
! or left as Start_time by MOM_initialize.
Time = Start_time
call initialize_MOM(Time, param_file, dirs, MOM_CSp)
call initialize_MOM(Time, param_file, dirs, MOM_CSp, do_online_out=do_online)
endif
fluxes%C_p = MOM_CSp%tv%C_p ! Copy the heat capacity for consistency.

Expand Down Expand Up @@ -308,16 +309,7 @@ program MOM_main
call get_param(param_file, mod, "DT_FORCING", time_step, &
"The time step for changing forcing, coupling with other \n"//&
"components, or potentially writing certain diagnostics. \n"//&
"The default value is given by DT.", units="s", default=dt)

call get_param(param_file, mod, "DO_ONLINE", do_online, &
"If true, use the model in prognostic mode where\n"//&
"the barotropic and baroclinic dynamics, thermodynamics,\n"//&
"etc. are stepped forward integrated in time.\n"//&
"If false, the all of the above are bypassed with all\n"//&
"fields necessary to integrate only the tracer advection\n"//&
"and diffusion equation are read in from files stored from\n"//&
"a previous integration of the prognostic model", default=.true.)
"The default value is given by DT.", units="s", default=dt)
if (.not. do_online) then
call get_param(param_file, mod, "DT_OFFLINE", time_step, &
"Time step for the offline time step")
Expand Down Expand Up @@ -478,16 +470,17 @@ program MOM_main
call disable_averaging(MOM_CSp%diag)

if (do_online) then
if (fluxes%fluxes_used) then
call enable_averaging(fluxes%dt_buoy_accum, Time, MOM_CSp%diag)
call forcing_diagnostics(fluxes, state, fluxes%dt_buoy_accum, grid, &
MOM_CSp%diag, surface_forcing_CSp%handles)
call accumulate_net_input(fluxes, state, fluxes%dt_buoy_accum, grid, sum_output_CSp)
call disable_averaging(MOM_CSp%diag)
else
call MOM_error(FATAL, "The solo MOM_driver is not yet set up to handle "//&
"thermodynamic time steps that are longer than the coupling timestep.")
endif ; endif
if (fluxes%fluxes_used) then
call enable_averaging(fluxes%dt_buoy_accum, Time, MOM_CSp%diag)
call forcing_diagnostics(fluxes, state, fluxes%dt_buoy_accum, grid, &
MOM_CSp%diag, surface_forcing_CSp%handles)
call accumulate_net_input(fluxes, state, fluxes%dt_buoy_accum, grid, sum_output_CSp)
call disable_averaging(MOM_CSp%diag)
else
call MOM_error(FATAL, "The solo MOM_driver is not yet set up to handle "//&
"thermodynamic time steps that are longer than the coupling timestep.")
endif
endif



Expand Down
48 changes: 30 additions & 18 deletions src/core/MOM.F90
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ module MOM
!! set by calling the function useRegridding() from the
!! MOM_regridding module.
logical :: do_dynamics !< If false, does not call step_MOM_dyn_*. This is an

!! undocumented run-time flag that is fragile.
logical :: do_online !< If false, step_tracers is called instead of step_MOM.
!! This is intended for running MOM6 in offline tracer mode
real :: dt !< (baroclinic) dynamics time step (seconds)
real :: dt_therm !< thermodynamics time step (seconds)
logical :: thermo_spans_coupling !< If true, thermodynamic and tracer time
Expand Down Expand Up @@ -464,10 +466,6 @@ subroutine step_MOM(fluxes, state, Time_start, time_interval, CS)
eta_av, & ! average sea surface height or column mass over a timestep (meter or kg/m2)
ssh ! sea surface height based on eta_av (meter or kg/m2)

real, dimension(SZIB_(CS%G),SZJ_(CS%G),SZK_(CS%G)) :: write_all_3du
real, dimension(SZI_(CS%G),SZJB_(CS%G),SZK_(CS%G)) :: write_all_3dv
real, dimension(SZI_(CS%G),SZJ_(CS%G),SZK_(CS%G)) :: write_all_3dt

real, allocatable, dimension(:,:) :: &
tmp, & ! temporary 2d field
zos, & ! dynamic sea lev (zero area mean) from inverse-barometer adjusted ssh (meter)
Expand Down Expand Up @@ -711,7 +709,6 @@ subroutine step_MOM(fluxes, state, Time_start, time_interval, CS)
fluxes%fluxes_used = .true.
call cpu_clock_end(id_clock_diabatic)

write_all_3dt(:,:,:) = 1.
if (CS%id_u_preale > 0) call post_data(CS%id_u_preale, u, CS%diag)
if (CS%id_v_preale > 0) call post_data(CS%id_v_preale, v, CS%diag)
if (CS%id_h_preale > 0) call post_data(CS%id_h_preale, h, CS%diag)
Expand Down Expand Up @@ -1006,7 +1003,6 @@ subroutine step_MOM(fluxes, state, Time_start, time_interval, CS)

call cpu_clock_begin(id_clock_tracer)

! Post fields used for offline tracer model
call advect_tracer(h, CS%uhtr, CS%vhtr, CS%OBC, CS%dt_trans, G, GV, &
CS%tracer_adv_CSp, CS%tracer_Reg)
call tracer_hordiff(h, CS%dt_trans, CS%MEKE, CS%VarMix, G, GV, &
Expand Down Expand Up @@ -1060,7 +1056,6 @@ subroutine step_MOM(fluxes, state, Time_start, time_interval, CS)
! Regridding/remapping is done here, at the end of the thermodynamics time step
! (that may comprise several dynamical time steps)
! The routine 'ALE_main' can be found in 'MOM_ALE.F90'.
write_all_3dt(:,:,:) = 1.
if (CS%id_u_preale > 0) call post_data(CS%id_u_preale, u, CS%diag)
if (CS%id_v_preale > 0) call post_data(CS%id_v_preale, v, CS%diag)
if (CS%id_h_preale > 0) call post_data(CS%id_h_preale, h, CS%diag)
Expand Down Expand Up @@ -1465,6 +1460,9 @@ subroutine step_tracers(fluxes, state, Time_start, time_interval, CS)
integer :: IsdB, IedB, JsdB, JedB
logical :: z_first, x_before_y

! Fail out if do_online is true
if(CS%do_online) call MOM_error(FATAL,"DO_ONLINE=True when calling step_tracers")

! Grid-related pointer assignments
G => CS%G
GV => CS%GV
Expand Down Expand Up @@ -1541,7 +1539,7 @@ subroutine step_tracers(fluxes, state, Time_start, time_interval, CS)

! Do horizontal diffusion first (but only half of it), remainder will be applied after advection
call tracer_hordiff(h_pre, CS%offline_CSp%dt_offline*0.5, CS%MEKE, CS%VarMix, G, GV, &
CS%tracer_diff_CSp, CS%tracer_Reg, CS%tv, do_online_flag=.false., read_khdt_x=khdt_x*0.5, &
CS%tracer_diff_CSp, CS%tracer_Reg, CS%tv, do_online_flag=CS%do_online, read_khdt_x=khdt_x*0.5, &
read_khdt_y=khdt_y*0.5)

do j=jsd,jed ; do i=isd,ied
Expand Down Expand Up @@ -1843,13 +1841,14 @@ end subroutine step_tracers


!> This subroutine initializes MOM.
subroutine initialize_MOM(Time, param_file, dirs, CS, Time_in)
subroutine initialize_MOM(Time, param_file, dirs, CS, Time_in, do_online_out)
type(time_type), target, intent(inout) :: Time !< model time, set in this routine
type(param_file_type), intent(out) :: param_file !< structure indicating paramater file to parse
type(directories), intent(out) :: dirs !< structure with directory paths
type(MOM_control_struct), pointer :: CS !< pointer set in this routine to MOM control structure
type(time_type), optional, intent(in) :: Time_in !< time passed to MOM_initialize_state when
!! model is not being started from a restart file
logical, optional, intent(out) :: do_online_out !< .false. if tracers are being run offline

! local
type(ocean_grid_type), pointer :: G => NULL() ! A pointer to a structure with metrics and related
Expand Down Expand Up @@ -1962,7 +1961,15 @@ subroutine initialize_MOM(Time, param_file, dirs, CS, Time_in)
"If False, skips the dynamics calls that update u & v, as well as\n"//&
"the gravity wave adjustment to h. This is a fragile feature and\n"//&
"thus undocumented.", default=.true., do_not_log=.true. )

call get_param(param_file, "MOM", "DO_ONLINE", CS%do_online, &
"If false, use the model in prognostic mode where\n"//&
"the barotropic and baroclinic dynamics, thermodynamics,\n"//&
"etc. are stepped forward integrated in time.\n"//&
"If true, the all of the above are bypassed with all\n"//&
"fields necessary to integrate only the tracer advection\n"//&
"and diffusion equation are read in from files stored from\n"//&
"a previous integration of the prognostic model\n"//&
"NOTE: This option only used in the ocean_solo_driver.", default=.true.)
call get_param(param_file, "MOM", "USE_REGRIDDING", CS%use_ALE_algorithm , &
"If True, use the ALE algorithm (regridding/remapping).\n"//&
"If False, use the layered isopycnal algorithm.", default=.false. )
Expand All @@ -1977,8 +1984,8 @@ subroutine initialize_MOM(Time, param_file, dirs, CS, Time_in)
call get_param(param_file, "MOM", "THICKNESSDIFFUSE", CS%thickness_diffuse, &
"If true, interface heights are diffused with a \n"//&
"coefficient of KHTH.", default=.false.)
call get_param(param_file, "MOM", "`_FIRST", &
CS%thickness_diffuse_first, &
call get_param(param_file, "MOM", "THICKNESSDIFFUSE_FIRST", &
CS%thickness_diffuse_first, &
"If true, do thickness diffusion before dynamics.\n"//&
"This is only used if THICKNESSDIFFUSE is true.", &
default=.false.)
Expand Down Expand Up @@ -2545,9 +2552,14 @@ subroutine initialize_MOM(Time, param_file, dirs, CS, Time_in)
cmor_long_name ="Sea Water Salinity")
endif

call offline_transport_init(param_file, CS%offline_CSp, CS%diabatic_CSp, G, GV)
call register_diags_offline_transport(Time, CS%diag, CS%offline_CSp)

! If running in offline tracer mode, initialize the necessary control structure and
! parameters
if(present(do_online_out)) do_online_out=CS%do_online

if(.not. CS%do_online) then
call offline_transport_init(param_file, CS%offline_CSp, CS%diabatic_CSp%diabatic_aux_CSp, G, GV)
call register_diags_offline_transport(Time, CS%diag, CS%offline_CSp)
endif

! This subroutine initializes any tracer packages.
new_sim = ((dirs%input_filename(1:1) == 'n') .and. &
Expand Down Expand Up @@ -2850,7 +2862,7 @@ subroutine register_diags(Time, G, GV, CS, ADp)
'Layer Thickness before diabatic forcing', thickness_units, v_cell_method='sum')
CS%id_e_predia = register_diag_field('ocean_model', 'e_predia', diag%axesTi, Time, &
'Interface Heights before diabatic forcing', 'meter')
! if (CS%diabatic_first .and. (.not. CS%adiabatic)) then
if (CS%diabatic_first .and. (.not. CS%adiabatic)) then
CS%id_u_preale = register_diag_field('ocean_model', 'u_preale', diag%axesCuL, Time, &
'Zonal velocity before remapping', 'meter second-1')
CS%id_v_preale = register_diag_field('ocean_model', 'v_preale', diag%axesCvL, Time, &
Expand All @@ -2863,7 +2875,7 @@ subroutine register_diags(Time, G, GV, CS, ADp)
'Salinity before remapping', 'ppt')
CS%id_e_preale = register_diag_field('ocean_model', 'e_preale', diag%axesTi, Time, &
'Interface Heights before remapping', 'meter')
! endif
endif

if (CS%use_temperature) then
CS%id_T_predia = register_diag_field('ocean_model', 'temp_predia', diag%axesTL, Time, &
Expand Down
4 changes: 1 addition & 3 deletions src/parameterizations/vertical/MOM_diabatic_aux.F90
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ subroutine applyBoundaryFluxesInOut(CS, G, GV, dt, fluxes, optics, h, tv, &
! Pen_SW_bnd and netMassOut
netSalt, & ! surface salt flux ( g(salt)/m2 for non-Bouss and ppt*H for Bouss )
nonpenSW ! non-downwelling SW, which is absorbed at ocean surface
real, dimension(SZI_(G), SZK_(G)) :: h2d, T2d, hloss
real, dimension(SZI_(G), SZK_(G)) :: h2d, T2d
real, dimension(SZI_(G), SZK_(G)) :: pen_TKE_2d, dSV_dT_2d
real, dimension(max(optics%nbands,1),SZI_(G)) :: Pen_SW_bnd
real, dimension(max(optics%nbands,1),SZI_(G),SZK_(G)) :: opacityBand
Expand Down Expand Up @@ -894,7 +894,6 @@ subroutine applyBoundaryFluxesInOut(CS, G, GV, dt, fluxes, optics, h, tv, &
do k=1,nz ; do i=is,ie
h2d(i,k) = h(i,j,k)
T2d(i,k) = tv%T(i,j,k)
hloss(i,k) = 0.0
do n=1,nsw
opacityBand(n,i,k) = (1.0 / GV%m_to_H)*optics%opacity_band(n,i,j,k)
enddo
Expand Down Expand Up @@ -1010,7 +1009,6 @@ subroutine applyBoundaryFluxesInOut(CS, G, GV, dt, fluxes, optics, h, tv, &
! Update state
hOld = h2d(i,k) ! Keep original thickness in hand
h2d(i,k) = h2d(i,k) + dThickness ! New thickness
hloss(i,k) = dThickness
if (h2d(i,k) > 0.0) then
if (calculate_energetics .and. (dThickness > 0.)) then
! Calculate the energy required to mix the newly added water over
Expand Down
22 changes: 6 additions & 16 deletions src/parameterizations/vertical/MOM_diabatic_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ module MOM_diabatic_driver
integer :: id_Tdif_z = -1, id_Tadv_z = -1, id_Sdif_z = -1, id_Sadv_z = -1
integer :: id_Tdif = -1, id_Tadv = -1, id_Sdif = -1, id_Sadv = -1
integer :: id_MLD_003 = -1, id_MLD_0125 = -1, id_MLD_user = -1, id_mlotstsq = -1
integer :: id_subMLN2 = -1, id_brine_lay = -1, id_hloss_boundary
integer :: id_subMLN2 = -1, id_brine_lay = -1

integer :: id_diabatic_diff_temp_tend = -1
integer :: id_diabatic_diff_saln_tend = -1
Expand Down Expand Up @@ -256,8 +256,7 @@ subroutine diabatic(u, v, h, tv, fluxes, visc, ADp, CDp, dt, G, GV, CS)
dSV_dS, & ! and salinity in m^3/(kg K) and m^3/(kg ppt).
cTKE, & ! convective TKE requirements for each layer in J/m^2.
u_h, & ! zonal and meridional velocities at thickness points after
v_h, & ! entrainment (m/s)
hloss_boundary ! Change in layer thickness because of freshwater fluxes at the surfac
v_h ! entrainment (m/s)

real, dimension(SZI_(G),SZJ_(G),CS%nMode) :: &
cn ! baroclinic gravity wave speeds (formerly cg1 - BDM)
Expand Down Expand Up @@ -331,7 +330,6 @@ subroutine diabatic(u, v, h, tv, fluxes, visc, ADp, CDp, dt, G, GV, CS)
! (H units = m for Bouss, kg/m^2 for non-Bouss).
real :: dt_mix ! amount of time over which to apply mixing (seconds)
real :: Idt ! inverse time step (1/s)
real, dimension(SZI_(G),SZJ_(G),SZK_(G)) :: write_all_3dt

type(p3d) :: z_ptrs(7) ! pointers to diagnostics to be interpolated to depth
integer :: num_z_diags ! number of diagnostics to be interpolated to depth
Expand Down Expand Up @@ -777,7 +775,6 @@ subroutine diabatic(u, v, h, tv, fluxes, visc, ADp, CDp, dt, G, GV, CS)
(0.5*(h(i,j,k-1) + h(i,j,k)) + h_neglect)
eb(i,j,k-1) = eb(i,j,k-1) + Ent_int
ea(i,j,k) = ea(i,j,k) + Ent_int
! eb(i,j,k-1) = ea(i,j,k)
Kd_int(i,j,K) = Kd_int(i,j,K) + Kd_add_here

! for diagnostics
Expand Down Expand Up @@ -1138,18 +1135,14 @@ subroutine diabatic(u, v, h, tv, fluxes, visc, ADp, CDp, dt, G, GV, CS)
eatr(i,j,k) = eatr(i,j,k) + add_ent
endif ; endif
enddo ; enddo

if (CS%useALEalgorithm) then
do i=is,ie ; eatr(i,j,1) = ea(i,j,1) ; enddo
else
do i=is,ie ; eatr(i,j,1) = ea(i,j,1) ; enddo
endif
do i=is,ie ; eatr(i,j,1) = ea(i,j,1) ; enddo

enddo

if (CS%useALEalgorithm) then
! For passive tracers, the changes in thickness due to boundary fluxes has yet to be applied
! so hold should be h_orig
call call_tracer_column_fns(h_prebound, h, eatr, ebtr, fluxes, dt, G, GV, tv, &
call call_tracer_column_fns(h_prebound, h, ea, eb, fluxes, dt, G, GV, tv, &
CS%optics, CS%tracer_flow_CSp, CS%debug, &
evap_CFL_limit = CS%diabatic_aux_CSp%evap_CFL_limit, &
minimum_forcing_depth = CS%diabatic_aux_CSp%minimum_forcing_depth)
Expand Down Expand Up @@ -1192,7 +1185,7 @@ subroutine diabatic(u, v, h, tv, fluxes, visc, ADp, CDp, dt, G, GV, CS)
else
if (CS%useALEalgorithm) then
! For passive tracers, the changes in thickness due to boundary fluxes has yet to be applied
call call_tracer_column_fns(h_prebound, h, ea, eb, fluxes, dt, G, GV, tv, &
call call_tracer_column_fns(h_prebound, h, eatr, ebtr, fluxes, dt, G, GV, tv, &
CS%optics, CS%tracer_flow_CSp, CS%debug, &
evap_CFL_limit = CS%diabatic_aux_CSp%evap_CFL_limit, &
minimum_forcing_depth = CS%diabatic_aux_CSp%minimum_forcing_depth)
Expand Down Expand Up @@ -1414,7 +1407,6 @@ subroutine diabatic(u, v, h, tv, fluxes, visc, ADp, CDp, dt, G, GV, CS)
if (CS%id_Kd_salt > 0) call post_data(CS%id_Kd_salt, Kd_salt, CS%diag)
if (CS%id_Kd_ePBL > 0) call post_data(CS%id_Kd_ePBL, Kd_ePBL, CS%diag)

write_all_3dt(:,:,:) = 1.
if (CS%id_ea > 0) call post_data(CS%id_ea, ea, CS%diag)
if (CS%id_eb > 0) call post_data(CS%id_eb, eb, CS%diag)

Expand Down Expand Up @@ -1938,8 +1930,6 @@ subroutine diabatic_driver_init(Time, G, GV, param_file, useALEalgorithm, diag,
'Layer entrainment from above per timestep','meter')
CS%id_eb = register_diag_field('ocean_model','eb',diag%axesTL,Time, &
'Layer entrainment from below per timestep', 'meter')
CS%id_hloss_boundary = register_diag_field('ocean_model','hloss_boundary',diag%axesTL,Time, &
'Layer thickness lost/gained due to fluxes at the boundary', 'meter')
CS%id_dudt_dia = register_diag_field('ocean_model','dudt_dia',diag%axesCuL,Time, &
'Zonal Acceleration from Diapycnal Mixing', 'meter second-2')
CS%id_dvdt_dia = register_diag_field('ocean_model','dvdt_dia',diag%axesCvL,Time, &
Expand Down
Loading

0 comments on commit 56a7685

Please sign in to comment.