From 852b8ac33ac8658518d2993ae8c8ddd27e10b792 Mon Sep 17 00:00:00 2001 From: Yalin Li Date: Tue, 15 Sep 2026 07:43:23 -0400 Subject: [PATCH 1/3] try fixing vle bug --- thermosteam/equilibrium/vle.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/thermosteam/equilibrium/vle.py b/thermosteam/equilibrium/vle.py index bf2474d4..2d7ae1cf 100644 --- a/thermosteam/equilibrium/vle.py +++ b/thermosteam/equilibrium/vle.py @@ -1449,27 +1449,31 @@ def _setup(self, gas_conversion=None, liquid_conversion=None, T=None, P=None): LNK_index = chemicals._light_indices HNK_index = chemicals._heavy_indices if self._thermo.Gamma is not None: + new_light_chems = [] if T is not None: - new_light_chems = [] for i in index: chemical = chemicals.tuple[i] - if T > chemical.Tc: + Tc = chemical.Tc + if Tc is not None and T > Tc: nonzero.remove(i) # Exclude from VLE new_light_chems.append(i) if new_light_chems: - if HNK_index: + if HNK_index: LNK_index = [*LNK_index, *new_light_chems] else: LNK_index = new_light_chems if P is not None: new_heavy_chems = [] for i in index: + if i in new_light_chems: + continue chemical = chemicals.tuple[i] - if P > chemical.Pc: + Pc = chemical.Pc + if Pc is not None and P > Pc: nonzero.remove(i) # Exclude from VLE new_heavy_chems.append(i) if new_heavy_chems: - if HNK_index: + if HNK_index: HNK_index = [*HNK_index, *new_heavy_chems] else: HNK_index = new_heavy_chems From 1a082e66f7b103a3dae980272bea217063b0fbf9 Mon Sep 17 00:00:00 2001 From: Yalin Li Date: Tue, 15 Sep 2026 07:58:44 -0400 Subject: [PATCH 2/3] fix LNK_index typo --- thermosteam/equilibrium/vle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thermosteam/equilibrium/vle.py b/thermosteam/equilibrium/vle.py index 2d7ae1cf..dcb1acff 100644 --- a/thermosteam/equilibrium/vle.py +++ b/thermosteam/equilibrium/vle.py @@ -1458,7 +1458,7 @@ def _setup(self, gas_conversion=None, liquid_conversion=None, T=None, P=None): nonzero.remove(i) # Exclude from VLE new_light_chems.append(i) if new_light_chems: - if HNK_index: + if LNK_index: LNK_index = [*LNK_index, *new_light_chems] else: LNK_index = new_light_chems From 138aaa9c241c642341d2ad1ec798297ed16f9a86 Mon Sep 17 00:00:00 2001 From: Yalin Li Date: Tue, 15 Sep 2026 09:32:32 -0400 Subject: [PATCH 3/3] fix HNK_index size --- thermosteam/equilibrium/vle.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/thermosteam/equilibrium/vle.py b/thermosteam/equilibrium/vle.py index dcb1acff..b927849b 100644 --- a/thermosteam/equilibrium/vle.py +++ b/thermosteam/equilibrium/vle.py @@ -1448,6 +1448,7 @@ def _setup(self, gas_conversion=None, liquid_conversion=None, T=None, P=None): index = chemicals.get_vle_indices(nonzero) LNK_index = chemicals._light_indices HNK_index = chemicals._heavy_indices + heavy_solutes = chemicals._heavy_solutes if self._thermo.Gamma is not None: new_light_chems = [] if T is not None: @@ -1473,6 +1474,11 @@ def _setup(self, gas_conversion=None, liquid_conversion=None, T=None, P=None): nonzero.remove(i) # Exclude from VLE new_heavy_chems.append(i) if new_heavy_chems: + # Newly-excluded chemicals are not literal solutes; + # treat each as contributing 1 solute-equivalent. + heavy_solutes = np.concatenate( + [heavy_solutes, np.ones(len(new_heavy_chems))] + ) if HNK_index: HNK_index = [*HNK_index, *new_heavy_chems] else: @@ -1508,7 +1514,7 @@ def _setup(self, gas_conversion=None, liquid_conversion=None, T=None, P=None): liquid_mol[LNK_index] = 0 liquid_mol[HNK_index] = heavy_mol = mol[HNK_index] self._F_mol_light = F_mol_light = light_mol.sum() - self._F_mol_heavy = F_mol_heavy = (heavy_mol * chemicals._heavy_solutes).sum() + self._F_mol_heavy = F_mol_heavy = (heavy_mol * heavy_solutes).sum() self._F_mol_vle = F_mol_vle = mol_vle.sum() if F_mol_vle == 0: F_mol_vle = 1e-16 self._F_mol = F_mol = F_mol_vle + F_mol_light + F_mol_heavy