Skip to content

Commit

Permalink
Avoid an overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBell committed May 15, 2021
1 parent 824eb8f commit 5ba59e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion chemicals/dippr.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,14 @@ def EQ106(T, Tc, A, B, C=0.0, D=0.0, E=0.0, order=0):
'''
if order == 0:
Tr = T/Tc
return A*(1. - Tr)**(B + Tr*(C + Tr*(D + E*Tr)))
tau = (1.0 - Tr)
power = (B + Tr*(C + Tr*(D + E*Tr)))
try:
return A*tau**power
except:
# TODO: after more testing with regression, maybe return a more
# precise value or allow A to impact the result
return 1e300
elif order == 1:
x0 = 1.0/Tc
x1 = T*x0
Expand Down
5 changes: 5 additions & 0 deletions tests/test_dippr.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def test_EQ106_more():
d3_numerical = derivative(lambda T: EQ106(T, 647.096, 0.17766, 2.567, -3.3377, 1.9699, order=2), 300.0, dx=1e-4)
assert_close(d3_analytical, -5.524739890945817e-09, rtol=1e-13)
assert_close(d3_analytical, d3_numerical, rtol=1e-8)

# check that this regression set of points does not produce an error
overflow_kwargs = {'T': 304.747, 'Tc': 405.4, 'A': 56.743647419038744, 'B': -75.36242555958763,
'C': -141.1028969227863, 'D': -254.76349199392695, 'E': -442.5916844036474, 'order': 0}
EQ106(**overflow_kwargs)


def test_EQ101_more():
Expand Down

0 comments on commit 5ba59e1

Please sign in to comment.