Skip to content

Commit

Permalink
Last unit model diagnostics tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlee94 committed Mar 14, 2024
1 parent cc9c240 commit 2189347
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 122 deletions.
25 changes: 12 additions & 13 deletions idaes/models/unit_models/tests/test_hx_ntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
BlockTriangularizationInitializer,
InitializationStatus,
)
from idaes.core.util import DiagnosticsToolbox


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
161 changes: 52 additions & 109 deletions idaes/models/unit_models/tests/test_shell_and_tube_1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2189347

Please sign in to comment.