From a8a0a547a2872f99e728417ab1eca646a1b18750 Mon Sep 17 00:00:00 2001 From: Claire Yung Date: Wed, 24 Apr 2024 13:08:47 -0400 Subject: [PATCH 1/2] Add maximum number of iterations in find_depth_of_pressure_in_cell --- src/core/MOM_density_integrals.F90 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core/MOM_density_integrals.F90 b/src/core/MOM_density_integrals.F90 index 9fed528e71..ac3bfb1661 100644 --- a/src/core/MOM_density_integrals.F90 +++ b/src/core/MOM_density_integrals.F90 @@ -1562,6 +1562,7 @@ subroutine find_depth_of_pressure_in_cell(T_t, T_b, S_t, S_b, z_t, z_b, P_t, P_t real :: F_guess, F_l, F_r ! Fractional positions [nondim] real :: GxRho ! The product of the gravitational acceleration and reference density [R L2 Z-1 T-2 ~> Pa m-1] real :: Pa, Pa_left, Pa_right, Pa_tol ! Pressure anomalies, P = integral of g*(rho-rho_ref) dz [R L2 T-2 ~> Pa] + integer :: m ! A counter for how many iterations have been done in the while loop [nondim] character(len=240) :: msg GxRho = G_e * rho_ref @@ -1589,8 +1590,14 @@ subroutine find_depth_of_pressure_in_cell(T_t, T_b, S_t, S_b, z_t, z_b, P_t, P_t F_guess = F_l - Pa_left / (Pa_right - Pa_left) * (F_r - F_l) Pa = Pa_right - Pa_left ! To get into iterative loop + m = 0 ! Reset the counter for the loop to be zero do while ( abs(Pa) > Pa_tol ) + m = m + 1 + if (m > 30) then !Call an error, because convergence to the tolerance has not been achieved + write(msg,*) Pa_left,Pa,Pa_right,P_t-P_tgt,P_b-P_tgt + call MOM_error(FATAL, 'find_depth_of_pressure_in_cell completes too many iterations: /n'//msg) + endif z_out = z_t + ( z_b - z_t ) * F_guess Pa = frac_dp_at_pos(T_t, T_b, S_t, S_b, z_t, z_b, rho_ref, G_e, F_guess, EOS) - ( P_tgt - P_t ) From dbe45c9341e9756c296349b9d0697fef9eed7bd0 Mon Sep 17 00:00:00 2001 From: Claire Yung Date: Thu, 16 May 2024 10:31:17 +1000 Subject: [PATCH 2/2] Fix minor issues --- src/core/MOM_density_integrals.F90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/MOM_density_integrals.F90 b/src/core/MOM_density_integrals.F90 index ac3bfb1661..a0aa98684b 100644 --- a/src/core/MOM_density_integrals.F90 +++ b/src/core/MOM_density_integrals.F90 @@ -1562,7 +1562,7 @@ subroutine find_depth_of_pressure_in_cell(T_t, T_b, S_t, S_b, z_t, z_b, P_t, P_t real :: F_guess, F_l, F_r ! Fractional positions [nondim] real :: GxRho ! The product of the gravitational acceleration and reference density [R L2 Z-1 T-2 ~> Pa m-1] real :: Pa, Pa_left, Pa_right, Pa_tol ! Pressure anomalies, P = integral of g*(rho-rho_ref) dz [R L2 T-2 ~> Pa] - integer :: m ! A counter for how many iterations have been done in the while loop [nondim] + integer :: m ! A counter for how many iterations have been done in the while loop character(len=240) :: msg GxRho = G_e * rho_ref @@ -1594,9 +1594,9 @@ subroutine find_depth_of_pressure_in_cell(T_t, T_b, S_t, S_b, z_t, z_b, P_t, P_t do while ( abs(Pa) > Pa_tol ) m = m + 1 - if (m > 30) then !Call an error, because convergence to the tolerance has not been achieved + if (m > 30) then ! Call an error, because convergence to the tolerance has not been achieved write(msg,*) Pa_left,Pa,Pa_right,P_t-P_tgt,P_b-P_tgt - call MOM_error(FATAL, 'find_depth_of_pressure_in_cell completes too many iterations: /n'//msg) + call MOM_error(FATAL, 'find_depth_of_pressure_in_cell completes too many iterations: '//msg) endif z_out = z_t + ( z_b - z_t ) * F_guess Pa = frac_dp_at_pos(T_t, T_b, S_t, S_b, z_t, z_b, rho_ref, G_e, F_guess, EOS) - ( P_tgt - P_t )