Skip to content

Commit

Permalink
add more auxiliary features
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Aug 5, 2024
1 parent b3ac9dd commit 498b00e
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions thermosteam/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,9 +1029,12 @@ def __init__(self,
#: Whether to prioritize unit operation specification within recycle loop (if any).
self.prioritize: bool = False

#: Safety toggle to prevent infinite recursion
#: Safety toggle to prevent infinite recursion.
self._active_specifications: set[ProcessSpecification] = set()

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

self._init(**kwargs)

def _init_inlets(self, ins):
Expand Down Expand Up @@ -1187,9 +1190,29 @@ def _unit_auxouts(self, N_streams, streams, thermo):
else:
return [self.auxout(i, thermo=thermo) for i in streams]

def register_auxiliary(self, unit, name=None):
if isinstance(unit, AbstractUnit):
if name is None: name = unit._ID
self.auxiliary_unit_names.add(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)
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)
setattr(self, name, i)
else:
raise ValueError('`unit` must be a unit, list of units, or a system')

def auxiliary(
self, name, cls, ins=None, outs=(), thermo=None,
**kwargs
register=False, **kwargs
):
"""
Create and register an auxiliary unit operation. Inlet and outlet
Expand All @@ -1205,6 +1228,8 @@ def auxiliary(
stack.append(auxunit)
else:
setattr(self, name, auxunit)
if register and name not in self.auxiliary_unit_names:
self.auxiliary_unit_names.add(name)
auxunit.owner = self # Avoids property package checks
auxunit.__init__(
'.' + name,
Expand Down

0 comments on commit 498b00e

Please sign in to comment.