Skip to content

Commit

Permalink
minor enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Jan 13, 2024
1 parent 8db0ad9 commit 79ecb35
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
7 changes: 3 additions & 4 deletions thermosteam/_multi_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,17 +752,16 @@ def copy_flow(self,
"""
if self.chemicals is not other.chemicals and self.chemicals.IDs != other.chemicals.IDs:
raise ValueError('other stream must have the same chemicals defined to copy flow')
other_ismultistream = isinstance(other, MultiStream)
if other_ismultistream: self.phases = [*self.phases, *other.phases]
IDs_index = self.chemicals.get_index(IDs)
phase_index = self.imol.get_phase_index(phase)
data = self.imol.data
other_data = other.imol.data
multiphase = other_data.ndim == 2
if exclude:
data = self.imol.data
other_data = other.imol.data
original_data = data.copy()
if other_ismultistream:
if multiphase:
data[:] = other_data
data[phase_index, IDs_index] = original_data[phase_index, IDs_index]
if remove:
Expand All @@ -777,7 +776,7 @@ def copy_flow(self,
excluded_data = other_data[IDs_index]
other_data[:] = 0.
other_data[IDs_index] = excluded_data
elif other_ismultistream:
elif multiphase:
data[phase_index, IDs_index] = other_data[phase_index, IDs_index]
if remove: other_data[phase_index, IDs_index] = 0.
else:
Expand Down
11 changes: 8 additions & 3 deletions thermosteam/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,13 @@ def F_mass(self) -> float:
@F_mass.setter
def F_mass(self, value):
F_mass = self.F_mass
if not F_mass: raise AttributeError("undefined composition; cannot set flow rate")
self.imol.data *= value/F_mass
if F_mass:
self.imol.data *= value/F_mass
elif value:
raise AttributeError("undefined composition; cannot set flow rate")
else:
self.empty()

@property
def F_vol(self) -> float:
"""Total volumetric flow rate [m3/hr]."""
Expand Down Expand Up @@ -1968,7 +1973,7 @@ def empty(self):
0
"""
self._imol.data[:] = 0.
self._imol.data.clear()

### Equilibrium ###

Expand Down
12 changes: 9 additions & 3 deletions thermosteam/equilibrium/lle.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,15 @@ def __call__(self, T, P=None, top_chemical=None, update=True):
try: top_chemical_index = IDs[top_chemical]
except: pass
else:
C_L = mass_L[top_chemical_index] / mass_L.sum()
C_l = mass_l[top_chemical_index] / mass_l.sum()
if C_L < C_l: mol_l, mol_L = mol_L, mol_l
ML = mass_L.sum()
Ml = mass_l.sum()
if ML and Ml:
C_L = mass_L[top_chemical_index] / ML
C_l = mass_l[top_chemical_index] / Ml
if C_L < C_l: mol_l, mol_L = mol_L, mol_l
elif Ml:
mol_l, mol_L = mol_L, mol_l

F_mol_l = mol_l.sum()
F_mol_L = mol_L.sum()
if not F_mol_L:
Expand Down

0 comments on commit 79ecb35

Please sign in to comment.