Skip to content
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
29 changes: 29 additions & 0 deletions idaes/core/base/control_volume1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ def material_holdup_calculation(b, t, x, p, j):
doc="Kinetic reaction stoichiometry constraint",
)
def rate_reaction_stoichiometry_constraint(b, t, x, p, j):
# TODO what about collocation?
if (
b.config.transformation_scheme != "FORWARD"
and x == b.length_domain.first()
Expand Down Expand Up @@ -830,6 +831,7 @@ def equilibrium_reaction_stoichiometry_constraint(b, t, x, p, j):
doc="Inherent reaction stoichiometry",
)
def inherent_reaction_stoichiometry_constraint(b, t, x, p, j):
# TODO Collocation
if (
b.config.transformation_scheme != "FORWARD"
and x == b.length_domain.first()
Expand Down Expand Up @@ -910,6 +912,7 @@ def user_term_mass(b, t, x, p, j):
doc="Material balances",
)
def material_balances(b, t, x, p, j):
# TODO Collocation
if (
b.config.transformation_scheme != "FORWARD"
and x == b.length_domain.first()
Expand Down Expand Up @@ -2516,13 +2519,22 @@ def calculate_scaling_factors(self):
overwrite=False,
)

if hasattr(self, "_flow_terms_cont_eq"):
for (t, x, p, j), c in self._flow_terms_cont_eq.items():
iscale.constraint_scaling_transform(
c,
iscale.get_scaling_factor(self._flow_terms[t, x, p, j]),
overwrite=False,
)

if hasattr(self, "material_accumulation_disc_eq"):
for (t, x, p, j), c in self.material_accumulation_disc_eq.items():
iscale.constraint_scaling_transform(
c,
iscale.get_scaling_factor(self.material_accumulation[t, x, p, j]),
overwrite=False,
)
# TODO continuity

# Scaling for discretization equations
if hasattr(self, "enthalpy_flow_dx_disc_eq"):
Expand All @@ -2532,6 +2544,13 @@ def calculate_scaling_factors(self):
iscale.get_scaling_factor(self.enthalpy_flow_dx[t, x, p]),
overwrite=False,
)
if hasattr(self, "_enthalpy_flow_length_domain_cont_eq"):
for (t, x, p), c in self._enthalpy_flow_length_domain_cont_eq.items():
iscale.constraint_scaling_transform(
c,
iscale.get_scaling_factor(self._enthalpy_flow[t, x, p]),
overwrite=False,
)

if hasattr(self, "energy_accumulation_disc_eq"):
for (t, x, p), c in self.energy_accumulation_disc_eq.items():
Expand All @@ -2540,6 +2559,7 @@ def calculate_scaling_factors(self):
iscale.get_scaling_factor(self.energy_accumulation[t, x, p]),
overwrite=False,
)
# TODO continuity

if hasattr(self, "pressure_dx_disc_eq"):
for (t, x), c in self.pressure_dx_disc_eq.items():
Expand All @@ -2548,6 +2568,13 @@ def calculate_scaling_factors(self):
iscale.get_scaling_factor(self.pressure_dx[t, x]),
overwrite=False,
)
if hasattr(self, "pressure_length_domain_cont_eq"):
for (t, x), c in self.pressure_length_domain_cont_eq.items():
iscale.constraint_scaling_transform(
c,
iscale.get_scaling_factor(self.properties[t, x].pressure),
overwrite=False,
)

if hasattr(self, "elemental_flow_dx_disc_eq"):
for (t, x, e), c in self.elemental_flow_dx_disc_eq.items():
Expand All @@ -2564,3 +2591,5 @@ def calculate_scaling_factors(self):
iscale.get_scaling_factor(self.element_accumulation[t, x, e]),
overwrite=False,
)

# TODO continuity equation
58 changes: 30 additions & 28 deletions idaes/models/unit_models/heat_exchanger_1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,38 +517,40 @@ def build(self):
if self.config.flow_type == HeatExchangerFlowPattern.cocurrent:
set_direction_hot = FlowDirection.forward
set_direction_cold = FlowDirection.forward
if self.config.hot_side.transformation_scheme != "BACKWARD":
_log_upwinding_disclaimer(
"hot_side",
"cocurrent",
self.config.hot_side.transformation_scheme,
"BACKWARD",
)
if self.config.cold_side.transformation_scheme != "BACKWARD":
_log_upwinding_disclaimer(
"cold_side",
"cocurrent",
self.config.cold_side.transformation_scheme,
"BACKWARD",
)
if self.config.hot_side.transformation_method == "dae.finite_difference":
if self.config.hot_side.transformation_scheme != "BACKWARD":
_log_upwinding_disclaimer(
"hot_side",
"cocurrent",
self.config.hot_side.transformation_scheme,
"BACKWARD",
)
if self.config.cold_side.transformation_scheme != "BACKWARD":
_log_upwinding_disclaimer(
"cold_side",
"cocurrent",
self.config.cold_side.transformation_scheme,
"BACKWARD",
)

elif self.config.flow_type == HeatExchangerFlowPattern.countercurrent:
set_direction_hot = FlowDirection.forward
set_direction_cold = FlowDirection.backward
if self.config.hot_side.transformation_scheme != "BACKWARD":
_log_upwinding_disclaimer(
"hot_side",
"countercurrent",
self.config.hot_side.transformation_scheme,
"BACKWARD",
)
if self.config.cold_side.transformation_scheme != "FORWARD":
_log_upwinding_disclaimer(
"cold_side",
"countercurrent",
self.config.cold_side.transformation_scheme,
"FORWARD",
)
if self.config.hot_side.transformation_method == "dae.finite_difference":
if self.config.hot_side.transformation_scheme != "BACKWARD":
_log_upwinding_disclaimer(
"hot_side",
"countercurrent",
self.config.hot_side.transformation_scheme,
"BACKWARD",
)
if self.config.cold_side.transformation_scheme != "FORWARD":
_log_upwinding_disclaimer(
"cold_side",
"countercurrent",
self.config.cold_side.transformation_scheme,
"FORWARD",
)
else:
raise ConfigurationError(
"{} HeatExchanger1D only supports cocurrent and "
Expand Down
37 changes: 37 additions & 0 deletions idaes/models/unit_models/tests/test_heat_exchanger_1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,43 @@ def test_config_validation_mismatched_collocation(caplog):
)


@pytest.mark.unit
def test_config_validation_collocation_no_warning(caplog):
m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)
m.fs.properties = BTXParameterBlock(valid_phase="Liq")
caplog.clear()

with caplog.at_level(idaeslog.INFO):
m.fs.HX_cocurrent = HX1D(
hot_side={
"property_package": m.fs.properties,
"transformation_method": "dae.collocation",
"transformation_scheme": "LAGRANGE-LEGENDRE",
},
cold_side={
"property_package": m.fs.properties,
"transformation_method": "dae.collocation",
"transformation_scheme": "LAGRANGE-LEGENDRE",
},
flow_type=HeatExchangerFlowPattern.cocurrent,
)
m.fs.HX_countercurrent = HX1D(
hot_side={
"property_package": m.fs.properties,
"transformation_method": "dae.collocation",
"transformation_scheme": "LAGRANGE-LEGENDRE",
},
cold_side={
"property_package": m.fs.properties,
"transformation_method": "dae.collocation",
"transformation_scheme": "LAGRANGE-LEGENDRE",
},
flow_type=HeatExchangerFlowPattern.countercurrent,
)
assert len(caplog.text) == 0


# -----------------------------------------------------------------------------
class TestBTX_cocurrent(object):
@pytest.fixture(scope="class")
Expand Down
Loading
Loading