diff --git a/idaes/core/util/scaling.py b/idaes/core/util/scaling.py index 5e03a2a9b8..ccb305c041 100644 --- a/idaes/core/util/scaling.py +++ b/idaes/core/util/scaling.py @@ -1472,10 +1472,14 @@ def _get_nominal_value_expr_if(self, node, child_nominal_values): def _get_nominal_value_external_function(self, node, child_nominal_values): # First, need to get expected magnitudes of input terms, which may be sub-expressions - input_mag = [ - self._get_nominal_value_for_sum_subexpression(i) - for i in child_nominal_values - ] + input_mag = [] + for i in child_nominal_values: + if isinstance(i[0], str): + # Sometimes external functions might have string arguments + # Check here, and return the string if true + input_mag.append(i[0]) + else: + input_mag.append(self._get_nominal_value_for_sum_subexpression(i)) # Next, create a copy of the external function with expected magnitudes as inputs newfunc = node.create_node_with_local_data(input_mag) diff --git a/idaes/core/util/tests/test_scaling.py b/idaes/core/util/tests/test_scaling.py index e5ed63844d..f07ad129cd 100644 --- a/idaes/core/util/tests/test_scaling.py +++ b/idaes/core/util/tests/test_scaling.py @@ -39,6 +39,7 @@ CubicThermoExpressions, CubicType as CubicEoS, ) +from idaes.models.properties import iapws95 __author__ = "John Eslick, Tim Bartholomew" @@ -2230,6 +2231,16 @@ def test_constraint(self, m): expr=m.constraint.expr ) == [21, 0.5 ** (22 + 23 + 24)] + @pytest.mark.component + def test_external_function_w_string_argument(self): + m = pyo.ConcreteModel() + m.properties = iapws95.Iapws95ParameterBlock() + m.state = m.properties.build_state_block([0]) + + assert sc.NominalValueExtractionVisitor().walk_expression( + expr=m.state[0].temperature + ) == [pytest.approx(235.0, rel=1e-8)] + @pytest.fixture(scope="function") def m():