Skip to content

Commit

Permalink
+(*)Avoid segmentation faults if PEN_SW_NBANDS = 0
Browse files Browse the repository at this point in the history
  Modified three routines in MOM_opacity to avoid segmentation faults if
PEN_SW_NBANDS = 0, and hence if the optics type is not being allocated.  In the
case of optics_nbands(), this involved formally changing an optics_type argument
into a pointer to an optics_type.  (Pointers to an optics_type were already been
used as the argument in all calls to optics_nbands(), but it was not always
associated.)  In two other routines, the change is simply to add a return call
if there are 0 bands of shortwave radiation.  With these changes, the single
column test cases with no penetrating shortwave radiation now successfully run
if PEN_SW_NBANDS = 0 and give answers that are identical to those obtained with
PEN_SW_NBANDS = 1.  All answers and output in cases that ran previously are
bitwise identical, but there is a subtle change in a public interface.
  • Loading branch information
Hallberg-NOAA committed Dec 16, 2021
1 parent 08cd63b commit 0544f9f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/parameterizations/vertical/MOM_opacity.F90
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,15 @@ end subroutine extract_optics_fields

!> Return the number of bands of penetrating shortwave radiation.
function optics_nbands(optics)
type(optics_type), intent(in) :: optics !< An optics structure that has values of opacities
type(optics_type), pointer :: optics !< An optics structure that has values of opacities
!! and shortwave fluxes.
integer :: optics_nbands !< The number of penetrating bands of SW radiation

optics_nbands = optics%nbands
if (associated(optics)) then
optics_nbands = optics%nbands
else
optics_nbands = 0
endif
end function optics_nbands

!> Apply shortwave heating below the boundary layer (when running with the bulk mixed layer inherited
Expand Down Expand Up @@ -617,8 +621,10 @@ subroutine absorbRemainingSW(G, GV, US, h, opacity_band, nsw, optics, j, dt, H_l
! TKE budget of the shortwave heating.
real :: C1_6, C1_60
integer :: is, ie, nz, i, k, ks, n
SW_Remains = .false.

if (nsw < 1) return

SW_Remains = .false.
min_SW_heat = optics%PenSW_flux_absorb * dt
I_Habs = optics%PenSW_absorb_Invlen

Expand Down Expand Up @@ -842,12 +848,16 @@ subroutine sumSWoverBands(G, GV, US, h, nsw, optics, j, dt, &
integer :: is, ie, nz, i, k, ks, n
SW_Remains = .false.

min_SW_heat = optics%PenSW_flux_absorb*dt ! Default of 2.5e-11*US%T_to_s*GV%m_to_H
I_Habs = 1e3*GV%H_to_m ! optics%PenSW_absorb_Invlen

h_min_heat = 2.0*GV%Angstrom_H + GV%H_subroundoff
is = G%isc ; ie = G%iec ; nz = GV%ke

if (nsw < 1) then
netPen(:,:) = 0.0
return
endif

pen_SW_bnd(:,:) = iPen_SW_bnd(:,:)
do i=is,ie ; h_heat(i) = 0.0 ; enddo
do i=is,ie
Expand All @@ -859,6 +869,7 @@ subroutine sumSWoverBands(G, GV, US, h, nsw, optics, j, dt, &

! Apply penetrating SW radiation to remaining parts of layers.
! Excessively thin layers are not heated to avoid runaway temps.
min_SW_heat = optics%PenSW_flux_absorb*dt ! Default of 2.5e-11*US%T_to_s*GV%m_to_H
do k=1,nz

do i=is,ie
Expand Down

0 comments on commit 0544f9f

Please sign in to comment.