Skip to content

Commit

Permalink
keep auxiliary units order
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Sep 18, 2024
1 parent 514a827 commit b6ebbd3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions thermosteam/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ def __init__(self,
self._active_specifications: set[ProcessSpecification] = set()

#: Auxiliary unit operation names.
self.auxiliary_unit_names = set(self.auxiliary_unit_names)
self.auxiliary_unit_names = list(self.auxiliary_unit_names)

self._init(**kwargs)

Expand Down Expand Up @@ -1207,21 +1207,23 @@ def _unit_auxouts(self, N_streams, streams, thermo):
return [self.auxout(i, thermo=thermo) for i in streams]

def register_auxiliary(self, unit, name=None):
names_list = self.auxiliary_unit_names
names_set = set(names_list)
if isinstance(unit, AbstractUnit):
if name is None: name = unit._ID
self.auxiliary_unit_names.add(name)
if name not in names_set: names_list.append(name)
setattr(self, name, unit)
elif isinstance(unit, Iterable):
if name is None: raise ValueError('`name` must be a string')
self.auxiliary_unit_names.add(name)
if name not in names_set: names_list.append(name)
setattr(self, name, unit)
elif hasattr(unit, 'units'):
system = unit
if name is None: name = system._ID
setattr(self, name, system)
for i in system.units:
name = i._ID
self.auxiliary_unit_names.add(name)
if name not in names_set: names_list.append(name)
setattr(self, name, i)
else:
raise ValueError('`unit` must be a unit, list of units, or a system')
Expand Down

0 comments on commit b6ebbd3

Please sign in to comment.