Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maximum number of iterations in find_depth_of_pressure_in_cell #609

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/core/MOM_density_integrals.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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]
marshallward marked this conversation as resolved.
Show resolved Hide resolved
character(len=240) :: msg

GxRho = G_e * rho_ref
Expand Down Expand Up @@ -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
marshallward marked this conversation as resolved.
Show resolved Hide resolved
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)
marshallward marked this conversation as resolved.
Show resolved Hide resolved
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
Loading