5. Managing flowsheets#

5.1. Retrieve any Unit, Stream or System object by ID#

All BioSTEAM objects are registered in the main flowsheet. When BioSTEAM is first imported, the main flowsheet defaults to the ‘default’ flowsheet:

[1]:
from biosteam import main_flowsheet as F, settings, units
import biosteam as bst
bst.nbtutorial() # Light-mode html diagrams and filter warnings
F
[1]:
<MainFlowsheet: default>

Find a Unit object:

[2]:
settings.set_thermo(['Water', 'Ethanol'])
units.Mixer('M1')
F.M1.diagram()
F.M1.show()
Mixer: M1
ins...
[0] -
    phase: 'l', T: 298.15 K, P: 101325 Pa
    flow: 0
[1] -
    phase: 'l', T: 298.15 K, P: 101325 Pa
    flow: 0
outs...
[0] s1
    phase: 'l', T: 298.15 K, P: 101325 Pa
    flow: 0

Find a Stream object:

[3]:
F.s1.show()
Stream: s1 from <Mixer: M1>
phase: 'l', T: 298.15 K, P: 101325 Pa
flow: 0

All Unit objects can be viewed as a diagram:

[4]:
units.Mixer('M2')
F.diagram()

All Stream, Unit, and System objects are stored within Registry objects in the main_flowsheet:

[5]:
F.stream
Registry:
<Stream: s1>
<Stream: s2>
[6]:
F.unit
Registry:
<Mixer: M1>
<Mixer: M2>
[7]:
F.system
Registry: (Empty)

5.2. Switch between flowsheets#

A new flowsheet may be created and set as the main flowsheet:

[8]:
F.set_flowsheet('new_flowsheet')
F
[8]:
<MainFlowsheet: new_flowsheet>

Now all new objects will be registered in the new flowsheet:

[9]:
units.Mixer('M3')
F.diagram()

Note that objects in the original flowsheet are not defined anymore and searching them would raise an error:

[10]:
F.M1
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[10], line 1
----> 1 F.M1

File ~\code\biosteam\biosteam\_flowsheet.py:133, in Flowsheet.__getattr__(self, name)
    129 def __getattr__(self, name):
    130     obj = (self.stream.search(name)
    131            or self.unit.search(name)
    132            or self.system.search(name))
--> 133     if not obj: raise AttributeError(f"no registered item '{name}'")
    134     return obj

AttributeError: no registered item 'M1'

All Flowsheet objects are added to the flowsheet registry. Switching between flowsheets is easy:

[11]:
F.set_flowsheet('default') # Switch back to default flowsheet
F
[11]:
<MainFlowsheet: default>

Biorefineries within the Bioindustrial-Park define their own flowsheet when you import it:

[12]:
from biorefineries.sugarcane import sugarcane_sys
F.diagram(format='png')
../_images/tutorial_Managing_flowsheets_24_0.png