diff --git a/src/watertap_contrib/reflo/unit_models/multi_effect_crystallizer.py b/src/watertap_contrib/reflo/unit_models/multi_effect_crystallizer.py index 97e60b06..e2d5253e 100644 --- a/src/watertap_contrib/reflo/unit_models/multi_effect_crystallizer.py +++ b/src/watertap_contrib/reflo/unit_models/multi_effect_crystallizer.py @@ -13,9 +13,7 @@ # Import Pyomo libraries from pyomo.environ import ( - ConcreteModel, check_optimal_termination, - assert_optimal_termination, Var, Constraint, Expression, @@ -32,15 +30,12 @@ UnitModelBlockData, useDefault, FlowsheetBlock, - UnitModelCostingBlock, ) from idaes.core.util.exceptions import InitializationError, ConfigurationError import idaes.core.util.scaling as iscale from idaes.core.util.config import is_physical_parameter_block from idaes.core.util.model_statistics import degrees_of_freedom -from idaes.core.util.tables import create_stream_table_dataframe import idaes.logger as idaeslog -from idaes.core.util.constants import Constants from watertap.core import InitializationMixin, ControlVolume0DBlock from watertap.core.solvers import get_solver @@ -283,7 +278,7 @@ def eq_heating_steam_flow_rate(b): - effect.temperature_operating, doc=f"Change in temperature at inlet for effect {n}", ) - effect.add_component( + self.add_component( f"eq_delta_temperature_inlet_effect_{n}", del_temp_in_constr ) @@ -293,7 +288,7 @@ def eq_heating_steam_flow_rate(b): - effect.properties_in[0].temperature, doc=f"Change in temperature at outlet for effect {n}", ) - effect.add_component( + self.add_component( f"eq_delta_temperature_outlet_effect_{n}", del_temp_out_constr ) @@ -304,14 +299,14 @@ def eq_heating_steam_flow_rate(b): * effect.delta_temperature[0], doc=f"Heat transfer equation for effect {n}", ) - effect.add_component(f"eq_heat_transfer_effect_{n}", hx_constr) + self.add_component(f"eq_heat_transfer_effect_{n}", hx_constr) energy_flow_constr = Constraint( expr=effect.work_mechanical[0] == prev_effect.energy_flow_superheated_vapor, doc=f"Energy supplied to effect {n}", ) - effect.add_component( + self.add_component( f"eq_energy_for_effect_{n}_from_effect_{n - 1}", energy_flow_constr ) @@ -456,7 +451,7 @@ def initialize_build( else: # Deactivate contraint that links energy flow between effects linking_constr = getattr( - eff.effect, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" + self, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" ) linking_constr.deactivate() eff.effect.initialize(**init_args) diff --git a/src/watertap_contrib/reflo/unit_models/tests/test_multi_effect_crystallizer.py b/src/watertap_contrib/reflo/unit_models/tests/test_multi_effect_crystallizer.py index 33728bb2..78b07f79 100644 --- a/src/watertap_contrib/reflo/unit_models/tests/test_multi_effect_crystallizer.py +++ b/src/watertap_contrib/reflo/unit_models/tests/test_multi_effect_crystallizer.py @@ -441,9 +441,6 @@ def test_build(self, MEC2_frame): assert hasattr(eff.effect, e) for c in effect_constr: assert hasattr(eff.effect, c) - assert hasattr(eff.effect, f"eq_delta_temperature_inlet_effect_{n}") - assert hasattr(eff.effect, f"eq_delta_temperature_outlet_effect_{n}") - assert hasattr(eff.effect, f"eq_heat_transfer_effect_{n}") if n == 1: assert number_variables(eff.effect) == 154 assert number_total_constraints(eff.effect) == 128 @@ -454,10 +451,13 @@ def test_build(self, MEC2_frame): assert hasattr(eff.effect, "eq_heating_steam_flow_rate") if n != 1: assert number_variables(eff.effect) == 148 - assert number_total_constraints(eff.effect) == 126 - assert number_unused_variables(eff.effect) == 0 + assert number_total_constraints(eff.effect) == 122 + assert number_unused_variables(eff.effect) == 4 + assert hasattr(m.fs.unit, f"eq_delta_temperature_inlet_effect_{n}") + assert hasattr(m.fs.unit, f"eq_delta_temperature_outlet_effect_{n}") + assert hasattr(m.fs.unit, f"eq_heat_transfer_effect_{n}") assert hasattr( - eff.effect, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" + m.fs.unit, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" ) assert number_variables(m) == 461 @@ -476,10 +476,7 @@ def test_dof(self, MEC2_frame): # Fixing flow rates into individual effects will reduce DOF... for n, eff in m.fs.unit.effects.items(): eff.effect.properties_in[0].flow_mass_phase_comp.fix() - if n == 1: - assert degrees_of_freedom(eff.effect) == 0 - else: - assert degrees_of_freedom(eff.effect) == 3 + assert degrees_of_freedom(eff.effect) == 0 # ... and result in an overspecified model. assert degrees_of_freedom(m) == -2 @@ -557,12 +554,12 @@ def test_initialize(self, MEC2_frame): .is_fixed() ) linking_constr = getattr( - eff.effect, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" + m.fs.unit, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" ) assert linking_constr.active assert eff.effect.overall_heat_transfer_coefficient.is_fixed() assert value(eff.effect.overall_heat_transfer_coefficient) == htc - assert degrees_of_freedom(eff.effect) == 3 + assert degrees_of_freedom(eff.effect) == 1 @pytest.mark.component def test_solve(self, MEC2_frame): @@ -969,9 +966,6 @@ def test_build(self, MEC3_frame): assert hasattr(eff.effect, e) for c in effect_constr: assert hasattr(eff.effect, c) - assert hasattr(eff.effect, f"eq_delta_temperature_inlet_effect_{n}") - assert hasattr(eff.effect, f"eq_delta_temperature_outlet_effect_{n}") - assert hasattr(eff.effect, f"eq_heat_transfer_effect_{n}") if n == 1: assert number_variables(eff.effect) == 154 assert number_total_constraints(eff.effect) == 128 @@ -982,10 +976,13 @@ def test_build(self, MEC3_frame): assert hasattr(eff.effect, "eq_heating_steam_flow_rate") if n != 1: assert number_variables(eff.effect) == 148 - assert number_total_constraints(eff.effect) == 126 - assert number_unused_variables(eff.effect) == 0 + assert number_total_constraints(eff.effect) == 122 + assert number_unused_variables(eff.effect) == 4 + assert hasattr(m.fs.unit, f"eq_delta_temperature_inlet_effect_{n}") + assert hasattr(m.fs.unit, f"eq_delta_temperature_outlet_effect_{n}") + assert hasattr(m.fs.unit, f"eq_heat_transfer_effect_{n}") assert hasattr( - eff.effect, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" + m.fs.unit, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" ) assert number_variables(m) == 609 @@ -1010,10 +1007,7 @@ def test_dof(self, MEC3_frame): ].unfix() assert degrees_of_freedom(m) == 0 for n, eff in m.fs.unit.effects.items(): - if n == 1: - assert degrees_of_freedom(eff.effect) == 0 - else: - assert degrees_of_freedom(eff.effect) == 3 + assert degrees_of_freedom(eff.effect) == 0 m.fs.unit.control_volume.properties_in[0].flow_mass_phase_comp[ "Liq", "H2O" ].fix() @@ -1097,12 +1091,12 @@ def test_initialize(self, MEC3_frame): .is_fixed() ) linking_constr = getattr( - eff.effect, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" + m.fs.unit, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" ) assert linking_constr.active assert eff.effect.overall_heat_transfer_coefficient.is_fixed() assert value(eff.effect.overall_heat_transfer_coefficient) == htc - assert degrees_of_freedom(eff.effect) == 3 + assert degrees_of_freedom(eff.effect) == 1 @pytest.mark.component def test_solve(self, MEC3_frame): @@ -1512,9 +1506,6 @@ def test_build(self, MEC4_frame): assert hasattr(eff.effect, e) for c in effect_constr: assert hasattr(eff.effect, c) - assert hasattr(eff.effect, f"eq_delta_temperature_inlet_effect_{n}") - assert hasattr(eff.effect, f"eq_delta_temperature_outlet_effect_{n}") - assert hasattr(eff.effect, f"eq_heat_transfer_effect_{n}") if n == 1: assert number_variables(eff.effect) == 154 assert number_total_constraints(eff.effect) == 128 @@ -1525,10 +1516,13 @@ def test_build(self, MEC4_frame): assert hasattr(eff.effect, "eq_heating_steam_flow_rate") if n != 1: assert number_variables(eff.effect) == 148 - assert number_total_constraints(eff.effect) == 126 - assert number_unused_variables(eff.effect) == 0 + assert number_total_constraints(eff.effect) == 122 + assert number_unused_variables(eff.effect) == 4 + assert hasattr(m.fs.unit, f"eq_delta_temperature_inlet_effect_{n}") + assert hasattr(m.fs.unit, f"eq_delta_temperature_outlet_effect_{n}") + assert hasattr(m.fs.unit, f"eq_heat_transfer_effect_{n}") assert hasattr( - eff.effect, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" + m.fs.unit, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" ) assert number_variables(m) == 757 @@ -1554,10 +1548,7 @@ def test_dof(self, MEC4_frame): ].unfix() assert degrees_of_freedom(m) == 0 for n, eff in m.fs.unit.effects.items(): - if n == 1: - assert degrees_of_freedom(eff.effect) == 0 - else: - assert degrees_of_freedom(eff.effect) == 3 + assert degrees_of_freedom(eff.effect) == 0 m.fs.unit.control_volume.properties_in[0].flow_mass_phase_comp[ "Liq", "H2O" ].fix() @@ -1641,12 +1632,12 @@ def test_initialize(self, MEC4_frame): .is_fixed() ) linking_constr = getattr( - eff.effect, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" + m.fs.unit, f"eq_energy_for_effect_{n}_from_effect_{n - 1}" ) assert linking_constr.active assert eff.effect.overall_heat_transfer_coefficient.is_fixed() assert value(eff.effect.overall_heat_transfer_coefficient) == htc - assert degrees_of_freedom(eff.effect) == 3 + assert degrees_of_freedom(eff.effect) == 1 @pytest.mark.component def test_solve(self, MEC4_frame):