Skip to content

Commit 6608730

Browse files
authored
Merge pull request #6 from Hallberg-NOAA/initialized_tests
Add initialization tests using CS%initialized
2 parents b2f6678 + 4e6e73f commit 6608730

28 files changed

Lines changed: 291 additions & 0 deletions

src/core/MOM_CoriolisAdv.F90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module MOM_CoriolisAdv
2525

2626
!> Control structure for mom_coriolisadv
2727
type, public :: CoriolisAdv_CS ; private
28+
logical :: initialized = .false. !< True if this control structure has been initialized.
2829
integer :: Coriolis_Scheme !< Selects the discretization for the Coriolis terms.
2930
!! Valid values are:
3031
!! - SADOURNY75_ENERGY - Sadourny, 1975
@@ -245,6 +246,9 @@ subroutine CorAdCalc(u, v, h, uh, vh, CAu, CAv, OBC, AD, G, GV, US, CS)
245246
! v(is-1:ie+2,js-1:je+1), u(is-1:ie+1,js-1:je+2), h(is-1:ie+2,js-1:je+2),
246247
! uh(is-1,ie,js:je+1) and vh(is:ie+1,js-1:je).
247248

249+
if (.not.CS%initialized) call MOM_error(FATAL, &
250+
"MOM_CoriolisAdv: Module must be initialized before it is used.")
251+
248252
is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec
249253
Isq = G%IscB ; Ieq = G%IecB ; Jsq = G%JscB ; Jeq = G%JecB ; nz = GV%ke
250254
vol_neglect = GV%H_subroundoff * (1e-4 * US%m_to_L)**2
@@ -1123,6 +1127,7 @@ subroutine CoriolisAdv_init(Time, G, GV, US, param_file, diag, AD, CS)
11231127
isd = G%isd ; ied = G%ied ; jsd = G%jsd ; jed = G%jed ; nz = GV%ke
11241128
IsdB = G%IsdB ; IedB = G%IedB ; JsdB = G%JsdB ; JedB = G%JedB
11251129

1130+
CS%initialized = .true.
11261131
CS%diag => diag ; CS%Time => Time
11271132

11281133
! Read all relevant parameters and write them to the model log.

src/core/MOM_PressureForce_FV.F90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module MOM_PressureForce_FV
3434

3535
!> Finite volume pressure gradient control structure
3636
type, public :: PressureForce_FV_CS ; private
37+
logical :: initialized = .false. !< True if this control structure has been initialized.
3738
logical :: tides !< If true, apply tidal momentum forcing.
3839
real :: Rho0 !< The density used in the Boussinesq
3940
!! approximation [R ~> kg m-3].
@@ -163,6 +164,9 @@ subroutine PressureForce_FV_nonBouss(h, tv, PFu, PFv, G, GV, US, CS, ALE_CSp, p_
163164
Isq = G%IscB ; Ieq = G%IecB ; Jsq = G%JscB ; Jeq = G%JecB
164165
EOSdom(1) = Isq - (G%isd-1) ; EOSdom(2) = G%iec+1 - (G%isd-1)
165166

167+
if (.not.CS%initialized) call MOM_error(FATAL, &
168+
"MOM_PressureForce_FV_nonBouss: Module must be initialized before it is used.")
169+
166170
if (CS%Stanley_T2_det_coeff>=0.) call MOM_error(FATAL, &
167171
"MOM_PressureForce_FV_nonBouss: The Stanley parameterization is not yet"//&
168172
"implemented in non-Boussinesq mode.")
@@ -497,6 +501,9 @@ subroutine PressureForce_FV_Bouss(h, tv, PFu, PFv, G, GV, US, CS, ALE_CSp, p_atm
497501
Isq = G%IscB ; Ieq = G%IecB ; Jsq = G%JscB ; Jeq = G%JecB
498502
EOSdom(1) = Isq - (G%isd-1) ; EOSdom(2) = G%iec+1 - (G%isd-1)
499503

504+
if (.not.CS%initialized) call MOM_error(FATAL, &
505+
"MOM_PressureForce_FV_Bouss: Module must be initialized before it is used.")
506+
500507
use_p_atm = associated(p_atm)
501508
use_EOS = associated(tv%eqn_of_state)
502509
do i=Isq,Ieq+1 ; p0(i) = 0.0 ; enddo
@@ -809,6 +816,7 @@ subroutine PressureForce_FV_init(Time, G, GV, US, param_file, diag, CS, tides_CS
809816
character(len=40) :: mdl ! This module's name.
810817
logical :: use_ALE
811818

819+
CS%initialized = .true.
812820
CS%diag => diag ; CS%Time => Time
813821
if (present(tides_CSp)) &
814822
CS%tides_CSp => tides_CSp

src/core/MOM_PressureForce_Montgomery.F90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module MOM_PressureForce_Mont
3030

3131
!> Control structure for the Montgomery potential form of pressure gradient
3232
type, public :: PressureForce_Mont_CS ; private
33+
logical :: initialized = .false. !< True if this control structure has been initialized.
3334
logical :: tides !< If true, apply tidal momentum forcing.
3435
real :: Rho0 !< The density used in the Boussinesq
3536
!! approximation [R ~> kg m-3].
@@ -137,6 +138,9 @@ subroutine PressureForce_Mont_nonBouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm, pb
137138
is_split = present(pbce)
138139
use_EOS = associated(tv%eqn_of_state)
139140

141+
if (.not.CS%initialized) call MOM_error(FATAL, &
142+
"MOM_PressureForce_Mont: Module must be initialized before it is used.")
143+
140144
if (use_EOS) then
141145
if (query_compressible(tv%eqn_of_state)) call MOM_error(FATAL, &
142146
"PressureForce_Mont_nonBouss: The Montgomery form of the pressure force "//&
@@ -422,6 +426,9 @@ subroutine PressureForce_Mont_Bouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm, pbce,
422426
is_split = present(pbce)
423427
use_EOS = associated(tv%eqn_of_state)
424428

429+
if (.not.CS%initialized) call MOM_error(FATAL, &
430+
"MOM_PressureForce_Mont: Module must be initialized before it is used.")
431+
425432
if (use_EOS) then
426433
if (query_compressible(tv%eqn_of_state)) call MOM_error(FATAL, &
427434
"PressureForce_Mont_Bouss: The Montgomery form of the pressure force "//&
@@ -829,6 +836,7 @@ subroutine PressureForce_Mont_init(Time, G, GV, US, param_file, diag, CS, tides_
829836
# include "version_variable.h"
830837
character(len=40) :: mdl ! This module's name.
831838

839+
CS%initialized = .true.
832840
CS%diag => diag ; CS%Time => Time
833841
if (present(tides_CSp)) &
834842
CS%tides_CSp => tides_CSp

src/core/MOM_barotropic.F90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,9 @@ subroutine btstep(U_in, V_in, eta_in, dt, bc_accel_u, bc_accel_v, forces, pbce,
694694
integer :: ioff, joff
695695
integer :: l_seg
696696

697+
if (.not.CS%module_is_initialized) call MOM_error(FATAL, &
698+
"btstep: Module MOM_barotropic must be initialized before it is used.")
699+
697700
if (.not.CS%split) return
698701
is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec ; nz = GV%ke
699702
Isq = G%IscB ; Ieq = G%IecB ; Jsq = G%JscB ; Jeq = G%JecB
@@ -2764,6 +2767,9 @@ subroutine set_dtbt(G, GV, US, CS, eta, pbce, BT_cont, gtot_est, SSH_add)
27642767
character(len=200) :: mesg
27652768
integer :: i, j, k, is, ie, js, je, nz
27662769

2770+
if (.not.CS%module_is_initialized) call MOM_error(FATAL, &
2771+
"set_dtbt: Module MOM_barotropic must be initialized before it is used.")
2772+
27672773
if (.not.CS%split) return
27682774
is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec ; nz = GV%ke
27692775
MS%isdw = G%isd ; MS%iedw = G%ied ; MS%jsdw = G%jsd ; MS%jedw = G%jed
@@ -3298,6 +3304,9 @@ subroutine btcalc(h, G, GV, CS, h_u, h_v, may_use_default, OBC)
32983304

32993305
! This section interpolates thicknesses onto u & v grid points with the
33003306
! second order accurate estimate h = 2*(h+ * h-)/(h+ + h-).
3307+
if (.not.CS%module_is_initialized) call MOM_error(FATAL, &
3308+
"btcalc: Module MOM_barotropic must be initialized before it is used.")
3309+
33013310
if (.not.CS%split) return
33023311

33033312
use_default = .false.
@@ -4186,6 +4195,9 @@ subroutine bt_mass_source(h, eta, set_cor, G, GV, CS)
41864195
! thicknesses [H ~> m or kg m-2].
41874196
integer :: is, ie, js, je, nz, i, j, k
41884197

4198+
if (.not.CS%module_is_initialized) call MOM_error(FATAL, "bt_mass_source: "// &
4199+
"Module MOM_barotropic must be initialized before it is used.")
4200+
41894201
if (.not.CS%split) return
41904202

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

src/core/MOM_continuity_PPM.F90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module MOM_continuity_PPM
2626

2727
!> Control structure for mom_continuity_ppm
2828
type, public :: continuity_PPM_CS ; private
29+
logical :: initialized = .false. !< True if this control structure has been initialized.
2930
type(diag_ctrl), pointer :: diag !< Diagnostics control structure.
3031
logical :: upwind_1st !< If true, use a first-order upwind scheme.
3132
logical :: monotonic !< If true, use the Colella & Woodward monotonic
@@ -134,6 +135,9 @@ subroutine continuity_PPM(u, v, hin, h, uh, vh, dt, G, GV, US, CS, OBC, uhbt, vh
134135

135136
h_min = GV%Angstrom_H
136137

138+
if (.not.CS%initialized) call MOM_error(FATAL, &
139+
"MOM_continuity_PPM: Module must be initialized before it is used.")
140+
137141
x_first = (MOD(G%first_direction,2) == 0)
138142

139143
if (present(visc_rem_u) .neqv. present(visc_rem_v)) call MOM_error(FATAL, &
@@ -2202,6 +2206,8 @@ subroutine continuity_PPM_init(Time, G, GV, US, param_file, diag, CS)
22022206
real :: tol_eta_m ! An unscaled version of tol_eta [m].
22032207
character(len=40) :: mdl = "MOM_continuity_PPM" ! This module's name.
22042208

2209+
CS%initialized = .true.
2210+
22052211
! Read all relevant parameters and write them to the model log.
22062212
call log_version(param_file, mdl, version, "")
22072213
call get_param(param_file, mdl, "MONOTONIC_CONTINUITY", CS%monotonic, &

src/diagnostics/MOM_diagnostics.F90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module MOM_diagnostics
4949

5050
!> The control structure for the MOM_diagnostics module
5151
type, public :: diagnostics_CS ; private
52+
logical :: initialized = .false. !< True if this control structure has been initialized.
5253
real :: mono_N2_column_fraction = 0. !< The lower fraction of water column over which N2 is limited as
5354
!! monotonic for the purposes of calculating the equivalent
5455
!! barotropic wave speed.
@@ -267,6 +268,9 @@ subroutine calculate_diagnostic_fields(u, v, h, uh, vh, tv, ADp, CDp, p_surf, &
267268
if (loc(CS)==0) call MOM_error(FATAL, &
268269
"calculate_diagnostic_fields: Module must be initialized before used.")
269270

271+
if (.not. CS%initialized) call MOM_error(FATAL, &
272+
"calculate_diagnostic_fields: Module must be initialized before used.")
273+
270274
call calculate_derivs(dt, G, CS)
271275

272276
if (dt > 0.0) then
@@ -1245,6 +1249,9 @@ subroutine register_time_deriv(lb, f_ptr, deriv_ptr, CS)
12451249
integer :: m !< New index of deriv_ptr in CS%deriv
12461250
integer :: ub(3) !< Upper index bound of f_ptr, based on shape.
12471251

1252+
if (.not.CS%initialized) call MOM_error(FATAL, &
1253+
"register_time_deriv: Module must be initialized before it is used.")
1254+
12481255
if (CS%num_time_deriv >= MAX_FIELDS_) then
12491256
call MOM_error(WARNING,"MOM_diagnostics: Attempted to register more than " // &
12501257
"MAX_FIELDS_ diagnostic time derivatives via register_time_deriv.")
@@ -1604,6 +1611,8 @@ subroutine MOM_diagnostics_init(MIS, ADp, CDp, Time, G, GV, US, param_file, diag
16041611
isd = G%isd ; ied = G%ied ; jsd = G%jsd ; jed = G%jed ; nz = GV%ke
16051612
IsdB = G%IsdB ; IedB = G%IedB ; JsdB = G%JsdB ; JedB = G%JedB
16061613

1614+
CS%initialized = .true.
1615+
16071616
CS%diag => diag
16081617
use_temperature = associated(tv%T)
16091618
call get_param(param_file, mdl, "ADIABATIC", adiabatic, default=.false., &

src/diagnostics/MOM_sum_output.F90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ module MOM_sum_output
5959

6060
!> The control structure for the MOM_sum_output module
6161
type, public :: sum_output_CS ; private
62+
logical :: initialized = .false. !< True if this control structure has been initialized.
63+
6264
type(Depth_List) :: DL !< The sorted depth list.
6365

6466
integer, allocatable, dimension(:) :: lH
@@ -160,6 +162,8 @@ subroutine MOM_sum_output_init(G, GV, US, param_file, directory, ntrnc, &
160162
endif
161163
allocate(CS)
162164

165+
CS%initialized = .true.
166+
163167
! Read all relevant parameters and write them to the model log.
164168
call log_version(param_file, mdl, version, "")
165169
call get_param(param_file, mdl, "CALCULATE_APE", CS%do_APE_calc, &
@@ -490,6 +494,9 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
490494
if (.not.associated(CS)) call MOM_error(FATAL, &
491495
"write_energy: Module must be initialized before it is used.")
492496

497+
if (.not.CS%initialized) call MOM_error(FATAL, &
498+
"write_energy: Module must be initialized before it is used.")
499+
493500
do j=js,je ; do i=is,ie
494501
areaTm(i,j) = G%mask2dT(i,j)*G%areaT(i,j)
495502
enddo ; enddo

src/diagnostics/MOM_wave_speed.F90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module MOM_wave_speed
2626

2727
!> Control structure for MOM_wave_speed
2828
type, public :: wave_speed_CS ; private
29+
logical :: initialized = .false. !< True if this control structure has been initialized.
2930
logical :: use_ebt_mode = .false. !< If true, calculate the equivalent barotropic wave speed instead
3031
!! of the first baroclinic wave speed.
3132
!! This parameter controls the default behavior of wave_speed() which
@@ -146,6 +147,9 @@ subroutine wave_speed(h, tv, G, GV, US, cg1, CS, full_halos, use_ebt_mode, mono_
146147

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

150+
if (.not. CS%initialized) call MOM_error(FATAL, "MOM_wave_speed: "// &
151+
"Module must be initialized before it is used.")
152+
149153
if (present(full_halos)) then ; if (full_halos) then
150154
is = G%isd ; ie = G%ied ; js = G%jsd ; je = G%jed
151155
endif ; endif
@@ -722,6 +726,11 @@ subroutine wave_speeds(h, tv, G, GV, US, nmodes, cn, CS, full_halos)
722726

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

729+
if (present(CS)) then
730+
if (.not. CS%initialized) call MOM_error(FATAL, "MOM_wave_speed: "// &
731+
"Module must be initialized before it is used.")
732+
endif
733+
725734
if (present(full_halos)) then ; if (full_halos) then
726735
is = G%isd ; ie = G%ied ; js = G%jsd ; je = G%jed
727736
endif ; endif
@@ -1185,6 +1194,8 @@ subroutine wave_speed_init(CS, use_ebt_mode, mono_N2_column_fraction, mono_N2_de
11851194
# include "version_variable.h"
11861195
character(len=40) :: mdl = "MOM_wave_speed" ! This module's name.
11871196

1197+
CS%initialized = .true.
1198+
11881199
! Write all relevant parameters to the model log.
11891200
call log_version(mdl, version)
11901201

src/diagnostics/MOM_wave_structure.F90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module MOM_wave_structure
3636

3737
!> The control structure for the MOM_wave_structure module
3838
type, public :: wave_structure_CS ; !private
39+
logical :: initialized = .false. !< True if this control structure has been initialized.
3940
type(diag_ctrl), pointer :: diag => NULL() !< A structure that is used to
4041
!! regulate the timing of diagnostic output.
4142
real, allocatable, dimension(:,:,:) :: w_strct
@@ -191,6 +192,9 @@ subroutine wave_structure(h, tv, G, GV, US, cn, ModeNum, freq, CS, En, full_halo
191192
is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec ; nz = GV%ke
192193
I_a_int = 1/a_int
193194

195+
if (.not. CS%initialized) call MOM_error(FATAL, "MOM_wave_structure: "// &
196+
"Module must be initialized before it is used.")
197+
194198
if (present(full_halos)) then ; if (full_halos) then
195199
is = G%isd ; ie = G%ied ; js = G%jsd ; je = G%jed
196200
endif ; endif
@@ -728,6 +732,8 @@ subroutine wave_structure_init(Time, G, GV, param_file, diag, CS)
728732

729733
isd = G%isd ; ied = G%ied ; jsd = G%jsd ; jed = G%jed ; nz = GV%ke
730734

735+
CS%initialized = .true.
736+
731737
call get_param(param_file, mdl, "INTERNAL_TIDE_SOURCE_X", CS%int_tide_source_x, &
732738
"X Location of generation site for internal tide", default=1.)
733739
call get_param(param_file, mdl, "INTERNAL_TIDE_SOURCE_Y", CS%int_tide_source_y, &

0 commit comments

Comments
 (0)