diff --git a/idaes/models_extra/temperature_swing_adsorption/fixed_bed_tsa0d.py b/idaes/models_extra/temperature_swing_adsorption/fixed_bed_tsa0d.py index 62d14c6aad..62f0a22a8b 100644 --- a/idaes/models_extra/temperature_swing_adsorption/fixed_bed_tsa0d.py +++ b/idaes/models_extra/temperature_swing_adsorption/fixed_bed_tsa0d.py @@ -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( @@ -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, @@ -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, @@ -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) diff --git a/idaes/models_extra/temperature_swing_adsorption/tests/test_fixed_bed_tsa0d.py b/idaes/models_extra/temperature_swing_adsorption/tests/test_fixed_bed_tsa0d.py index e0a95d2e8d..93ab2ed8cd 100644 --- a/idaes/models_extra/temperature_swing_adsorption/tests/test_fixed_bed_tsa0d.py +++ b/idaes/models_extra/temperature_swing_adsorption/tests/test_fixed_bed_tsa0d.py @@ -17,6 +17,7 @@ __author__ = "Alex Noring" import pytest +import numpy as np from pyomo.environ import ( check_optimal_termination, @@ -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) diff --git a/idaes/models_extra/temperature_swing_adsorption/util.py b/idaes/models_extra/temperature_swing_adsorption/util.py index 6e84988a3d..8e3d4d3b0e 100644 --- a/idaes/models_extra/temperature_swing_adsorption/util.py +++ b/idaes/models_extra/temperature_swing_adsorption/util.py @@ -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): """