Skip to content

Commit

Permalink
get tests passings
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Sep 18, 2024
1 parent ccbca3b commit 6563b92
Show file tree
Hide file tree
Showing 12 changed files with 597 additions and 306 deletions.
1 change: 1 addition & 0 deletions biosteam/_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ def set_design_result(self, key: str, units: str, value: float):
>>> tank = bst.StorageTank(None, feed)
>>> tank.simulate()
>>> tank.set_design_result('Total volume', 'm3', 1000)
1000
>>> tank.get_design_result('Total volume', 'm3')
1000.0
Expand Down
22 changes: 13 additions & 9 deletions biosteam/digraph/digraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,19 @@ def get_unit_names(f: Digraph, path, with_auxiliaries):
fill_info_from_path(path, [0], info_by_unit)
for u, (index, time) in info_by_unit.items():
node = u.get_node()
label = node['label']
if 'xlabel' in node:
key = 'xlabel'
else:
key = 'label'
label = node[key]
info = ', '.join(index)
if time is not None:
if info:
info = f"{info}; {time}"
else:
info = time
if info: label = f"[{info}] {label}"
node['label'] = label
node[key] = label
unit_names[u] = node['name']
if (with_auxiliaries and all([i in info_by_unit for i in u.auxiliary_units])
and u._assembled_from_auxiliary_units()): continue
Expand Down Expand Up @@ -490,10 +494,10 @@ def fix_valve_symbol_in_svg_output(
p.attrib["fill"] = unit_color.split(':')[-1] # In case of gradiant color (white:#CDCDCD)
p.attrib["stroke"] = unit_periphery_color
# fix label text color and position
label_image = [(c,i) for i in images for c in getchildren(parent_map[parent_map[parent_map[i]]]) if 'text' in c.tag]
label_image = [(c, i) for i in images for c in getchildren(parent_map[parent_map[parent_map[i]]]) if 'text' in c.tag]
for l,i in label_image:
l.attrib["fill"] = label_color
width = int(i.attrib['width'].replace('px',''))
width = float(i.attrib['width'].replace('px',''))
x = float(i.attrib["x"])
l.attrib["x"] = f"{x+width/2}"
# delete image tags
Expand Down Expand Up @@ -564,19 +568,19 @@ def inject_javascript(img:bytes):
def display_digraph(digraph, format, height=None): # pragma: no coverage
if format is None: format = preferences.graphviz_format
if height is None: height = '400px'
if format == 'svg':
img = digraph.pipe(format=format)
# TODO: Output is not displayed if this line is uncommented
# img = fix_valve_symbol_in_svg_output(img)
if format == 'svg' or format=='html':
img = digraph.pipe(format='svg')
img = fix_valve_symbol_in_svg_output(img)
x = display.SVG(img)
display.display(x)
# TODO: Consult about this complicated Javascript injection
elif format == 'html':
img = digraph.pipe(format='svg')
img = fix_valve_symbol_in_svg_output(img)
img = inject_javascript(img)
data_uri = 'data:text/html;charset=utf-8,' + urllib.parse.quote(img)
x = display.IFrame(src=data_uri, width='100%', height=height,
extras=['allowtransparency="true"'])
extras=['allowtransparency="true"'])
display.display(x)
else:
x = display.Image(digraph.pipe(format='png'))
Expand Down
14 changes: 7 additions & 7 deletions biosteam/process_tools/unit_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ class UnitGroup:
>>> ugroup.show()
UnitGroup: Example group
units: P1, T1, H1
metrics: Installed equipment cost [MM$]
Cooling duty [GJ/hr]
Heating duty [GJ/hr]
Electricity consumption [MW]
Electricity production [MW]
Material cost [USD/hr]
metrics: Installed equipment cost
Cooling duty
Heating duty
Electricity consumption
Electricity production
Material cost
Moisture content
Sucrose flow rate [kg/hr]
Sucrose flow rate
>>> ugroup.to_dict()
{'Installed equipment cost [MM$]': 0.05, 'Cooling duty [GJ/hr]': 0.37, 'Heating duty [GJ/hr]': 0.0, 'Electricity consumption [MW]': 0.0, 'Electricity production [MW]': 0.0, 'Material cost [USD/hr]': 0.0, 'Moisture content': 0.63, 'Sucrose flow rate [kg/hr]': 1026.8}
Expand Down
46 changes: 23 additions & 23 deletions biosteam/units/_multi_effect_evaporator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,26 @@ class MultiEffectEvaporator(Unit):
>>> E1.show()
MultiEffectEvaporator: E1
ins...
[0] feed
[0] feed
phase: 'l', T: 298.15 K, P: 101325 Pa
flow (kmol/hr): Water 55.5
AceticAcid 0.00833
Furfural 0.00104
HMF 0.000793
Glucose 0.555
outs...
[0] solids
[0] solids
phase: 'l', T: 333.21 K, P: 20000 Pa
flow (kmol/hr): Water 20.5
AceticAcid 0.00183
Furfural 5.96e-05
AceticAcid 0.00181
Furfural 5.29e-05
HMF 0.000793
Glucose 0.555
[1] liquid
[1] liquid
phase: 'l', T: 352.11 K, P: 20000 Pa
flow (kmol/hr): Water 35
AceticAcid 0.0065
Furfural 0.000981
AceticAcid 0.00651
Furfural 0.000988
>>> E1.results()
Multi-effect evaporator Units E1
Expand Down Expand Up @@ -151,26 +151,26 @@ class MultiEffectEvaporator(Unit):
>>> E1.show()
MultiEffectEvaporator: E1
ins...
[0] feed
[0] feed
phase: 'l', T: 298.15 K, P: 101325 Pa
flow (kmol/hr): Water 55.5
AceticAcid 0.00833
Furfural 0.00104
HMF 0.000793
Glucose 0.555
outs...
[0] solids
[0] solids
phase: 'l', T: 354.91 K, P: 50892 Pa
flow (kmol/hr): Water 50
AceticAcid 0.00683
Furfural 0.000535
AceticAcid 0.0069
Furfural 0.000577
HMF 0.000793
Glucose 0.555
[1] liquid
phase: 'l', T: 361.13 K, P: 50892 Pa
[1] liquid
phase: 'l', T: 361.12 K, P: 50892 Pa
flow (kmol/hr): Water 5.55
AceticAcid 0.0015
Furfural 0.000506
AceticAcid 0.00143
Furfural 0.000464
>>> E1.results()
Multi-effect evaporator Units E1
Expand Down Expand Up @@ -205,26 +205,26 @@ class MultiEffectEvaporator(Unit):
>>> E1.show()
MultiEffectEvaporator: E1
ins...
[0] feed
[0] feed
phase: 'l', T: 298.15 K, P: 101325 Pa
flow (kmol/hr): Water 55.5
AceticAcid 0.00833
Furfural 0.00104
HMF 0.000793
Glucose 0.555
outs...
[0] solids
[0] solids
phase: 'l', T: 354.91 K, P: 50892 Pa
flow (kmol/hr): Water 50
AceticAcid 0.00683
Furfural 0.000535
AceticAcid 0.0069
Furfural 0.000577
HMF 0.000793
Glucose 0.555
[1] liquid
phase: 'l', T: 361.13 K, P: 50892 Pa
[1] liquid
phase: 'l', T: 361.12 K, P: 50892 Pa
flow (kmol/hr): Water 5.55
AceticAcid 0.0015
Furfural 0.000506
AceticAcid 0.00143
Furfural 0.000464
>>> E1.results()
Multi-effect evaporator Units E1
Expand Down
44 changes: 22 additions & 22 deletions biosteam/units/distillation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,12 +1224,12 @@ class BinaryDistillation(Distillation, new_graphics=False):
Divided Distillation Column Units D1
Electricity Power kW 0.644
Cost USD/hr 0.0504
Low pressure steam Duty kJ/hr 1.02e+07
Flow kmol/hr 263
Cost USD/hr 62.6
Cooling water Duty kJ/hr -4.88e+06
Flow kmol/hr 3.33e+03
Cost USD/hr 1.63
Low pressure steam Duty kJ/hr 1.02e+07
Flow kmol/hr 263
Cost USD/hr 62.6
Design Theoretical feed stage 9
Theoretical stages 13
Minimum reflux Ratio 0.687
Expand All @@ -1250,12 +1250,12 @@ class BinaryDistillation(Distillation, new_graphics=False):
Stripper platform and ladders USD 1.39e+04
Stripper tower USD 3.83e+04
Rectifier platform and ladders USD 1.14e+04
Pump - Pump USD 4.37e+03
Pump - Motor USD 368
Condenser - Floating head USD 3.33e+04
Reflux drum - Horizontal pressur... USD 1.02e+04
Reflux drum - Platform and ladders USD 3.02e+03
Pump - Pump USD 4.37e+03
Pump - Motor USD 368
Reboiler - Floating head USD 2.71e+04
Condenser - Floating head USD 3.33e+04
Total purchase cost USD 2.15e+05
Utility cost USD/hr 64.3
Expand Down Expand Up @@ -1743,12 +1743,12 @@ class ShortcutColumn(Distillation, new_graphics=False):
Divided Distillation Column Units D1
Electricity Power kW 0.761
Cost USD/hr 0.0595
Low pressure steam Duty kJ/hr 1.34e+07
Flow kmol/hr 346
Cost USD/hr 82.4
Cooling water Duty kJ/hr -7.54e+06
Flow kmol/hr 5.15e+03
Cost USD/hr 2.51
Low pressure steam Duty kJ/hr 1.34e+07
Flow kmol/hr 346
Cost USD/hr 82.4
Design Theoretical feed stage 8
Theoretical stages 16
Minimum reflux Ratio 1.06
Expand All @@ -1769,12 +1769,12 @@ class ShortcutColumn(Distillation, new_graphics=False):
Stripper platform and ladders USD 1.42e+04
Stripper tower USD 5.38e+04
Rectifier platform and ladders USD 1.81e+04
Pump - Pump USD 4.37e+03
Pump - Motor USD 379
Condenser - Floating head USD 4.07e+04
Reflux drum - Horizontal pressur... USD 1.03e+04
Reflux drum - Platform and ladders USD 3.02e+03
Pump - Pump USD 4.37e+03
Pump - Motor USD 379
Reboiler - Floating head USD 2.98e+04
Condenser - Floating head USD 4.07e+04
Total purchase cost USD 2.57e+05
Utility cost USD/hr 84.9
Expand Down Expand Up @@ -2431,12 +2431,12 @@ class MESHDistillation(MultiStageEquilibrium, new_graphics=False):
Distillation Units
Electricity Power kW 0.574
Cost USD/hr 0.0449
Low pressure steam Duty kJ/hr 7.8e+06
Flow kmol/hr 202
Cost USD/hr 48
Cooling water Duty kJ/hr -2.98e+06
Flow kmol/hr 2.03e+03
Cost USD/hr 0.992
Low pressure steam Duty kJ/hr 7.8e+06
Flow kmol/hr 202
Cost USD/hr 48
Design Theoretical stages 5
Actual stages 7
Height ft 24.3
Expand All @@ -2446,12 +2446,12 @@ class MESHDistillation(MultiStageEquilibrium, new_graphics=False):
Purchase cost Trays USD 8.11e+03
Tower USD 3.43e+04
Platform and ladders USD 9.43e+03
Pump - Pump USD 4.35e+03
Pump - Motor USD 358
Condenser - Floating head USD 2.36e+04
Reflux drum - Vertical pressure ... USD 1.29e+04
Reflux drum - Platform and ladders USD 3.89e+03
Pump - Pump USD 4.35e+03
Pump - Motor USD 358
Reboiler - Floating head USD 2.34e+04
Condenser - Floating head USD 2.36e+04
Total purchase cost USD 1.2e+05
Utility cost USD/hr 49
Expand All @@ -2478,12 +2478,12 @@ class MESHDistillation(MultiStageEquilibrium, new_graphics=False):
Distillation Units
Electricity Power kW 0.918
Cost USD/hr 0.0718
Low pressure steam Duty kJ/hr 9.62e+06
Flow kmol/hr 249
Cost USD/hr 59.2
Cooling water Duty kJ/hr -9.13e+06
Flow kmol/hr 6.24e+03
Cost USD/hr 3.04
Low pressure steam Duty kJ/hr 9.62e+06
Flow kmol/hr 249
Cost USD/hr 59.2
Design Theoretical stages 5
Actual stages 6
Height ft 22.9
Expand All @@ -2493,10 +2493,10 @@ class MESHDistillation(MultiStageEquilibrium, new_graphics=False):
Purchase cost Trays USD 7.58e+03
Tower USD 3.62e+04
Platform and ladders USD 9.8e+03
Condenser - Floating head USD 3.5e+04
Pump - Pump USD 4.33e+03
Pump - Motor USD 390
Reboiler - Floating head USD 2.41e+04
Condenser - Floating head USD 3.5e+04
Total purchase cost USD 1.17e+05
Utility cost USD/hr 62.3
Expand Down
28 changes: 14 additions & 14 deletions biosteam/units/liquid_liquid_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ class LLEUnit(bst.Unit, isabstract=True):
>>> C1.outs[0].show()
Stream: light from <LLEUnit: C1>
phase: 'l', T: 333.15 K, P: 101325 Pa
flow (kmol/hr): Methanol 10.2
Glycerol 0.0239
Biodiesel 26.9
flow (kmol/hr): Methanol 11.5
Glycerol 0.033
Biodiesel 26.7
TriOlein 0.996
"""
Expand Down Expand Up @@ -300,9 +300,9 @@ class LLECentrifuge(LLEUnit, LiquidsCentrifuge):
>>> C1.outs[0].show()
Stream: light from <LLECentrifuge: C1>
phase: 'l', T: 333.15 K, P: 101325 Pa
flow (kmol/hr): Methanol 10.2
Glycerol 0.0239
Biodiesel 26.9
flow (kmol/hr): Methanol 11.5
Glycerol 0.033
Biodiesel 26.7
TriOlein 0.996
>>> C1.results()
Liquids centrifuge Units C1
Expand Down Expand Up @@ -361,21 +361,21 @@ class SLLECentrifuge(Unit):
>>> C1.show()
SLLECentrifuge: C1
ins...
[0] feed
[0] feed
phase: 'l', T: 298.15 K, P: 101325 Pa
flow (kmol/hr): Water 100
Hexane 100
Solids 10
outs...
[0] oil
[0] oil
phase: 'l', T: 298.15 K, P: 101325 Pa
flow (kmol/hr): Water 0.791
flow (kmol/hr): Water 0.747
Hexane 100
[1] aqueous
[1] aqueous
phase: 'l', T: 298.15 K, P: 101325 Pa
flow (kmol/hr): Water 98.7
Hexane 0.015
[2] solids
Hexane 0.0156
[2] solids
phase: 'l', T: 298.15 K, P: 101325 Pa
flow (kmol/hr): Water 0.555
Solids 10
Expand Down Expand Up @@ -836,9 +836,9 @@ class MixerSettler(bst.Unit):
>>> MS1 = bst.MixerSettler('MS1', ins=(feed, solvent), outs=('extract', 'raffinate'))
>>> MS1.simulate()
>>> MS1.extract.imol['Methanol'] / MS1.feed.imol['Methanol']
0.66
0.63
>>> MS1.raffinate.imol['Water'] / MS1.feed.imol['Water']
0.82
0.85
>>> MS1.extract.imol['Octanol'] / MS1.solvent.imol['Octanol']
0.99
>>> MS1.results() # doctest: +SKIP
Expand Down
Loading

0 comments on commit 6563b92

Please sign in to comment.