Skip to content

Commit

Permalink
Conditionally deallocate spherical harmonic fields
Browse files Browse the repository at this point in the history
This patch moves the local `use_tides` flag of the split RK2 solver,
which tracks the TIDES parameter, into the RK2 control structure (CS),
and uses it to conditionally call `tidal_forcing_end().

The `tidal_forcing_init()` function conditionally allocates the
spherical harmonic fields, but `tidal_forcing_end()` is always called,
which will in turn always attempt to deallocate the fields.  In some
compilers, under certain levels of debugging, this can raise a runtime
error.
  • Loading branch information
marshallward committed Nov 7, 2022
1 parent 84682aa commit 7c4dfd4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/MOM_dynamics_split_RK2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ module MOM_dynamics_split_RK2
!! end of the timestep have been stored for use in the next
!! predictor step. This is used to accomodate various generations
!! of restart files.
logical :: use_tides !< If true, tidal forcing is enabled.

real :: be !< A nondimensional number from 0.5 to 1 that controls
!! the backward weighting of the time stepping scheme [nondim]
Expand Down Expand Up @@ -1224,7 +1225,7 @@ subroutine initialize_dyn_split_RK2(u, v, h, uh, vh, eta, Time, G, GV, US, param
real :: accel_rescale ! A rescaling factor for accelerations from the representation in a
! restart file to the internal representation in this run [various units ~> 1]
type(group_pass_type) :: pass_av_h_uvh
logical :: use_tides, debug_truncations
logical :: debug_truncations
logical :: read_uv, read_h2

integer :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz
Expand All @@ -1245,7 +1246,7 @@ subroutine initialize_dyn_split_RK2(u, v, h, uh, vh, eta, Time, G, GV, US, param
CS%diag => diag

call log_version(param_file, mdl, version, "")
call get_param(param_file, mdl, "TIDES", use_tides, &
call get_param(param_file, mdl, "TIDES", CS%use_tides, &
"If true, apply tidal momentum forcing.", default=.false.)
call get_param(param_file, mdl, "BE", CS%be, &
"If SPLIT is true, BE determines the relative weighting "//&
Expand Down Expand Up @@ -1340,7 +1341,7 @@ subroutine initialize_dyn_split_RK2(u, v, h, uh, vh, eta, Time, G, GV, US, param
call continuity_init(Time, G, GV, US, param_file, diag, CS%continuity_CSp)
cont_stencil = continuity_stencil(CS%continuity_CSp)
call CoriolisAdv_init(Time, G, GV, US, param_file, diag, CS%ADp, CS%CoriolisAdv)
if (use_tides) call tidal_forcing_init(Time, G, US, param_file, CS%tides_CSp)
if (CS%use_tides) call tidal_forcing_init(Time, G, US, param_file, CS%tides_CSp)
call PressureForce_init(Time, G, GV, US, param_file, diag, CS%PressureForce_CSp, &
CS%tides_CSp)
call hor_visc_init(Time, G, GV, US, param_file, diag, CS%hor_visc, ADp=CS%ADp)
Expand Down Expand Up @@ -1702,7 +1703,7 @@ subroutine end_dyn_split_RK2(CS)
deallocate(CS%vertvisc_CSp)

call hor_visc_end(CS%hor_visc)
call tidal_forcing_end(CS%tides_CSp)
if (CS%use_tides) call tidal_forcing_end(CS%tides_CSp)
call CoriolisAdv_end(CS%CoriolisAdv)

DEALLOC_(CS%diffu) ; DEALLOC_(CS%diffv)
Expand Down

0 comments on commit 7c4dfd4

Please sign in to comment.