From 55b1838c3e5472344ecedf558aa8655f4adfedf2 Mon Sep 17 00:00:00 2001 From: jstilley Date: Fri, 1 Nov 2024 09:58:35 -0700 Subject: [PATCH 1/6] Fixing a couple of plots to use initial block height --- armi/utils/plotting.py | 12 ++++++--- armi/utils/reportPlotting.py | 16 +++++++++--- armi/utils/tests/test_plotting.py | 20 +++++++++++++++ armi/utils/tests/test_reportPlotting.py | 33 +++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/armi/utils/plotting.py b/armi/utils/plotting.py index 5e99c48a4..d52bd6c27 100644 --- a/armi/utils/plotting.py +++ b/armi/utils/plotting.py @@ -766,7 +766,7 @@ def plotAssemblyTypes( maxAssems = numAssems if yAxisLabel is None: - yAxisLabel = "THERMALLY EXPANDED AXIAL HEIGHTS (CM)" + yAxisLabel = "Thermally Expanded Axial Heights (cm)" if title is None: title = "Assembly Designs" @@ -864,9 +864,11 @@ def _plotBlocksInAssembly( xBlockLoc = xAssemLoc xTextLoc = xBlockLoc + blockWidth / 20.0 for b in assem: - blockHeight = b.getHeight() - blockXsId = b.p.xsType - yBlockCenterLoc = yBlockLoc + blockHeight / 2.5 + # get block height + try: + blockHeight = b.getInputHeight() + except AttributeError: + blockHeight = b.getHeight() # Get the basic text label for the block try: @@ -881,6 +883,7 @@ def _plotBlocksInAssembly( color = "grey" # Get the detailed text label for the block + blockXsId = b.p.xsType dLabel = "" if b.hasFlags(Flags.FUEL): dLabel = " {:0.2f}%".format(b.getFissileMassEnrich() * 100) @@ -901,6 +904,7 @@ def _plotBlocksInAssembly( ls="solid", ) axis.add_patch(blockPatch) + yBlockCenterLoc = yBlockLoc + blockHeight / 2.5 axis.text( xTextLoc, yBlockCenterLoc, diff --git a/armi/utils/reportPlotting.py b/armi/utils/reportPlotting.py index 936bbec1d..cf055a042 100644 --- a/armi/utils/reportPlotting.py +++ b/armi/utils/reportPlotting.py @@ -416,11 +416,19 @@ def _getMechanicalVals(r): def _getPhysicalVals(r): avgHeight = 0.0 fuelA = r.core.getAssemblies(Flags.FUEL) - avgHeight = sum( - b.getHeight() for a in fuelA for b in a.getBlocks(Flags.FUEL) - ) / len(fuelA) - radius = r.core.getCoreRadius() + # get average height + avgHeight = 0 + for a in fuelA: + for b in a.getBlocks(Flags.FUEL): + try: + avgHeight += b.getInputHeight() + except AttributeError: + assert False + avgHeight += b.getHeight() + avgHeight /= len(fuelA) + + radius = r.core.getCoreRadius() labels, vals = list( zip( *[ diff --git a/armi/utils/tests/test_plotting.py b/armi/utils/tests/test_plotting.py index bc28b5991..2c930b91e 100644 --- a/armi/utils/tests/test_plotting.py +++ b/armi/utils/tests/test_plotting.py @@ -16,6 +16,7 @@ import os import unittest +import matplotlib.pyplot as plt import numpy as np from armi import settings @@ -83,6 +84,25 @@ def test_plotAssemblyTypes(self): if os.path.exists(plotPath): os.remove(plotPath) + def test_plotBlocksInAssembly(self): + _fig, ax = plt.subplots(figsize=(15, 15), dpi=300) + xBlockLoc, yBlockHeights, yBlockAxMesh = plotting._plotBlocksInAssembly( + ax, + self.r.core.getFirstAssembly(Flags.FUEL), + True, + [], + set(), + 0.5, + 5.6, + True, + ) + self.assertEqual(xBlockLoc, 0.5) + self.assertEqual(yBlockHeights[0], 25.0) + yBlockAxMesh = list(yBlockAxMesh)[0] + self.assertIn(10.0, yBlockAxMesh) + self.assertIn(25.0, yBlockAxMesh) + self.assertIn(1, yBlockAxMesh) + def test_plotBlockFlux(self): with TemporaryDirectoryChanger(): xslib = isotxs.readBinary(ISOAA_PATH) diff --git a/armi/utils/tests/test_reportPlotting.py b/armi/utils/tests/test_reportPlotting.py index 5e0268bff..5537a3800 100644 --- a/armi/utils/tests/test_reportPlotting.py +++ b/armi/utils/tests/test_reportPlotting.py @@ -18,10 +18,12 @@ import numpy as np +from armi.reactor.flags import Flags from armi.reactor.tests import test_reactors from armi.tests import TEST_ROOT from armi.utils.directoryChangers import TemporaryDirectoryChanger from armi.utils.reportPlotting import ( + _getPhysicalVals, createPlotMetaData, keffVsTime, movesVsCycle, @@ -47,6 +49,37 @@ def test_radar(self): """Test execution of radar plot. Note this has no asserts and is therefore a smoke test.""" r2 = copy.deepcopy(self.r) plotCoreOverviewRadar([self.r, r2], ["Label1", "Label2"]) + self.assertTrue(os.path.exists("reactor_comparison.png")) + + def test_getPhysicalVals(self): + dims, labels, vals = _getPhysicalVals(self.r) + self.assertEqual(dims, "Dimensions") + + self.assertEqual(labels[0], "Fuel height") + self.assertEqual(labels[1], "Fuel assems") + self.assertEqual(labels[2], "Assem weight") + self.assertEqual(labels[3], "Core radius") + self.assertEqual(labels[4], "Core aspect ratio") + self.assertEqual(labels[5], "Fissile mass") + self.assertEqual(len(labels), 6) + + self.assertEqual(vals[0], 25.0) + self.assertEqual(vals[1], 1) + self.assertAlmostEqual(vals[2], 52474.8927038, delta=1e-5) + self.assertEqual(vals[3], 16.8) + self.assertAlmostEqual(vals[5], 4290.60340961, delta=1e-5) + self.assertEqual(len(vals), 6) + + # this test will use getInputHeight() instead of getHeight() + radius = self.r.core.getCoreRadius() + avgHeight = 0 + fuelA = self.r.core.getAssemblies(Flags.FUEL) + for a in fuelA: + for b in a.getBlocks(Flags.FUEL): + avgHeight += b.getInputHeight() + avgHeight /= len(fuelA) + coreAspectRatio = (2 * radius) / avgHeight + self.assertEqual(vals[4], coreAspectRatio) def test_createPlotMetaData(self): title = "test_createPlotMetaData" From 71334c7f90abace459f51b6c30d9c3363f228a24 Mon Sep 17 00:00:00 2001 From: jstilley Date: Fri, 1 Nov 2024 11:44:53 -0700 Subject: [PATCH 2/6] correcting label --- armi/utils/plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armi/utils/plotting.py b/armi/utils/plotting.py index d52bd6c27..5b1c2908b 100644 --- a/armi/utils/plotting.py +++ b/armi/utils/plotting.py @@ -766,7 +766,7 @@ def plotAssemblyTypes( maxAssems = numAssems if yAxisLabel is None: - yAxisLabel = "Thermally Expanded Axial Heights (cm)" + yAxisLabel = "Axial Heights (cm)" if title is None: title = "Assembly Designs" From 54cddd2555958d343b978480baf2d2e7708122ce Mon Sep 17 00:00:00 2001 From: John Stilley <1831479+john-science@users.noreply.github.com> Date: Tue, 3 Dec 2024 09:37:33 -0800 Subject: [PATCH 3/6] Review comments --- armi/utils/plotting.py | 1 + armi/utils/reportPlotting.py | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/armi/utils/plotting.py b/armi/utils/plotting.py index 5b1c2908b..147e1c20c 100644 --- a/armi/utils/plotting.py +++ b/armi/utils/plotting.py @@ -868,6 +868,7 @@ def _plotBlocksInAssembly( try: blockHeight = b.getInputHeight() except AttributeError: + runLog.debug(f"No ancestor of {b} has blueprints", single=True) blockHeight = b.getHeight() # Get the basic text label for the block diff --git a/armi/utils/reportPlotting.py b/armi/utils/reportPlotting.py index cf055a042..4d71300b1 100644 --- a/armi/utils/reportPlotting.py +++ b/armi/utils/reportPlotting.py @@ -421,10 +421,7 @@ def _getPhysicalVals(r): avgHeight = 0 for a in fuelA: for b in a.getBlocks(Flags.FUEL): - try: - avgHeight += b.getInputHeight() - except AttributeError: - assert False + avgHeight += b.getInputHeight() avgHeight += b.getHeight() avgHeight /= len(fuelA) From 54d6bc8e0ecae3c0b5e9c8b788ebf94ec1c3c796 Mon Sep 17 00:00:00 2001 From: jstilley Date: Tue, 3 Dec 2024 09:41:50 -0800 Subject: [PATCH 4/6] whoops --- armi/utils/reportPlotting.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/armi/utils/reportPlotting.py b/armi/utils/reportPlotting.py index 4d71300b1..2ac05c686 100644 --- a/armi/utils/reportPlotting.py +++ b/armi/utils/reportPlotting.py @@ -421,7 +421,9 @@ def _getPhysicalVals(r): avgHeight = 0 for a in fuelA: for b in a.getBlocks(Flags.FUEL): - avgHeight += b.getInputHeight() + try: + avgHeight += b.getInputHeight() + except AttributeError: avgHeight += b.getHeight() avgHeight /= len(fuelA) From 00f9c4a6002b437cb055b45b70462596f5282755 Mon Sep 17 00:00:00 2001 From: jstilley Date: Tue, 3 Dec 2024 09:42:54 -0800 Subject: [PATCH 5/6] review comment --- armi/utils/reportPlotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armi/utils/reportPlotting.py b/armi/utils/reportPlotting.py index 2ac05c686..a0de0f807 100644 --- a/armi/utils/reportPlotting.py +++ b/armi/utils/reportPlotting.py @@ -431,7 +431,7 @@ def _getPhysicalVals(r): labels, vals = list( zip( *[ - ("Fuel height", avgHeight), + ("Cold fuel height", avgHeight), ("Fuel assems", len(fuelA)), ("Assem weight", r.core.getFirstAssembly(Flags.FUEL).getMass()), ("Core radius", radius), From 2638f19a9d069cbd717fab617f6932d570515963 Mon Sep 17 00:00:00 2001 From: jstilley Date: Tue, 3 Dec 2024 09:54:03 -0800 Subject: [PATCH 6/6] fixed test --- armi/utils/tests/test_reportPlotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armi/utils/tests/test_reportPlotting.py b/armi/utils/tests/test_reportPlotting.py index 5537a3800..3c09f1a62 100644 --- a/armi/utils/tests/test_reportPlotting.py +++ b/armi/utils/tests/test_reportPlotting.py @@ -55,7 +55,7 @@ def test_getPhysicalVals(self): dims, labels, vals = _getPhysicalVals(self.r) self.assertEqual(dims, "Dimensions") - self.assertEqual(labels[0], "Fuel height") + self.assertEqual(labels[0], "Cold fuel height") self.assertEqual(labels[1], "Fuel assems") self.assertEqual(labels[2], "Assem weight") self.assertEqual(labels[3], "Core radius")