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

Fixing HexBlock rotation in plotBlockDiagram #1926

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion armi/reactor/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,13 @@ def coords(self):
round(y, units.FLOAT_DIMENSION_DECIMALS),
)

def cornersUp(self):
"""Determine if the hex shape of is corners up or flats up, in relation to the Y axis."""
if self.spatialGrid is None:
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is false-like? But returning None from a bool-like method feels weird.

Would it make more sense to return False or error here?

Copy link
Member Author

Choose a reason for hiding this comment

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

A Python None is a null value. It is just as valid to use None for a null value when a return type is an int, numpy.ndarray or bool.

Seems standard enough to return an empty value from a method.

What would you rather do? I don't want to return an error, because this does not seem like a scenario in which I want to kill a simulation.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmmm


return self.spatialGrid.cornersUp

def createHomogenizedCopy(self, pinSpatialLocators=False):
"""
Create a new homogenized copy of a block that is less expensive than a full deepcopy.
Expand Down Expand Up @@ -1901,7 +1908,6 @@ def getMaxArea(self):
This method first retrieves the pitch of the hexagonal Block
(:need:`I_ARMI_UTIL_HEXAGON0`) and then leverages the
area calculation via :need:`I_ARMI_UTIL_HEXAGON0`.

"""
pitch = self.getPitch()
if not pitch:
Expand Down
139 changes: 73 additions & 66 deletions armi/reactor/tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,12 +1558,8 @@ def test_expandAllElementalsToIsotopics(self):
"It adds to {1}".format(initialM[elemental], newMass, elemental),
)

def test_setPitch(self):
r"""
Checks consistency after adjusting pitch.

Needed to verify fix to Issue #165.
"""
def test_setPitchDoesNotAffectBOL(self):
"""Verify that changing a Blocks pitch doesn't alter physical parameters defined at BOL."""
b = self.block
moles1 = b.p.molesHmBOL
b.setPitch(17.5)
Expand Down Expand Up @@ -1891,30 +1887,41 @@ def test_negativeVolume(self):
class HexBlock_TestCase(unittest.TestCase):
def setUp(self):
_ = settings.Settings()
self.HexBlock = blocks.HexBlock("TestHexBlock")
self.hexBlock = blocks.HexBlock("TestHexBlock")
hexDims = {"Tinput": 273.0, "Thot": 273.0, "op": 70.6, "ip": 70.0, "mult": 1.0}
self.hexComponent = components.Hexagon("duct", "UZr", **hexDims)
self.HexBlock.add(self.hexComponent)
self.HexBlock.add(
self.hexBlock.add(self.hexComponent)
self.hexBlock.add(
components.Circle(
"clad", "HT9", Tinput=273.0, Thot=273.0, od=0.1, mult=169.0
)
)
self.HexBlock.add(
self.hexBlock.add(
components.Circle(
"wire", "HT9", Tinput=273.0, Thot=273.0, od=0.01, mult=169.0
)
)
self.HexBlock.add(
self.hexBlock.add(
components.DerivedShape("coolant", "Sodium", Tinput=273.0, Thot=273.0)
)
self.HexBlock.autoCreateSpatialGrids()
self.hexBlock.autoCreateSpatialGrids()
r = tests.getEmptyHexReactor()
a = makeTestAssembly(1, 1)
a.add(self.HexBlock)
a.add(self.hexBlock)
loc1 = r.core.spatialGrid[0, 1, 0]
r.core.add(a, loc1)

def test_cornersUp(self):
# check corners-up
self.assertTrue(self.hexBlock.cornersUp())

# replace the spatialGrid with one to make it flats-up
grid0 = grids.HexGrid.fromPitch(
self.hexBlock.getPinPitch(cold=True), numRings=0, cornersUp=False
)
self.hexBlock.spatialGrid = grid0
self.assertFalse(self.hexBlock.cornersUp())

def test_getArea(self):
"""Test that we can correctly calculate the area of a hexagonal block.

Expand Down Expand Up @@ -1951,7 +1958,7 @@ def test_component_type(self):
:id: T_ARMI_BLOCK_HEX1
:tests: R_ARMI_BLOCK_HEX
"""
pitch_comp_type = self.HexBlock.PITCH_COMPONENT_TYPE[0]
pitch_comp_type = self.hexBlock.PITCH_COMPONENT_TYPE[0]
self.assertEqual(pitch_comp_type.__name__, "Hexagon")

def test_coords(self):
Expand All @@ -1962,17 +1969,17 @@ def test_coords(self):
:id: T_ARMI_BLOCK_POSI1
:tests: R_ARMI_BLOCK_POSI
"""
core = self.HexBlock.core
a = self.HexBlock.parent
core = self.hexBlock.core
a = self.hexBlock.parent
loc1 = core.spatialGrid[0, 1, 0]
a.spatialLocator = loc1
x0, y0 = self.HexBlock.coords()
x0, y0 = self.hexBlock.coords()
a.spatialLocator = core.spatialGrid[0, -1, 0] # symmetric
x2, y2 = self.HexBlock.coords()
x2, y2 = self.hexBlock.coords()
a.spatialLocator = loc1
self.HexBlock.p.displacementX = 0.01
self.HexBlock.p.displacementY = 0.02
x1, y1 = self.HexBlock.coords()
self.hexBlock.p.displacementX = 0.01
self.hexBlock.p.displacementY = 0.02
x1, y1 = self.hexBlock.coords()

# make sure displacements are working
self.assertAlmostEqual(x1 - x0, 1.0)
Expand All @@ -1983,7 +1990,7 @@ def test_coords(self):
self.assertAlmostEqual(y0, -y2)

def test_getNumPins(self):
self.assertEqual(self.HexBlock.getNumPins(), 169)
self.assertEqual(self.hexBlock.getNumPins(), 169)

def test_block_dims(self):
"""
Expand All @@ -1993,58 +2000,58 @@ def test_block_dims(self):
:id: T_ARMI_BLOCK_DIMS
:tests: R_ARMI_BLOCK_DIMS
"""
self.assertAlmostEqual(4316.582, self.HexBlock.getVolume(), 3)
self.assertAlmostEqual(70.6, self.HexBlock.getPitch(), 1)
self.assertAlmostEqual(4316.582, self.HexBlock.getMaxArea(), 3)
self.assertAlmostEqual(4316.582, self.hexBlock.getVolume(), 3)
self.assertAlmostEqual(70.6, self.hexBlock.getPitch(), 1)
self.assertAlmostEqual(4316.582, self.hexBlock.getMaxArea(), 3)

self.assertEqual(70, self.HexBlock.getDuctIP())
self.assertEqual(70.6, self.HexBlock.getDuctOP())
self.assertEqual(70, self.hexBlock.getDuctIP())
self.assertEqual(70.6, self.hexBlock.getDuctOP())

self.assertAlmostEqual(34.273, self.HexBlock.getPinToDuctGap(), 3)
self.assertEqual(0.11, self.HexBlock.getPinPitch())
self.assertAlmostEqual(300.889, self.HexBlock.getWettedPerimeter(), 3)
self.assertAlmostEqual(4242.184, self.HexBlock.getFlowArea(), 3)
self.assertAlmostEqual(56.395, self.HexBlock.getHydraulicDiameter(), 3)
self.assertAlmostEqual(34.273, self.hexBlock.getPinToDuctGap(), 3)
self.assertEqual(0.11, self.hexBlock.getPinPitch())
self.assertAlmostEqual(300.889, self.hexBlock.getWettedPerimeter(), 3)
self.assertAlmostEqual(4242.184, self.hexBlock.getFlowArea(), 3)
self.assertAlmostEqual(56.395, self.hexBlock.getHydraulicDiameter(), 3)

def test_symmetryFactor(self):
# full hex
self.HexBlock.spatialLocator = self.HexBlock.core.spatialGrid[2, 0, 0]
self.HexBlock.clearCache()
self.assertEqual(1.0, self.HexBlock.getSymmetryFactor())
a0 = self.HexBlock.getArea()
v0 = self.HexBlock.getVolume()
m0 = self.HexBlock.getMass()
self.hexBlock.spatialLocator = self.hexBlock.core.spatialGrid[2, 0, 0]
self.hexBlock.clearCache()
self.assertEqual(1.0, self.hexBlock.getSymmetryFactor())
a0 = self.hexBlock.getArea()
v0 = self.hexBlock.getVolume()
m0 = self.hexBlock.getMass()

# 1/3 symmetric
self.HexBlock.spatialLocator = self.HexBlock.core.spatialGrid[0, 0, 0]
self.HexBlock.clearCache()
self.assertEqual(3.0, self.HexBlock.getSymmetryFactor())
self.assertEqual(a0 / 3.0, self.HexBlock.getArea())
self.assertEqual(v0 / 3.0, self.HexBlock.getVolume())
self.assertAlmostEqual(m0 / 3.0, self.HexBlock.getMass())
self.hexBlock.spatialLocator = self.hexBlock.core.spatialGrid[0, 0, 0]
self.hexBlock.clearCache()
self.assertEqual(3.0, self.hexBlock.getSymmetryFactor())
self.assertEqual(a0 / 3.0, self.hexBlock.getArea())
self.assertEqual(v0 / 3.0, self.hexBlock.getVolume())
self.assertAlmostEqual(m0 / 3.0, self.hexBlock.getMass())

def test_retainState(self):
"""Ensure retainState restores params and spatialGrids."""
self.HexBlock.spatialGrid = grids.HexGrid.fromPitch(1.0)
self.HexBlock.setType("intercoolant")
with self.HexBlock.retainState():
self.HexBlock.setType("fuel")
self.HexBlock.spatialGrid.changePitch(2.0)
self.assertAlmostEqual(self.HexBlock.spatialGrid.pitch, 1.0)
self.assertTrue(self.HexBlock.hasFlags(Flags.INTERCOOLANT))
self.hexBlock.spatialGrid = grids.HexGrid.fromPitch(1.0)
self.hexBlock.setType("intercoolant")
with self.hexBlock.retainState():
self.hexBlock.setType("fuel")
self.hexBlock.spatialGrid.changePitch(2.0)
self.assertAlmostEqual(self.hexBlock.spatialGrid.pitch, 1.0)
self.assertTrue(self.hexBlock.hasFlags(Flags.INTERCOOLANT))

def test_getPinCoords(self):
blockPitch = self.HexBlock.getPitch()
pinPitch = self.HexBlock.getPinPitch()
nPins = self.HexBlock.getNumPins()
blockPitch = self.hexBlock.getPitch()
pinPitch = self.hexBlock.getPinPitch()
nPins = self.hexBlock.getNumPins()
side = hexagon.side(blockPitch)
xyz = self.HexBlock.getPinCoordinates()
xyz = self.hexBlock.getPinCoordinates()
x, y, _z = zip(*xyz)
self.assertAlmostEqual(
y[1], y[2]
) # first two pins should be side by side on top.
self.assertNotAlmostEqual(x[1], x[2])
self.assertEqual(len(xyz), self.HexBlock.getNumPins())
self.assertEqual(len(xyz), self.hexBlock.getNumPins())

# ensure all pins are within the proper bounds of a
# flats-up oriented hex block
Expand Down Expand Up @@ -2137,17 +2144,17 @@ def test_getPitchHomogeneousBlock(self):
self.assertAlmostEqual(sum(c.getArea() for c in hexBlock), hexTotalArea)

def test_getDuctPitch(self):
ductIP = self.HexBlock.getDuctIP()
ductIP = self.hexBlock.getDuctIP()
self.assertAlmostEqual(70.0, ductIP)
ductOP = self.HexBlock.getDuctOP()
ductOP = self.hexBlock.getDuctOP()
self.assertAlmostEqual(70.6, ductOP)

def test_getPinCenterFlatToFlat(self):
nRings = hexagon.numRingsToHoldNumCells(self.HexBlock.getNumPins())
pinPitch = self.HexBlock.getPinPitch()
nRings = hexagon.numRingsToHoldNumCells(self.hexBlock.getNumPins())
pinPitch = self.hexBlock.getPinPitch()
pinCenterCornerToCorner = 2 * (nRings - 1) * pinPitch
pinCenterFlatToFlat = math.sqrt(3.0) / 2.0 * pinCenterCornerToCorner
f2f = self.HexBlock.getPinCenterFlatToFlat()
f2f = self.hexBlock.getPinCenterFlatToFlat()
self.assertAlmostEqual(pinCenterFlatToFlat, f2f)

def test_gridCreation(self):
Expand All @@ -2157,7 +2164,7 @@ def test_gridCreation(self):
:id: T_ARMI_GRID_MULT
:tests: R_ARMI_GRID_MULT
"""
b = self.HexBlock
b = self.hexBlock
# The block should have a spatial grid at construction,
# since it has mults = 1 or 169 from setup
b.autoCreateSpatialGrids()
Expand Down Expand Up @@ -2220,12 +2227,12 @@ def test_gridNotCreatedMultipleMultiplicities(self):
}
# add a wire only some places in the block, so grid should not be created.
wire = components.Helix("wire", "HT9", **wireDims)
self.HexBlock.add(wire)
self.HexBlock.spatialGrid = None # clear existing
self.hexBlock.add(wire)
self.hexBlock.spatialGrid = None # clear existing
with self.assertRaises(ValueError):
self.HexBlock.autoCreateSpatialGrids()
self.hexBlock.autoCreateSpatialGrids()

self.assertIsNone(self.HexBlock.spatialGrid)
self.assertIsNone(self.hexBlock.spatialGrid)


class ThRZBlock_TestCase(unittest.TestCase):
Expand Down
1 change: 0 additions & 1 deletion armi/utils/hexagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def corners(rotation=0):
)

rotation = rotation / 180.0 * math.pi

rotation = np.array(
[
[math.cos(rotation), -math.sin(rotation)],
Expand Down
Loading
Loading