Skip to content

Commit

Permalink
fix recent bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed May 24, 2024
1 parent c5743fd commit 7fffc8f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
36 changes: 20 additions & 16 deletions thermosteam/equilibrium/vle.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def xV_iter(xVlogK, pcf_Psat_over_P, T, P,
xVlogK = xVlogK.copy()
xV = xVlogK[:-n]
Ks = np.exp(xVlogK[-n:])
x, y = xy(xV, Ks)
try:
x, y = xy(xV, Ks)
except:
breakpoint()
Ks[:] = pcf_Psat_over_P * f_gamma(x, T, *gamma_args) / f_phi(y, T, P)
V = binary.solve_phase_fraction_Rashford_Rice(z, Ks, xV[-1], z_light, z_heavy)
update_xV(xV, V, Ks, z)
Expand Down Expand Up @@ -1290,22 +1293,23 @@ def _solve_y(self, y, pcf_Psat_over_P, T, P):
N = self._N
z = self._z
Ks = pcf_Psat_over_P.copy()
n = z.size
if N > 2 or self._z_light or self._z_heavy:
f = xV_iter
args = (pcf_Psat_over_P, T, P, z, self._z_light,
self._z_heavy, gamma.f, gamma.args, self._phi, N)
self._z_heavy, gamma.f, gamma.args, self._phi, n)
elif N == 2:
f = xV_iter_2n
args = (pcf_Psat_over_P, T, P, z, gamma.f, gamma.args, self._phi, N)
args = (pcf_Psat_over_P, T, P, z, gamma.f, gamma.args, self._phi, n)
xVlogK = np.zeros(2*x.size + 1)
xVlogK[:N] = x
xVlogK[N] = self._V
xVlogK[-N:] = np.log(Ks)
xVlogK[:n] = x
xVlogK[n] = self._V
xVlogK[-n:] = np.log(Ks)
xVlogK = flx.aitken(f, xVlogK, self.x_tol, args, checkiter=False,
checkconvergence=False, convergenceiter=5,
maxiter=self.maxiter, subset=N)
x = xVlogK[:N]
self._V = V = xVlogK[N]
maxiter=self.maxiter, subset=n)
x = xVlogK[:n]
self._V = V = xVlogK[n]
x[x < 1e-32] = 1e-32
self._x = x = fn.normalize(x)
if V == 0:
Expand Down Expand Up @@ -1373,22 +1377,22 @@ def _solve_y_reactive(self, y, pcf_Psat_over_P, T, P, gas_reaction, liquid_react
z = self._z
Ks = pcf_Psat_over_P.copy()
f = xV_reactive_iter
N = self._N
index = self._index
n = z.size
args = (pcf_Psat_over_P, T, P, z, self._z_light, self._z_heavy,
gamma.f, gamma.args, self._phi, N,
gamma.f, gamma.args, self._phi, n,
gas_reaction, liquid_reaction, index)
xVlogK = np.zeros(2*x.size + 1)
xVlogK[:N] = x
xVlogK[N] = self._V
xVlogK[-N:] = np.log(Ks)
xVlogK[:n] = x
xVlogK[n] = self._V
xVlogK[-n:] = np.log(Ks)
xVlogK = flx.aitken(
f, xVlogK, self.x_tol, args, checkiter=False,
checkconvergence=False, convergenceiter=5,
maxiter=self.maxiter
)
x = xVlogK[:N]
self._V = V = xVlogK[N]
x = xVlogK[:n]
self._V = V = xVlogK[n]
x[x < 1e-32] = 1e-32
self._x = x = fn.normalize(x)
if V == 0:
Expand Down
4 changes: 4 additions & 0 deletions thermosteam/reaction/_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ class ReactionItem(Reaction):
"""
__slots__ = ('_index', '_parent')
kinetics = Reaction.kinetics
_kinetics = Reaction._kinetics
phases = MaterialIndexer.phases

def __init__(self, rxnset, index):
Expand Down Expand Up @@ -1154,6 +1156,8 @@ class ReactionSet:
__slots__ = (*Reaction.__slots__, '_parent_index')
copy = Reaction.copy
phases = MaterialIndexer.phases
kinetics = Reaction.kinetics
_kinetics = Reaction._kinetics
_get_stoichiometry_by_mol = Reaction._get_stoichiometry_by_mol
_get_stoichiometry_by_wt = Reaction._get_stoichiometry_by_wt
force_reaction = Reaction.force_reaction
Expand Down

0 comments on commit 7fffc8f

Please sign in to comment.