Skip to content

Commit

Permalink
Changed Hx Value error to Analysis error for 3 instances. (#62)
Browse files Browse the repository at this point in the history
* heat exchanger raise value error precisions

* init version update

* test_heat_exchangers

* Fix black complaints

* new conflict resolution between upstream main and hbx_issue

---------

Co-authored-by: Marie J Vaucher <mvaucher@umich.edu>
Co-authored-by: Eytan Adler <eytana@umich.edu>
  • Loading branch information
3 people committed Mar 5, 2024
1 parent 773de3a commit 5f2cb40
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion openconcept/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.1"
__version__ = "1.1.2"
12 changes: 8 additions & 4 deletions openconcept/thermal/heat_exchanger.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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)

Expand Down
35 changes: 33 additions & 2 deletions openconcept/thermal/tests/test_heat_exchanger.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 5f2cb40

Please sign in to comment.