From 5cd90c6332ff112b8d7e718aa9bb5058b19ff0d1 Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Mon, 28 Oct 2024 11:58:02 -0600 Subject: [PATCH 1/2] Two changes to fpmix indexing There were two instances of indexing arrays out of bounds: 1. kfsc>=1, but we were looking for iFaceHeight(ksfc-1); I changed this to ksfc instead 2. kbl was set to nint(CS%kOBL(i,j)), and nint() would round up to ke+1 in some instances so I changed this to int(CS%kOBL(i,j,)) instead --- src/parameterizations/vertical/MOM_CVMix_KPP.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parameterizations/vertical/MOM_CVMix_KPP.F90 b/src/parameterizations/vertical/MOM_CVMix_KPP.F90 index 816d5d7498..9a7b997299 100644 --- a/src/parameterizations/vertical/MOM_CVMix_KPP.F90 +++ b/src/parameterizations/vertical/MOM_CVMix_KPP.F90 @@ -1152,7 +1152,7 @@ subroutine KPP_compute_BLD(CS, G, GV, US, h, Temp, Salt, u, v, tv, uStar, buoyFl StokesVt_1d(k) = StokesXI ! average temperature, salinity, u and v over surface layer starting at ksfc - delH = SLdepth_0d + iFaceHeight(ksfc-1) + delH = SLdepth_0d + iFaceHeight(ksfc) surfHtemp = Temp(i,j,ksfc) * delH surfHsalt = Salt(i,j,ksfc) * delH surfHu = (uE_H(ksfc) + uSbar_SLD) * delH @@ -1368,7 +1368,7 @@ subroutine KPP_compute_BLD(CS, G, GV, US, h, Temp, Salt, u, v, tv, uStar, buoyFl CS%OBLdepth(i,j) = US%m_to_Z * KPP_OBL_depth if (CS%StokesMOST) then - kbl = nint(CS%kOBL(i,j)) + kbl = int(CS%kOBL(i,j)) SLdepth_0d = CS%surf_layer_ext*CS%OBLdepth(i,j) surfBuoyFlux = surfBuoyFlux2(kbl) ! find ksfc for cell where "surface layer" sits From b3f55b28b37e8aff88b2d7eb987900471f5c19cf Mon Sep 17 00:00:00 2001 From: Michael Levy Date: Tue, 29 Oct 2024 14:36:29 -0600 Subject: [PATCH 2/2] Update to run with CESM gnu debug hbl_u and hbl_v were not being initialized in vertFPmix unless G%mask2dCu(I,j) and G%mask2dCv(i,J) were > 0.5 (2dCu for hbl_u and 2dCv for hbl_v), but we were using those values to determine whether to compute uInc_u and vInc_v. Now the computation of those two values are also in the if (G%mask2d...) block. --- .../vertical/MOM_vert_friction.F90 | 80 ++++++++++--------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/src/parameterizations/vertical/MOM_vert_friction.F90 b/src/parameterizations/vertical/MOM_vert_friction.F90 index 3f968b2101..8fa199df1d 100644 --- a/src/parameterizations/vertical/MOM_vert_friction.F90 +++ b/src/parameterizations/vertical/MOM_vert_friction.F90 @@ -225,8 +225,8 @@ subroutine vertFPmix(ui, vi, uold, vold, hbl_h, h, forces, dt, lpost, Cemp_NL, G real, dimension(SZI_(G),SZJB_(G)) :: hbl_v !< boundary layer depth (v-pts) [H ~> m] real, dimension(SZIB_(G),SZJ_(G)) :: taux_u !< kinematic zonal wind stress (u-pts) [L2 T-2 ~> m2 s-2] real, dimension(SZI_(G),SZJB_(G)) :: tauy_v !< kinematic merid wind stress (v-pts) [L2 T-2 ~> m2 s-2] - real, dimension(SZI_(G),SZJB_(G)) :: uS0 !< surface zonal Stokes drift [L T-1 ~> m s-1] - real, dimension(SZI_(G),SZJB_(G)) :: vS0 !< surface zonal Stokes drift [L T-1 ~> m s-1] + real, dimension(SZI_(G),SZJ_(G)) :: uS0 !< surface zonal Stokes drift h-pts [L T-1 ~> m s-1] + real, dimension(SZI_(G),SZJ_(G)) :: vS0 !< surface zonal Stokes drift h-pts [L T-1 ~> m s-1] real, dimension(SZIB_(G),SZJ_(G),SZK_(GV)) :: uE_u !< zonal Eulerian u-pts [L T-1 ~> m s-1] real, dimension(SZI_(G) ,SZJ_(G),SZK_(GV)) :: uE_h !< zonal Eulerian h-pts [L T-1 ~> m s-1] real, dimension(SZI_(G),SZJB_(G),SZK_(GV)) :: vE_v !< merid Eulerian v-pts [L T-1 ~> m s-1] @@ -264,25 +264,29 @@ subroutine vertFPmix(ui, vi, uold, vold, hbl_h, h, forces, dt, lpost, Cemp_NL, G ! h to u-pts tmp_u = MAX (1.0 ,(G%mask2dT(i,j) + G%mask2dT(i+1,j) ) ) hbl_u(I,j) = (G%mask2dT(i,j)* hbl_h(i,j) + G%mask2dT(i+1,j) * hbl_h(i+1,j)) / tmp_u - endif - depth = 0. - Gat1 = 0. - do k=1, nz - ! cell center - depth = depth + 0.5*CS%h_u(I,j,k) - uE_u(I,j,k) = ui(I,j,k) - waves%Us_x(I,j,k) - if ( depth < hbl_u(I,j) ) then - sigma = depth / hbl_u(i,j) - ! cell bottom + depth = 0. + Gat1 = 0. + do k=1, nz + ! cell center depth = depth + 0.5*CS%h_u(I,j,k) - call cvmix_kpp_composite_Gshape(sigma,Gat1,Gsig,dGdsig) - ! nonlocal boundary-layer increment - uInc_u(I,j,k) = dt * Cemp_NL * taux_u(I,j) * dGdsig / hbl_u(I,j) - ui(I,j,k) = ui(I,j,k) + uInc_u(I,j,k) - else + uE_u(I,j,k) = ui(I,j,k) - waves%Us_x(I,j,k) + if ( depth < hbl_u(I,j) ) then + sigma = depth / hbl_u(i,j) + ! cell bottom + depth = depth + 0.5*CS%h_u(I,j,k) + call cvmix_kpp_composite_Gshape(sigma,Gat1,Gsig,dGdsig) + ! nonlocal boundary-layer increment + uInc_u(I,j,k) = dt * Cemp_NL * taux_u(I,j) * dGdsig / hbl_u(I,j) + ui(I,j,k) = ui(I,j,k) + uInc_u(I,j,k) + else + uInc_u(I,j,k) = 0.0 + endif + enddo + else + do k=1, nz uInc_u(I,j,k) = 0.0 - endif - enddo + enddo + endif enddo enddo @@ -294,25 +298,29 @@ subroutine vertFPmix(ui, vi, uold, vold, hbl_h, h, forces, dt, lpost, Cemp_NL, G ! h to v-pts tmp_v = max( 1.0 ,(G%mask2dT(i,j) + G%mask2dT(i,j+1))) hbl_v(i,J) = (G%mask2dT(i,j) * hbl_h(i,J) + G%mask2dT(i,j+1) * hbl_h(i,j+1)) / tmp_v - endif - depth = 0. - Gat1 = 0. - do k=1, nz - ! cell center - depth = depth + 0.5* CS%h_v(i,J,k) - vE_v(i,J,k) = vi(i,J,k) - waves%Us_y(i,J,k) - if ( depth < hbl_v(i,J) ) then - sigma = depth / hbl_v(i,J) - ! cell bottom + depth = 0. + Gat1 = 0. + do k=1, nz + ! cell center depth = depth + 0.5* CS%h_v(i,J,k) - call cvmix_kpp_composite_Gshape(sigma,Gat1,Gsig,dGdsig) - ! nonlocal boundary-layer increment - vInc_v(i,J,k) = dt * Cemp_NL * tauy_v(i,J) * dGdsig / hbl_v(i,J) - vi(i,J,k) = vi(i,J,k) + vInc_v(i,J,k) - else + vE_v(i,J,k) = vi(i,J,k) - waves%Us_y(i,J,k) + if ( depth < hbl_v(i,J) ) then + sigma = depth / hbl_v(i,J) + ! cell bottom + depth = depth + 0.5* CS%h_v(i,J,k) + call cvmix_kpp_composite_Gshape(sigma,Gat1,Gsig,dGdsig) + ! nonlocal boundary-layer increment + vInc_v(i,J,k) = dt * Cemp_NL * tauy_v(i,J) * dGdsig / hbl_v(i,J) + vi(i,J,k) = vi(i,J,k) + vInc_v(i,J,k) + else + vInc_v(i,J,k) = 0.0 + endif + enddo + else + do k=1, nz vInc_v(i,J,k) = 0.0 - endif - enddo + enddo + endif enddo enddo