Skip to content

Commit

Permalink
add optional isothermal assumption
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Dec 16, 2024
1 parent e8aa9d6 commit 5b37ae5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
34 changes: 14 additions & 20 deletions benchmark/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,30 +227,36 @@ def plot_monte_carlo(system='alcohol_wide_flash'):
system_convergence_times = {}
system_tickmarks = {}
system_labels = {}
system_yticks = {}

def register(name, title, time, tickmarks, label):
def register(name, title, time, tickmarks, label, yticks=None):
f = getattr(systems, 'create_system_' + name, None) or getattr(systems, 'create_' + name + '_system')
if yticks is None: yticks = [(-10, -5, 0, 5), (-10, -5, 0, 5)]
all_systems[name] = f
system_titles[name] = title
system_convergence_times[name] = time
system_tickmarks[name] = tickmarks
system_labels[name] = label
system_yticks[name] = yticks

# register(
# 'acetic_acid_reactive_purification', 'Acetic acid reactive purification',
# 10, [2, 4, 6, 8, 10], 'AA\nr. sep.'
# )
register(
'acetic_acid_simple', 'Subsystem',
40, [0, 6, 12, 18, 24], 'AcOH sep.\nsubsystem'
40, [0, 6, 12, 18, 24], 'AcOH sep.\nsubsystem',
[(-15, -10, -5, 0, 5, 10), (-15, -10, -5, 0, 5, 10)],
)
register(
'acetic_acid_complex_decoupled', 'Shortcut system',
10, [0, 2, 4, 6, 8, 10], 'AcOH sep.\nshortcut',
[(-15, -10, -5, 0, 5), (-15, -10, -5, 0, 5)],
)
register(
'acetic_acid_complex', 'Rigorous system',
500, [0, 100, 200, 300, 400, 500], 'AcOH sep.\nrigorous'
500, [0, 100, 200, 300, 400, 500], 'AcOH sep.\nrigorous',
[[-5, -2.5, 0, 2.5, 5], [-8, -5, -2, 1, 4]],
)
register(
'alcohol_narrow_flash', 'Alcohol flash narrow',
Expand Down Expand Up @@ -282,7 +288,8 @@ def register(name, title, time, tickmarks, label):
# )
register(
'haber_bosch_process', 'Haber-Bosch',
0.05, [0.01, 0.02, 0.03, 0.04, 0.05], 'HB',
0.03, [0.005, 0.010, 0.015, 0.02, 0.025, 0.03], 'HB',
[[-10, -7.5, -5, -2.5, 0], [-10, -7.5, -5, -2.5, 0]],
)

# %% Testing
Expand Down Expand Up @@ -940,6 +947,7 @@ def plot_profile(
'Material balance': 'Stage material\nbalance error',
'Energy balance': 'Stage energy\nbalance error',
}
yticks_list = system_yticks[sys]
for n, (i, ax, u) in enumerate(zip(keys, axes, units)):
plt.sca(ax)
if n == n_rows-1: plt.xlabel('Time [s]')
Expand All @@ -955,23 +963,9 @@ def plot_profile(
plt.plot(tsm, ysm, lw=0, marker='.', color=csm, markersize=2.5)
plt.plot(tpo, ypo, lw=0, marker='.', color=cpo, markersize=2.5)
plt.plot(tpo, ypo, '-', color=cpo, lw=1.5, alpha=0.5)
ypo_finite = ypo[~np.isnan(ypo)]
yticklabels = m == 0
lb = -15
ub = 10
yticks = yticks_list[n]
if yticklabels:
# lb = ypo_finite.min()
# ub = ypo_finite.max()
step = 5
# if (ub - lb) < 18:
# step = 3
# elif (ub - lb) < 20:
# step = 5
# else:
# step = 10
# lb = int(np.floor(ypo_finite.min() / step) * step)
# ub = int(np.ceil(ypo_finite.max() / step) * step)
yticks = [i for i in range(lb, ub+1, step)]
yticklabels = [r'$\mathrm{10}^{' f'{i}' '}$' for i in yticks]
if m == 0 and n == 0:
index = int(len(tsm) * 0.5)
Expand Down Expand Up @@ -1001,7 +995,7 @@ def plot_profile(
ytick0 = n == n_rows-1
ytickf = n == 0
plt.xlim(0, xticks[-1])
plt.ylim(lb, ub)
plt.ylim(yticks[0], yticks[-1])
bst.utils.style_axis(
ax, xticks=xticks, yticks=yticks,
xtick0=xtick0, xtickf=xtickf, ytick0=ytick0, ytickf=ytickf,
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion biosteam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""
from __future__ import annotations
__version__ = '2.49.0'
__version__ = '2.49.1'

#: Chemical engineering plant cost index (defaults to 567.5 at 2017).
CE: float = 567.5
Expand Down
3 changes: 2 additions & 1 deletion biosteam/units/distillation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,7 @@ def _init(self,
vapor_side_draws=None,
liquid_side_draws=None,
P=101325,
T=None,
partition_data=None,
vessel_material='Carbon steel',
tray_material='Carbon steel',
Expand All @@ -2191,7 +2192,7 @@ def _init(self,
bottom_side_draws=liquid_side_draws,
partition_data=partition_data,
phases=("g", "l"), collapsed_init=collapsed_init,
P=P, use_cache=use_cache, method=method)
P=P, T=T, use_cache=use_cache, method=method)

# Construction specifications
self.solute = solute
Expand Down
6 changes: 6 additions & 0 deletions biosteam/units/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,7 @@ def _init(self,
feed_stages=None,
phases=None,
P=101325,
T=None,
stage_specifications=None,
stage_reactions=None,
partition_data=None,
Expand All @@ -1292,6 +1293,10 @@ def _init(self,
if feed_stages is None: feed_stages = (0, -1)
if stage_specifications is None: stage_specifications = {}
elif not isinstance(stage_specifications, dict): stage_specifications = dict(stage_specifications)
if T is not None:
for i in range(N_stages):
if i in stage_specifications: continue
stage_specifications[i] = ('Temperature', T)
if stage_reactions is None: stage_reactions = {}
elif not isinstance(stage_reactions, dict): stage_reactions = dict(stage_reactions)
if top_side_draws is None: top_side_draws = {}
Expand All @@ -1302,6 +1307,7 @@ def _init(self,
self.multi_stream = tmo.MultiStream(None, P=P, phases=phases, thermo=self.thermo)
self.N_stages = N_stages
self.P = P
self.T = T
self.phases = phases = self.multi_stream.phases # Corrected order
self._has_vle = 'g' in phases
self._has_lle = 'L' in phases
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name='biosteam',
packages=['biosteam'],
license='MIT',
version='2.49.0',
version='2.49.1',
description='The Biorefinery Simulation and Techno-Economic Analysis Modules',
long_description=open('README.rst', encoding='utf-8').read(),
author='Yoel Cortes-Pena',
Expand Down
2 changes: 1 addition & 1 deletion thermosteam

0 comments on commit 5b37ae5

Please sign in to comment.