Skip to content

Commit

Permalink
fixing bug in FixedBedTSA tests (#1295)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Noring <[email protected]>
Co-authored-by: Ludovico Bianchi <[email protected]>
Co-authored-by: Andrew Lee <[email protected]>
  • Loading branch information
4 people authored Dec 7, 2023
1 parent 3e9b43c commit edc8416
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
34 changes: 22 additions & 12 deletions idaes/models_extra/temperature_swing_adsorption/fixed_bed_tsa0d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,29 +1167,35 @@ def pressure_n2_rich_stream_eq(b, t):
self.flow_mol_h2o_o2_stream = Var(
self.flowsheet().time,
self.component_list - self.isotherm_components,
initialize=1,
units=units.mol / units.s,
doc="Component mole flow rate at H2O+O2 stream",
)
self.temperature_h2o_o2_stream = Var(
self.flowsheet().time, units=units.K, doc="Temperature at H2O+O2 stream"
self.flowsheet().time,
initialize=300,
units=units.K,
doc="Temperature at H2O+O2 stream",
)
self.pressure_h2o_o2_stream = Var(
self.flowsheet().time, units=units.Pa, doc="Pressure at H2O+O2 stream"
self.flowsheet().time,
initialize=101325,
units=units.Pa,
doc="Pressure at H2O+O2 stream",
)

# create empty port
p = Port(noruleinit=True, doc="Outlet port for H2O+O2 stream")
# add port object as an attribute to model
setattr(self, "h2o_o2_stream", p)
# dictionary containing state of outlet h2o_o2_stream
h2o_o2_stream_dict = {
"flow_mol_comp": self.flow_mol_h2o_o2_stream,
"temperature": self.temperature_h2o_o2_stream,
"pressure": self.pressure_h2o_o2_stream,
}
# populate port and map names to actual variables as defined
for key, item in h2o_o2_stream_dict.items():
p.add(item, name=key)
# create port
self.h2o_o2_stream = Port(
noruleinit=True,
initialize=h2o_o2_stream_dict,
doc="Outlet port for H2O+O2 stream",
)

# add constraints to populate h2o_o2_stream
@self.Constraint(
Expand Down Expand Up @@ -1632,7 +1638,9 @@ def _add_pressurization_step(self):
units=units.dimensionless,
doc="Mole fraction in pressurization step",
)
self.pressurization.time = Var(units=units.s, doc="Time of pressurization step")
self.pressurization.time = Var(
initialize=1e2, units=units.s, doc="Time of pressurization step"
)
self.pressurization.loading = Var(
self.isotherm_components,
units=units.mol / units.kg,
Expand Down Expand Up @@ -1758,7 +1766,9 @@ def _add_adsorption_step(self):
self.adsorption = SkeletonUnitModel()

# variables
self.adsorption.time = Var(units=units.s, doc="Time of adsorption step")
self.adsorption.time = Var(
initialize=1e2, units=units.s, doc="Time of adsorption step"
)
self.adsorption.loading = Var(
self.isotherm_components,
units=units.mol / units.kg,
Expand Down Expand Up @@ -2843,7 +2853,7 @@ def _get_stream_table_contents(self, time_point=0):
"Inlet": "inlet",
"CO2 Rich Stream": "co2_rich_stream",
"N2 Rich Stream": "n2_rich_stream",
"H20 Stream": "h2o_o2_stream",
"H2O Stream": "h2o_o2_stream",
}.items():
port_obj = getattr(self, v)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
__author__ = "Alex Noring"

import pytest
import numpy as np

from pyomo.environ import (
check_optimal_termination,
Expand Down Expand Up @@ -161,11 +162,28 @@ def test_solution(self, model):
# air velocity
assert pytest.approx(2.44178, abs=1e-3) == value(model.fs.unit.velocity_in)

@pytest.mark.ui
@pytest.mark.unit
def test_report(self, model):
model.fs.unit.report()
tsa_summary(model.fs.unit)
stream_table_df = model.fs.unit._get_stream_table_contents()
expected_columns = ["Inlet", "CO2 Rich Stream", "N2 Rich Stream", "H2O Stream"]
for column in expected_columns:
assert column in stream_table_df.columns
assert not np.isnan(stream_table_df[column]["temperature"])
assert not np.isnan(stream_table_df[column]["pressure"])

performance_dict = model.fs.unit._get_performance_contents()
for k in performance_dict["vars"]:
assert performance_dict["vars"][k] is not None

@pytest.mark.unit
def test_summary(self, model):
summary_df = tsa_summary(model.fs.unit)
assert "Adsorption temperature [K]" in summary_df.index
assert "Cycle time [h]" in summary_df.index
assert "Pressure drop [Pa]" in summary_df.index

@pytest.mark.unit
def test_plotting(self, model):
plot_tsa_profiles(model.fs.unit)


Expand Down
2 changes: 2 additions & 0 deletions idaes/models_extra/temperature_swing_adsorption/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def tsa_summary(tsa, stream=stdout, export=False):
stream.write(textwrap.indent(stream_table_dataframe_to_string(df), " " * 4))
stream.write("\n" + "=" * 84 + "\n")

return df


def plot_tsa_profiles(tsa):
"""
Expand Down

0 comments on commit edc8416

Please sign in to comment.