Skip to content

Commit

Permalink
Add max number of iterations for the pH calc.
Browse files Browse the repository at this point in the history
  • Loading branch information
rqthomas authored Feb 8, 2020
1 parent e34393d commit cdf830a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/aed2_carbon.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1119,13 +1119,19 @@ SUBROUTINE Cal_pHfromTATC(TAx, TCx, pHx, K1F, K2F, TBF, KBF, KWF, KP1F, KP2F, KP

REAL :: H, Denom, CAlk, BAlk, OH, PhosTop, PhosBot, PAlk, SiAlk, &
& FREEtoTOT, Hfree, HSO4, HF, Residual, Slope, deltapH, pHTol, ln10

INTEGER :: count
INTEGER :: max_count

pHx = 8. !This is the first guess
pHTol = 0.0001 !tolerance for iterations end
ln10 = log(10.)
deltapH = pHTol + 1

count = 0
max_count = 100

DO WHILE (abs(deltapH) > pHTol)
DO WHILE (abs(deltapH) > pHTol .AND. count < max_count)
H = 10.**(-pHx)
Denom = (H*H + K1F*H + K1F*K2F)
CAlk = TCx*K1F*(H + 2.*K2F)/Denom
Expand All @@ -1149,7 +1155,7 @@ SUBROUTINE Cal_pHfromTATC(TAx, TCx, pHx, K1F, K2F, TBF, KBF, KWF, KP1F, KP2F, KP
END DO

pHx = pHx + deltapH !% Is on the same scale as K1 and K2 were calculated...

count = count + 1
END DO

END SUBROUTINE Cal_pHfromTATC
Expand Down

0 comments on commit cdf830a

Please sign in to comment.