From 218934713d90fb0f3e8de2cc124faeedc3e7cd1e Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 14 Mar 2024 11:36:59 -0400 Subject: [PATCH] Last unit model diagnostics tests --- idaes/models/unit_models/tests/test_hx_ntu.py | 25 ++- .../tests/test_shell_and_tube_1D.py | 161 ++++++------------ 2 files changed, 64 insertions(+), 122 deletions(-) diff --git a/idaes/models/unit_models/tests/test_hx_ntu.py b/idaes/models/unit_models/tests/test_hx_ntu.py index e382246652..86af622fa1 100644 --- a/idaes/models/unit_models/tests/test_hx_ntu.py +++ b/idaes/models/unit_models/tests/test_hx_ntu.py @@ -49,6 +49,7 @@ BlockTriangularizationInitializer, InitializationStatus, ) +from idaes.core.util import DiagnosticsToolbox # ----------------------------------------------------------------------------- @@ -281,20 +282,11 @@ def test_build(self, model): assert model.fs.unit.default_initializer is HXNTUInitializer @pytest.mark.component - def test_units(self, model): - assert_units_consistent(model) - - assert_units_equivalent(model.fs.unit.area, pyunits.m**2) - assert_units_equivalent( - model.fs.unit.heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, + def test_structural_issues(self, model): + dt = DiagnosticsToolbox(model) + dt.assert_no_structural_warnings( + ignore_evaluation_errors=True, ) - assert_units_equivalent(model.fs.unit.effectiveness[0], pyunits.dimensionless) - assert_units_equivalent(model.fs.unit.NTU[0], pyunits.dimensionless) - - @pytest.mark.unit - def test_dof(self, model): - assert degrees_of_freedom(model) == 0 @pytest.mark.ui @pytest.mark.unit @@ -505,6 +497,13 @@ def test_conservation(self, model): <= 1e-6 ) + @pytest.mark.solver + @pytest.mark.skipif(solver is None, reason="Solver not available") + @pytest.mark.component + def test_numerical_issues(self, model): + dt = DiagnosticsToolbox(model) + dt.assert_no_numerical_warnings() + class TestInitializers(object): @pytest.fixture(scope="class") diff --git a/idaes/models/unit_models/tests/test_shell_and_tube_1D.py b/idaes/models/unit_models/tests/test_shell_and_tube_1D.py index 65a44fa7a0..11c14c6dd1 100644 --- a/idaes/models/unit_models/tests/test_shell_and_tube_1D.py +++ b/idaes/models/unit_models/tests/test_shell_and_tube_1D.py @@ -62,6 +62,7 @@ from idaes.core.util.testing import PhysicalParameterTestBlock, initialization_tester from idaes.core.util import scaling as iscale from idaes.core.solvers import get_solver +from idaes.core.util import DiagnosticsToolbox # Imports to assemble BT-PR with different units from idaes.core import LiquidPhase, VaporPhase, Component @@ -414,28 +415,9 @@ def test_build(self, btx): assert number_unused_variables(btx) == 8 @pytest.mark.integration - def test_units(self, btx): - assert_units_equivalent(btx.fs.unit.length, pyunits.m) - assert_units_equivalent(btx.fs.unit.shell_diameter, pyunits.m) - assert_units_equivalent(btx.fs.unit.tube_inner_diameter, pyunits.m) - assert_units_equivalent(btx.fs.unit.tube_outer_diameter, pyunits.m) - assert_units_equivalent(btx.fs.unit.number_of_tubes, pyunits.dimensionless) - - assert_units_equivalent( - btx.fs.unit.hot_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, - ) - assert_units_equivalent( - btx.fs.unit.cold_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, - ) - assert_units_equivalent(btx.fs.unit.temperature_wall, pyunits.K) - - assert_units_consistent(btx) - - @pytest.mark.unit - def test_dof(self, btx): - assert degrees_of_freedom(btx) == 0 + def test_structural_issues(self, btx): + dt = DiagnosticsToolbox(btx) + dt.assert_no_structural_warnings() @pytest.mark.ui @pytest.mark.unit @@ -575,6 +557,13 @@ def test_conservation(self, btx): ) assert abs(hot_side - cold_side) <= 1e-6 + @pytest.mark.solver + @pytest.mark.skipif(solver is None, reason="Solver not available") + @pytest.mark.component + def test_numerical_issues(self, btx): + dt = DiagnosticsToolbox(btx) + dt.assert_no_numerical_warnings() + # ----------------------------------------------------------------------------- class TestBTX_countercurrent(object): @@ -671,28 +660,9 @@ def test_build(self, btx): assert number_unused_variables(btx) == 8 @pytest.mark.integration - def test_units(self, btx): - assert_units_equivalent(btx.fs.unit.length, pyunits.m) - assert_units_equivalent(btx.fs.unit.shell_diameter, pyunits.m) - assert_units_equivalent(btx.fs.unit.tube_inner_diameter, pyunits.m) - assert_units_equivalent(btx.fs.unit.tube_outer_diameter, pyunits.m) - assert_units_equivalent(btx.fs.unit.number_of_tubes, pyunits.dimensionless) - - assert_units_equivalent( - btx.fs.unit.hot_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, - ) - assert_units_equivalent( - btx.fs.unit.cold_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, - ) - assert_units_equivalent(btx.fs.unit.temperature_wall, pyunits.K) - - assert_units_consistent(btx) - - @pytest.mark.unit - def test_dof(self, btx): - assert degrees_of_freedom(btx) == 0 + def test_structural_issues(self, btx): + dt = DiagnosticsToolbox(btx) + dt.assert_no_structural_warnings() @pytest.mark.ui @pytest.mark.unit @@ -832,6 +802,13 @@ def test_conservation(self, btx): ) assert abs(hot_side - cold_side) <= 1e-6 + @pytest.mark.solver + @pytest.mark.skipif(solver is None, reason="Solver not available") + @pytest.mark.component + def test_numerical_issues(self, btx): + dt = DiagnosticsToolbox(btx) + dt.assert_no_numerical_warnings() + # ----------------------------------------------------------------------------- @pytest.mark.iapws @@ -916,28 +893,9 @@ def test_build(self, iapws): assert number_unused_variables(iapws) == 10 @pytest.mark.integration - def test_units(self, iapws): - assert_units_equivalent(iapws.fs.unit.length, pyunits.m) - assert_units_equivalent(iapws.fs.unit.shell_diameter, pyunits.m) - assert_units_equivalent(iapws.fs.unit.tube_inner_diameter, pyunits.m) - assert_units_equivalent(iapws.fs.unit.tube_outer_diameter, pyunits.m) - assert_units_equivalent(iapws.fs.unit.number_of_tubes, pyunits.dimensionless) - - assert_units_equivalent( - iapws.fs.unit.hot_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, - ) - assert_units_equivalent( - iapws.fs.unit.cold_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, - ) - assert_units_equivalent(iapws.fs.unit.temperature_wall, pyunits.K) - - assert_units_consistent(iapws) - - @pytest.mark.unit - def test_dof(self, iapws): - assert degrees_of_freedom(iapws) == 0 + def test_structural_issues(self, iapws): + dt = DiagnosticsToolbox(iapws) + dt.assert_no_structural_warnings() @pytest.mark.ui @pytest.mark.unit @@ -1079,6 +1037,13 @@ def test_conservation(self, iapws): ) assert abs(hot_side + cold_side) <= 1e-6 + @pytest.mark.solver + @pytest.mark.skipif(solver is None, reason="Solver not available") + @pytest.mark.component + def test_numerical_issues(self, iapws): + dt = DiagnosticsToolbox(iapws) + dt.assert_no_numerical_warnings() + # ----------------------------------------------------------------------------- @pytest.mark.iapws @@ -1163,28 +1128,9 @@ def test_build(self, iapws): assert number_unused_variables(iapws) == 10 @pytest.mark.integration - def test_units(self, iapws): - assert_units_equivalent(iapws.fs.unit.length, pyunits.m) - assert_units_equivalent(iapws.fs.unit.shell_diameter, pyunits.m) - assert_units_equivalent(iapws.fs.unit.tube_inner_diameter, pyunits.m) - assert_units_equivalent(iapws.fs.unit.tube_outer_diameter, pyunits.m) - assert_units_equivalent(iapws.fs.unit.number_of_tubes, pyunits.dimensionless) - - assert_units_equivalent( - iapws.fs.unit.hot_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, - ) - assert_units_equivalent( - iapws.fs.unit.cold_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, - ) - assert_units_equivalent(iapws.fs.unit.temperature_wall, pyunits.K) - - assert_units_consistent(iapws) - - @pytest.mark.unit - def test_dof(self, iapws): - assert degrees_of_freedom(iapws) == 0 + def test_structural_issues(self, iapws): + dt = DiagnosticsToolbox(iapws) + dt.assert_no_structural_warnings() @pytest.mark.ui @pytest.mark.unit @@ -1326,6 +1272,13 @@ def test_conservation(self, iapws): ) assert abs(hot_side + cold_side) <= 1e-6 + @pytest.mark.solver + @pytest.mark.skipif(solver is None, reason="Solver not available") + @pytest.mark.component + def test_numerical_issues(self, iapws): + dt = DiagnosticsToolbox(iapws) + dt.assert_no_numerical_warnings() + # ----------------------------------------------------------------------------- @pytest.mark.skipif(not cubic_roots_available(), reason="Cubic functions not available") @@ -1532,28 +1485,11 @@ def test_build(self, btx): assert number_unused_variables(btx) == 34 @pytest.mark.integration - def test_units(self, btx): - assert_units_equivalent(btx.fs.unit.length, pyunits.m) - assert_units_equivalent(btx.fs.unit.shell_diameter, pyunits.m) - assert_units_equivalent(btx.fs.unit.tube_inner_diameter, pyunits.m) - assert_units_equivalent(btx.fs.unit.tube_outer_diameter, pyunits.m) - assert_units_equivalent(btx.fs.unit.number_of_tubes, pyunits.dimensionless) - - assert_units_equivalent( - btx.fs.unit.hot_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, - ) - assert_units_equivalent( - btx.fs.unit.cold_side_heat_transfer_coefficient, - pyunits.W / pyunits.m**2 / pyunits.K, + def test_structural_issues(self, btx): + dt = DiagnosticsToolbox(btx) + dt.assert_no_structural_warnings( + ignore_evaluation_errors=True, ) - assert_units_equivalent(btx.fs.unit.temperature_wall, pyunits.K) - - assert_units_consistent(btx) - - @pytest.mark.component - def test_dof(self, btx): - assert degrees_of_freedom(btx) == 0 @pytest.mark.ui @pytest.mark.unit @@ -1697,6 +1633,13 @@ def test_conservation(self, btx): ) assert abs((hot_side - cold_side) / hot_side) <= 3e-4 + @pytest.mark.solver + @pytest.mark.skipif(solver is None, reason="Solver not available") + @pytest.mark.integration + def test_numerical_issues(self, btx): + dt = DiagnosticsToolbox(btx) + dt.assert_no_numerical_warnings() + @pytest.mark.component def test_initialization_error(self, btx): btx.fs.unit.hot_side_outlet.flow_mol[0].fix(20)