From 0532559c67ba57fecdae7b7af3adcd5794bff2b7 Mon Sep 17 00:00:00 2001 From: Michael Jarrett Date: Thu, 15 Feb 2024 12:01:12 -0800 Subject: [PATCH 1/5] Add cornersUp property to HexGrid. --- armi/reactor/grids/hexagonal.py | 18 ++++++++++++++++++ armi/utils/plotting.py | 15 +++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/armi/reactor/grids/hexagonal.py b/armi/reactor/grids/hexagonal.py index 2365b1001..8a8c4f421 100644 --- a/armi/reactor/grids/hexagonal.py +++ b/armi/reactor/grids/hexagonal.py @@ -160,6 +160,24 @@ 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" + + Corners up corners: + * + * * + * * + * + + Flats up hexagon corners: + * * + * * + * * + """ + return self._unitSteps[0][1] != 0.0 + @staticmethod def indicesToRingPos(i: int, j: int) -> Tuple[int, int]: """ diff --git a/armi/utils/plotting.py b/armi/utils/plotting.py index cdfad1219..8fc272fb1 100644 --- a/armi/utils/plotting.py +++ b/armi/utils/plotting.py @@ -1212,7 +1212,14 @@ def _makeBlockPinPatches(block, cold): # goes through each location # want to place a patch at that location - blockPatches = _makeComponentPatch(component, (x, y), cold) + if isinstance(block.spatialGrid, grids.HexGrid): + hexRotation = 30 if block.spatialGrid.cornersUp else 0 + else: + hexRotation = 0 + + blockPatches = _makeComponentPatch( + component, (x, y), cold, hexRotation=hexRotation + ) for element in blockPatches: patches.append(element) @@ -1227,7 +1234,7 @@ def _makeBlockPinPatches(block, cold): return patches, data, names -def _makeComponentPatch(component, position, cold): +def _makeComponentPatch(component, position, cold, hexRotation=30): """Makes a component shaped patch to later be used for making block diagrams. Parameters @@ -1283,10 +1290,10 @@ def _makeComponentPatch(component, position, cold): elif isinstance(component, Hexagon): if component.getDimension("ip", cold=cold) != 0: 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): From 651e76f21a38e49e040693a170630b8654a6b1a5 Mon Sep 17 00:00:00 2001 From: Michael Jarrett Date: Thu, 15 Feb 2024 12:13:49 -0800 Subject: [PATCH 2/5] Add a period and simplify docstring. --- armi/reactor/grids/hexagonal.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/armi/reactor/grids/hexagonal.py b/armi/reactor/grids/hexagonal.py index 8a8c4f421..3eb123696 100644 --- a/armi/reactor/grids/hexagonal.py +++ b/armi/reactor/grids/hexagonal.py @@ -163,18 +163,10 @@ def pitch(self) -> float: @property def cornersUp(self) -> bool: """ - Check whether the hexagonal grid is "corners up" or "flats up" - - Corners up corners: - * - * * - * * - * - - Flats up hexagon corners: - * * - * * - * * + 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 From d4807066a27073ee90f4a28db720cd38bbdb1226 Mon Sep 17 00:00:00 2001 From: Michael Jarrett Date: Mon, 26 Feb 2024 11:18:51 -0800 Subject: [PATCH 3/5] Address review comments. --- armi/utils/plotting.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/armi/utils/plotting.py b/armi/utils/plotting.py index 8fc272fb1..3dc1d0768 100644 --- a/armi/utils/plotting.py +++ b/armi/utils/plotting.py @@ -1168,6 +1168,12 @@ def _makeBlockPinPatches(block, cold): sortedComps = sorted(block, reverse=True) + if isinstance(block.spatialGrid, grids.HexGrid): + hexRotation = 0 if block.spatialGrid.cornersUp else 30 + print(f"Corners up: {block.spatialGrid.cornersUp}; hexRotation = {hexRotation}") + else: + hexRotation = 0 + derivedComponents = block.getComponentsOfShape(DerivedShape) if len(derivedComponents) == 1: derivedComponent = derivedComponents[0] @@ -1185,7 +1191,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( @@ -1212,11 +1221,6 @@ def _makeBlockPinPatches(block, cold): # goes through each location # want to place a patch at that location - if isinstance(block.spatialGrid, grids.HexGrid): - hexRotation = 30 if block.spatialGrid.cornersUp else 0 - else: - hexRotation = 0 - blockPatches = _makeComponentPatch( component, (x, y), cold, hexRotation=hexRotation ) @@ -1247,6 +1251,9 @@ def _makeComponentPatch(component, position, cold, hexRotation=30): cold: boolean True if looking for dimension at cold temps + hexRotation: float, optional + Amount of counterclockwise rotation (in degrees) for a hexagon component patch + Return ------ blockPatch: List @@ -1254,7 +1261,7 @@ def _makeComponentPatch(component, position, cold, hexRotation=30): 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] @@ -1308,7 +1315,10 @@ def _makeComponentPatch(component, position, cold, hexRotation=30): 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): From a1a49d5ed71e65e31750ea8a034b4f9a90ec5172 Mon Sep 17 00:00:00 2001 From: Michael Jarrett Date: Mon, 26 Feb 2024 12:03:51 -0800 Subject: [PATCH 4/5] Remove print statement. --- armi/utils/plotting.py | 1 - 1 file changed, 1 deletion(-) diff --git a/armi/utils/plotting.py b/armi/utils/plotting.py index 3dc1d0768..fefbbee2c 100644 --- a/armi/utils/plotting.py +++ b/armi/utils/plotting.py @@ -1170,7 +1170,6 @@ def _makeBlockPinPatches(block, cold): if isinstance(block.spatialGrid, grids.HexGrid): hexRotation = 0 if block.spatialGrid.cornersUp else 30 - print(f"Corners up: {block.spatialGrid.cornersUp}; hexRotation = {hexRotation}") else: hexRotation = 0 From 7e7d2a12b7329a88b9656c00b8ddb7db2847ad57 Mon Sep 17 00:00:00 2001 From: Michael Jarrett Date: Mon, 26 Feb 2024 15:49:04 -0800 Subject: [PATCH 5/5] Update armi/utils/plotting.py Co-authored-by: Chris Keckler --- armi/utils/plotting.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/armi/utils/plotting.py b/armi/utils/plotting.py index fefbbee2c..6690f238b 100644 --- a/armi/utils/plotting.py +++ b/armi/utils/plotting.py @@ -1251,7 +1251,8 @@ def _makeComponentPatch(component, position, cold, hexRotation=30): True if looking for dimension at cold temps hexRotation: float, optional - Amount of counterclockwise rotation (in degrees) for a hexagon component patch + Amount of counterclockwise rotation (in degrees) for a hexagon component patch. 0 degrees + corresponds to a hexagon with its corner pointing up. Return ------