diff --git a/openconcept/__init__.py b/openconcept/__init__.py index a82b376d..72f26f59 100644 --- a/openconcept/__init__.py +++ b/openconcept/__init__.py @@ -1 +1 @@ -__version__ = "1.1.1" +__version__ = "1.1.2" diff --git a/openconcept/thermal/heat_exchanger.py b/openconcept/thermal/heat_exchanger.py index d2e831d2..edada7f0 100644 --- a/openconcept/thermal/heat_exchanger.py +++ b/openconcept/thermal/heat_exchanger.py @@ -1,5 +1,5 @@ import numpy as np -from openmdao.api import ExplicitComponent, Group +from openmdao.api import ExplicitComponent, Group, AnalysisError from openconcept.utilities import DVLabel @@ -264,7 +264,7 @@ def compute(self, inputs, outputs): fc_1 = inputs["alpha_cold"] ** -0.1856 * inputs["delta_cold"] ** 0.3053 * inputs["gamma_cold"] ** -0.2659 fc_2 = inputs["alpha_cold"] ** 0.92 * inputs["delta_cold"] ** 3.767 * inputs["gamma_cold"] ** 0.236 if np.min(inputs["Re_dh_cold"]) <= 0.0: - raise ValueError(self.msginfo, inputs["Re_dh_cold"]) + raise AnalysisError(f"One of the Re numbers in {inputs['Re_dh_cold']} is negative", msginfo=self.msginfo) outputs["j_cold"] = ( 0.6522 * inputs["Re_dh_cold"] ** -0.5403 @@ -682,7 +682,9 @@ def compute(self, inputs, outputs): outputs["h_conv_cold"] = inputs["Nu_dh_cold"] * inputs["k_cold"] / inputs["dh_cold"] outputs["h_conv_hot"] = inputs["Nu_dh_hot"] * inputs["k_hot"] / inputs["dh_hot"] if np.min(outputs["h_conv_cold"]) <= 0.0: - raise ValueError(self.msginfo) + raise AnalysisError( + f"One of the heat tranfer coeffcients in {outputs['h_conv_cold']} is negative", msginfo=self.msginfo + ) def compute_partials(self, inputs, J): J["h_conv_cold", "Nu_dh_cold"] = inputs["k_cold"] / inputs["dh_cold"] @@ -777,7 +779,9 @@ def compute(self, inputs, outputs): m_cold = np.sqrt(2 * h_c / k / t_f) if np.min(h_c) <= 0.0: - raise ValueError(self.msginfo) + raise AnalysisError( + f"One of the heat tranfer coeffcients in {inputs['h_conv_cold']} is negative", msginfo=self.msginfo + ) eta_f_cold = 2 * np.tanh(m_cold * l_f_c / 2) / m_cold / l_f_c outputs["eta_overall_cold"] = 1 - inputs["fin_area_ratio_cold"] * (1 - eta_f_cold) diff --git a/openconcept/thermal/tests/test_heat_exchanger.py b/openconcept/thermal/tests/test_heat_exchanger.py index 10413335..7efc5632 100644 --- a/openconcept/thermal/tests/test_heat_exchanger.py +++ b/openconcept/thermal/tests/test_heat_exchanger.py @@ -1,8 +1,13 @@ import unittest import numpy as np from openmdao.utils.assert_utils import assert_near_equal, assert_check_partials -from openmdao.api import IndepVarComp, Group, Problem -from openconcept.thermal.heat_exchanger import HXGroup +from openmdao.api import IndepVarComp, Group, Problem, AnalysisError +from openconcept.thermal.heat_exchanger import ( + OffsetStripFinData, + ConvectiveCoefficient, + FinEfficiency, + HXGroup, +) class OSFGeometryTestGroup(Group): @@ -52,6 +57,32 @@ def setup(self): self.add_subsystem("hx", HXGroup(), promotes=["*"]) +class AnalysisErrorChecks(unittest.TestCase): + def test_OSFdata(self): + prob = Problem() + prob.model.add_subsystem("OSFData", OffsetStripFinData(), promotes_inputs=["*"], promotes_outputs=["*"]) + prob.setup() + prob.set_val("Re_dh_cold", val=-1.0) + with self.assertRaises(AnalysisError): + prob.run_model() + + def test_Conv_coeff(self): + prob = Problem() + prob.model.add_subsystem("Conv_coeff", ConvectiveCoefficient(), promotes_inputs=["*"], promotes_outputs=["*"]) + prob.setup() + prob.set_val("Nu_dh_cold", val=-1.0) + with self.assertRaises(AnalysisError): + prob.run_model() + + def test_Fin_eff(self): + prob = Problem() + prob.model.add_subsystem("Fin_eff", FinEfficiency(), promotes_inputs=["*"], promotes_outputs=["*"]) + prob.setup() + prob.set_val("h_conv_cold", val=-1.0) + with self.assertRaises(AnalysisError): + prob.run_model() + + class OSFGeometryTestCase(unittest.TestCase): def test_default_settings(self): prob = Problem(OSFGeometryTestGroup(num_nodes=1))