Skip to content

Commit e7c9ada

Browse files
committed
solve minor conflict in mom_cap.F90 mom_ocean_model_nuopc.F90 and MOM_energetic_PBL.F90, add two new files: src/parameterizations/stochastic/MOM_stochastics.F90 and config_src/external/stochastic_physics/stochastic_physics.F90
2 parents 90d5961 + 9cb9304 commit e7c9ada

5 files changed

Lines changed: 237 additions & 24 deletions

File tree

config_src/drivers/nuopc_cap/mom_cap.F90

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ module MOM_cap_mod
9898
use NUOPC_Model, only: model_label_Finalize => label_Finalize
9999
use NUOPC_Model, only: SetVM
100100

101-
use MOM_stochastics, only : write_mom_restart_stoch
102101
!$use omp_lib , only : omp_set_num_threads
103102

104103
implicit none; private
@@ -1526,7 +1525,7 @@ subroutine ModelAdvance(gcomp, rc)
15261525
integer :: nc
15271526
type(ESMF_Time) :: MyTime
15281527
integer :: seconds, day, year, month, hour, minute
1529-
character(ESMF_MAXSTR) :: restartname, cvalue
1528+
character(ESMF_MAXSTR) :: restartname, cvalue, stoch_restartname
15301529
character(240) :: msgString
15311530
character(ESMF_MAXSTR) :: casename
15321531
integer :: iostat
@@ -1740,26 +1739,19 @@ subroutine ModelAdvance(gcomp, rc)
17401739
! write the final restart without a timestamp
17411740
if (ESMF_AlarmIsRinging(stop_alarm, rc=rc)) then
17421741
write(restartname,'(A)')"MOM.res"
1742+
write(stoch_restartname,'(A)')"ocn_stoch.res.nc"
17431743
else
17441744
write(restartname,'(A,I4.4,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2)') &
17451745
"MOM.res.", year, month, day, hour, minute, seconds
1746+
write(stoch_restartname,'(A,I4.4,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2,A)') &
1747+
"ocn_stoch.res.", year, month, day, hour, minute, seconds,".nc"
17461748
endif
17471749
call ESMF_LogWrite("MOM_cap: Writing restart : "//trim(restartname), ESMF_LOGMSG_INFO)
17481750

17491751
! write restart file(s)
1750-
call ocean_model_restart(ocean_state, restartname=restartname)
1752+
call ocean_model_restart(ocean_state, restartname=restartname, &
1753+
stoch_restartname=stoch_restartname)
17511754

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
17631755
endif
17641756

17651757
if (is_root_pe()) then

config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ 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
65+
use get_stochy_pattern_mod, only : write_stoch_restart_ocn
6766
use iso_fortran_env, only : int64
6867

6968
#include <MOM_memory.h>
@@ -178,8 +177,10 @@ module MOM_ocean_model_nuopc
178177
!! steps can span multiple coupled time steps.
179178
logical :: diabatic_first !< If true, apply diabatic and thermodynamic
180179
!! 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
180+
logical :: do_sppt !< If true, stochastically perturb the diabatic and
181+
!! write restarts
182+
logical :: pert_epbl !< If true, then randomly perturb the KE dissipation and
183+
!! genration termsand write restarts
183184

184185
real :: eps_omesh !< Max allowable difference between ESMF mesh and MOM6
185186
!! domain coordinates
@@ -428,18 +429,18 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i
428429

429430
endif
430431

431-
! check to see if stochastic physics is active
432+
call extract_surface_state(OS%MOM_CSp, OS%sfc_state)
433+
! get number of processors and PE list for stocasthci physics initialization
432434
call get_param(param_file, mdl, "DO_SPPT", OS%do_sppt, &
433435
"If true, then stochastically perturb the thermodynamic "//&
434-
"tendemcies of T,S, amd h. Amplitude and correlations are "//&
436+
"tendencies of T,S, and h. Amplitude and correlations are "//&
435437
"controlled by the nam_stoch namelist in the UFS model only.", &
436438
default=.false.)
437439
call get_param(param_file, mdl, "PERT_EPBL", OS%pert_epbl, &
438440
"If true, then stochastically perturb the kinetic energy "//&
439441
"production and dissipation terms. Amplitude and correlations are "//&
440442
"controlled by the nam_stoch namelist in the UFS model only.", &
441443
default=.false.)
442-
call extract_surface_state(OS%MOM_CSp, OS%sfc_state)
443444

444445
call close_param_file(param_file)
445446
call diag_mediator_close_registration(OS%diag)
@@ -701,14 +702,17 @@ subroutine update_ocean_model(Ice_ocean_boundary, OS, Ocean_sfc, &
701702
end subroutine update_ocean_model
702703

703704
!> This subroutine writes out the ocean model restart file.
704-
subroutine ocean_model_restart(OS, timestamp, restartname, num_rest_files)
705+
subroutine ocean_model_restart(OS, timestamp, restartname, stoch_restartname, num_rest_files)
705706
type(ocean_state_type), pointer :: OS !< A pointer to the structure containing the
706707
!! internal ocean state being saved to a restart file
707708
character(len=*), optional, intent(in) :: timestamp !< An optional timestamp string that should be
708709
!! prepended to the file name. (Currently this is unused.)
709710
character(len=*), optional, intent(in) :: restartname !< Name of restart file to use
710711
!! This option distinguishes the cesm interface from the
711712
!! non-cesm interface
713+
character(len=*), optional, intent(in) :: stoch_restartname !< Name of restart file to use
714+
!! This option distinguishes the cesm interface from the
715+
!! non-cesm interface
712716
integer, optional, intent(out) :: num_rest_files !< number of restart files written
713717

714718
if (.not.MOM_state_is_synchronized(OS%MOM_CSp)) &
@@ -748,6 +752,11 @@ subroutine ocean_model_restart(OS, timestamp, restartname, num_rest_files)
748752
endif
749753
endif
750754
endif
755+
if (present(stoch_restartname)) then
756+
if (OS%do_sppt .OR. OS%pert_epbl) then
757+
call write_stoch_restart_ocn('RESTART/'//trim(stoch_restartname))
758+
endif
759+
endif
751760

752761
end subroutine ocean_model_restart
753762
! </SUBROUTINE> NAME="ocean_model_restart"
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
! The are stubs for ocean stochastic physics
2+
! the fully functional code is available at
3+
! http://github.com/noaa-psd/stochastic_physics
4+
module stochastic_physics
5+
6+
implicit none
7+
8+
private
9+
10+
public :: init_stochastic_physics_ocn
11+
public :: run_stochastic_physics_ocn
12+
13+
contains
14+
15+
!!!!!!!!!!!!!!!!!!!!
16+
subroutine init_stochastic_physics_ocn(delt,geoLonT,geoLatT,nx,ny,nz,pert_epbl_in,do_sppt_in, &
17+
mpiroot, mpicomm, iret)
18+
implicit none
19+
real,intent(in) :: delt !< timestep in seconds between calls to run_stochastic_physics_ocn
20+
integer,intent(in) :: nx !< number of gridpoints in the x-direction of the compute grid
21+
integer,intent(in) :: ny !< number of gridpoints in the y-direction of the compute grid
22+
integer,intent(in) :: nz !< number of gridpoints in the z-direction of the compute grid
23+
real,intent(in) :: geoLonT(nx,ny) !< Longitude in degrees
24+
real,intent(in) :: geoLatT(nx,ny) !< Latitude in degrees
25+
logical,intent(in) :: pert_epbl_in !< logical flag, if true generate random pattern for ePBL perturbations
26+
logical,intent(in) :: do_sppt_in !< logical flag, if true generate random pattern for SPPT perturbations
27+
integer,intent(in) :: mpiroot !< root processor
28+
integer,intent(in) :: mpicomm !< mpi communicator
29+
integer, intent(out) :: iret !< return code
30+
31+
iret=0
32+
if (pert_epbl_in .EQV. .true. ) then
33+
print*,'pert_epbl needs to be false if using the stub'
34+
iret=-1
35+
endif
36+
if (do_sppt_in.EQV. .true. ) then
37+
print*,'do_sppt needs to be false if using the stub'
38+
iret=-1
39+
endif
40+
return
41+
end subroutine init_stochastic_physics_ocn
42+
43+
subroutine run_stochastic_physics_ocn(sppt_wts,t_rp1,t_rp2)
44+
implicit none
45+
real, intent(inout) :: sppt_wts(:,:) !< array containing random weights for SPPT range [0,2]
46+
real, intent(inout) :: t_rp1(:,:) !< array containing random weights for ePBL
47+
!! perturbations (KE generation) range [0,2]
48+
real, intent(inout) :: t_rp2(:,:) !< array containing random weights for ePBL
49+
!! perturbations (KE dissipation) range [0,2]
50+
return
51+
end subroutine run_stochastic_physics_ocn
52+
53+
end module stochastic_physics
54+
55+
module get_stochy_pattern_mod
56+
57+
private
58+
59+
public :: write_stoch_restart_ocn
60+
61+
contains
62+
subroutine write_stoch_restart_ocn(sfile)
63+
64+
character(len=*) :: sfile !< name of restart file
65+
return
66+
end subroutine write_stoch_restart_ocn
67+
68+
end module get_stochy_pattern_mod
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
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+
integer :: id_sppt_wts = -1 !< Diagnostic id for SPPT
34+
integer :: id_epbl1_wts=-1 !< Diagnostic id for epbl generation perturbation
35+
integer :: id_epbl2_wts=-1 !< Diagnostic id for epbl dissipation perturbation
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 !< stochastic control structure
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 :: pe_zero ! 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+
pe_zero=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,pe_zero,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+
end module MOM_stochastics
144+

src/parameterizations/vertical/MOM_energetic_PBL.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,8 @@ subroutine ePBL_column(h, u, v, T0, S0, dSV_dT, dSV_dS, TKE_forcing, B_flux, abs
600600
optional, pointer :: Waves !< Wave CS for Langmuir turbulence
601601
type(ocean_grid_type), &
602602
optional, intent(inout) :: G !< The ocean's grid structure.
603-
real, optional, intent(in) :: epbl1_wt ! random number to perturb KE generation
604-
real, optional, intent(in) :: epbl2_wt ! random number to perturb KE dissipation
603+
real, optional, intent(in) :: epbl1_wt !< random number to perturb KE generation
604+
real, optional, intent(in) :: epbl2_wt !< random number to perturb KE dissipation
605605
integer, optional, intent(in) :: i !< The i-index to work on (used for Waves)
606606
integer, optional, intent(in) :: j !< The i-index to work on (used for Waves)
607607

0 commit comments

Comments
 (0)