Skip to content

Commit

Permalink
save users from themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
dallan-keylogic committed Feb 24, 2025
1 parent 4f87ae6 commit a71283c
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ def test_all_types_components(self):
)

m.props = m.params.build_state_block([1], defined_state=False)

l_phase, v_phase, vl_comps, henry_comps, l_only_comps, v_only_comps = (
identify_VL_component_list(m.props[1], ("p1", "p2"))
)
Expand All @@ -721,6 +720,102 @@ def test_all_types_components(self):
assert l_only_comps == ["b"]
assert v_only_comps == ["c"]

@pytest.mark.unit
def test_henry_components_only(self):
m = ConcreteModel()
m.params = DummyParameterBlock(
components={
"b": {
"valid_phase_types": PT.liquidPhase,
},
"c": {
"valid_phase_types": PT.vaporPhase,
},
"d": {
"valid_phase_types": PT.solidPhase,
},
"e": {
"parameter_data": {"henry_ref": {"p1": 86}},
"henry_component": {
"p1": {"method": ConstantH, "type": HenryType.Kpx}
},
},
},
phases={
"p1": {
"type": LiquidPhase,
"equation_of_state": DummyEoS,
},
"p2": {
"type": VaporPhase,
"equation_of_state": DummyEoS,
},
"p3": {
"type": SolidPhase,
"equation_of_state": DummyEoS,
},
},
state_definition=self,
pressure_ref=100000.0,
temperature_ref=300,
base_units=self.base_units,
)

m.props = m.params.build_state_block([1], defined_state=False)
l_phase, v_phase, vl_comps, henry_comps, l_only_comps, v_only_comps = (
identify_VL_component_list(m.props[1], ("p1", "p2"))
)
assert l_phase == "p1"
assert v_phase == "p2"
assert vl_comps == []
assert henry_comps == ["e"]
assert l_only_comps == ["b"]
assert v_only_comps == ["c"]

@pytest.mark.unit
def test_no_vle_components(self):
m = ConcreteModel()
m.params = DummyParameterBlock(
components={
"b": {
"valid_phase_types": PT.liquidPhase,
},
"c": {
"valid_phase_types": PT.vaporPhase,
},
"d": {
"valid_phase_types": PT.solidPhase,
},
},
phases={
"p1": {
"type": LiquidPhase,
"equation_of_state": DummyEoS,
},
"p2": {
"type": VaporPhase,
"equation_of_state": DummyEoS,
},
"p3": {
"type": SolidPhase,
"equation_of_state": DummyEoS,
},
},
state_definition=self,
pressure_ref=100000.0,
temperature_ref=300,
base_units=self.base_units,
)

m.props = m.params.build_state_block([1], defined_state=False)
with pytest.raises(
PropertyPackageError,
match="Phase pair p1-p2 was identified as "
"being a VLE pair, however are no components present in both "
"the vapor and liquid phases simultaneously.",
):
_ = identify_VL_component_list(m.props[1], ("p1", "p2"))


# Property configuration for pure water to use in bubble and dew point tests
configuration = {
Expand Down
7 changes: 7 additions & 0 deletions idaes/models/properties/modular_properties/base/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ def identify_VL_component_list(blk, phase_pair):
elif (v_phase, j) in blk.phase_component_set:
v_only_comps.append(j)

if len(vl_comps) == 0 and len(henry_comps) == 0:
raise PropertyPackageError(
f"Phase pair {phase_pair[0]}-{phase_pair[1]} was identified as "
"being a VLE pair, however are no components present in both "
"the vapor and liquid phases simultaneously."
)

return l_phase, v_phase, vl_comps, henry_comps, l_only_comps, v_only_comps


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,8 @@ def state_initialization(b):
else:
_pe_pairs = b.params._pe_pairs

vl_comps = []
henry_comps = []
init_VLE = False
num_VLE = 0

for pp in _pe_pairs:
# Look for a VLE pair with this phase - should only be 1
if (
Expand All @@ -395,7 +394,7 @@ def state_initialization(b):
b.params.get_phase(pp[1]).is_liquid_phase()
and b.params.get_phase(pp[0]).is_vapor_phase()
):
init_VLE = True
num_VLE += 1
# Get bubble and dew points
tbub = None
tdew = None
Expand All @@ -409,10 +408,6 @@ def state_initialization(b):
tdew = b.temperature_dew[pp].value
except KeyError:
pass
if len(vl_comps) > 0:
# More than one VLE. Just use the default initialization for
# now
init_VLE = False
(
l_phase,
v_phase,
Expand All @@ -423,7 +418,7 @@ def state_initialization(b):
) = identify_VL_component_list(b, pp)
pp_VLE = pp

if init_VLE:
if num_VLE == 1: # Only support initialization when a single VLE is present
henry_mole_frac = []
henry_conc = []
henry_other = []
Expand Down Expand Up @@ -471,7 +466,7 @@ def state_initialization(b):

# Default is no initialization of VLE
vap_frac = None
if init_VLE:
if num_VLE == 1:
raoult_init = False
if tdew is not None and b.temperature.value > tdew:
# Pure vapour
Expand Down

0 comments on commit a71283c

Please sign in to comment.