Skip to content

Commit 36f17eb

Browse files
authored
Merge pull request mom-ocean#72 from pjpegion/ocn_stoch_july2021
Ocean stochastic physics
2 parents 14ca4a1 + a9a957e commit 36f17eb

7 files changed

Lines changed: 357 additions & 20 deletions

File tree

config_src/drivers/nuopc_cap/mom_cap.F90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ module MOM_cap_mod
9797
use NUOPC_Model, only: model_label_SetRunClock => label_SetRunClock
9898
use NUOPC_Model, only: model_label_Finalize => label_Finalize
9999
use NUOPC_Model, only: SetVM
100+
101+
use MOM_stochastics, only : write_mom_restart_stoch
100102
!$use omp_lib , only : omp_set_num_threads
101103

102104
implicit none; private
@@ -1746,6 +1748,18 @@ subroutine ModelAdvance(gcomp, rc)
17461748

17471749
! write restart file(s)
17481750
call ocean_model_restart(ocean_state, restartname=restartname)
1751+
1752+
if (ocean_state%do_sppt .OR. ocean_state%pert_epbl) then
1753+
if (ESMF_AlarmIsRinging(stop_alarm, rc=rc)) then
1754+
write(restartname,'(A)')"ocn_stoch.res.nc"
1755+
else
1756+
write(restartname,'(A,I4.4,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2,A)') &
1757+
"ocn_stoch.res.", year, month, day, hour, minute, seconds,".nc"
1758+
endif
1759+
call ESMF_LogWrite("MOM_cap: Writing stoch restart : "//trim(restartname), &
1760+
ESMF_LOGMSG_INFO)
1761+
call write_mom_restart_stoch('RESTART/'//trim(restartname))
1762+
endif
17491763
endif
17501764

17511765
if (is_root_pe()) then

config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ module MOM_ocean_model_nuopc
6262
use MOM_surface_forcing_nuopc, only : convert_IOB_to_forces, ice_ocn_bnd_type_chksum
6363
use MOM_surface_forcing_nuopc, only : ice_ocean_boundary_type, surface_forcing_CS
6464
use MOM_surface_forcing_nuopc, only : forcing_save_restart
65+
use MOM_domains, only : root_PE,num_PEs
66+
use MOM_coms, only : Get_PElist
6567
use iso_fortran_env, only : int64
6668

6769
#include <MOM_memory.h>
@@ -176,6 +178,8 @@ module MOM_ocean_model_nuopc
176178
!! steps can span multiple coupled time steps.
177179
logical :: diabatic_first !< If true, apply diabatic and thermodynamic
178180
!! processes before time stepping the dynamics.
181+
logical,public :: do_sppt !< If true, write stochastic physics restarts
182+
logical,public :: pert_epbl !< If true, write stochastic physics restarts
179183

180184
real :: eps_omesh !< Max allowable difference between ESMF mesh and MOM6
181185
!! domain coordinates
@@ -424,6 +428,17 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
424428

425429
endif
426430

431+
! check to see if stochastic physics is active
432+
call get_param(param_file, mdl, "DO_SPPT", OS%do_sppt, &
433+
"If true, then stochastically perturb the thermodynamic "//&
434+
"tendemcies of T,S, amd h. Amplitude and correlations are "//&
435+
"controlled by the nam_stoch namelist in the UFS model only.", &
436+
default=.false.)
437+
call get_param(param_file, mdl, "PERT_EPBL", OS%pert_epbl, &
438+
"If true, then stochastically perturb the kinetic energy "//&
439+
"production and dissipation terms. Amplitude and correlations are "//&
440+
"controlled by the nam_stoch namelist in the UFS model only.", &
441+
default=.false.)
427442
call extract_surface_state(OS%MOM_CSp, OS%sfc_state)
428443

429444
call close_param_file(param_file)
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
!> Top-level module for the MOM6 ocean model in coupled mode.
2+
module MOM_stochastics
3+
4+
! This file is part of MOM6. See LICENSE.md for the license.
5+
6+
! This is the top level module for the MOM6 ocean model. It contains routines
7+
! for initialization, update, and writing restart of stochastic physics. This
8+
! particular version wraps all of the calls for MOM6 in the calls that had
9+
! been used for MOM4.
10+
!
11+
use MOM_diag_mediator, only : register_diag_field, diag_ctrl, time_type
12+
use MOM_grid, only : ocean_grid_type
13+
use MOM_verticalGrid, only : verticalGrid_type
14+
use MOM_error_handler, only : MOM_error, FATAL, WARNING, is_root_pe
15+
use MOM_error_handler, only : callTree_enter, callTree_leave
16+
use MOM_file_parser, only : get_param, log_version, close_param_file, param_file_type
17+
use mpp_domains_mod, only : domain2d, mpp_get_layout, mpp_get_global_domain
18+
use mpp_domains_mod, only : mpp_define_domains, mpp_get_compute_domain, mpp_get_data_domain
19+
use MOM_domains, only : root_PE,num_PEs
20+
use MOM_coms, only : Get_PElist
21+
use stochastic_physics, only : init_stochastic_physics_ocn, run_stochastic_physics_ocn
22+
use get_stochy_pattern_mod, only: write_stoch_restart_ocn
23+
24+
#include <MOM_memory.h>
25+
26+
implicit none ; private
27+
28+
public stochastics_init, update_stochastics, write_mom_restart_stoch
29+
30+
!> This control structure holds parameters for the MOM_stochastics module
31+
type, public:: stochastic_CS
32+
logical :: do_sppt !< If true, stochastically perturb the diabatic
33+
logical :: pert_epbl !! If true, then randomly perturb the KE dissipation and genration terms
34+
integer :: id_sppt_wts = -1
35+
integer :: id_epbl1_wts=-1,id_epbl2_wts=-1
36+
! stochastic patterns
37+
real, allocatable :: sppt_wts(:,:) !< Random pattern for ocean SPPT
38+
!! tendencies with a number between 0 and 2
39+
real, allocatable :: epbl1_wts(:,:) !< Random pattern for K.E. generation
40+
real, allocatable :: epbl2_wts(:,:) !< Random pattern for K.E. dissipation
41+
type(diag_ctrl), pointer :: diag !< structure used to regulate timing of diagnostic output
42+
type(time_type), pointer :: Time !< Pointer to model time (needed for sponges)
43+
end type stochastic_CS
44+
45+
contains
46+
47+
!! This subroutine initializes the stochastics physics control structure.
48+
subroutine stochastics_init(dt, grid, GV, CS, param_file, diag, Time)
49+
real, intent(in) :: dt !< time step [T ~> s]
50+
type(ocean_grid_type), intent(in) :: grid ! horizontal grid information
51+
type(verticalGrid_type), intent(in) :: GV ! vertical grid structure
52+
type(stochastic_CS), pointer, intent(inout):: CS
53+
type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters
54+
type(diag_ctrl), target, intent(inout) :: diag !< structure to regulate diagnostic output
55+
type(time_type), target :: Time !< model time
56+
! Local variables
57+
integer,allocatable :: pelist(:) ! list of pes for this instance of the ocean
58+
integer :: mom_comm ! list of pes for this instance of the ocean
59+
integer :: num_procs ! number of processors to pass to stochastic physics
60+
integer :: iret ! return code from stochastic physics
61+
integer :: me ! my pe
62+
integer :: master ! root pe
63+
integer :: nx ! number of x-points including halo
64+
integer :: ny ! number of x-points including halo
65+
66+
! This include declares and sets the variable "version".
67+
#include "version_variable.h"
68+
character(len=40) :: mdl = "ocean_stochastics_init" ! This module's name.
69+
70+
call callTree_enter("ocean_model_stochastic_init(), MOM_stochastics.F90")
71+
if (associated(CS)) then
72+
call MOM_error(WARNING, "MOM_stochastics_init called with an "// &
73+
"associated control structure.")
74+
return
75+
else ; allocate(CS) ; endif
76+
77+
CS%diag => diag
78+
CS%Time => Time
79+
80+
! Read all relevant parameters and write them to the model log.
81+
call log_version(param_file, mdl, version, "")
82+
83+
! get number of processors and PE list for stocasthci physics initialization
84+
call get_param(param_file, mdl, "DO_SPPT", CS%do_sppt, &
85+
"If true, then stochastically perturb the thermodynamic "//&
86+
"tendemcies of T,S, amd h. Amplitude and correlations are "//&
87+
"controlled by the nam_stoch namelist in the UFS model only.", &
88+
default=.false.)
89+
call get_param(param_file, mdl, "PERT_EPBL", CS%pert_epbl, &
90+
"If true, then stochastically perturb the kinetic energy "//&
91+
"production and dissipation terms. Amplitude and correlations are "//&
92+
"controlled by the nam_stoch namelist in the UFS model only.", &
93+
default=.false.)
94+
if (CS%do_sppt .OR. CS%pert_epbl) then
95+
num_procs=num_PEs()
96+
allocate(pelist(num_procs))
97+
call Get_PElist(pelist,commID = mom_comm)
98+
master=root_PE()
99+
nx = grid%ied - grid%isd + 1
100+
ny = grid%jed - grid%jsd + 1
101+
call init_stochastic_physics_ocn(dt,grid%geoLonT,grid%geoLatT,nx,ny,GV%ke, &
102+
CS%pert_epbl,CS%do_sppt,master,mom_comm,iret)
103+
if (iret/=0) then
104+
call MOM_error(FATAL, "call to init_stochastic_physics_ocn failed")
105+
return
106+
endif
107+
108+
if (CS%do_sppt) allocate(CS%sppt_wts(grid%isd:grid%ied,grid%jsd:grid%jed))
109+
if (CS%pert_epbl) then
110+
allocate(CS%epbl1_wts(grid%isd:grid%ied,grid%jsd:grid%jed))
111+
allocate(CS%epbl2_wts(grid%isd:grid%ied,grid%jsd:grid%jed))
112+
endif
113+
endif
114+
CS%id_sppt_wts = register_diag_field('ocean_model', 'sppt_pattern', CS%diag%axesT1, Time, &
115+
'random pattern for sppt', 'None')
116+
CS%id_epbl1_wts = register_diag_field('ocean_model', 'epbl1_wts', CS%diag%axesT1, Time, &
117+
'random pattern for KE generation', 'None')
118+
CS%id_epbl2_wts = register_diag_field('ocean_model', 'epbl2_wts', CS%diag%axesT1, Time, &
119+
'random pattern for KE dissipation', 'None')
120+
121+
if (is_root_pe()) &
122+
write(*,'(/12x,a/)') '=== COMPLETED MOM STOCHASTIC INITIALIZATION ====='
123+
124+
call callTree_leave("ocean_model_init(")
125+
return
126+
end subroutine stochastics_init
127+
128+
!> update_ocean_model uses the forcing in Ice_ocean_boundary to advance the
129+
!! ocean model's state from the input value of Ocean_state (which must be for
130+
!! time time_start_update) for a time interval of Ocean_coupling_time_step,
131+
!! returning the publicly visible ocean surface properties in Ocean_sfc and
132+
!! storing the new ocean properties in Ocean_state.
133+
subroutine update_stochastics(CS)
134+
type(stochastic_CS), intent(inout) :: CS !< diabatic control structure
135+
call callTree_enter("update_stochastics(), MOM_stochastics.F90")
136+
137+
! update stochastic physics patterns before running next time-step
138+
call run_stochastic_physics_ocn(CS%sppt_wts,CS%epbl1_wts,CS%epbl2_wts)
139+
140+
return
141+
end subroutine update_stochastics
142+
143+
!< wrapper to write ocean stochastic restarts
144+
subroutine write_mom_restart_stoch(filename)
145+
character(len=*) :: filename
146+
147+
call callTree_enter("write_mom_restart_stoch(), MOM_stochastics.F90")
148+
149+
call write_stoch_restart_ocn(filename)
150+
151+
return
152+
end subroutine write_mom_restart_stoch
153+
154+
end module MOM_stochastics
155+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
!> Top-level module for the MOM6 ocean model in coupled mode.
2+
module MOM_stochastics
3+
4+
! This file is part of MOM6. See LICENSE.md for the license.
5+
6+
! This is the top level module for the MOM6 ocean model. It contains
7+
! placeholder for initialization, update, and writing restarts of ocean stochastic physics.
8+
! The actualy stochastic physics is available at
9+
! https://github.com/ufs-community/ufs-weather-model
10+
!
11+
12+
use MOM_diag_mediator, only : register_diag_field, diag_ctrl, time_type
13+
use MOM_grid, only : ocean_grid_type
14+
use MOM_verticalGrid, only : verticalGrid_type
15+
use MOM_error_handler, only : MOM_error, FATAL, WARNING, is_root_pe
16+
use MOM_error_handler, only : callTree_enter, callTree_leave
17+
use MOM_file_parser, only : get_param, log_version, close_param_file, param_file_type
18+
use mpp_domains_mod, only : domain2d, mpp_get_layout, mpp_get_global_domain
19+
use mpp_domains_mod, only : mpp_define_domains, mpp_get_compute_domain, mpp_get_data_domain
20+
use MOM_domains, only : root_PE,num_PEs
21+
use MOM_coms, only : Get_PElist
22+
23+
#include <MOM_memory.h>
24+
25+
implicit none ; private
26+
27+
public stochastics_init, update_stochastics
28+
29+
!> This control structure holds parameters for the MOM_stochastics module
30+
type, public:: stochastic_CS
31+
logical :: do_sppt !< If true, stochastically perturb the diabatic
32+
logical :: pert_epbl !< If true, then randomly perturb the KE dissipation and genration terms
33+
!>@{ Diagnostic IDs
34+
integer :: id_sppt_wts = -1
35+
integer :: id_epbl1_wts=-1,id_epbl2_wts=-1
36+
!>@}
37+
! stochastic patterns
38+
real, allocatable :: sppt_wts(:,:) !< Random pattern for ocean SPPT
39+
!! tendencies with a number between 0 and 2
40+
real, allocatable :: epbl1_wts(:,:) !< Random pattern for K.E. generation
41+
real, allocatable :: epbl2_wts(:,:) !< Random pattern for K.E. dissipation
42+
type(diag_ctrl), pointer :: diag !< structure used to regulate timing of diagnostic output
43+
type(time_type), pointer :: Time !< Pointer to model time (needed for sponges)
44+
end type stochastic_CS
45+
46+
contains
47+
48+
subroutine stochastics_init(dt, grid, GV, CS, param_file, diag, Time)
49+
real, intent(in) :: dt !< time step [T ~> s]
50+
type(ocean_grid_type), intent(in) :: grid ! horizontal grid information
51+
type(verticalGrid_type), intent(in) :: GV ! vertical grid structure
52+
type(stochastic_CS), pointer, intent(inout):: CS
53+
type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters
54+
type(diag_ctrl), target, intent(inout) :: diag !< structure to regulate diagnostic output
55+
type(time_type), target :: Time !< model time
56+
return
57+
end subroutine stochastics_init
58+
59+
subroutine update_stochastics(CS)
60+
type(stochastic_CS), intent(inout) :: CS !< diabatic control structure
61+
return
62+
end subroutine update_stochastics
63+
subroutine write_mom_restart_stoch(filename)
64+
character(len=*) :: filename
65+
return
66+
end subroutine write_mom_restart_stoch
67+
end module MOM_stochastics
68+

src/core/MOM.F90

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module MOM
5959
use MOM_coord_initialization, only : MOM_initialize_coord
6060
use MOM_diabatic_driver, only : diabatic, diabatic_driver_init, diabatic_CS, extract_diabatic_member
6161
use MOM_diabatic_driver, only : adiabatic, adiabatic_driver_init, diabatic_driver_end
62+
use MOM_stochastics, only : stochastics_init, update_stochastics, stochastic_CS
6263
use MOM_diagnostics, only : calculate_diagnostic_fields, MOM_diagnostics_init
6364
use MOM_diagnostics, only : register_transport_diags, post_transport_diagnostics
6465
use MOM_diagnostics, only : register_surface_diags, write_static_fields
@@ -391,6 +392,7 @@ module MOM
391392
type(ODA_CS), pointer :: odaCS => NULL() !< a pointer to the control structure for handling
392393
!! ensemble model state vectors and data assimilation
393394
!! increments and priors
395+
type(stochastic_CS), pointer :: stoch_CS => NULL() !< a pointer to the stochastics control structure
394396
end type MOM_control_struct
395397

396398
public initialize_MOM, finish_MOM_initialization, MOM_end
@@ -635,6 +637,8 @@ subroutine step_MOM(forces_in, fluxes_in, sfc_state, Time_start, time_int_in, CS
635637
call disable_averaging(CS%diag)
636638
endif
637639
endif
640+
! advance the random pattern if stochastic physics is active
641+
if (CS%stoch_CS%do_sppt .OR. CS%stoch_CS%pert_epbl) call update_stochastics(CS%stoch_CS)
638642

639643
if (do_dyn) then
640644
if (G%nonblocking_updates) &
@@ -785,6 +789,7 @@ subroutine step_MOM(forces_in, fluxes_in, sfc_state, Time_start, time_int_in, CS
785789
enddo ; enddo
786790
endif
787791

792+
788793
call step_MOM_dynamics(forces, CS%p_surf_begin, CS%p_surf_end, dt, &
789794
dt_therm_here, bbl_time_int, CS, &
790795
Time_local, Waves=Waves)
@@ -1316,7 +1321,7 @@ subroutine step_MOM_thermo(CS, G, GV, US, u, v, h, tv, fluxes, dtdia, &
13161321
call cpu_clock_begin(id_clock_diabatic)
13171322

13181323
call diabatic(u, v, h, tv, CS%Hml, fluxes, CS%visc, CS%ADp, CS%CDp, dtdia, &
1319-
Time_end_thermo, G, GV, US, CS%diabatic_CSp, OBC=CS%OBC, Waves=Waves)
1324+
Time_end_thermo, G, GV, US, CS%diabatic_CSp, CS%stoch_CS,OBC=CS%OBC, Waves=Waves)
13201325
fluxes%fluxes_used = .true.
13211326

13221327
if (showCallTree) call callTree_waypoint("finished diabatic (step_MOM_thermo)")
@@ -2814,6 +2819,9 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
28142819
call init_oda(Time, G, GV, CS%odaCS)
28152820
endif
28162821

2822+
! initialize stochastic physics
2823+
call stochastics_init(CS%dt_therm, CS%G, CS%GV, CS%stoch_CS, param_file, diag, Time)
2824+
28172825
!### This could perhaps go here instead of in finish_MOM_initialization?
28182826
! call fix_restart_scaling(GV)
28192827
! call fix_restart_unit_scaling(US)

0 commit comments

Comments
 (0)