Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving tests and crumbs to Components #1547

Merged
merged 9 commits into from
Dec 13, 2023
8 changes: 4 additions & 4 deletions armi/reactor/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ def _removeDimensionNameSpaces(attrs):


class NullComponent(Component):
r"""Returns zero for all dimensions. is none."""
"""Returns zero for all dimensions."""

def __cmp__(self, other):
r"""Be smaller than everything."""
"""Be smaller than everything."""
return -1

def __lt__(self, other):
return True

def __bool__(self):
r"""Handles truth testing."""
"""Handles truth testing."""
return False

__nonzero__ = __bool__ # Python2 compatibility
Expand Down Expand Up @@ -326,7 +326,7 @@ def computeVolume(self):
"""Cannot compute volume until it is derived.

.. impl:: The volume of a DerivedShape depends on the solid shapes surrounding them.
:id: I_ARMI_COMP_FLUID
:id: I_ARMI_COMP_FLUID0
:implements: R_ARMI_COMP_FLUID
"""
return self._deriveVolumeAndArea()
Expand Down
16 changes: 14 additions & 2 deletions armi/reactor/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ class Component(composites.Composite, metaclass=ComponentType):
:id: I_ARMI_COMP_ORDER
:implements: R_ARMI_COMP_ORDER

This is done via the __lt__() method, which is used to control sort() as the
standard approach in Python. However, __lt__() does not show up in the API.

Attributes
----------
temperatureInC : float
Expand Down Expand Up @@ -286,7 +289,12 @@ def _linkAndStoreDimensions(self, components, **dims):
self.resolveLinkedDims(components)

def resolveLinkedDims(self, components):
"""Convert dimension link strings to actual links."""
"""Convert dimension link strings to actual links.

.. impl:: The volume of some defined shapes depend on the solid components surrounding them.
:id: I_ARMI_COMP_FLUID1
:implements: R_ARMI_COMP_FLUID
"""
for dimName in self.DIMENSION_NAMES:
value = self.p[dimName]
if not isinstance(value, str):
Expand Down Expand Up @@ -794,6 +802,10 @@ def setDimension(self, key, val, retainLink=False, cold=True):
"""
Set a single dimension on the component.

.. impl:: Set a component dimension, considering thermal expansion.
:id: I_ARMI_COMP_EXPANSION1
:implements: R_ARMI_COMP_EXPANSION

Parameters
----------
key : str
Expand Down Expand Up @@ -904,7 +916,7 @@ def getThermalExpansionFactor(self, Tc=None, T0=None):
Retrieves the material thermal expansion fraction.

.. impl:: Calculates radial thermal expansion factor.
:id: I_ARMI_COMP_EXPANSION
:id: I_ARMI_COMP_EXPANSION0
:implements: R_ARMI_COMP_EXPANSION

Parameters
Expand Down
65 changes: 38 additions & 27 deletions armi/reactor/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ def test_initializeComponentMaterial(self):
.. test:: Components are made of one material.
:id: T_ARMI_COMP_1MAT0
:tests: R_ARMI_COMP_1MAT

.. test:: Define a component.
:id: T_ARMI_COMP_DEF0
:tests: R_ARMI_COMP_DEF
"""
expectedName = "TestComponent"
actualName = self.component.getName()
Expand Down Expand Up @@ -241,12 +237,7 @@ class TestNullComponent(TestGeneralComponents):
componentCls = NullComponent

def test_cmp(self):
"""Test null component.

.. test:: Define a component.
:id: T_ARMI_COMP_DEF1
:tests: R_ARMI_COMP_DEF
"""
"""Test null component."""
cur = self.component
ref = DerivedShape("DerivedShape", "Material", 0, 0)
self.assertLess(cur, ref)
Expand All @@ -263,7 +254,8 @@ def test_getDimension(self):
:id: T_ARMI_COMP_DIMS0
:tests: R_ARMI_COMP_DIMS
"""
self.assertEqual(self.component.getDimension(""), 0.0)
for temp in range(400, 901, 25):
self.assertEqual(self.component.getDimension("", Tc=temp), 0.0)


class TestUnshapedComponent(TestGeneralComponents):
Expand Down Expand Up @@ -496,10 +488,6 @@ class TestCircle(TestShapedComponent):
def test_getThermalExpansionFactorConservedMassByLinearExpansionPercent(self):
"""Test that when ARMI thermally expands a circle, mass is conserved.

.. test:: Circle shaped component
:id: T_ARMI_COMP_SHAPES0
:tests: R_ARMI_COMP_SHAPES

.. test:: Calculate thermal expansion.
:id: T_ARMI_COMP_EXPANSION0
:tests: R_ARMI_COMP_EXPANSION
Expand All @@ -523,10 +511,10 @@ def test_getDimension(self):
:id: T_ARMI_COMP_EXPANSION1
:tests: R_ARMI_COMP_EXPANSION
"""
hotTemp = 700.0
ref = self._od * self.component.getThermalExpansionFactor(Tc=hotTemp)
cur = self.component.getDimension("od", Tc=hotTemp)
self.assertAlmostEqual(cur, ref)
for hotTemp in range(600, 901, 25):
ref = self._od * self.component.getThermalExpansionFactor(Tc=hotTemp)
cur = self.component.getDimension("od", Tc=hotTemp)
self.assertAlmostEqual(cur, ref)

def test_thermallyExpands(self):
"""Test that ARMI can thermally expands a circle."""
Expand Down Expand Up @@ -555,15 +543,28 @@ def test_getArea(self):
:id: T_ARMI_COMP_VOL1
:tests: R_ARMI_COMP_VOL
"""
# show we can calculate the area once
od = self.component.getDimension("od")
idd = self.component.getDimension("id")
mult = self.component.getDimension("mult")
ref = math.pi * ((od / 2) ** 2 - (idd / 2) ** 2) * mult
cur = self.component.getArea()
self.assertAlmostEqual(cur, ref)

# show we can clear the cache, change the temp, and correctly re-calc the area
for newTemp in range(500, 690, 19):
self.component.clearCache()

# re-calc area
self.component.temperatureInC = newTemp
od = self.component.getDimension("od", Tc=newTemp)
idd = self.component.getDimension("id", Tc=newTemp)
ref = math.pi * ((od / 2) ** 2 - (idd / 2) ** 2) * mult
cur = self.component.getArea()
self.assertAlmostEqual(cur, ref)

def test_componentInteractionsLinkingByDimensions(self):
r"""Tests linking of components by dimensions."""
"""Tests linking of components by dimensions."""
nPins = 217
fuelDims = {"Tinput": 25.0, "Thot": 430.0, "od": 0.9, "id": 0.0, "mult": nPins}
cladDims = {"Tinput": 25.0, "Thot": 430.0, "od": 1.1, "id": 1.0, "mult": nPins}
Expand Down Expand Up @@ -916,6 +917,13 @@ def test_getBoundingCircleOuterDiameter(self):
cur = self.component.getBoundingCircleOuterDiameter(cold=True)
self.assertAlmostEqual(ref, cur)

# verify the area of the rectangle is correct
ref = self.componentDims["lengthOuter"] * self.componentDims["widthOuter"]
ref -= self.componentDims["lengthInner"] * self.componentDims["widthInner"]
ref *= self.componentDims["mult"]
cur = self.component.getArea(cold=True)
self.assertAlmostEqual(cur, ref)

def test_getCircleInnerDiameter(self):
cur = self.component.getCircleInnerDiameter(cold=True)
self.assertAlmostEqual(math.sqrt(25.0), cur)
Expand Down Expand Up @@ -965,12 +973,7 @@ class TestSolidRectangle(TestShapedComponent):
}

def test_getBoundingCircleOuterDiameter(self):
"""Test get bounding circle of the outer diameter.

.. test:: Define a component.
:id: T_ARMI_COMP_DEF2
:tests: R_ARMI_COMP_DEF
"""
"""Test get bounding circle of the outer diameter."""
ref = math.sqrt(50)
cur = self.component.getBoundingCircleOuterDiameter(cold=True)
self.assertAlmostEqual(ref, cur)
Expand Down Expand Up @@ -1042,6 +1045,14 @@ def test_getBoundingCircleOuterDiameter(self):
cur = self.component.getBoundingCircleOuterDiameter(cold=True)
self.assertAlmostEqual(ref, cur)

# verify the area of the circle is correct
ref = (
self.componentDims["widthOuter"] ** 2
- self.componentDims["widthInner"] ** 2
)
cur = self.component.getComponentArea(cold=True)
self.assertAlmostEqual(cur, ref)

def test_getCircleInnerDiameter(self):
ref = math.sqrt(8.0)
cur = self.component.getCircleInnerDiameter(cold=True)
Expand Down Expand Up @@ -1507,7 +1518,7 @@ class TestSphere(TestShapedComponent):
def test_getVolume(self):
"""Calculate area of sphere.

.. test:: Calculate area of sphere.
.. test:: Calculate volume of sphere.
:id: T_ARMI_COMP_VOL12
:tests: R_ARMI_COMP_VOL
"""
Expand Down
Loading