diff --git a/config_src/drivers/nuopc_cap/mom_cap.F90 b/config_src/drivers/nuopc_cap/mom_cap.F90 index 0bad9638f4..652f9e5b47 100644 --- a/config_src/drivers/nuopc_cap/mom_cap.F90 +++ b/config_src/drivers/nuopc_cap/mom_cap.F90 @@ -98,7 +98,6 @@ module MOM_cap_mod use NUOPC_Model, only: model_label_Finalize => label_Finalize use NUOPC_Model, only: SetVM -use MOM_stochastics, only : write_mom_restart_stoch !$use omp_lib , only : omp_set_num_threads implicit none; private @@ -1526,7 +1525,7 @@ subroutine ModelAdvance(gcomp, rc) integer :: nc type(ESMF_Time) :: MyTime integer :: seconds, day, year, month, hour, minute - character(ESMF_MAXSTR) :: restartname, cvalue + character(ESMF_MAXSTR) :: restartname, cvalue, stoch_restartname character(240) :: msgString character(ESMF_MAXSTR) :: casename integer :: iostat @@ -1740,26 +1739,19 @@ subroutine ModelAdvance(gcomp, rc) ! write the final restart without a timestamp if (ESMF_AlarmIsRinging(stop_alarm, rc=rc)) then write(restartname,'(A)')"MOM.res" + write(stoch_restartname,'(A)')"ocn_stoch.res.nc" else write(restartname,'(A,I4.4,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2)') & "MOM.res.", year, month, day, hour, minute, seconds + write(stoch_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) ! write restart file(s) - call ocean_model_restart(ocean_state, restartname=restartname) + call ocean_model_restart(ocean_state, restartname=restartname, & + stoch_restartname=stoch_restartname) - if (ocean_state%do_sppt .OR. ocean_state%pert_epbl) then - 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 stoch restart : "//trim(restartname), & - ESMF_LOGMSG_INFO) - call write_mom_restart_stoch('RESTART/'//trim(restartname)) - endif endif if (is_root_pe()) then diff --git a/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90 b/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90 index 1064c13d85..448f23140e 100644 --- a/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90 +++ b/config_src/drivers/nuopc_cap/mom_ocean_model_nuopc.F90 @@ -62,8 +62,7 @@ module MOM_ocean_model_nuopc use MOM_surface_forcing_nuopc, only : convert_IOB_to_forces, ice_ocn_bnd_type_chksum use MOM_surface_forcing_nuopc, only : ice_ocean_boundary_type, surface_forcing_CS use MOM_surface_forcing_nuopc, only : forcing_save_restart -use MOM_domains, only : root_PE,num_PEs -use MOM_coms, only : Get_PElist +use get_stochy_pattern_mod, only : write_stoch_restart_ocn use iso_fortran_env, only : int64 #include @@ -178,8 +177,10 @@ module MOM_ocean_model_nuopc !! steps can span multiple coupled time steps. logical :: diabatic_first !< If true, apply diabatic and thermodynamic !! processes before time stepping the dynamics. - logical,public :: do_sppt !< If true, write stochastic physics restarts - logical,public :: pert_epbl !< If true, write stochastic physics restarts + logical :: do_sppt !< If true, stochastically perturb the diabatic and + !! write restarts + logical :: pert_epbl !< If true, then randomly perturb the KE dissipation and + !! genration termsand write restarts real :: eps_omesh !< Max allowable difference between ESMF mesh and MOM6 !! domain coordinates @@ -428,10 +429,11 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i endif - ! check to see if stochastic physics is active + call extract_surface_state(OS%MOM_CSp, OS%sfc_state) +! get number of processors and PE list for stocasthci physics initialization call get_param(param_file, mdl, "DO_SPPT", OS%do_sppt, & "If true, then stochastically perturb the thermodynamic "//& - "tendemcies of T,S, amd h. Amplitude and correlations are "//& + "tendencies of T,S, and h. Amplitude and correlations are "//& "controlled by the nam_stoch namelist in the UFS model only.", & default=.false.) call get_param(param_file, mdl, "PERT_EPBL", OS%pert_epbl, & @@ -439,7 +441,6 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i "production and dissipation terms. Amplitude and correlations are "//& "controlled by the nam_stoch namelist in the UFS model only.", & default=.false.) - call extract_surface_state(OS%MOM_CSp, OS%sfc_state) call close_param_file(param_file) call diag_mediator_close_registration(OS%diag) @@ -701,7 +702,7 @@ subroutine update_ocean_model(Ice_ocean_boundary, OS, Ocean_sfc, & end subroutine update_ocean_model !> This subroutine writes out the ocean model restart file. -subroutine ocean_model_restart(OS, timestamp, restartname, num_rest_files) +subroutine ocean_model_restart(OS, timestamp, restartname, stoch_restartname, num_rest_files) type(ocean_state_type), pointer :: OS !< A pointer to the structure containing the !! internal ocean state being saved to a restart file character(len=*), optional, intent(in) :: timestamp !< An optional timestamp string that should be @@ -709,6 +710,9 @@ subroutine ocean_model_restart(OS, timestamp, restartname, num_rest_files) character(len=*), optional, intent(in) :: restartname !< Name of restart file to use !! This option distinguishes the cesm interface from the !! non-cesm interface + character(len=*), optional, intent(in) :: stoch_restartname !< Name of restart file to use + !! This option distinguishes the cesm interface from the + !! non-cesm interface integer, optional, intent(out) :: num_rest_files !< number of restart files written if (.not.MOM_state_is_synchronized(OS%MOM_CSp)) & @@ -748,6 +752,11 @@ subroutine ocean_model_restart(OS, timestamp, restartname, num_rest_files) endif endif endif + if (present(stoch_restartname)) then + if (OS%do_sppt .OR. OS%pert_epbl) then + call write_stoch_restart_ocn('RESTART/'//trim(stoch_restartname)) + endif + endif end subroutine ocean_model_restart ! NAME="ocean_model_restart" diff --git a/config_src/external/OCEAN_stochastic_phyiscs/MOM_stochastics_stub.F90 b/config_src/external/OCEAN_stochastic_phyiscs/MOM_stochastics_stub.F90 deleted file mode 100644 index 349d56c0c7..0000000000 --- a/config_src/external/OCEAN_stochastic_phyiscs/MOM_stochastics_stub.F90 +++ /dev/null @@ -1,68 +0,0 @@ -!> Top-level module for the MOM6 ocean model in coupled mode. -module MOM_stochastics - -! This file is part of MOM6. See LICENSE.md for the license. - -! This is the top level module for the MOM6 ocean model. It contains -! placeholder for initialization, update, and writing restarts of ocean stochastic physics. -! The actualy stochastic physics is available at -! https://github.com/ufs-community/ufs-weather-model -! - -use MOM_diag_mediator, only : register_diag_field, diag_ctrl, time_type -use MOM_grid, only : ocean_grid_type -use MOM_verticalGrid, only : verticalGrid_type -use MOM_error_handler, only : MOM_error, FATAL, WARNING, is_root_pe -use MOM_error_handler, only : callTree_enter, callTree_leave -use MOM_file_parser, only : get_param, log_version, close_param_file, param_file_type -use mpp_domains_mod, only : domain2d, mpp_get_layout, mpp_get_global_domain -use mpp_domains_mod, only : mpp_define_domains, mpp_get_compute_domain, mpp_get_data_domain -use MOM_domains, only : root_PE,num_PEs -use MOM_coms, only : Get_PElist - -#include - -implicit none ; private - -public stochastics_init, update_stochastics - -!> This control structure holds parameters for the MOM_stochastics module -type, public:: stochastic_CS - logical :: do_sppt !< If true, stochastically perturb the diabatic - logical :: pert_epbl !< If true, then randomly perturb the KE dissipation and genration terms - !>@{ Diagnostic IDs - integer :: id_sppt_wts = -1 - integer :: id_epbl1_wts=-1,id_epbl2_wts=-1 - !>@} - ! stochastic patterns - real, allocatable :: sppt_wts(:,:) !< Random pattern for ocean SPPT - !! tendencies with a number between 0 and 2 - real, allocatable :: epbl1_wts(:,:) !< Random pattern for K.E. generation - real, allocatable :: epbl2_wts(:,:) !< Random pattern for K.E. dissipation - type(diag_ctrl), pointer :: diag !< structure used to regulate timing of diagnostic output - type(time_type), pointer :: Time !< Pointer to model time (needed for sponges) -end type stochastic_CS - -contains - -subroutine stochastics_init(dt, grid, GV, CS, param_file, diag, Time) - real, intent(in) :: dt !< time step [T ~> s] - type(ocean_grid_type), intent(in) :: grid ! horizontal grid information - type(verticalGrid_type), intent(in) :: GV ! vertical grid structure - type(stochastic_CS), pointer, intent(inout):: CS - type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters - type(diag_ctrl), target, intent(inout) :: diag !< structure to regulate diagnostic output - type(time_type), target :: Time !< model time - return -end subroutine stochastics_init - -subroutine update_stochastics(CS) - type(stochastic_CS), intent(inout) :: CS !< diabatic control structure - return -end subroutine update_stochastics -subroutine write_mom_restart_stoch(filename) - character(len=*) :: filename - return -end subroutine write_mom_restart_stoch -end module MOM_stochastics - diff --git a/config_src/external/stochastic_physics/stochastic_physics.F90 b/config_src/external/stochastic_physics/stochastic_physics.F90 new file mode 100644 index 0000000000..df62aa1591 --- /dev/null +++ b/config_src/external/stochastic_physics/stochastic_physics.F90 @@ -0,0 +1,68 @@ +! The are stubs for ocean stochastic physics +! the fully functional code is available at +! http://github.com/noaa-psd/stochastic_physics +module stochastic_physics + +implicit none + +private + +public :: init_stochastic_physics_ocn +public :: run_stochastic_physics_ocn + +contains + +!!!!!!!!!!!!!!!!!!!! +subroutine init_stochastic_physics_ocn(delt,geoLonT,geoLatT,nx,ny,nz,pert_epbl_in,do_sppt_in, & + mpiroot, mpicomm, iret) +implicit none +real,intent(in) :: delt !< timestep in seconds between calls to run_stochastic_physics_ocn +integer,intent(in) :: nx !< number of gridpoints in the x-direction of the compute grid +integer,intent(in) :: ny !< number of gridpoints in the y-direction of the compute grid +integer,intent(in) :: nz !< number of gridpoints in the z-direction of the compute grid +real,intent(in) :: geoLonT(nx,ny) !< Longitude in degrees +real,intent(in) :: geoLatT(nx,ny) !< Latitude in degrees +logical,intent(in) :: pert_epbl_in !< logical flag, if true generate random pattern for ePBL perturbations +logical,intent(in) :: do_sppt_in !< logical flag, if true generate random pattern for SPPT perturbations +integer,intent(in) :: mpiroot !< root processor +integer,intent(in) :: mpicomm !< mpi communicator +integer, intent(out) :: iret !< return code + +iret=0 +if (pert_epbl_in .EQV. .true. ) then + print*,'pert_epbl needs to be false if using the stub' + iret=-1 +endif +if (do_sppt_in.EQV. .true. ) then + print*,'do_sppt needs to be false if using the stub' + iret=-1 +endif +return +end subroutine init_stochastic_physics_ocn + +subroutine run_stochastic_physics_ocn(sppt_wts,t_rp1,t_rp2) +implicit none +real, intent(inout) :: sppt_wts(:,:) !< array containing random weights for SPPT range [0,2] +real, intent(inout) :: t_rp1(:,:) !< array containing random weights for ePBL + !! perturbations (KE generation) range [0,2] +real, intent(inout) :: t_rp2(:,:) !< array containing random weights for ePBL + !! perturbations (KE dissipation) range [0,2] +return +end subroutine run_stochastic_physics_ocn + +end module stochastic_physics + +module get_stochy_pattern_mod + +private + +public :: write_stoch_restart_ocn + +contains +subroutine write_stoch_restart_ocn(sfile) + +character(len=*) :: sfile !< name of restart file +return +end subroutine write_stoch_restart_ocn + +end module get_stochy_pattern_mod diff --git a/config_src/external/OCEAN_stochastic_phyiscs/MOM_stochastics.F90 b/src/parameterizations/stochastic/MOM_stochastics.F90 similarity index 86% rename from config_src/external/OCEAN_stochastic_phyiscs/MOM_stochastics.F90 rename to src/parameterizations/stochastic/MOM_stochastics.F90 index e6b0c80280..21a22a222e 100644 --- a/config_src/external/OCEAN_stochastic_phyiscs/MOM_stochastics.F90 +++ b/src/parameterizations/stochastic/MOM_stochastics.F90 @@ -19,20 +19,20 @@ module MOM_stochastics use MOM_domains, only : root_PE,num_PEs use MOM_coms, only : Get_PElist use stochastic_physics, only : init_stochastic_physics_ocn, run_stochastic_physics_ocn -use get_stochy_pattern_mod, only: write_stoch_restart_ocn #include implicit none ; private -public stochastics_init, update_stochastics, write_mom_restart_stoch +public stochastics_init, update_stochastics !> This control structure holds parameters for the MOM_stochastics module type, public:: stochastic_CS - logical :: do_sppt !< If true, stochastically perturb the diabatic - logical :: pert_epbl !! If true, then randomly perturb the KE dissipation and genration terms - integer :: id_sppt_wts = -1 - integer :: id_epbl1_wts=-1,id_epbl2_wts=-1 + logical :: do_sppt !< If true, stochastically perturb the diabatic + logical :: pert_epbl !< If true, then randomly perturb the KE dissipation and genration terms + integer :: id_sppt_wts = -1 !< Diagnostic id for SPPT + integer :: id_epbl1_wts=-1 !< Diagnostic id for epbl generation perturbation + integer :: id_epbl2_wts=-1 !< Diagnostic id for epbl dissipation perturbation ! stochastic patterns real, allocatable :: sppt_wts(:,:) !< Random pattern for ocean SPPT !! tendencies with a number between 0 and 2 @@ -47,9 +47,9 @@ module MOM_stochastics !! This subroutine initializes the stochastics physics control structure. subroutine stochastics_init(dt, grid, GV, CS, param_file, diag, Time) real, intent(in) :: dt !< time step [T ~> s] - type(ocean_grid_type), intent(in) :: grid ! horizontal grid information - type(verticalGrid_type), intent(in) :: GV ! vertical grid structure - type(stochastic_CS), pointer, intent(inout):: CS + type(ocean_grid_type), intent(in) :: grid !< horizontal grid information + type(verticalGrid_type), intent(in) :: GV !< vertical grid structure + type(stochastic_CS), pointer, intent(inout):: CS !< stochastic control structure type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters type(diag_ctrl), target, intent(inout) :: diag !< structure to regulate diagnostic output type(time_type), target :: Time !< model time @@ -59,7 +59,7 @@ subroutine stochastics_init(dt, grid, GV, CS, param_file, diag, Time) 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 + integer :: pe_zero ! root pe integer :: nx ! number of x-points including halo integer :: ny ! number of x-points including halo @@ -95,11 +95,11 @@ subroutine stochastics_init(dt, grid, GV, CS, param_file, diag, Time) num_procs=num_PEs() allocate(pelist(num_procs)) call Get_PElist(pelist,commID = mom_comm) - master=root_PE() + pe_zero=root_PE() nx = grid%ied - grid%isd + 1 ny = grid%jed - grid%jsd + 1 call init_stochastic_physics_ocn(dt,grid%geoLonT,grid%geoLatT,nx,ny,GV%ke, & - CS%pert_epbl,CS%do_sppt,master,mom_comm,iret) + CS%pert_epbl,CS%do_sppt,pe_zero,mom_comm,iret) if (iret/=0) then call MOM_error(FATAL, "call to init_stochastic_physics_ocn failed") return @@ -140,16 +140,5 @@ subroutine update_stochastics(CS) return end subroutine update_stochastics -!< wrapper to write ocean stochastic restarts -subroutine write_mom_restart_stoch(filename) - character(len=*) :: filename - - call callTree_enter("write_mom_restart_stoch(), MOM_stochastics.F90") - - call write_stoch_restart_ocn(filename) - - return -end subroutine write_mom_restart_stoch - end module MOM_stochastics diff --git a/src/parameterizations/vertical/MOM_energetic_PBL.F90 b/src/parameterizations/vertical/MOM_energetic_PBL.F90 index 3828e9483b..351f55984f 100644 --- a/src/parameterizations/vertical/MOM_energetic_PBL.F90 +++ b/src/parameterizations/vertical/MOM_energetic_PBL.F90 @@ -600,8 +600,8 @@ subroutine ePBL_column(h, u, v, T0, S0, dSV_dT, dSV_dS, TKE_forcing, B_flux, abs optional, pointer :: Waves !< Wave CS for Langmuir turbulence type(ocean_grid_type), & optional, intent(inout) :: G !< The ocean's grid structure. - real, optional, intent(in) :: epbl1_wt ! random number to perturb KE generation - real, optional, intent(in) :: epbl2_wt ! random number to perturb KE dissipation + real, optional, intent(in) :: epbl1_wt !< random number to perturb KE generation + real, optional, intent(in) :: epbl2_wt !< random number to perturb KE dissipation integer, optional, intent(in) :: i !< The i-index to work on (used for Waves) integer, optional, intent(in) :: j !< The i-index to work on (used for Waves)