From a71283c6436a211b2227a5b19435c499a90c17d2 Mon Sep 17 00:00:00 2001 From: Doug A Date: Mon, 24 Feb 2025 17:55:46 -0500 Subject: [PATCH] save users from themselves --- .../base/tests/test_utility.py | 97 ++++++++++++++++++- .../modular_properties/base/utility.py | 7 ++ .../state_definitions/FTPx.py | 15 +-- 3 files changed, 108 insertions(+), 11 deletions(-) diff --git a/idaes/models/properties/modular_properties/base/tests/test_utility.py b/idaes/models/properties/modular_properties/base/tests/test_utility.py index 5ba2acee27..8e7d35bbd9 100644 --- a/idaes/models/properties/modular_properties/base/tests/test_utility.py +++ b/idaes/models/properties/modular_properties/base/tests/test_utility.py @@ -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")) ) @@ -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 = { diff --git a/idaes/models/properties/modular_properties/base/utility.py b/idaes/models/properties/modular_properties/base/utility.py index c4e526dc09..c52a5e7af8 100644 --- a/idaes/models/properties/modular_properties/base/utility.py +++ b/idaes/models/properties/modular_properties/base/utility.py @@ -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 diff --git a/idaes/models/properties/modular_properties/state_definitions/FTPx.py b/idaes/models/properties/modular_properties/state_definitions/FTPx.py index 9369f2f227..2b01e92705 100644 --- a/idaes/models/properties/modular_properties/state_definitions/FTPx.py +++ b/idaes/models/properties/modular_properties/state_definitions/FTPx.py @@ -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 ( @@ -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 @@ -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, @@ -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 = [] @@ -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