Skip to content

Commit

Permalink
Adding a little code coverage to key Assembly methods (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Apr 5, 2024
1 parent 24aa6ca commit 6222242
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
18 changes: 6 additions & 12 deletions armi/reactor/assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,10 @@ def add(self, obj: blocks.Block):
"""
composites.Composite.add(self, obj)
obj.spatialLocator = self.spatialGrid[0, 0, len(self) - 1]
# assemblies have bounds-based 1-D spatial grids. Adjust it to the right value.
if len(self.spatialGrid._bounds[2]) < len(self):
self.spatialGrid._bounds[2][len(self)] = (
self.spatialGrid._bounds[2][len(self) - 1] + obj.getHeight()
)
else:
# more work is needed, make a new mesh
self.reestablishBlockOrder()
self.calculateZCoords()

# more work is needed, make a new mesh
self.reestablishBlockOrder()
self.calculateZCoords()

def moveTo(self, locator):
"""Move an assembly somewhere else."""
Expand Down Expand Up @@ -323,9 +318,8 @@ def getAveragePlenumTemperature(self):
plenumBlocks = self.getBlocks(Flags.PLENUM)
plenumTemps = [b.p.THcoolantOutletT for b in plenumBlocks]

if (
not plenumTemps
): # no plenum blocks, use the top block of the assembly for plenum temperature
# no plenum blocks, use the top block of the assembly for plenum temperature
if not plenumTemps:
runLog.warning("No plenum blocks exist. Using outlet coolant temperature.")
plenumTemps = [self[-1].p.THcoolantOutletT]

Expand Down
26 changes: 20 additions & 6 deletions armi/reactor/tests/test_assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,15 @@ def test_extend(self):

def test_add(self):
a = makeTestAssembly(1, 1)
b = blocks.HexBlock("TestBlock")
a.add(b)
self.assertIn(b, a)
self.assertEqual(b.parent, a)

# successfully add some Blocks to an Assembly
for n in range(3):
self.assertEqual(len(a), n)
b = blocks.HexBlock("TestBlock")
a.add(b)
self.assertIn(b, a)
self.assertEqual(b.parent, a)
self.assertEqual(len(a), n + 1)

def test_moveTo(self):
ref = self.r.core.spatialGrid.getLocatorFromRingAndPos(3, 10)
Expand Down Expand Up @@ -363,10 +368,14 @@ def test_getArea(self):
:id: T_ARMI_ASSEM_DIMS0
:tests: R_ARMI_ASSEM_DIMS
"""
# Default case: for assemblies with no blocks
a = HexAssembly("TestAssem", assemNum=10)
self.assertEqual(a.getArea(), 1)

# more realistic case: a hex block/assembly
cur = self.assembly.getArea()
ref = math.sqrt(3) / 2.0 * self.hexDims["op"] ** 2
places = 6
self.assertAlmostEqual(cur, ref, places=places)
self.assertAlmostEqual(cur, ref, places=6)

def test_getVolume(self):
"""Tests volume calculation for hex assembly.
Expand Down Expand Up @@ -870,6 +879,11 @@ def test_getDim(self):
:id: T_ARMI_ASSEM_DIMS3
:tests: R_ARMI_ASSEM_DIMS
"""
# quick test, if there are no blocks
a = HexAssembly("TestAssem", assemNum=10)
self.assertIsNone(a.getDim(Flags.FUEL, "op"))

# more interesting test, with blocks
cur = self.assembly.getDim(Flags.FUEL, "op")
ref = self.hexDims["op"]
places = 6
Expand Down
1 change: 1 addition & 0 deletions doc/release/0.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Changes that Affect Requirements
--------------------------------
#. Very minor change to ``Block.coords()``, removing unused argument. (`PR#1651 <https://github.com/terrapower/armi/pull/1651>`_)
#. Touched ``HexGrid`` by adding a "cornersUp" property and fixing two bugs. (`PR#1649 <https://github.com/terrapower/armi/pull/1649>`_)
#. Very slightly modified the implementation of ``Assembly.add()``. (`PR#1670 <https://github.com/terrapower/armi/pull/1670>`_)
#. TBD


Expand Down

0 comments on commit 6222242

Please sign in to comment.