Skip to content

Commit

Permalink
Adding deprecation warning for has_phase_equilibrium but only 1 phase
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlee94 authored and lbianchi-lbl committed Aug 3, 2023
1 parent 1406bb3 commit f02fca8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 55 deletions.
47 changes: 27 additions & 20 deletions idaes/core/base/control_volume0d.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# Import Pyomo libraries
from pyomo.environ import Constraint, Reals, units as pyunits, Var, value
from pyomo.dae import DerivativeVar
from pyomo.common.deprecation import deprecation_warning

# Import IDAES cores
from idaes.core import (
Expand Down Expand Up @@ -228,29 +229,35 @@ def _add_material_balance_common(
if has_phase_equilibrium:
# First, check that phase equilibrium makes sense
if len(self.config.property_package.phase_list) < 2:
raise ConfigurationError(
msg = (
"Property package has only one phase; control volume cannot include phase "
"equilibrium terms. Some property packages support phase equilibrium "
"implicitly in which case additional terms are not necessary."
"implicitly in which case additional terms are not necessary. "
"You should set has_phase_equilibrium=False."
)
# Check that state blocks are set to calculate equilibrium
for t in self.flowsheet().time:
if not self.properties_out[t].config.has_phase_equilibrium:
raise ConfigurationError(
"{} material balance was set to include phase "
"equilibrium, however the associated outlet "
"StateBlock was not set to include equilibrium "
"constraints (has_phase_equilibrium=False). Please"
" correct your configuration arguments.".format(self.name)
)
if not self.properties_in[t].config.has_phase_equilibrium:
raise ConfigurationError(
"{} material balance was set to include phase "
"equilibrium, however the associated inlet "
"StateBlock was not set to include equilibrium "
"constraints (has_phase_equilibrium=False). Please"
" correct your configuration arguments.".format(self.name)
)
deprecation_warning(
msg=msg, logger=_log, version="2.0.0", remove_in="3.0.0"
)
has_phase_equilibrium = False
else:
# Check that state blocks are set to calculate equilibrium
for t in self.flowsheet().time:
if not self.properties_out[t].config.has_phase_equilibrium:
raise ConfigurationError(
"{} material balance was set to include phase "
"equilibrium, however the associated outlet "
"StateBlock was not set to include equilibrium "
"constraints (has_phase_equilibrium=False). Please"
" correct your configuration arguments.".format(self.name)
)
if not self.properties_in[t].config.has_phase_equilibrium:
raise ConfigurationError(
"{} material balance was set to include phase "
"equilibrium, however the associated inlet "
"StateBlock was not set to include equilibrium "
"constraints (has_phase_equilibrium=False). Please"
" correct your configuration arguments.".format(self.name)
)

# Get units from property package
units = self.config.property_package.get_metadata().get_derived_units
Expand Down
35 changes: 22 additions & 13 deletions idaes/core/base/control_volume1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
)
from pyomo.dae import ContinuousSet, DerivativeVar
from pyomo.common.config import ConfigValue, In
from pyomo.common.deprecation import deprecation_warning

# Import IDAES cores
from idaes.core import (
Expand Down Expand Up @@ -438,22 +439,30 @@ def _add_material_balance_common(
if has_phase_equilibrium:
# First, check that phase equilibrium makes sense
if len(self.config.property_package.phase_list) < 2:
raise ConfigurationError(
msg = (
"Property package has only one phase; control volume cannot include phase "
"equilibrium terms. Some property packages support phase equilibrium "
"implicitly in which case additional terms are not necessary."
"implicitly in which case additional terms are not necessary. "
"You should set has_phase_equilibrium=False."
)
# Check that state blocks are set to calculate equilibrium
for t in self.flowsheet().time:
for x in self.length_domain:
if not self.properties[t, x].config.has_phase_equilibrium:
raise ConfigurationError(
"{} material balance was set to include phase "
"equilibrium, however the associated "
"StateBlock was not set to include equilibrium "
"constraints (has_phase_equilibrium=False). Please"
" correct your configuration arguments.".format(self.name)
)
deprecation_warning(
msg=msg, logger=_log, version="2.0.0", remove_in="3.0.0"
)
has_phase_equilibrium = False
else:
# Check that state blocks are set to calculate equilibrium
for t in self.flowsheet().time:
for x in self.length_domain:
if not self.properties[t, x].config.has_phase_equilibrium:
raise ConfigurationError(
"{} material balance was set to include phase "
"equilibrium, however the associated "
"StateBlock was not set to include equilibrium "
"constraints (has_phase_equilibrium=False). Please"
" correct your configuration arguments.".format(
self.name
)
)

# Get units from property package
units = self.config.property_package.get_metadata().get_derived_units
Expand Down
26 changes: 15 additions & 11 deletions idaes/core/base/tests/test_control_volume_0d.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def test_add_material_balances_rxn_mass():


@pytest.mark.unit
def test_add_material_balances_single_phase_w_equilibrium():
def test_add_material_balances_single_phase_w_equilibrium(caplog):
from idaes.models.properties import iapws95

m = ConcreteModel()
Expand All @@ -627,16 +627,20 @@ def test_add_material_balances_single_phase_w_equilibrium():

m.fs.cv.add_state_blocks(has_phase_equilibrium=False)

with pytest.raises(
ConfigurationError,
match="Property package has only one phase; control volume cannot include phase "
"equilibrium terms. Some property packages support phase equilibrium "
"implicitly in which case additional terms are not necessary.",
):
m.fs.cv.add_material_balances(
balance_type=MaterialBalanceType.useDefault,
has_phase_equilibrium=True,
)
m.fs.cv.add_material_balances(
balance_type=MaterialBalanceType.useDefault,
has_phase_equilibrium=True,
)
msg = (
"DEPRECATED: Property package has only one phase; control volume cannot "
"include phase equilibrium terms. Some property packages support phase "
"equilibrium implicitly in which case additional terms are not "
"necessary. You should set has_phase_equilibrium=False. (deprecated in "
"2.0.0, will be removed in (or after) 3.0.0)"
)
assert msg.replace(" ", "") in caplog.records[0].message.replace("\n", "").replace(
" ", ""
)


# -----------------------------------------------------------------------------
Expand Down
27 changes: 16 additions & 11 deletions idaes/core/base/tests/test_control_volume_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ def test_add_material_balances_rxn_mass():


@pytest.mark.unit
def test_add_material_balances_single_phase_w_equilibrium():
def test_add_material_balances_single_phase_w_equilibrium(caplog):
from idaes.models.properties import iapws95

m = ConcreteModel()
Expand All @@ -1264,16 +1264,21 @@ def test_add_material_balances_single_phase_w_equilibrium():
m.fs.cv.add_geometry()
m.fs.cv.add_state_blocks(has_phase_equilibrium=False)

with pytest.raises(
ConfigurationError,
match="Property package has only one phase; control volume cannot include phase "
"equilibrium terms. Some property packages support phase equilibrium "
"implicitly in which case additional terms are not necessary.",
):
m.fs.cv.add_material_balances(
balance_type=MaterialBalanceType.useDefault,
has_phase_equilibrium=True,
)
m.fs.cv.add_material_balances(
balance_type=MaterialBalanceType.useDefault,
has_phase_equilibrium=True,
)

msg = (
"DEPRECATED: Property package has only one phase; control volume cannot "
"include phase equilibrium terms. Some property packages support phase "
"equilibrium implicitly in which case additional terms are not "
"necessary. You should set has_phase_equilibrium=False. (deprecated in "
"2.0.0, will be removed in (or after) 3.0.0)"
)
assert msg.replace(" ", "") in caplog.records[0].message.replace("\n", "").replace(
" ", ""
)


# -----------------------------------------------------------------------------
Expand Down

0 comments on commit f02fca8

Please sign in to comment.