From c0cb724aa12484712d085b47e9e8340d1d242593 Mon Sep 17 00:00:00 2001 From: Francesco Witte Date: Fri, 2 Aug 2024 15:17:10 +0200 Subject: [PATCH 1/4] Except heat exchanger effectiveness calculation, when the other side temperature is out of bounds for a fluid --- src/tespy/components/heat_exchangers/base.py | 36 +++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/tespy/components/heat_exchangers/base.py b/src/tespy/components/heat_exchangers/base.py index cbae4d31..31a8445a 100644 --- a/src/tespy/components/heat_exchangers/base.py +++ b/src/tespy/components/heat_exchangers/base.py @@ -16,6 +16,7 @@ from tespy.components.component import Component from tespy.components.component import component_registry +from tespy.tools import logger from tespy.tools.data_containers import ComponentCharacteristics as dc_cc from tespy.tools.data_containers import ComponentProperties as dc_cp from tespy.tools.data_containers import GroupedComponentCharacteristics as dc_gcc @@ -1057,15 +1058,32 @@ def calc_parameters(self): self.kA.val = -self.Q.val / self.td_log.val # heat exchanger efficiencies - self.eff_hot.val = ( - (self.outl[0].h.val_SI - self.inl[0].h.val_SI) - / self.calc_dh_max_hot() - ) - - self.eff_cold.val = ( - (self.outl[1].h.val_SI - self.inl[1].h.val_SI) - / self.calc_dh_max_cold() - ) + try: + self.eff_hot.val = ( + (self.outl[0].h.val_SI - self.inl[0].h.val_SI) + / self.calc_dh_max_hot() + ) + except ValueError: + self.eff_hot.val = np.nan + msg = ( + "Cannot calculate heat exchanger hot side effectiveness " + "because cold side inlet temperature is out of bounds for hot " + "side fluid." + ) + logger.warning(msg) + try: + self.eff_cold.val = ( + (self.outl[1].h.val_SI - self.inl[1].h.val_SI) + / self.calc_dh_max_cold() + ) + except ValueError: + self.eff_cold.val = np.nan + msg = ( + "Cannot calculate heat exchanger cold side effectiveness " + "because hot side inlet temperature is out of bounds for cold " + "side fluid." + ) + logger.warning(msg) self.eff_max.val = max(self.eff_hot.val, self.eff_cold.val) def entropy_balance(self): From 7f5a41f1c1ecd8e658feb00aca1bbed1b76bd79d Mon Sep 17 00:00:00 2001 From: Francesco Witte Date: Fri, 2 Aug 2024 15:44:00 +0200 Subject: [PATCH 2/4] Test the new feature --- tests/test_components/test_heat_exchangers.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_components/test_heat_exchangers.py b/tests/test_components/test_heat_exchangers.py index ff11ea81..b4479a2d 100644 --- a/tests/test_components/test_heat_exchangers.py +++ b/tests/test_components/test_heat_exchangers.py @@ -476,6 +476,37 @@ def test_HeatExchanger(self, tmp_path): ) assert round(self.c3.m.val, 2) == 7.96 + def test_HeatExchanger_effectiveness_invalid(self): + + instance = HeatExchanger('heat exchanger') + self.setup_HeatExchanger_network(instance) + + # remove fluid specifications + self.c1.set_attr(fluid={f: None for f in self.c1.fluid.val}) + self.c3.set_attr(fluid={f: None for f in self.c3.fluid.val}) + + # add new fluids + # temperature range > 300 °C + self.c1.set_attr(fluid={"INCOMP::NaK": 1}, m=10, T=400, p=1) + self.c2.set_attr(T=350, p=1) + # temperature range < 100 °C at 1 bar + self.c3.set_attr(fluid={"INCOMP::Water": 1}, T=25, p=1) + self.c4.set_attr(T=50, p=1) + instance.set_attr(eff_cold=None, eff_hot=None, pr1=None, pr2=None) + + self.nw.solve("design") + self.nw._convergence_check() + msg = ( + 'Value of cold effectiveness must be nan but is ' + f'{round(instance.eff_cold.val, 1)}.' + ) + assert np.isnan(instance.eff_cold.val), msg + msg = ( + 'Value of hot effectiveness must be nan but is ' + f'{round(instance.eff_hot.val, 1)}.' + ) + assert np.isnan(instance.eff_hot.val), msg + def test_Condenser(self, tmp_path): """Test component properties of Condenser.""" instance = Condenser('condenser') From e2be159fd8cc626ca5da8c3493be4ca0b4630970 Mon Sep 17 00:00:00 2001 From: Francesco Witte Date: Fri, 2 Aug 2024 15:49:46 +0200 Subject: [PATCH 3/4] Update what's new --- docs/whats_new.rst | 1 + docs/whats_new/v0-7-6-001.rst | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 docs/whats_new/v0-7-6-001.rst diff --git a/docs/whats_new.rst b/docs/whats_new.rst index d6c38a46..91229a01 100644 --- a/docs/whats_new.rst +++ b/docs/whats_new.rst @@ -3,6 +3,7 @@ What's New Discover notable new features and improvements in each release +.. include:: whats_new/v0-7-6-001.rst .. include:: whats_new/v0-7-6.rst .. include:: whats_new/v0-7-5.rst .. include:: whats_new/v0-7-4.rst diff --git a/docs/whats_new/v0-7-6-001.rst b/docs/whats_new/v0-7-6-001.rst new file mode 100644 index 00000000..0692718f --- /dev/null +++ b/docs/whats_new/v0-7-6-001.rst @@ -0,0 +1,17 @@ +v0.7.6.post1 - Newton's Nature (August, 02, 2024) ++++++++++++++++++++++++++++++++++++++++++++++++++ + +This is a post release for version 0.7.6 to fix a bug in the postprocessing of +the :code:`HeatExchanger` classes. + +Bug Fixes +######### +- An exception is catched in the heat exchanger post processing, in case the + heat exchanger effectiveness cannot be calculated when hot side or cold side + inlet temperature value are out of bounds of the fluid properties for the + other side respectively + (`PR #533 `__). + +Contributors +############ +- Francesco Witte (`@fwitte `__) From afc962f22351e1cb4542a300613b4d11df69cc5f Mon Sep 17 00:00:00 2001 From: Francesco Witte Date: Fri, 2 Aug 2024 15:51:10 +0200 Subject: [PATCH 4/4] Bump version --- pyproject.toml | 2 +- src/tespy/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 43da22c3..46e2a852 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ exclude = ["docs/_build"] [project] name = "tespy" -version = "0.7.6" +version = "0.7.6.post1" description = "Thermal Engineering Systems in Python (TESPy)" readme = "README.rst" authors = [ diff --git a/src/tespy/__init__.py b/src/tespy/__init__.py index 5342b863..9b198713 100644 --- a/src/tespy/__init__.py +++ b/src/tespy/__init__.py @@ -3,7 +3,7 @@ import os __datapath__ = os.path.join(importlib.resources.files("tespy"), "data") -__version__ = '0.7.6 - Newton\'s Nature' +__version__ = '0.7.6.post1 - Newton\'s Nature' # tespy data and connections import from . import connections # noqa: F401