Skip to content

Commit

Permalink
keep ports during disconnections
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Sep 18, 2024
1 parent b6ebbd3 commit 8a8796d
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions thermosteam/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,15 @@ def isproduct(self):
"""Return whether stream has a source but no sink."""
return bool(self._source and not self._sink)

def disconnect_source(self, resize=True):
def disconnect_source(self):
"""Disconnect stream from source."""
source = self._source
if source:
if resize:
source.outs.remove(self)
else:
source.outs.replace(self, source.MissingStream())
if source: source.outs.remove(self)

def disconnect_sink(self, resize=True):
def disconnect_sink(self):
"""Disconnect stream from sink."""
sink = self._sink
if sink:
if resize:
sink.ins.remove(self)
else:
sink.ins.replace(self, sink.MissingStream())
if sink: sink.ins.remove(self)

def disconnect(self):
"""Disconnect stream from unit."""
Expand Down Expand Up @@ -451,11 +443,7 @@ def pop(self, index):
return stream

def remove(self, stream):
if self._fixed_size:
self.replace(stream, self._create_missing_stream())
else:
self._undock(stream)
self._streams.remove(stream)
self.replace(stream, self._create_missing_stream())

def clear(self):
if self._fixed_size:
Expand Down Expand Up @@ -591,12 +579,12 @@ def reconnect(self):
if not (sink and getattr(sink, '_owner', None) is source):
source.outs[self.source_index] = self.stream
else:
self.stream.disconnect_source(resize=False)
self.stream.disconnect_source()
if sink:
if not (source and getattr(source, '_owner', None) is sink):
sink.ins[self.sink_index] = self.stream
else:
self.stream.disconnect_sink(resize=False)
self.stream.disconnect_sink()


# %% Piping notation
Expand Down Expand Up @@ -1592,12 +1580,12 @@ def disconnect(self, discard=False, inlets=None, outlets=None, join_ends=False):
ins = self._ins
outs = self._outs
if inlets is None:
inlets = tuple(ins)
inlets = [i for i in ins if i]
ins[:] = ()
else:
for i in inlets: ins[ins.index(i) if isinstance(i, AbstractStream) else i] = None
if outlets is None:
outlets = tuple(outs)
outlets = [i for i in outs if i]
outs[:] = ()
else:
for o in outlets: outs[ins.index(o) if isinstance(o, AbstractStream) else o] = None
Expand Down Expand Up @@ -2534,8 +2522,7 @@ def from_feedstock(cls, feedstock, feeds=(), ends=None, units=None, final=True,
if recycles: network.reduce_recycles()
network.sort(recycle_ends)
# network._add_interaction_units({}, [])
if interaction:
network.add_interaction_units(old_connections, ends)
if interaction: network.add_interaction_units(old_connections, ends)
return network

@classmethod
Expand Down

0 comments on commit 8a8796d

Please sign in to comment.