|
12 | 12 | from .equilibrium import Equilibrium |
13 | 13 | from ..exceptions import NoEquilibrium |
14 | 14 | from .binary_phase_fraction import phase_fraction |
15 | | -from .tangential_plane_stability import lle_tangential_plan_analysis |
| 15 | +from .tangential_plane_stability import lle_tangential_plane_analysis |
16 | 16 | from scipy.optimize import shgo, differential_evolution |
17 | 17 | import flexsolve as flx |
18 | 18 | import numpy as np |
@@ -121,28 +121,22 @@ def pseudo_equilibrium(K, phi, z, T, n, f_gamma, gamma_args, inner_loop_options, |
121 | 121 | # Light weight |
122 | 122 | def solve_lle_mol(gamma, z, T, P, sample=None, phi=1): |
123 | 123 | n = z.size |
124 | | - stability = lle_tangential_plan_analysis(gamma, z, T, P, sample=sample) |
| 124 | + stability = lle_tangential_plane_analysis(gamma, z, T, P, samples=sample) |
125 | 125 | if stability.unstable: |
126 | 126 | y = stability.candidate |
127 | 127 | y[y < 1e-64] = 1e-64 |
128 | | - if stability.sample_unstable: |
129 | | - phi = min(0.99 * (z / y).min(), phi) |
130 | | - else: |
131 | | - phi = 0.99 * (z / y).min() |
| 128 | + phi = 0.99 * (z / y).min() |
132 | 129 | x = z - phi * y |
133 | 130 | x /= x.sum() |
134 | 131 | K = gamma(y, T) / gamma(x, T) |
135 | 132 | else: |
136 | 133 | return z |
137 | 134 | K[K <= 0] = 1e-9 |
138 | | - try: |
139 | | - mol = pseudo_equilibrium( |
140 | | - K, phi, z, T, n, gamma.f, gamma.args, |
141 | | - LLE.pseudo_equilibrium_inner_loop_options, |
142 | | - LLE.pseudo_equilibrium_outer_loop_options, |
143 | | - ) |
144 | | - except: |
145 | | - breakpoint() |
| 135 | + mol = pseudo_equilibrium( |
| 136 | + K, phi, z, T, n, gamma.f, gamma.args, |
| 137 | + LLE.pseudo_equilibrium_inner_loop_options, |
| 138 | + LLE.pseudo_equilibrium_outer_loop_options, |
| 139 | + ) |
146 | 140 | if mol.any(): |
147 | 141 | return mol / mol.sum() |
148 | 142 | else: |
@@ -357,22 +351,32 @@ def solve_lle_liquid_mol(self, z, T, lle_chemicals, single_loop): |
357 | 351 | K = self._K |
358 | 352 | phi = self._phi |
359 | 353 | x0 = z / (1. + phi * (K - 1.)) |
| 354 | + x0 /= x0.sum() |
360 | 355 | sample = x0 |
361 | 356 | else: |
362 | 357 | sample = None |
363 | | - stability = lle_tangential_plan_analysis(gamma, z, T, 101325, sample=sample) |
| 358 | + stability = lle_tangential_plane_analysis(gamma, z, T, 101325, sample=sample) |
364 | 359 | if stability.unstable: |
365 | 360 | y = stability.candidate |
366 | | - y[y < 1e-64] = 1e-64 |
367 | | - if stability.sample_unstable: |
368 | | - phi = min(0.99 * (z / y).min(), phi) |
369 | | - else: |
370 | | - phi = 0.99 * (z / y).min() |
| 361 | + y[y < 1e-32] = 1e-32 |
| 362 | + phi = 0.999 * (z / y).min() |
371 | 363 | x = z - phi * y |
372 | 364 | x /= x.sum() |
373 | 365 | K = gamma(y, T) / gamma(x, T) |
374 | 366 | else: |
375 | | - return z |
| 367 | + indices = np.argsort(z * np.array([i.MW for i in lle_chemicals])) |
| 368 | + x = z.copy() |
| 369 | + y = z.copy() |
| 370 | + a = indices[-1] |
| 371 | + b = indices[-2] |
| 372 | + x[a] = 0.99 |
| 373 | + y[a] = 1e-3 |
| 374 | + x[b] = 1e-3 |
| 375 | + y[b] = 0.99 |
| 376 | + x /= x.sum() |
| 377 | + y /= y.sum() |
| 378 | + K = gamma(y, T) / gamma(x, T) |
| 379 | + phi = 0.5 |
376 | 380 | if single_loop: |
377 | 381 | f_gamma = gamma.f |
378 | 382 | gamma_args = gamma.args |
|
0 commit comments