Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small Modification to Multi Effect Crystallizer #163

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

# Import Pyomo libraries
from pyomo.environ import (
ConcreteModel,
check_optimal_termination,
assert_optimal_termination,
Var,
Constraint,
Expression,
Expand All @@ -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
Expand Down Expand Up @@ -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
)

Expand All @@ -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
)

Expand All @@ -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
)

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
Loading