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

Initial stochastic physics implementation #48

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
671c714
Merge pull request #1 from NOAA-EMC/dev/emc
pjpegion May 5, 2020
182ef34
additions for stochastic physics and ePBL perts
May 5, 2020
c2aa2a8
updates from dev/emc
May 5, 2020
3cad1ba
Merge pull request #8 from NOAA-EMC/dev/emc
pjpegion Oct 1, 2020
0a62737
Merge branch 'ocn_stoch' into dev/emc_merge
pjpegion Oct 1, 2020
9896d61
Merge pull request #9 from pjpegion/dev/emc_merge
pjpegion Oct 1, 2020
cd06356
Merge pull request #11 from NOAA-EMC/dev/emc
pjpegion Dec 2, 2020
7de295c
cleanup of code and enhancement of ePBL perts
pjpegion Dec 2, 2020
7212400
Update MOM_diabatic_driver.F90
pjpegion Dec 2, 2020
bd477a9
Update MOM_diabatic_driver.F90
pjpegion Dec 2, 2020
167a62e
Merge pull request #12 from pjpegion/dev/emc
pjpegion Dec 2, 2020
0c15f4c
Update MOM_diabatic_driver.F90
pjpegion Dec 2, 2020
a2a374b
add stochy_restart writing to mom_cap
pjpegion Dec 14, 2020
25ed5ef
additions for stochy restarts
pjpegion Dec 22, 2020
4bd9b9e
clean up debug statements
pjpegion Dec 23, 2020
1dc0f4f
Merge remote-tracking branch 'upstream/dev/emc' into dev/emc
pjpegion Dec 23, 2020
2cba995
Merge branch 'dev/emc' into ocn_stoch
pjpegion Dec 23, 2020
040e1f1
Merge pull request #13 from NOAA-EMC/dev/emc
pjpegion Jan 6, 2021
1d7ffa3
clean up code
pjpegion Jan 6, 2021
6bb9d0b
fix non stochastic ePBL calculation
pjpegion Jan 7, 2021
600ebf9
Merge remote-tracking branch 'upstream/dev/emc' into ocn_stoch
pjpegion Jan 22, 2021
1727d9a
re-write of stochastic code to remove CPP directives
pjpegion Jan 29, 2021
5443f8e
remove blank link in MOM_diagnostics
pjpegion Jan 29, 2021
80f9f44
clean up MOM_domains
pjpegion Jan 29, 2021
85023f8
Merge remote-tracking branch 'upstream/dev/emc' into ocn_stoch
pjpegion Feb 1, 2021
0b99c1f
make stochastics optional
pjpegion Feb 2, 2021
6e3ea1b
correct coupled_driver/ocean_model_MOM.F90 and other cleanup
pjpegion Feb 2, 2021
eb88219
clean up of code for MOM6 coding standards
pjpegion Feb 2, 2021
d984a7e
remove stochastics container
pjpegion Feb 4, 2021
b8d9888
place stochastic array in fluxes container and make SPPT specific arr…
pjpegion Feb 4, 2021
25ed4fc
revert MOM_domains.F90
pjpegion Feb 5, 2021
8afe969
clean up of mom_ocean_model_nuopc.F90
pjpegion Feb 5, 2021
689a73f
remove PE_here from mom_ocean_model_nuopc.F90
pjpegion Feb 5, 2021
a4c0411
Merge remote-tracking branch 'upstream/dev/emc' into ocn_stoch
pjpegion Feb 16, 2021
565e0bb
remove debug statements
pjpegion Feb 26, 2021
61717ee
Merge remote-tracking branch 'origin/dev/emc' into ocn_stoch
pjpegion Feb 26, 2021
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
15 changes: 15 additions & 0 deletions config_src/nuopc_driver/mom_cap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ module MOM_cap_mod
use NUOPC_Model, only: model_label_SetRunClock => label_SetRunClock
use NUOPC_Model, only: model_label_Finalize => label_Finalize
use NUOPC_Model, only: SetVM
#ifdef UFS
use get_stochy_pattern_mod, only: write_stoch_restart_ocn
#endif

implicit none; private

Expand Down Expand Up @@ -1584,6 +1587,18 @@ subroutine ModelAdvance(gcomp, rc)

! write restart file(s)
call ocean_model_restart(ocean_state, restartname=restartname)

DeniseWorthen marked this conversation as resolved.
Show resolved Hide resolved
! write stochastic physics restart file if active
#ifdef UFS
if (ESMF_AlarmIsRinging(stop_alarm, rc=rc)) then
write(restartname,'(A)')"ocn_stoch.res.nc"
else
write(restartname,'(A,I4.4,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2,A)') &
"ocn_stoch.res.", year, month, day, hour, minute, seconds,".nc"
endif
call ESMF_LogWrite("MOM_cap: Writing restart : "//trim(restartname), ESMF_LOGMSG_INFO)
call write_stoch_restart_ocn('RESTART/'//trim(restartname))
#endif
endif

if (is_root_pe()) then
Expand Down
26 changes: 26 additions & 0 deletions src/core/MOM.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module MOM
use MOM_domains, only : To_All, Omit_corners, CGRID_NE, SCALAR_PAIR
use MOM_domains, only : create_group_pass, do_group_pass, group_pass_type
use MOM_domains, only : start_group_pass, complete_group_pass, Omit_Corners
use MOM_domains, only : root_PE,PE_here,Get_PElist,num_PEs
use MOM_error_handler, only : MOM_error, MOM_mesg, FATAL, WARNING, is_root_pe
use MOM_error_handler, only : MOM_set_verbosity, callTree_showQuery
use MOM_error_handler, only : callTree_enter, callTree_leave, callTree_waypoint
Expand Down Expand Up @@ -141,6 +142,9 @@ module MOM
use MOM_offline_main, only : offline_fw_fluxes_into_ocean, offline_fw_fluxes_out_ocean
use MOM_offline_main, only : offline_advection_layer, offline_transport_end
use MOM_ALE, only : ale_offline_tracer_final, ALE_main_offline
#ifdef UFS
use stochastic_physics, only : init_stochastic_physics_ocn
#endif

implicit none ; private

Expand Down Expand Up @@ -1685,13 +1689,20 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
logical :: calc_dtbt ! Indicates whether the dynamically adjusted barotropic
! time step needs to be updated before it is used.
logical :: debug_truncations ! If true, turn on diagnostics useful for debugging truncations.
logical :: do_epbl,do_sppt
integer :: first_direction ! An integer that indicates which direction is to be
! updated first in directionally split parts of the
! calculation. This can be altered during the course
! of the run via calls to set_first_direction.
integer :: nkml, nkbl, verbosity, write_geom
integer :: dynamics_stencil ! The computational stencil for the calculations
! in the dynamic core.
integer,allocatable :: pelist(:) ! list of pes for this instance of the ocean
integer :: mom_comm ! list of pes for this instance of the ocean
integer :: num_procs ! number of processors to pass to stochastic physics
integer :: iret ! return code from stochastic physics
integer :: me ! my pe
integer :: master ! root pe
real :: conv2watt, conv2salt
real :: RL2_T2_rescale, Z_rescale, QRZ_rescale ! Unit conversion factors
character(len=48) :: flux_units, S_flux_units
Expand Down Expand Up @@ -2349,6 +2360,18 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
call copy_dyngrid_to_MOM_grid(dG_in, G_in, US)
call destroy_dyn_horgrid(dG_in)

do_epbl=.false.
do_sppt=.false.
#ifdef UFS
num_procs=num_PEs()
allocate(pelist(num_procs))
call Get_PElist(pelist,commID = mom_comm)
me=PE_here()
master=root_PE()

call init_stochastic_physics_ocn(CS%dt_therm,G%geoLonT,G%geoLatT,G%ied-G%isd+1,G%jed-G%jsd+1,nz,do_epbl,do_sppt,master,mom_comm,iret)
#endif

! Set a few remaining fields that are specific to the ocean grid type.
call set_first_direction(G, first_direction)
! Allocate the auxiliary non-symmetric domain for debugging or I/O purposes.
Expand Down Expand Up @@ -2761,6 +2784,9 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
! call fix_restart_scaling(GV)
! call fix_restart_unit_scaling(US)

CS%diabatic_CSp%do_epbl=do_epbl
CS%diabatic_CSp%do_sppt=do_sppt

call callTree_leave("initialize_MOM()")
call cpu_clock_end(id_clock_init)

Expand Down
1 change: 1 addition & 0 deletions src/diagnostics/MOM_diagnostics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,7 @@ subroutine register_surface_diags(Time, G, US, IDs, diag, tv)
'Heat flux into ocean from geothermal or other internal sources', &
'W m-2', conversion=US%QRZ_T_to_W_m2)


pjpegion marked this conversation as resolved.
Show resolved Hide resolved
end subroutine register_surface_diags

!> Register certain diagnostics related to transports
Expand Down
7 changes: 5 additions & 2 deletions src/framework/MOM_domains.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ module MOM_domains

! This file is part of MOM6. See LICENSE.md for the license.


use MOM_array_transform, only : rotate_array
use MOM_coms, only : PE_here, root_PE, num_PEs, MOM_infra_init, MOM_infra_end
use MOM_coms, only : PE_here, root_PE, num_PEs, MOM_infra_init, MOM_infra_end, Get_PElist
pjpegion marked this conversation as resolved.
Show resolved Hide resolved

use MOM_coms, only : PE_here, root_PE, num_PEs, MOM_infra_init, MOM_infra_end, Get_PElist
use MOM_coms, only : broadcast, sum_across_PEs, min_across_PEs, max_across_PEs
use MOM_cpu_clock, only : cpu_clock_begin, cpu_clock_end
use MOM_error_handler, only : MOM_error, MOM_mesg, NOTE, WARNING, FATAL, is_root_pe
Expand Down Expand Up @@ -37,7 +40,7 @@ module MOM_domains

public :: MOM_domains_init, MOM_infra_init, MOM_infra_end, get_domain_extent, get_domain_extent_dsamp2
public :: MOM_define_domain, MOM_define_io_domain, clone_MOM_domain
public :: pass_var, pass_vector, PE_here, root_PE, num_PEs
public :: pass_var, pass_vector, PE_here, root_PE, num_PEs, Get_PElist
pjpegion marked this conversation as resolved.
Show resolved Hide resolved
public :: pass_var_start, pass_var_complete, fill_symmetric_edges, broadcast
public :: pass_vector_start, pass_vector_complete
public :: global_field_sum, sum_across_PEs, min_across_PEs, max_across_PEs
Expand Down
82 changes: 75 additions & 7 deletions src/parameterizations/vertical/MOM_diabatic_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ module MOM_diabatic_driver
use MOM_verticalGrid, only : verticalGrid_type, get_thickness_units
use MOM_wave_speed, only : wave_speeds
use MOM_wave_interface, only : wave_parameters_CS
#ifdef UFS
use stochastic_physics, only : run_stochastic_physics_ocn
#endif


implicit none ; private
Expand Down Expand Up @@ -175,7 +178,7 @@ module MOM_diabatic_driver
integer :: id_Kd_heat = -1, id_Kd_salt = -1, id_Kd_interface = -1, id_Kd_ePBL = -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
integer :: id_subMLN2 = -1, id_sppt_wts = -1, id_t_rp1=-1,id_t_rp2=-1

! diagnostic for fields prior to applying diapycnal physics
integer :: id_u_predia = -1, id_v_predia = -1, id_h_predia = -1
Expand Down Expand Up @@ -207,6 +210,8 @@ module MOM_diabatic_driver
logical :: diabatic_diff_tendency_diag = .false. !< If true calculate diffusive tendency diagnostics
logical :: boundary_forcing_tendency_diag = .false. !< If true calculate frazil diagnostics
logical :: frazil_tendency_diag = .false. !< If true calculate frazil tendency diagnostics
logical,public :: do_epbl = .false. !< If true pertrub u_start in ePBL calculation
logical,public :: do_sppt = .false. !< If true perturb all physics tendenceies in MOM_diabatic_driver
real, allocatable, dimension(:,:,:) :: frazil_heat_diag !< diagnose 3d heat tendency from frazil
real, allocatable, dimension(:,:,:) :: frazil_temp_diag !< diagnose 3d temp tendency from frazil

Expand Down Expand Up @@ -287,8 +292,37 @@ subroutine diabatic(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end, &
integer :: i, j, k, m, is, ie, js, je, nz
logical :: showCallTree ! If true, show the call tree

real, dimension(SZI_(G),SZJ_(G)) :: sppt_wts
real, dimension(SZI_(G),SZJ_(G),2) :: t_rp
#ifdef UFS
real, dimension(SZI_(G),SZJ_(G),SZK_(G)) :: h_in
real, dimension(SZI_(G),SZJ_(G),SZK_(G)) :: t_in !< thickness [H ~> m or kg m-2]
real, dimension(SZI_(G),SZJ_(G),SZK_(G)) :: s_in !< thickness [H ~> m or kg m-2]
real :: t_tend,s_tend,h_tend ! holder for tendencey needed for SPPT
real :: t_pert,s_pert,h_pert ! holder for tendencey needed for SPPT
#endif

if (G%ke == 1) return

#ifdef UFS
! save copy of the date for SPPT
if (CS%do_sppt) then
h_in=h
t_in=tv%T
s_in=tv%S
endif
pjpegion marked this conversation as resolved.
Show resolved Hide resolved
call run_stochastic_physics_ocn(t_rp,sppt_wts)
if (CS%id_t_rp1 > 0) then
call post_data(CS%id_t_rp1, t_rp(:,:,1), CS%diag)
endif
if (CS%id_t_rp2 > 0) then
call post_data(CS%id_t_rp2, t_rp(:,:,2), CS%diag)
endif
if (CS%id_sppt_wts > 0) then
call post_data(CS%id_sppt_wts, sppt_wts, CS%diag)
endif
#endif

is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec ; nz = G%ke

if (.not. associated(CS)) call MOM_error(FATAL, "MOM_diabatic_driver: "// &
Expand Down Expand Up @@ -369,10 +403,10 @@ subroutine diabatic(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end, &
endif ! end CS%use_int_tides

if (CS%useALEalgorithm .and. CS%use_legacy_diabatic) then
call diabatic_ALE_legacy(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end, &
call diabatic_ALE_legacy(u, v, h, tv, Hml, fluxes, t_rp, visc, ADp, CDp, dt, Time_end, &
G, GV, US, CS, Waves)
elseif (CS%useALEalgorithm) then
call diabatic_ALE(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end, &
call diabatic_ALE(u, v, h, tv, Hml, fluxes, t_rp, visc, ADp, CDp, dt, Time_end, &
pjpegion marked this conversation as resolved.
Show resolved Hide resolved
G, GV, US, CS, Waves)
else
call layered_diabatic(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end, &
Expand Down Expand Up @@ -435,13 +469,39 @@ subroutine diabatic(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end, &

if (CS%debugConservation) call MOM_state_stats('leaving diabatic', u, v, h, tv%T, tv%S, G, GV, US)

#ifdef UFS
pjpegion marked this conversation as resolved.
Show resolved Hide resolved
if (CS%do_sppt) then
do k=1,nz
do j=js,je
do i=is,ie
h_tend = (h(i,j,k)-h_in(i,j,k))*sppt_wts(i,j)
t_tend = (tv%T(i,j,k)-t_in(i,j,k))*sppt_wts(i,j)
s_tend = (tv%S(i,j,k)-s_in(i,j,k))*sppt_wts(i,j)
h_pert=h_tend+h_in(i,j,k)
t_pert=t_tend+t_in(i,j,k)
s_pert=s_tend+s_in(i,j,k)
if (h_pert > GV%Angstrom_H) then
h(i,j,k)=h_pert
else
h(i,j,k)=GV%Angstrom_H
endif
tv%T(i,j,k)=t_pert
if (s_pert > 0.0) then
tv%S(i,j,k)=s_pert
endif
enddo
enddo
enddo
endif
#endif

end subroutine diabatic



!> Applies diabatic forcing and diapycnal mixing of temperature, salinity and other tracers for use
!! with an ALE algorithm. This version uses an older set of algorithms compared with diabatic_ALE.
subroutine diabatic_ALE_legacy(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end, &
subroutine diabatic_ALE_legacy(u, v, h, tv, Hml, fluxes, t_rp, visc, ADp, CDp, dt, Time_end, &
G, GV, US, CS, WAVES)
type(ocean_grid_type), intent(inout) :: G !< ocean grid structure
type(verticalGrid_type), intent(in) :: GV !< ocean vertical grid structure
Expand All @@ -454,6 +514,7 @@ subroutine diabatic_ALE_legacy(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Tim
real, dimension(:,:), pointer :: Hml !< Active mixed layer depth [Z ~> m]
type(forcing), intent(inout) :: fluxes !< points to forcing fields
!! unused fields have NULL ptrs
real, dimension(SZI_(G),SZJ_(G),2), intent(in) :: t_rp !< random pattern
type(vertvisc_type), intent(inout) :: visc !< vertical viscosities, BBL properies, and
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental removal of comment line continuation

type(accel_diag_ptrs), intent(inout) :: ADp !< related points to accelerations in momentum
!! equations, to enable the later derived
Expand Down Expand Up @@ -836,7 +897,7 @@ subroutine diabatic_ALE_legacy(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Tim
endif

call find_uv_at_h(u, v, h, u_h, v_h, G, GV, US)
call energetic_PBL(h, u_h, v_h, tv, fluxes, dt, Kd_ePBL, G, GV, US, &
call energetic_PBL(h, u_h, v_h, tv, fluxes, t_rp, CS%do_epbl, dt, Kd_ePBL, G, GV, US, &
CS%energetic_PBL_CSp, dSV_dT, dSV_dS, cTKE, SkinBuoyFlux, waves=waves)

if (associated(Hml)) then
Expand Down Expand Up @@ -1222,7 +1283,7 @@ end subroutine diabatic_ALE_legacy

!> This subroutine imposes the diapycnal mass fluxes and the
!! accompanying diapycnal advection of momentum and tracers.
subroutine diabatic_ALE(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end, &
subroutine diabatic_ALE(u, v, h, tv, Hml, fluxes, t_rp, visc, ADp, CDp, dt, Time_end, &
pjpegion marked this conversation as resolved.
Show resolved Hide resolved
G, GV, US, CS, Waves)
type(ocean_grid_type), intent(inout) :: G !< ocean grid structure
type(verticalGrid_type), intent(in) :: GV !< ocean vertical grid structure
Expand All @@ -1235,6 +1296,7 @@ subroutine diabatic_ALE(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end,
real, dimension(:,:), pointer :: Hml !< Active mixed layer depth [Z ~> m]
type(forcing), intent(inout) :: fluxes !< points to forcing fields
!! unused fields have NULL ptrs
real, dimension(SZI_(G),SZJ_(G),2), intent(in) :: t_rp !< random pattern
type(vertvisc_type), intent(inout) :: visc !< vertical viscosities, BBL properies, and
type(accel_diag_ptrs), intent(inout) :: ADp !< related points to accelerations in momentum
!! equations, to enable the later derived
Expand Down Expand Up @@ -1567,7 +1629,7 @@ subroutine diabatic_ALE(u, v, h, tv, Hml, fluxes, visc, ADp, CDp, dt, Time_end,
endif

call find_uv_at_h(u, v, h, u_h, v_h, G, GV, US)
call energetic_PBL(h, u_h, v_h, tv, fluxes, dt, Kd_ePBL, G, GV, US, &
call energetic_PBL(h, u_h, v_h, tv, fluxes, t_rp, CS%do_epbl, dt, Kd_ePBL, G, GV, US, &
CS%energetic_PBL_CSp, dSV_dT, dSV_dS, cTKE, SkinBuoyFlux, waves=waves)

if (associated(Hml)) then
Expand Down Expand Up @@ -3382,6 +3444,12 @@ subroutine diabatic_driver_init(Time, G, GV, US, param_file, useALEalgorithm, di
'Zonal Acceleration from Diapycnal Mixing', 'm s-2', conversion=US%L_T2_to_m_s2)
CS%id_dvdt_dia = register_diag_field('ocean_model', 'dvdt_dia', diag%axesCvL, Time, &
'Meridional Acceleration from Diapycnal Mixing', 'm s-2', conversion=US%L_T2_to_m_s2)
CS%id_t_rp1 = register_diag_field('ocean_model', 'random_pattern1', diag%axesT1, Time, &
'random pattern1 for stochastics', 'None')
CS%id_t_rp2 = register_diag_field('ocean_model', 'random_pattern2', diag%axesT1, Time, &
'random pattern2 for stochastics', 'None')
CS%id_sppt_wts = register_diag_field('ocean_model', 'sppt_pattern', diag%axesT1, Time, &
'random pattern for sppt', 'None')

if (CS%use_int_tides) then
CS%id_cg1 = register_diag_field('ocean_model', 'cn1', diag%axesT1, &
Expand Down
Loading