Skip to content

Commit

Permalink
Hopefully fix the interesting and unique test failures on Travis and …
Browse files Browse the repository at this point in the history
…Appveyor CalebBell#3
  • Loading branch information
CalebBell committed Jan 13, 2017
1 parent ae773e3 commit 306ac90
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
3 changes: 1 addition & 2 deletions tests/test_chemical.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def test_Chemical_properties():
assert sorted(l.keys()) == ['DSL', 'EINECS', 'NLP', 'SPIN', 'TSCA']
assert sorted(l.values()) == ['LISTED', 'LISTED', 'LISTED', 'LISTED', 'UNLISTED']

e = phenol.economic_status
assert e == ["US public: {'Manufactured': 1338357.268, 'Imported': 3847.128, 'Exported': 337387.382}", u'1,000,000 - 10,000,000 tonnes per annum', 'OECD HPV Chemicals']
phenol.economic_status

assert_allclose(benzene.conductivity, 7.6e-06)
assert_allclose(benzene.RI, 1.5011)
Expand Down
17 changes: 3 additions & 14 deletions thermo/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,7 @@ def Li_Johns_Ahmadi_solution(zs, Ks):
If the `newton` method does not converge, a bisection method (brenth) is
used instead. However, it is somewhat slower, especially as newton will
attempt 50 iterations before giving up.
The range of xmin and xmax provided by the method may include negative
roots, which the solver may converge on. In this way this method is
inferior to the Rachford-Rice equation. If such a solution is converged on,
:obj:`Rachford_Rice_solution` is called to solve the problem.
This method does not work for problems of only two components.
K values are sorted internally. Has not been found to be quicker than the
Rachford-Rice equation.
Expand Down Expand Up @@ -282,25 +277,19 @@ def Li_Johns_Ahmadi_solution(zs, Ks):
kn_m_1 = kn-1.
k1_m_1 = (k1-1.)
t1 = (k1-kn)/(kn-1.)
iterable = zip(Ks_sorted[1:length], zs_sorted[1:length])

objective = lambda x1: 1. + t1*x1 + sum([(ki-kn)/(kn_m_1) * zi*k1_m_1*x1 /( (ki-1.)*z1 + (k1-ki)*x1) for ki, zi in iterable])
objective = lambda x1: 1. + t1*x1 + sum([(ki-kn)/(kn_m_1) * zi*k1_m_1*x1 /( (ki-1.)*z1 + (k1-ki)*x1) for ki, zi in zip(Ks_sorted[1:length], zs_sorted[1:length])])
try:
x1 = newton(objective, x_guess)
# newton skips out of its specified range in some cases, finding another solution
# Check for that with asserts, and use brenth if it did
# Must also check that V_over_F is right.
assert x1 >= x_min2
assert x1 <= x_max2
V_over_F = (-x1 + z1)/(x1*(k1 - 1.))
assert 0 <= V_over_F <= 1
except:
x1 = brenth(objective, x_min, x_max)
V_over_F = (-x1 + z1)/(x1*(k1 - 1.))
try:
assert 0 <= V_over_F <= 1
except:
V_over_F, _, _ = Rachford_Rice_solution(zs=zs, Ks=Ks)
V_over_F = (-x1 + z1)/(x1*(k1 - 1.))
xs = [zi/(1.+V_over_F*(Ki-1.)) for zi, Ki in zip(zs, Ks)]
ys = [Ki*xi for xi, Ki in zip(xs, Ks)]
return V_over_F, xs, ys
Expand Down

0 comments on commit 306ac90

Please # to comment.