Skip to content

Commit

Permalink
Add plotting to the uniform mesh and fix some parameter assignments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehader committed Apr 19, 2022
1 parent 996291a commit 8bc64f1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
10 changes: 6 additions & 4 deletions armi/reactor/assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,9 @@ def getBlocksBetweenElevations(self, zLower, zUpper):
blocksHere.append((b, heightHere))

totalHeight = 0.0
allMeshPoints = sorted(allMeshPoints)
# The expected height snaps to the minimum height that is requested
expectedHeight = min(
sorted(allMeshPoints)[-1] - sorted(allMeshPoints)[0], zUpper - zLower
)
expectedHeight = min(allMeshPoints[-1] - allMeshPoints[0], zUpper - zLower)
for _b, height in blocksHere:
totalHeight += height

Expand All @@ -968,7 +967,10 @@ def getBlocksBetweenElevations(self, zLower, zUpper):
if abs(totalHeight - expectedHeight) > 1e-5:
raise ValueError(
f"The cumulative height of {blocksHere} is {totalHeight} cm "
f"and does not equal the expected height of {expectedHeight} cm"
f"and does not equal the expected height of {expectedHeight} cm.\n"
f"All mesh points: {allMeshPoints}\n"
f"Upper mesh point: {zUpper} cm\n"
f"Lower mesh point: {zLower} cm\n"
)

return blocksHere
Expand Down
6 changes: 4 additions & 2 deletions armi/reactor/assemblyParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ def detailedNDens(self, value):
pb.defParam(
"crCriticalFraction",
units="",
description=("The insertion fraction when the control rod assembly is in its critical configuration. "
"Note that the default of -1.0 is a trigger for this value not being set yet."),
description=(
"The insertion fraction when the control rod assembly is in its critical configuration. "
"Note that the default of -1.0 is a trigger for this value not being set yet."
),
saveToDB=True,
default=-1.0,
)
Expand Down
45 changes: 38 additions & 7 deletions armi/reactor/converters/uniformMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@
.. figure:: /.static/axial_homogenization.png
"""
import re
import glob
import copy
import logging

import numpy

import armi
from armi import runLog
from armi.utils.mathematics import average1DWithinTolerance
from armi.utils import iterables
Expand Down Expand Up @@ -244,13 +247,31 @@ def _buildAllUniformAssemblies(self):
src = sourceAssem.spatialLocator
newLoc = self.convReactor.core.spatialGrid[src.i, src.j, 0]
self.convReactor.core.add(newAssem, newLoc)
self.plotConvertedReactor()

def plotConvertedReactor(self):
assemsToPlot = self.convReactor.core[:12]
for plotNum, assemBatch in enumerate(iterables.chunk(assemsToPlot, 6), start=1):
assemPlotName = f"{self.convReactor.core.name}AssemblyTypes{plotNum}.png"
bpAssems = list(self.convReactor.blueprints.assemblies.values())
assemsToPlot = []
for bpAssem in bpAssems:
a = self.convReactor.core.getAssemblies(bpAssem.p.flags)[0]
assemsToPlot.append(a)

# Obtain the plot numbering based on the existing files so that existing plots
# are not overwritten.
start = 0
existingFiles = glob.glob(
f"{self.convReactor.core.name}AssemblyTypes" + "*" + ".png"
)
for f in existingFiles:
newStart = int(re.search(r"\d+", f).group())
if newStart > start:
start = newStart
for plotNum, assemBatch in enumerate(
iterables.chunk(assemsToPlot, 6), start=start + 1
):
assemPlotName = f"{self.convReactor.core.name}AssemblyTypes{plotNum}-rank{armi.MPI_RANK}.png"
plotting.plotAssemblyTypes(
self.convReactor.core.parent.blueprints,
self.convReactor.blueprints,
assemPlotName,
assemBatch,
maxAssems=6,
Expand Down Expand Up @@ -531,12 +552,17 @@ def _setStateFromOverlaps(
# be incorrect. This checks that the parameters have been cleared and fails otherwise.
for destBlock in destinationAssembly:
existingDestBlockParamVals = getter(destBlock, paramNames)
if existingDestBlockParamVals is not None:
noneVals = [
True if val is None else False for val in existingDestBlockParamVals
]
if not all(noneVals):
raise ValueError(
f"The state of {destBlock} on {destinationAssembly} "
f"was not cleared prior to calling ``_setStateFromOverlaps``. "
f"This is an implementation bug in the mesh converter that should "
"be reported to the developers."
f"be reported to the developers. The following parameters should be cleared:\n"
f"Parameters: {paramNames}\n"
f"Values: {existingDestBlockParamVals}"
)

# The destination assembly is the assembly that the results are being mapped to
Expand Down Expand Up @@ -572,6 +598,11 @@ def _setStateFromOverlaps(
paramNames, sourceBlockVals, destBlockVals
):

# The value can be `None` if it has not been set yet. In this case,
# the mapping can be skipped.
if sourceBlockVal is None:
continue

# Determine if the parameter is volumed integrated or not.
isVolIntegrated = sourceBlock.p.paramDefs[paramName].atLocation(
parameters.ParamLocation.VOLUME_INTEGRATED
Expand All @@ -597,4 +628,4 @@ def _setStateFromOverlaps(
sourceBlockVal * integrationFactor
)

setter(destBlock, [updatedDestVal], [paramName])
setter(destBlock, [updatedDestVal], [paramName])
10 changes: 5 additions & 5 deletions armi/reactor/reactorParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ def detailedNucKeys(self, value):

pb.defParam("numMoves", units="", description="numMoves", default=0)

with pDefs.createBuilder(
location="N/A", categories=["control rods"]
) as pb:
with pDefs.createBuilder(location="N/A", categories=["control rods"]) as pb:

pb.defParam(
"crMostValuablePrimaryRodLocation",
Expand Down Expand Up @@ -209,8 +207,10 @@ def detailedNucKeys(self, value):
default=0.0,
units="pcm",
saveToDB=True,
description=("Reactivity worth introduced by removal of the highest worth primary "
"control rod from the core, starting from its critical position"),
description=(
"Reactivity worth introduced by removal of the highest worth primary "
"control rod from the core, starting from its critical position"
),
)

with pDefs.createBuilder(default=0.0, location="N/A") as pb:
Expand Down

0 comments on commit 8bc64f1

Please sign in to comment.