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

Implement more detailed __lt__ for components. #1882

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
707aa88
Implement more detailed __lt__ for components.
mgjarrett Sep 11, 2024
35b63a8
Add a unit test for component sorting.
mgjarrett Sep 16, 2024
6bc7dc1
Update release notes.
mgjarrett Sep 16, 2024
1265d7c
Address linting error
mgjarrett Sep 16, 2024
dbed10f
Catch NotImplementedError
mgjarrett Sep 16, 2024
0fd1632
Remove all of the circular imports in components.
mgjarrett Sep 16, 2024
cca4a14
Fix broken unit tests.
mgjarrett Sep 16, 2024
06f1ec1
Fix unit test reference result.
mgjarrett Sep 16, 2024
37e8f0b
Register RadialSegment component type.
mgjarrett Sep 16, 2024
af44807
Black formatting.
mgjarrett Sep 16, 2024
c65a0c3
Merge branch 'main' into component_sort
mgjarrett Sep 16, 2024
9cb98e5
Refactor more unit tests.
mgjarrett Sep 16, 2024
d50b6dc
Ignore unused import
mgjarrett Sep 16, 2024
d1db895
Revert "Refactor more unit tests."
mgjarrett Sep 16, 2024
6c891fd
Revert "Fix broken unit tests."
mgjarrett Sep 16, 2024
914fe58
Revert "Remove all of the circular imports in components."
mgjarrett Sep 16, 2024
88feb80
Clear merge conflict.
mgjarrett Sep 16, 2024
0b1b6ef
Revert trivial change.
mgjarrett Sep 16, 2024
12980cd
Add getCircleInnerDiameter for UnshapedComponent.
mgjarrett Sep 16, 2024
a62fd41
Fix circular import.
mgjarrett Sep 16, 2024
acbf2fc
Black formatting.
mgjarrett Sep 16, 2024
53780e4
Update docstring.
mgjarrett Sep 16, 2024
2a7e4a1
Address review comments.
mgjarrett Sep 16, 2024
64d1d09
One more review comment.
mgjarrett Sep 16, 2024
37e4310
Remove commented code.
mgjarrett Sep 16, 2024
80d57ab
Remove kwargs
mgjarrett Sep 16, 2024
9457b49
Black formatting
mgjarrett Sep 16, 2024
6dca45a
Fix namespace errors.
mgjarrett Sep 16, 2024
4e2234b
Add getCircleInnerDiameter to RadialSegment.
mgjarrett Sep 16, 2024
48603a4
Update armi/reactor/components/__init__.py
mgjarrett Sep 16, 2024
3ccdc5b
Update doc/release/0.4.rst
mgjarrett Sep 16, 2024
2075f3a
Revert to main blocks.py
mgjarrett Sep 16, 2024
5b601f9
Revert import change.
mgjarrett Sep 16, 2024
15155be
Merge branch 'component_sort' of https://github.com/terrapower/armi i…
mgjarrett Sep 16, 2024
7733ad8
Revert more import changes.
mgjarrett Sep 16, 2024
9b61363
Revert more imports.
mgjarrett Sep 16, 2024
b87c1d1
Fix an import.
mgjarrett Sep 16, 2024
557a333
Merge branch 'main' into component_sort
john-science Oct 23, 2024
0fb4219
merging in main
john-science Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions armi/reactor/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ def getBoundingCircleOuterDiameter(self, Tc=None, cold=False):
"""
return 2 * math.sqrt(self.getComponentArea(cold=cold) / math.pi)

def getCircleInnerDiameter(self, Tc=None, cold=False):
"""
Component is unshaped; assume it is circular and there is no ID (return 0.0).

Parameters
----------
Tc : float, optional
Ignored for this component
cold : bool, optional
Ignored for this component

Notes
-----
Tc is not used in this method for this particular component.
"""
return 0.0

@staticmethod
def fromComponent(otherComponent):
"""
Expand Down
4 changes: 2 additions & 2 deletions armi/reactor/components/basicShapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"""
import math

from armi.reactor.components import ShapedComponent
from armi.reactor.components import componentParameters
from armi.reactor.components.component import ShapedComponent
from armi.reactor.components.component import componentParameters


class Circle(ShapedComponent):
Expand Down
29 changes: 22 additions & 7 deletions armi/reactor/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,34 @@ def __lt__(self, other):
"""
True if a circle encompassing this object has a smaller diameter than one encompassing another component.

If the bounding circles for both components have identical size, then revert to checking the inner
diameter of each component for sorting.

This allows sorting because the Python sort functions only use this method.
"""
thisOD = self.getBoundingCircleOuterDiameter(cold=True)
thatOD = other.getBoundingCircleOuterDiameter(cold=True)
try:
return thisOD < thatOD
except Exception:
raise ValueError(
"Components 1 ({} with OD {}) and 2 ({} and OD {}) cannot be ordered because their "
"bounding circle outer diameters are not comparable.".format(
self, thisOD, other, thatOD
if thisOD == thatOD:
thisID = self.getCircleInnerDiameter(cold=True)
thatID = other.getCircleInnerDiameter(cold=True)
return thisID < thatID
else:
return thisOD < thatOD
mgjarrett marked this conversation as resolved.
Show resolved Hide resolved
except (NotImplementedError, Exception) as e:
if isinstance(e, NotImplementedError):
raise NotImplementedError(
"getCircleInnerDiameter not implemented for at least one of {}, {}".format(
self, other
)
)
else:
raise ValueError(
"Components 1 ({} with OD {}) and 2 ({} and OD {}) cannot be ordered because their "
"bounding circle outer diameters are not comparable.".format(
self, thisOD, other, thatOD
)
)
)

def __setstate__(self, state):
composites.Composite.__setstate__(self, state)
Expand Down
5 changes: 4 additions & 1 deletion armi/reactor/components/volumetricShapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ def getComponentVolume(self):
return vol

def getBoundingCircleOuterDiameter(self, Tc=None, cold=False):
return self.getDimension("outer_radius", Tc, cold)
return 2.0 * self.getDimension("outer_radius", Tc, cold)
mgjarrett marked this conversation as resolved.
Show resolved Hide resolved

def getCircleInnerDiameter(self, Tc=None, cold=False):
return 2.0 * self.getDimension("inner_radius", Tc, cold)


class DifferentialRadialSegment(RadialSegment):
Expand Down
52 changes: 49 additions & 3 deletions armi/reactor/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
UnshapedVolumetricComponent,
ComponentType,
)
from armi.reactor.components import materials
from armi import materials
from armi.reactor.tests.test_reactors import loadTestReactor


Expand Down Expand Up @@ -508,6 +508,52 @@ def test_getAreaColdTrue(self):
self.assertAlmostEqual(totalAreaCold, totalAreaHot, delta=1e-10)


class TestComponentSort(unittest.TestCase):
def setUp(self):
self.components = []
pinComp = components.Circle(
"pin", "UZr", Tinput=273.0, Thot=273.0, od=0.08, mult=169.0
)
gapComp = components.Circle(
"gap", "Sodium", Tinput=273.0, Thot=273.0, id=0.08, od=0.08, mult=169.0
)
ductComp = components.Hexagon(
"duct", "HT9", Tinput=273.0, Thot=273.0, op=2.6, ip=2.0, mult=1.0
)
cladComp = components.Circle(
"clad", "HT9", Tinput=273.0, Thot=273.0, id=0.08, od=0.1, mult=169.0
)
wireComp = components.Helix(
"wire",
"HT9",
Tinput=273.0,
Thot=273.0,
axialPitch=10.0,
helixDiameter=0.11,
od=0.01,
mult=169.0,
)
self.components = [
wireComp,
cladComp,
ductComp,
pinComp,
gapComp,
]

def test_sorting(self):
"""Test that components are sorted as expected."""
sortedComps = sorted(self.components)
currentMaxOd = 0.0
for c in sortedComps:
self.assertGreaterEqual(
c.getBoundingCircleOuterDiameter(cold=True), currentMaxOd
)
currentMaxOd = c.getBoundingCircleOuterDiameter(cold=True)
self.assertEqual(sortedComps[1].name, "gap")
self.assertEqual(sortedComps[2].name, "clad")


class TestCircle(TestShapedComponent):
"""Test circle shaped component."""

Expand Down Expand Up @@ -1631,7 +1677,7 @@ def test_thermallyExpands(self):

def test_getBoundingCircleOuterDiameter(self):
self.assertEqual(
self.component.getBoundingCircleOuterDiameter(cold=True), 170.0
self.component.getBoundingCircleOuterDiameter(cold=True), 340.0
)


Expand Down Expand Up @@ -1678,7 +1724,7 @@ def test_thermallyExpands(self):
self.assertFalse(self.component.THERMAL_EXPANSION_DIMS)

def test_getBoundingCircleOuterDiameter(self):
self.assertEqual(self.component.getBoundingCircleOuterDiameter(cold=True), 170)
self.assertEqual(self.component.getBoundingCircleOuterDiameter(cold=True), 340)


class TestMaterialAdjustments(unittest.TestCase):
Expand Down
81 changes: 0 additions & 81 deletions doc/release/0.4.rst

This file was deleted.

1 change: 1 addition & 0 deletions doc/release/0.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ New Features
#. New plugin hook ``beforeReactorConstruction`` to process settings before reactor init. (`PR#1945 <https://github.com/terrapower/armi/pull/1945>`_)
#. Improving performance in the lattice physics interface by not updating cross sections at ``everyNode`` during coupled calculations. (`PR#1963 <https://github.com/terrapower/armi/pull/1963>`_)
#. Allow merging a component with zero area into another component. (`PR#1858 <https://github.com/terrapower/armi/pull/1858>`_)
#. Use inner diameter for sorting components when outer diameter is identical. (`PR#1882 <https://github.com/terrapower/armi/pull/1882>`_)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARMI 0.5.0 was released.

Can we move this release note up to the 0.5.1 release?

Thanks!

#. Updating ``copyOrWarn`` and ``getFileSHA1Hash`` to support directories. (`PR#1984 <https://github.com/terrapower/armi/pull/1984>`_)
#. Improve efficiency of reaction rate calculations. (`PR#1887 <https://github.com/terrapower/armi/pull/1887>`_)
#. Adding new options for simplifying 1D cross section modeling. (`PR#1949 <https://github.com/terrapower/armi/pull/1949>`_)
Expand Down
Loading