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

Force plotAssemblyTypes to always use instantiated assemblies, and al… #2030

Merged
merged 11 commits into from
Jan 2, 2025
18 changes: 13 additions & 5 deletions armi/bookkeeping/report/newReportUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,17 @@ def insertCoreAndAssemblyMaps(
generateFullCoreMap : bool, default False
showBlockAxMesh : bool, default True
"""
assemPrototypes = set()
assemPrototypes = []
for aKey in blueprint.assemDesigns.keys():
assemPrototypes.add(blueprint.constructAssem(cs, name=aKey))
a = blueprint.constructAssem(cs, name=aKey)
# since we will be plotting cold input heights, we need to make sure that
# that these new assemblies have access to a blueprints somewhere up the
# composite chain. normally this would happen through an assembly's parent
# reactor, but because these newly created assemblies are in the load queue,
# they will not have a parent reactor. to get around this, we just attach
# the blueprints to the assembly directly.
a.blueprints = blueprint
assemPrototypes.append(a)

counts = {
assemDesign.name: len(r.core.getChildrenOfType(assemDesign.name))
Expand All @@ -648,19 +656,19 @@ def insertCoreAndAssemblyMaps(
report[DESIGN]["Assembly Designs"] = newReports.Section("Assembly Designs")
currentSection = report[DESIGN]["Assembly Designs"]
for plotNum, assemBatch in enumerate(
iterables.chunk(list(assemPrototypes), MAX_ASSEMS_PER_ASSEM_PLOT), start=1
iterables.chunk(assemPrototypes, MAX_ASSEMS_PER_ASSEM_PLOT), start=1
):
assemPlotImage = newReports.Image(
imageCaption,
os.path.abspath(f"{core.name}AssemblyTypes{plotNum}.png"),
)
assemPlotName = os.path.abspath(f"{core.name}AssemblyTypes{plotNum}.png")
plotting.plotAssemblyTypes(
blueprint,
assemPlotName,
assemBatch,
assemPlotName,
maxAssems=MAX_ASSEMS_PER_ASSEM_PLOT,
showBlockAxMesh=showBlockAxMesh,
hot=False,
)
currentSection.addChildElement(assemPlotImage, assemPlotName)

Expand Down
20 changes: 16 additions & 4 deletions armi/bookkeeping/report/reportingUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,22 +1062,34 @@ def makeCoreAndAssemblyMaps(r, cs, generateFullCoreMap=False, showBlockAxMesh=Tr
generateFullCoreMap : bool, default False
showBlockAxMesh : bool, default True
"""
assemsInCore = list(r.blueprints.assemblies.values())
assems = []
blueprints = r.blueprints
for aKey in blueprints.assemDesigns.keys():
a = blueprints.constructAssem(cs, name=aKey)
# since we will be plotting cold input heights, we need to make sure that
# that these new assemblies have access to a blueprints somewhere up the
# composite chain. normally this would happen through an assembly's parent
# reactor, but because these newly created assemblies are in the load queue,
# they will not have a parent reactor. to get around this, we just attach
# the blueprints to the assembly directly.
a.blueprints = blueprints
assems.append(a)

core = r.core
for plotNum, assemBatch in enumerate(
iterables.chunk(assemsInCore, MAX_ASSEMS_PER_ASSEM_PLOT), start=1
iterables.chunk(assems, MAX_ASSEMS_PER_ASSEM_PLOT), start=1
):
assemPlotImage = copy(report.ASSEM_TYPES)
assemPlotImage.title = assemPlotImage.title + " ({})".format(plotNum)
report.data.Report.groupsOrderFirst.insert(-1, assemPlotImage)
report.data.Report.componentWellGroups.insert(-1, assemPlotImage)
assemPlotName = os.path.abspath(f"{core.name}AssemblyTypes{plotNum}.png")
plotting.plotAssemblyTypes(
core.parent.blueprints,
assemPlotName,
assemBatch,
assemPlotName,
maxAssems=MAX_ASSEMS_PER_ASSEM_PLOT,
showBlockAxMesh=showBlockAxMesh,
hot=False,
)

# Create radial core map
Expand Down
3 changes: 1 addition & 2 deletions armi/reactor/converters/uniformMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,9 +984,8 @@ def plotConvertedReactor(self):
):
assemPlotName = f"{self.convReactor.core.name}AssemblyTypes{plotNum}-rank{armi.MPI_RANK}.png"
plotting.plotAssemblyTypes(
self.convReactor.blueprints,
assemPlotName,
assemBatch,
assemPlotName,
maxAssems=6,
showBlockAxMesh=True,
)
Expand Down
44 changes: 20 additions & 24 deletions armi/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,28 +706,25 @@ def updatePageDepthColor(self, newVal):


def plotAssemblyTypes(
blueprints=None,
fileName=None,
assems=None,
fileName=None,
maxAssems=None,
showBlockAxMesh=True,
yAxisLabel=None,
title=None,
hot=True,
) -> plt.Figure:
"""
Generate a plot showing the axial block and enrichment distributions of each assembly type in the core.

Parameters
----------
blueprints: Blueprints
The blueprints to plot assembly types of. (Either this or ``assems`` must be non-None.)
assems: list
list of assembly objects to be plotted.

fileName : str or None
Base for filename to write, or None for just returning the fig

assems: list
list of assembly objects to be plotted. (Either this or ``blueprints`` must be non-None.)

maxAssems: integer
maximum number of assemblies to plot in the assems list.

Expand All @@ -740,24 +737,14 @@ def plotAssemblyTypes(
title: str
Optionally, provide a title for the plot.

hot : bool, optional
If True, plot the hot block heights. If False, use cold heights from the inputs.

Returns
-------
fig : plt.Figure
The figure object created
"""
# input validation
if assems is None and blueprints is None:
raise ValueError(
"At least one of these inputs must be non-None: blueprints, assems"
)

# handle defaults
if assems is None:
assems = list(blueprints.assemblies.values())

if not isinstance(assems, (list, set, tuple)):
assems = [assems]

if maxAssems is not None and not isinstance(maxAssems, int):
raise TypeError("Maximum assemblies should be an integer")

Expand Down Expand Up @@ -792,6 +779,7 @@ def plotAssemblyTypes(
xAssemLoc,
xAssemEndLoc,
showBlockAxMesh,
hot,
)
xAxisLabel = re.sub(" ", "\n", assem.getType().upper())
ax.text(
Expand Down Expand Up @@ -840,6 +828,7 @@ def _plotBlocksInAssembly(
xAssemLoc,
xAssemEndLoc,
showBlockAxMesh,
hot,
):
# Set dictionary of pre-defined block types and colors for the plot
lightsage = "xkcd:light sage"
Expand All @@ -865,11 +854,18 @@ def _plotBlocksInAssembly(
xTextLoc = xBlockLoc + blockWidth / 20.0
for b in assem:
# get block height
try:
blockHeight = b.getInputHeight()
except AttributeError:
runLog.debug(f"No ancestor of {b} has blueprints", single=True)
if hot:
blockHeight = b.getHeight()
else:
try:
blockHeight = b.getInputHeight()
except AttributeError:
raise ValueError(
f"Cannot plot cold height for block {b} in assembly {assem} "
"because it does not have access to a blueprints through any "
"of its parents. Either make sure that a blueprints is accessible "
" or plot the hot heights instead."
)

# Get the basic text label for the block
try:
Expand Down
10 changes: 5 additions & 5 deletions armi/utils/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ def test_plotDepthMap(self): # indirectly tests plot face map
def test_plotAssemblyTypes(self):
with TemporaryDirectoryChanger():
plotPath = "coreAssemblyTypes1.png"
plotting.plotAssemblyTypes(self.r.core.parent.blueprints, plotPath)
plotting.plotAssemblyTypes(
list(self.r.core.parent.blueprints.assemblies.values()), plotPath
)
self._checkFileExists(plotPath)

if os.path.exists(plotPath):
os.remove(plotPath)

plotPath = "coreAssemblyTypes2.png"
plotting.plotAssemblyTypes(
self.r.core.parent.blueprints,
list(self.r.core.parent.blueprints.assemblies.values()),
plotPath,
yAxisLabel="y axis",
title="title",
Expand All @@ -78,9 +80,6 @@ def test_plotAssemblyTypes(self):
if os.path.exists(plotPath):
os.remove(plotPath)

with self.assertRaises(ValueError):
plotting.plotAssemblyTypes(None, plotPath, None)

if os.path.exists(plotPath):
os.remove(plotPath)

Expand All @@ -95,6 +94,7 @@ def test_plotBlocksInAssembly(self):
0.5,
5.6,
True,
hot=True,
)
self.assertEqual(xBlockLoc, 0.5)
self.assertEqual(yBlockHeights[0], 25.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def buildSystems():
# build ARMI objects
o = case.initializeOperator()
fig = plotting.plotAssemblyTypes(
case.bp,
list(case.bp.assemblies.values()),
None,
showBlockAxMesh=True,
)
Expand Down