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

Fix rotation of hexagons in block diagrams #1648

Draft
wants to merge 5 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions armi/reactor/grids/hexagonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ def pitch(self) -> float:
"""
return self._unitSteps[1][1]

@property
def cornersUp(self) -> bool:
"""
Check whether the hexagonal grid is "corners up" or "flats up".

See the armi.reactor.grids.HexGrid class documentation for an
illustration of the two types of grid indexing.
"""
return self._unitSteps[0][1] != 0.0

@staticmethod
def indicesToRingPos(i: int, j: int) -> Tuple[int, int]:
"""
Expand Down
31 changes: 24 additions & 7 deletions armi/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,11 @@ def _makeBlockPinPatches(block, cold):

sortedComps = sorted(block, reverse=True)

if isinstance(block.spatialGrid, grids.HexGrid):
hexRotation = 0 if block.spatialGrid.cornersUp else 30
else:
hexRotation = 0

derivedComponents = block.getComponentsOfShape(DerivedShape)
if len(derivedComponents) == 1:
derivedComponent = derivedComponents[0]
Expand All @@ -1185,7 +1190,10 @@ def _makeBlockPinPatches(block, cold):
x, y, _ = location.getLocalCoordinates()
if isinstance(comp, Hexagon):
derivedPatch = matplotlib.patches.RegularPolygon(
(x, y), 6, radius=largestPitch / math.sqrt(3)
(x, y),
6,
radius=largestPitch / math.sqrt(3),
orientation=(hexRotation - 30.0) * (2.0 * math.pi) / 360.0,
)
elif isinstance(comp, Square):
derivedPatch = matplotlib.patches.Rectangle(
Expand All @@ -1212,7 +1220,9 @@ def _makeBlockPinPatches(block, cold):

# goes through each location
# want to place a patch at that location
blockPatches = _makeComponentPatch(component, (x, y), cold)
blockPatches = _makeComponentPatch(
component, (x, y), cold, hexRotation=hexRotation
)
for element in blockPatches:
patches.append(element)

Expand All @@ -1227,7 +1237,7 @@ def _makeBlockPinPatches(block, cold):
return patches, data, names


def _makeComponentPatch(component, position, cold):
def _makeComponentPatch(component, position, cold, hexRotation=30):
keckler marked this conversation as resolved.
Show resolved Hide resolved
keckler marked this conversation as resolved.
Show resolved Hide resolved
"""Makes a component shaped patch to later be used for making block diagrams.

Parameters
Expand All @@ -1240,14 +1250,18 @@ def _makeComponentPatch(component, position, cold):
cold: boolean
True if looking for dimension at cold temps

hexRotation: float, optional
Amount of counterclockwise rotation (in degrees) for a hexagon component patch. 0 degrees
corresponds to a hexagon with its corner pointing up.

Return
------
blockPatch: List
A list of Patch objects that together represent a component in the diagram.

Notes
-----
Currently accepts components of shape DerivedShape, Helix, Circle, or Square
Currently accepts components of shape DerivedShape, Helix, Circle, Hexagon, or Square
"""
x = position[0]
y = position[1]
Expand Down Expand Up @@ -1283,10 +1297,10 @@ def _makeComponentPatch(component, position, cold):
elif isinstance(component, Hexagon):
if component.getDimension("ip", cold=cold) != 0:
keckler marked this conversation as resolved.
Show resolved Hide resolved
innerPoints = numpy.array(
hexagon.corners(30) * component.getDimension("ip", cold=cold)
hexagon.corners(hexRotation) * component.getDimension("ip", cold=cold)
)
outerPoints = numpy.array(
hexagon.corners(30) * component.getDimension("op", cold=cold)
hexagon.corners(hexRotation) * component.getDimension("op", cold=cold)
)
blockPatch = []
for n in range(6):
Expand All @@ -1301,7 +1315,10 @@ def _makeComponentPatch(component, position, cold):
else:
# Just make it a hexagon...
blockPatch = matplotlib.patches.RegularPolygon(
(x, y), 6, radius=component.getDimension("op", cold=cold) / math.sqrt(3)
(x, y),
6,
radius=component.getDimension("op", cold=cold) / math.sqrt(3),
orientation=(hexRotation - 30.0) * (2.0 * math.pi) / 360.0,
)

elif isinstance(component, Rectangle):
Expand Down