From de948030029248138d0004b3aec4bcd50cf6688f Mon Sep 17 00:00:00 2001 From: Bill Sacks Date: Thu, 17 Oct 2024 16:45:36 -0600 Subject: [PATCH 1/3] Ensure psfc is always allocated This is needed to avoid a segmentation fault in the call to flux_atmocn in SMS_Ld2.ne30pg3_t232.BMT1850.derecho_gnu.allactive-defaultio when running with aoflux_grid=xgrid --- mediator/med_phases_aofluxes_mod.F90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mediator/med_phases_aofluxes_mod.F90 b/mediator/med_phases_aofluxes_mod.F90 index dcb73692..7c27abce 100644 --- a/mediator/med_phases_aofluxes_mod.F90 +++ b/mediator/med_phases_aofluxes_mod.F90 @@ -1647,6 +1647,8 @@ subroutine set_aoflux_in_pointers(fldbun_a, fldbun_o, aoflux_in, lsize, xgrid, r if (FB_fldchk(fldbun_a, 'Sa_pslv', rc=rc)) then call fldbun_getfldptr(fldbun_a, 'Sa_pslv', aoflux_in%psfc, xgrid=xgrid, rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return + else + allocate(aoflux_in%psfc(lsize)) end if ! if either density or potential temperature are computed, will need bottom level pressure From 0bbdcd010ff651b8b761863c10354c2f4dcd1f14 Mon Sep 17 00:00:00 2001 From: Bill Sacks Date: Fri, 18 Oct 2024 16:40:42 -0600 Subject: [PATCH 2/3] More correct fix to ensure psfc is allocated when needed This is needed to avoid a segmentation fault in the call to flux_atmocn in SMS_Ld2.ne30pg3_t232.BMT1850.derecho_gnu.allactive-defaultio when running with aoflux_grid=xgrid. I think that the previous fix wasn't correct when using xgrid, because I think nothing is originally in fldbun_a in that case. --- mediator/med_phases_aofluxes_mod.F90 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mediator/med_phases_aofluxes_mod.F90 b/mediator/med_phases_aofluxes_mod.F90 index 7c27abce..401cc287 100644 --- a/mediator/med_phases_aofluxes_mod.F90 +++ b/mediator/med_phases_aofluxes_mod.F90 @@ -1644,21 +1644,16 @@ subroutine set_aoflux_in_pointers(fldbun_a, fldbun_o, aoflux_in, lsize, xgrid, r if (chkerr(rc,__LINE__,u_FILE_u)) return end if - if (FB_fldchk(fldbun_a, 'Sa_pslv', rc=rc)) then + if ((trim(coupling_mode) == 'cesm') .or. & + (trim(coupling_mode) == 'ufs.frac.aoflux' .and. trim(aoflux_code) == 'ccpp')) then call fldbun_getfldptr(fldbun_a, 'Sa_pslv', aoflux_in%psfc, xgrid=xgrid, rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return - else - allocate(aoflux_in%psfc(lsize)) end if ! if either density or potential temperature are computed, will need bottom level pressure if (compute_atm_dens .or. compute_atm_thbot) then call fldbun_getfldptr(fldbun_a, 'Sa_pbot', aoflux_in%pbot, xgrid=xgrid, rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return - if (trim(coupling_mode) == 'ufs.frac.aoflux') then - call fldbun_getfldptr(fldbun_a, 'Sa_pslv', aoflux_in%psfc, xgrid=xgrid, rc=rc) - if (chkerr(rc,__LINE__,u_FILE_u)) return - end if end if if (flds_wiso) then From d9255d5f8ee1a4d3374f06c49c10866bc30712bc Mon Sep 17 00:00:00 2001 From: Bill Sacks Date: Tue, 22 Oct 2024 12:54:18 -0600 Subject: [PATCH 3/3] Tweak conditional for setting psfc for ufs Based on discussion in https://github.com/ESCOMP/CMEPS/pull/514 --- mediator/med_phases_aofluxes_mod.F90 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mediator/med_phases_aofluxes_mod.F90 b/mediator/med_phases_aofluxes_mod.F90 index 401cc287..6cf7280e 100644 --- a/mediator/med_phases_aofluxes_mod.F90 +++ b/mediator/med_phases_aofluxes_mod.F90 @@ -1644,8 +1644,13 @@ subroutine set_aoflux_in_pointers(fldbun_a, fldbun_o, aoflux_in, lsize, xgrid, r if (chkerr(rc,__LINE__,u_FILE_u)) return end if + ! The following conditional captures the cases where aoflux_in%psfc is needed in calls + ! to flux_atmocn / flux_atmocn_ccpp. Note that coupling_mode=='cesm' is equivalent to + ! the CESMCOUPLED CPP token, and coupling_mode(1:3)=='ufs' is roughly equivalent to + ! the UFS_AOFLUX CPP token (noting that we should only be in this subroutine if using + ! one of the aoflux variants of the ufs coupling_mode). if ((trim(coupling_mode) == 'cesm') .or. & - (trim(coupling_mode) == 'ufs.frac.aoflux' .and. trim(aoflux_code) == 'ccpp')) then + (coupling_mode(1:3) == 'ufs' .and. trim(aoflux_code) == 'ccpp')) then call fldbun_getfldptr(fldbun_a, 'Sa_pslv', aoflux_in%psfc, xgrid=xgrid, rc=rc) if (chkerr(rc,__LINE__,u_FILE_u)) return end if