Skip to content

Commit

Permalink
Add maximum number of iterations in find_depth_of_pressure_in_cell
Browse files Browse the repository at this point in the history
  • Loading branch information
claireyung authored and marshallward committed May 21, 2024
1 parent 83bc4a6 commit 758b5a3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/MOM_density_integrals.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,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
Expand Down Expand Up @@ -1780,8 +1781,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 )

Expand Down

0 comments on commit 758b5a3

Please sign in to comment.