SystemFactory#
- class SystemFactory(f=None, ID=None, ins=None, outs=None, fixed_ins_size=True, fixed_outs_size=True, fthermo=None)[source]#
Decorate a function to return a system from the unit operations it creates when called, allowing it to default the ID, ins, and outs parameters.
- Parameters:
f (Callable, optional) – Should create unit operations. f should have a signature of function(ins, outs, *args, **kwargs).
ID (str, optional) – Default system name.
ins (list[dict], optional) – List of key word arguments for initializing inlet streams.
outs (list[dict], optional) – List of key word arguments for initializing outlet streams.
fixed_ins_size (bool, optional) – Whether the number of inlets must match the number expected.
fixed_outs_size (bool, optional) – Whether the number of outlets must match the number expected.
fthermo (callable, optional) – Should return a
Thermo
object that may serve as a property package for the system. It may optionally accept an existingChemicals
object for compatibility with the default property package (i.e., bst.settings.chemicals).
Examples
Create a heating system with just a pump and a heat exchanger:
>>> from biosteam import * >>> @SystemFactory( ... ID='heating_sys', ... ins=[dict(ID='cold_stream', Water=100)], ... outs=[dict(ID='hot_stream')] ... ) ... def create_heating_system(ins, outs, T_out): ... cold_stream, = ins ... hot_stream, = outs ... P1 = Pump('P1', ins=cold_stream) ... H1 = HXutility('H1', ins=P1-0, outs=hot_stream, T=T_out) ... >>> create_heating_system.show() SystemFactory( f=<create_heating_system(ins, outs, T_out)>, ID='heating_sys', ins=[dict(ID='cold_stream', Water=100)], outs=[dict(ID='hot_stream')] ) >>> settings.set_thermo(['Water'], cache=True) >>> heating_sys = create_heating_system(T_out=350) >>> heating_sys.simulate() >>> heating_sys.show() System: heating_sys ins... [0] cold_stream phase: 'l', T: 298.15 K, P: 101325 Pa flow (kmol/hr): Water 100 outs... [0] hot_stream phase: 'l', T: 350 K, P: 101325 Pa flow (kmol/hr): Water 100
Create a mockup version, add a tank, then create the system:
>>> main_flowsheet.clear() # Remove old unit operations >>> sys = create_heating_system(outs=[''], T_out=350, mockup=True) >>> sys.show() # Mock systems have ins and outs, just like real systems MockSystem( ins=[0-P1], outs=[H1-0], units=[P1, H1] ) >>> T1 = StorageTank('T1', sys-0, 'hot_stream_from_storage') >>> heating_sys = main_flowsheet.create_system('heating_sys') >>> heating_sys.simulate() >>> heating_sys.show() System: heating_sys ins... [0] cold_stream phase: 'l', T: 298.15 K, P: 101325 Pa flow (kmol/hr): Water 100 outs... [0] hot_stream_from_storage phase: 'l', T: 350 K, P: 101325 Pa flow (kmol/hr): Water 100
Create the system and assign unit operation IDs by area convention:
>>> sys = create_heating_system(outs=[''], T_out=350, area=100, mockup=True) >>> sorted(main_flowsheet.unit, key=lambda u: u.ID) # Note how previous unit operations still exist in registry [<HXutility: H1>, <HXutility: H101>, <Pump: P1>, <Pump: P101>, <StorageTank: T1>]
To access unit operations by the original ID given in the system factory, you can request a unit dictionary as follows:
>>> sys, udct = create_heating_system(outs=[''], T_out=350, mockup=True, area=200, udct=True) >>> udct['P1'] # Originally, this unit was named P1 <Pump: P201>