Skip to content

Commit 0337147

Browse files
committed
Adds a vector of default values to get_param_real_array()
The `default=` optional argument to get_param() only provides a uniform value to initialize an array of reals. This commit adds the optional `defaults=` argument that must have the same length as the `values` argument. I've also added a few instances of this optional argument: - by adding the `initialize_thickness_param()` procedure, selected by `THICKNESS_CONFIG = "param"`. The procedure was based on the "uniform" method, and uses the parameter `THICKNESS_INIT_VALUES` which defaults to uniform values derived from `MAXIMUM_DEPTH` - the setting of MLD_EN_VALS in MOM_diabatic_driver.F90 which was previously using a work around to set defaults to 25, 2500, 250000 J/m2. - two vectors of 4 values in user/user_change_diffusivity.F90 There will be some doc file changes, but no answer changes.
1 parent cfb53f1 commit 0337147

File tree

5 files changed

+95
-17
lines changed

5 files changed

+95
-17
lines changed

src/framework/MOM_document.F90

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,16 @@ subroutine doc_param_real(doc, varname, desc, units, val, default, debuggingPara
303303
end subroutine doc_param_real
304304

305305
!> This subroutine handles parameter documentation for arrays of reals.
306-
subroutine doc_param_real_array(doc, varname, desc, units, vals, default, debuggingParam, like_default)
306+
subroutine doc_param_real_array(doc, varname, desc, units, vals, default, defaults, &
307+
debuggingParam, like_default)
307308
type(doc_type), pointer :: doc !< A pointer to a structure that controls where the
308309
!! documentation occurs and its formatting
309310
character(len=*), intent(in) :: varname !< The name of the parameter being documented
310311
character(len=*), intent(in) :: desc !< A description of the parameter being documented
311312
character(len=*), intent(in) :: units !< The units of the parameter being documented
312313
real, intent(in) :: vals(:) !< The array of values to record
313-
real, optional, intent(in) :: default !< The default value of this parameter
314+
real, optional, intent(in) :: default !< A uniform default value of this parameter
315+
real, optional, intent(in) :: defaults(:) !< The element-wise default values of this parameter
314316
logical, optional, intent(in) :: debuggingParam !< If present and true, this is a debugging parameter.
315317
logical, optional, intent(in) :: like_default !< If present and true, log this parameter as though
316318
!! it has the default value, even if there is no default.
@@ -334,6 +336,11 @@ subroutine doc_param_real_array(doc, varname, desc, units, vals, default, debugg
334336
do i=1,size(vals) ; if (vals(i) /= default) equalsDefault = .false. ; enddo
335337
mesg = trim(mesg)//" default = "//trim(real_string(default))
336338
endif
339+
if (present(defaults)) then
340+
equalsDefault = .true.
341+
do i=1,size(vals) ; if (vals(i) /= defaults(i)) equalsDefault = .false. ; enddo
342+
mesg = trim(mesg)//" default = "//trim(real_array_string(defaults))
343+
endif
337344
if (present(like_default)) then ; if (like_default) equalsDefault = .true. ; endif
338345

339346
if (mesgHasBeenDocumented(doc, varName, mesg)) return ! Avoid duplicates

src/framework/MOM_file_parser.F90

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ end subroutine log_param_real
14641464

14651465
!> Log the name and values of an array of real model parameter in documentation files.
14661466
subroutine log_param_real_array(CS, modulename, varname, value, desc, &
1467-
units, default, debuggingParam, like_default, unscale)
1467+
units, default, defaults, debuggingParam, like_default, unscale)
14681468
type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
14691469
!! it is also a structure to parse for run-time parameters
14701470
character(len=*), intent(in) :: modulename !< The name of the calling module
@@ -1473,7 +1473,8 @@ subroutine log_param_real_array(CS, modulename, varname, value, desc, &
14731473
character(len=*), optional, intent(in) :: desc !< A description of this variable; if not
14741474
!! present, this parameter is not written to a doc file
14751475
character(len=*), intent(in) :: units !< The units of this parameter
1476-
real, optional, intent(in) :: default !< The default value of the parameter
1476+
real, optional, intent(in) :: default !< A uniform default value of the parameter
1477+
real, optional, intent(in) :: defaults(:) !< The element-wise defaults of the parameter
14771478
logical, optional, intent(in) :: debuggingParam !< If present and true, this parameter is
14781479
!! logged in the debugging parameter file
14791480
logical, optional, intent(in) :: like_default !< If present and true, log this parameter as
@@ -1498,7 +1499,7 @@ subroutine log_param_real_array(CS, modulename, varname, value, desc, &
14981499

14991500
write(myunits(1:240),'(A)') trim(units)
15001501
if (present(desc)) &
1501-
call doc_param(CS%doc, varname, desc, myunits, log_val, default, &
1502+
call doc_param(CS%doc, varname, desc, myunits, log_val, default, defaults, &
15021503
debuggingParam=debuggingParam, like_default=like_default)
15031504

15041505
end subroutine log_param_real_array
@@ -1835,7 +1836,7 @@ end subroutine get_param_real
18351836
!> This subroutine reads the values of an array of real model parameters from a parameter file
18361837
!! and logs them in documentation files.
18371838
subroutine get_param_real_array(CS, modulename, varname, value, desc, units, &
1838-
default, fail_if_missing, do_not_read, do_not_log, debuggingParam, &
1839+
default, defaults, fail_if_missing, do_not_read, do_not_log, debuggingParam, &
18391840
scale, unscaled)
18401841
type(param_file_type), intent(in) :: CS !< The control structure for the file_parser module,
18411842
!! it is also a structure to parse for run-time parameters
@@ -1846,7 +1847,8 @@ subroutine get_param_real_array(CS, modulename, varname, value, desc, units, &
18461847
character(len=*), optional, intent(in) :: desc !< A description of this variable; if not
18471848
!! present, this parameter is not written to a doc file
18481849
character(len=*), intent(in) :: units !< The units of this parameter
1849-
real, optional, intent(in) :: default !< The default value of the parameter
1850+
real, optional, intent(in) :: default !< A uniform default value of the parameter
1851+
real, optional, intent(in) :: defaults(:) !< The element-wise defaults of the parameter
18501852
logical, optional, intent(in) :: fail_if_missing !< If present and true, a fatal error occurs
18511853
!! if this variable is not found in the parameter file
18521854
logical, optional, intent(in) :: do_not_read !< If present and true, do not read a
@@ -1865,14 +1867,22 @@ subroutine get_param_real_array(CS, modulename, varname, value, desc, units, &
18651867
do_read = .true. ; if (present(do_not_read)) do_read = .not.do_not_read
18661868
do_log = .true. ; if (present(do_not_log)) do_log = .not.do_not_log
18671869

1870+
if (present(defaults)) then
1871+
if (present(default)) call MOM_error(FATAL, &
1872+
"get_param_real_array: Only one of default and defaults can be specified at a time.")
1873+
if (size(defaults) /= size(value)) call MOM_error(FATAL, &
1874+
"get_param_real_array: The size of defaults nad value are not the same.")
1875+
endif
1876+
18681877
if (do_read) then
18691878
if (present(default)) value(:) = default
1879+
if (present(defaults)) value(:) = defaults(:)
18701880
call read_param_real_array(CS, varname, value, fail_if_missing)
18711881
endif
18721882

18731883
if (do_log) then
18741884
call log_param_real_array(CS, modulename, varname, value, desc, &
1875-
units, default, debuggingParam)
1885+
units, default, defaults, debuggingParam)
18761886
endif
18771887

18781888
if (present(unscaled)) unscaled(:) = value(:)

src/initialization/MOM_state_initialization.F90

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ subroutine MOM_initialize_state(u, v, h, tv, Time, G, GV, US, PF, dirs, &
278278
" \t uniform - uniform thickness layers evenly distributed \n"//&
279279
" \t\t between the surface and MAXIMUM_DEPTH. \n"//&
280280
" \t list - read a list of positive interface depths. \n"//&
281+
" \t param - use thicknesses from parameter THICKNESS_INIT_VALUES. \n"//&
281282
" \t DOME - use a slope and channel configuration for the \n"//&
282283
" \t\t DOME sill-overflow test case. \n"//&
283284
" \t ISOMIP - use a configuration for the \n"//&
@@ -318,6 +319,8 @@ subroutine MOM_initialize_state(u, v, h, tv, Time, G, GV, US, PF, dirs, &
318319
just_read=just_read)
319320
case ("list"); call initialize_thickness_list(dz, depth_tot, G, GV, US, PF, &
320321
just_read=just_read)
322+
case ("param"); call initialize_thickness_param(dz, depth_tot, G, GV, US, PF, &
323+
just_read=just_read)
321324
case ("DOME"); call DOME_initialize_thickness(dz, depth_tot, G, GV, PF, &
322325
just_read=just_read)
323326
case ("ISOMIP"); call ISOMIP_initialize_thickness(dz, depth_tot, G, GV, US, PF, tv, &
@@ -1011,6 +1014,68 @@ subroutine initialize_thickness_list(h, depth_tot, G, GV, US, param_file, just_r
10111014
call callTree_leave(trim(mdl)//'()')
10121015
end subroutine initialize_thickness_list
10131016

1017+
!> Initializes thickness based on a run-time parameter with nominal thickness
1018+
!! for each layer
1019+
subroutine initialize_thickness_param(h, depth_tot, G, GV, US, param_file, just_read)
1020+
type(ocean_grid_type), intent(in) :: G !< The ocean's grid structure.
1021+
type(verticalGrid_type), intent(in) :: GV !< The ocean's vertical grid structure.
1022+
type(unit_scale_type), intent(in) :: US !< A dimensional unit scaling type
1023+
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)), &
1024+
intent(out) :: h !< The thickness that is being initialized [Z ~> m]
1025+
real, dimension(SZI_(G),SZJ_(G)), &
1026+
intent(in) :: depth_tot !< The nominal total depth of the ocean [Z ~> m]
1027+
type(param_file_type), intent(in) :: param_file !< A structure indicating the open file
1028+
!! to parse for model parameter values.
1029+
logical, intent(in) :: just_read !< If true, this call will only read
1030+
!! parameters without changing h.
1031+
! Local variables
1032+
character(len=40) :: mdl = "initialize_thickness_param" ! This subroutine's name.
1033+
real :: e0(SZK_(GV)+1) ! The resting interface heights [Z ~> m], usually
1034+
! negative because it is positive upward.
1035+
real :: eta1D(SZK_(GV)+1)! Interface height relative to the sea surface,
1036+
! positive upward [Z ~> m].
1037+
real :: dz(SZK_(GV)) ! The nominal initial layer thickness [Z ~> m], usually
1038+
real :: h0_def(SZK_(GV)) ! Uniform default values for dz [Z ~> m], usually
1039+
integer :: i, j, k, is, ie, js, je, nz
1040+
1041+
call callTree_enter(trim(mdl)//"(), MOM_state_initialization.F90")
1042+
if (G%max_depth<=0.) call MOM_error(FATAL, "initialize_thickness_param: "// &
1043+
"MAXIMUM_DEPTH has a nonsensical value! Was it set?")
1044+
1045+
is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec ; nz = GV%ke
1046+
1047+
h0_def(:) = ( G%max_depth / real(nz) ) * US%Z_to_m
1048+
call get_param(param_file, mdl, "THICKNESS_INIT_VALUES", dz, &
1049+
"A list of nominal thickness for each layer to initialize with", &
1050+
units="m", scale=US%m_to_Z, defaults=h0_def, do_not_log=just_read)
1051+
if (just_read) return ! This subroutine has no run-time parameters.
1052+
1053+
e0(nz+1) = -G%max_depth
1054+
do k=nz, 1, -1
1055+
e0(K) = e0(K+1) + dz(k)
1056+
enddo
1057+
1058+
do j=js,je ; do i=is,ie
1059+
! This sets the initial thickness (in m) of the layers. The
1060+
! thicknesses are set to insure that: 1. each layer is at least an
1061+
! Angstrom thick, and 2. the interfaces are where they should be
1062+
! based on the resting depths and interface height perturbations,
1063+
! as long at this doesn't interfere with 1.
1064+
eta1D(nz+1) = -depth_tot(i,j)
1065+
do k=nz,1,-1
1066+
eta1D(K) = e0(K)
1067+
if (eta1D(K) < (eta1D(K+1) + GV%Angstrom_Z)) then
1068+
eta1D(K) = eta1D(K+1) + GV%Angstrom_Z
1069+
h(i,j,k) = GV%Angstrom_Z
1070+
else
1071+
h(i,j,k) = eta1D(K) - eta1D(K+1)
1072+
endif
1073+
enddo
1074+
enddo ; enddo
1075+
1076+
call callTree_leave(trim(mdl)//'()')
1077+
end subroutine initialize_thickness_param
1078+
10141079
!> Search density space for location of layers (not implemented!)
10151080
subroutine initialize_thickness_search
10161081
call MOM_error(FATAL," MOM_state_initialization.F90, initialize_thickness_search: NOT IMPLEMENTED")

src/parameterizations/vertical/MOM_diabatic_driver.F90

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,13 +3256,8 @@ subroutine diabatic_driver_init(Time, G, GV, US, param_file, useALEalgorithm, di
32563256
'Mixed layer depth (delta rho = 0.125)', 'm', conversion=US%Z_to_m)
32573257
call get_param(param_file, mdl, "MLD_EN_VALS", CS%MLD_En_vals, &
32583258
"The energy values used to compute MLDs. If not set (or all set to 0.), the "//&
3259-
"default will overwrite to 25., 2500., 250000.", &
3260-
units='J/m2', default=0., scale=US%W_m2_to_RZ3_T3*US%s_to_T)
3261-
if ((CS%MLD_En_vals(1)==0.).and.(CS%MLD_En_vals(2)==0.).and.(CS%MLD_En_vals(3)==0.)) then
3262-
CS%MLD_En_vals = (/ 25.*US%W_m2_to_RZ3_T3*US%s_to_T, &
3263-
2500.*US%W_m2_to_RZ3_T3*US%s_to_T, &
3264-
250000.*US%W_m2_to_RZ3_T3*US%s_to_T /)
3265-
endif
3259+
"default will overwrite to 25., 2500., 250000.", units='J/m2', &
3260+
defaults=(/25., 2500., 250000./), scale=US%W_m2_to_RZ3_T3*US%s_to_T)
32663261
write(EN1,'(F10.2)') CS%MLD_En_vals(1)*US%RZ3_T3_to_W_m2*US%T_to_s
32673262
write(EN2,'(F10.2)') CS%MLD_En_vals(2)*US%RZ3_T3_to_W_m2*US%T_to_s
32683263
write(EN3,'(F10.2)') CS%MLD_En_vals(3)*US%RZ3_T3_to_W_m2*US%T_to_s

src/user/user_change_diffusivity.F90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,15 @@ subroutine user_change_diff_init(Time, G, GV, US, param_file, diag, CS)
230230
"applied. The four values specify the latitudes at "//&
231231
"which the extra diffusivity starts to increase from 0, "//&
232232
"hits its full value, starts to decrease again, and is "//&
233-
"back to 0.", units="degrees_N", default=-1.0e9)
233+
"back to 0.", units="degrees_N", defaults=(/-1.0e9,-1.0e9,-1.0e9,-1.0e9/))
234234
call get_param(param_file, mdl, "USER_KD_ADD_RHO_RANGE", CS%rho_range(:), &
235235
"Four successive values that define a range of potential "//&
236236
"densities over which the user-given extra diffusivity "//&
237237
"is applied. The four values specify the density at "//&
238238
"which the extra diffusivity starts to increase from 0, "//&
239239
"hits its full value, starts to decrease again, and is "//&
240-
"back to 0.", units="kg m-3", default=-1.0e9, scale=US%kg_m3_to_R)
240+
"back to 0.", units="kg m-3", defaults=(/-1.0e9,-1.0e9,-1.0e9,-1.0e9/),&
241+
scale=US%kg_m3_to_R)
241242
call get_param(param_file, mdl, "USER_KD_ADD_USE_ABS_LAT", CS%use_abs_lat, &
242243
"If true, use the absolute value of latitude when "//&
243244
"checking whether a point fits into range of latitudes.", &

0 commit comments

Comments
 (0)