From fccb7ae4e0cc678893d1d1a6cb08f799aead2a85 Mon Sep 17 00:00:00 2001 From: Alistair Adcroft Date: Tue, 25 Jul 2017 15:10:23 -0400 Subject: [PATCH 1/2] Avoids a SEGV when OBC are not in use with bi-harmonic friction - If OBC is not associated, the if expression could lead to a segmentation violation even when apply_OBC is false. - No answer changes. --- src/parameterizations/lateral/MOM_hor_visc.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parameterizations/lateral/MOM_hor_visc.F90 b/src/parameterizations/lateral/MOM_hor_visc.F90 index 2ad88948d6..708e26babb 100644 --- a/src/parameterizations/lateral/MOM_hor_visc.F90 +++ b/src/parameterizations/lateral/MOM_hor_visc.F90 @@ -529,7 +529,7 @@ subroutine horizontal_viscosity(u, v, h, diffu, diffv, MEKE, VarMix, G, GV, CS, v0(i,J) = CS%IDXDY2v(i,J)*(CS%DY2q(I,J)*sh_xy(I,J) - CS%DY2q(I-1,J)*sh_xy(I-1,J)) - & CS%IDX2dyCv(i,J)*(CS%DX2h(i,j+1)*sh_xx(i,j+1) - CS%DX2h(i,j)*sh_xx(i,j)) enddo ; enddo - if (apply_OBC .and. OBC%zero_biharmonic) then + if (apply_OBC) then; if (OBC%zero_biharmonic) then do n=1,OBC%number_of_segments I = OBC%segment(n)%HI%IsdB ; J = OBC%segment(n)%HI%JsdB if (OBC%segment(n)%is_N_or_S .and. (J >= Jsq-1) .and. (J <= Jeq+1)) then @@ -542,7 +542,7 @@ subroutine horizontal_viscosity(u, v, h, diffu, diffv, MEKE, VarMix, G, GV, CS, enddo endif enddo - endif + endif; endif endif do j=Jsq,Jeq+1 ; do i=Isq,Ieq+1 From be46fee29445425ed471503e675c8ed1468eea24 Mon Sep 17 00:00:00 2001 From: Alistair Adcroft Date: Fri, 28 Jul 2017 00:49:53 -0400 Subject: [PATCH 2/2] (*)Fixes gprime(1) when no layer coordinates are set - The "none" option for COORD_CONFIG literally did nothing which meant that Rlay and gprime were unset (they actually appeared to be zero). This mode was added with the intent that the model should not need these coordinate variables in ALE mode. However, gprime(k=1) is used and should be set to GFS, which this commit now does. - I also added "ALE" as an option for COORD_CONFIG which is equivalent to "none" since "ALE" is bit more intuitive. - We might even use this as a master switch or check that COORD_CONFIG is consistent with USE_REGRIDDING (for later)? - This commit "appears" to changes answers but I don't think it does. What changes is the calculation of energy for some experiments in which Rlay was not set before this commit. A non-zero gprime(1) produces different APEs. Experiments affected are: - CVmix_SCM_tests/cooling_only/EPBL - CVmix_SCM_tests/cooling_only/KPP - CVmix_SCM_tests/mech_only/EPBL - CVmix_SCM_tests/mech_only/KPP - CVmix_SCM_tests/skin_warming_wind/EPBL - CVmix_SCM_tests/skin_warming_wind/KPP - CVmix_SCM_tests/wind_only/EPBL - CVmix_SCM_tests/wind_only/KPP - SCM_idealized_hurricane - single_column/EPBL - single_column/KPP - unit_tests All the above have COORD_CONFIG="none". --- .../MOM_coord_initialization.F90 | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/initialization/MOM_coord_initialization.F90 b/src/initialization/MOM_coord_initialization.F90 index f5acb96090..094e7617eb 100644 --- a/src/initialization/MOM_coord_initialization.F90 +++ b/src/initialization/MOM_coord_initialization.F90 @@ -58,6 +58,7 @@ subroutine MOM_initialize_coord(GV, PF, write_geom, output_dir, tv, max_depth) ! Set-up the layer densities, GV%Rlay, and reduced gravities, GV%g_prime. call get_param(PF, mod, "COORD_CONFIG", config, & "This specifies how layers are to be defined: \n"//& + " \t ALE or none - used to avoid defining layers in ALE mode \n"//& " \t file - read coordinate information from the file \n"//& " \t\t specified by (COORD_FILE).\n"//& " \t BFB - Custom coords for buoyancy-forced basin case \n"//& @@ -93,7 +94,8 @@ subroutine MOM_initialize_coord(GV, PF, write_geom, output_dir, tv, max_depth) call user_set_coord(GV%Rlay, GV%g_prime, GV, PF, eos) case ("BFB") call BFB_set_coord(GV%Rlay, GV%g_prime, GV, PF, eos) - case ("none") + case ("none", "ALE") + call set_coord_to_none(GV%Rlay, GV%g_prime, GV, PF) case default ; call MOM_error(FATAL,"MOM_initialize_coord: "// & "Unrecognized coordinate setup"//trim(config)) end select @@ -493,7 +495,38 @@ subroutine set_coord_linear(Rlay, g_prime, GV, param_file) call callTree_leave(trim(mod)//'()') end subroutine set_coord_linear -! ----------------------------------------------------------------------------- +!> Sets Rlay to Rho0 and g_prime to zero except for the free surface. +!! This is for use only in ALE mode where Rlay should not be used and g_prime(1) alone +!! might be used. +subroutine set_coord_to_none(Rlay, g_prime, GV, param_file) + real, dimension(:), intent(out) :: Rlay !< The layers' target coordinate values + !! (potential density). + real, dimension(:), intent(out) :: g_prime !< A structure indicating the open file to + !! parse for model parameter values. + type(verticalGrid_type), intent(in) :: GV !< The ocean's vertical grid structure. + type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters + real :: g_fs ! Reduced gravity across the free surface, in m s-2. + character(len=40) :: mdl = "set_coord_to_none" ! This subroutine's name. + integer :: k, nz + nz = GV%ke + + call callTree_enter(trim(mdl)//"(), MOM_coord_initialization.F90") + + call get_param(param_file, mdl, "GFS" , g_fs, & + "The reduced gravity at the free surface.", units="m s-2", & + default=GV%g_Earth) + + g_prime(1) = g_fs + do k=2,nz ; g_prime(k) = 0. ; enddo + Rlay(1) = GV%Rho0 + do k=2,nz ; Rlay(k) = Rlay(k-1) + g_prime(k)*(GV%Rho0/GV%g_Earth) ; enddo + + call callTree_leave(trim(mdl)//'()') + +end subroutine set_coord_to_none + +!> This subroutine writes out a file containing any available data related +!! to the vertical grid used by the MOM ocean model. subroutine write_vertgrid_file(GV, param_file, directory) type(verticalGrid_type), intent(in) :: GV !< The ocean's vertical grid structure type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters