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

Using fuelCycle settings constants #1107

Merged
merged 3 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions armi/bookkeeping/report/newReportUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import os
import numpy

from armi.reactor.components import component
from armi import runLog
from armi.reactor.flags import Flags
from armi.bookkeeping.report import newReports
from armi.materials import custom
from armi.physics.fuelCycle.settings import CONF_SHUFFLE_LOGIC
from armi.reactor.components import component
from armi.reactor.flags import Flags
from armi.utils import (
units,
plotting,
Expand All @@ -27,7 +29,6 @@
getCycleLengths,
getStepLengths,
)
from armi.materials import custom


def insertBlueprintContent(r, cs, report, blueprint):
Expand Down Expand Up @@ -193,7 +194,7 @@ def _setGeneralCoreDesignData(cs, coreDesignTable):
coreDesignTable.addRow(["Geometry File", "{}".format(cs["geomFile"])])
coreDesignTable.addRow(["Loading File", "{}".format(cs["loadingFile"])])
coreDesignTable.addRow(
["Fuel Shuffling Logic File", "{}".format(cs["shuffleLogic"])]
["Fuel Shuffling Logic File", "{}".format(cs[CONF_SHUFFLE_LOGIC])]
)
coreDesignTable.addRow(["Reactor State Loading", "{}".format(cs["loadStyle"])])
if cs["loadStyle"] == "fromDB":
Expand Down
5 changes: 3 additions & 2 deletions armi/bookkeeping/report/reportingUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
A collection of miscellaneous functions used by ReportInterface to generate
various reports
"""
from copy import copy
import collections
import os
import pathlib
Expand All @@ -24,7 +25,6 @@
import tabulate
import textwrap
import time
from copy import copy

import numpy

Expand All @@ -33,6 +33,7 @@
from armi import runLog
from armi.bookkeeping import report
from armi.operators import RunTypes
from armi.physics.fuelCycle.settings import CONF_SHUFFLE_LOGIC
from armi.reactor.components import ComponentType
from armi.reactor.flags import Flags
from armi.utils import getFileSHA1Hash
Expand Down Expand Up @@ -631,7 +632,7 @@ def _setGeneralCoreDesignData(cs, coreDesignTable):
)
report.setData(
"Fuel Shuffling Logic File",
"{}".format(cs["shuffleLogic"]),
"{}".format(cs[CONF_SHUFFLE_LOGIC]),
coreDesignTable,
report.DESIGN,
)
Expand Down
17 changes: 9 additions & 8 deletions armi/cases/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
from armi import plugins
from armi import runLog
from armi import settings
from armi.physics.fuelCycle.settings import CONF_SHUFFLE_LOGIC
from armi.reactor import blueprints
from armi.reactor import systemLayoutInput
from armi.settings import setMasterCs
from armi.tests import ARMI_RUN_PATH
from armi.tests import TEST_ROOT
from armi.tests import mockRunLogs
from armi.tests import TEST_ROOT
from armi.utils import directoryChangers


Expand Down Expand Up @@ -411,7 +412,7 @@ def test_writeInput(self):
with directoryChangers.TemporaryDirectoryChanger():
case = baseCase.clone()
case.writeInputs()
self.assertTrue(os.path.exists(cs["shuffleLogic"]))
self.assertTrue(os.path.exists(cs[CONF_SHUFFLE_LOGIC]))
# Availability factor is in the original settings file but since it is a
# default value, gets removed for the write-out
txt = open("armiRun.yaml", "r").read()
Expand Down Expand Up @@ -485,7 +486,7 @@ def tearDown(self):

def test_copyInputsHelper(self):
"""Test the helper function for copyInterfaceInputs."""
testSetting = "shuffleLogic"
testSetting = CONF_SHUFFLE_LOGIC
cs = settings.Settings(ARMI_RUN_PATH)
shuffleFile = cs[testSetting]

Expand Down Expand Up @@ -514,7 +515,7 @@ def test_copyInputsHelper(self):
self.assertEqual(destFilePath, shuffleFile)

def test_copyInterfaceInputs_singleFile(self):
testSetting = "shuffleLogic"
testSetting = CONF_SHUFFLE_LOGIC
cs = settings.Settings(ARMI_RUN_PATH)
shuffleFile = cs[testSetting]

Expand All @@ -527,7 +528,7 @@ def test_copyInterfaceInputs_singleFile(self):
self.assertEqual(newSettings[testSetting], str(newFilepath))

def test_copyInterfaceInputs_nonFilePath(self):
testSetting = "shuffleLogic"
testSetting = CONF_SHUFFLE_LOGIC
cs = settings.Settings(ARMI_RUN_PATH)
fakeShuffle = "fakeFile.py"
cs = cs.modified(newSettings={testSetting: fakeShuffle})
Expand Down Expand Up @@ -567,7 +568,7 @@ def test_copyInterfaceInputs_multipleFiles(self):
self.assertEqual(newSettings[testSetting], newFilepaths)

def test_copyInterfaceInputs_wildcardFile(self):
testSetting = "shuffleLogic"
testSetting = CONF_SHUFFLE_LOGIC
cs = settings.Settings(ARMI_RUN_PATH)
# Use something that isn't the shuffle logic file in the case settings
wcFile = "ISO*"
Expand All @@ -591,7 +592,7 @@ def test_copyInterfaceInputs_wildcardFile(self):
self.assertEqual(newSettings[testSetting], [wcFile])

def test_copyInterfaceInputs_relPath(self):
testSetting = "shuffleLogic"
testSetting = CONF_SHUFFLE_LOGIC
cs = settings.Settings(ARMI_RUN_PATH)
shuffleFile = cs[testSetting]
relFile = "../tests/" + shuffleFile
Expand All @@ -606,7 +607,7 @@ def test_copyInterfaceInputs_relPath(self):
self.assertEqual(newSettings[testSetting], newFilepath)

def test_copyInterfaceInputs_absPath(self):
testSetting = "shuffleLogic"
testSetting = CONF_SHUFFLE_LOGIC
cs = settings.Settings(ARMI_RUN_PATH)
shuffleFile = cs[testSetting]
absFile = os.path.dirname(os.path.abspath(ARMI_RUN_PATH))
Expand Down
3 changes: 2 additions & 1 deletion armi/operators/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from armi.bookkeeping.report import reportingUtils
from armi.operators import settingsValidation
from armi.operators.runTypes import RunTypes
from armi.physics.fuelCycle.settings import CONF_SHUFFLE_LOGIC
from armi.utils import codeTiming
from armi.utils import (
pathTools,
Expand Down Expand Up @@ -1037,7 +1038,7 @@ def snapshotRequest(self, cycle, node):
newFolder,
)
pathTools.copyOrWarn(
"Shuffle logic for snapshot", self.cs["shuffleLogic"], newFolder
"Shuffle logic for snapshot", self.cs[CONF_SHUFFLE_LOGIC], newFolder
)
pathTools.copyOrWarn(
"Geometry file for snapshot", self.cs["geomFile"], newFolder
Expand Down
2 changes: 1 addition & 1 deletion armi/physics/fuelCycle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def exposeInterfaces(cs):
The interface may import user input modules to customize the actual
fuel management.
"""
fuelHandlerNeedsToBeActive = cs["fuelHandlerName"] or (
fuelHandlerNeedsToBeActive = cs[settings.CONF_FUEL_HANDLER_NAME] or (
cs["eqDirect"] and cs["runType"].lower() == RunTypes.STANDARD.lower()
)
if not fuelHandlerNeedsToBeActive or "MCNP" in cs["neutronicsKernel"]:
Expand Down
5 changes: 3 additions & 2 deletions armi/physics/fuelCycle/assemblyRotationAlgorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from armi.physics.fuelCycle.hexAssemblyFuelMgmtUtils import (
getOptimalAssemblyOrientation,
)
from armi.physics.fuelCycle.settings import CONF_ASSEM_ROTATION_STATIONARY


def buReducingAssemblyRotation(fh):
Expand Down Expand Up @@ -58,7 +59,7 @@ def buReducingAssemblyRotation(fh):
)

# rotate NON-MOVING assemblies (stationary)
if fh.cs["assemblyRotationStationary"]:
if fh.cs[CONF_ASSEM_ROTATION_STATIONARY]:
for a in hist.getDetailAssemblies():
if a not in fh.moved:
rot = getOptimalAssemblyOrientation(a, a)
Expand Down Expand Up @@ -98,7 +99,7 @@ def simpleAssemblyRotation(fh):
numRotated = 0
hist = fh.o.getInterface("history")
for a in hist.getDetailAssemblies():
if a in fh.moved or fh.cs["assemblyRotationStationary"]:
if a in fh.moved or fh.cs[CONF_ASSEM_ROTATION_STATIONARY]:
a.rotatePins(1)
numRotated += 1
i, j = a.spatialLocator.getRingPos() # hex indices (i,j) = (ring,pos)
Expand Down
6 changes: 4 additions & 2 deletions armi/physics/fuelCycle/fuelHandlerFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

"""factory for the FuelHandler"""
from armi.physics.fuelCycle import fuelHandlers
from armi.physics.fuelCycle.settings import CONF_FUEL_HANDLER_NAME
from armi.physics.fuelCycle.settings import CONF_SHUFFLE_LOGIC
from armi.utils import directoryChangers, pathTools


Expand All @@ -26,8 +28,8 @@ def fuelHandlerFactory(operator):
called again to instantiate a new FuelHandler.
"""
cs = operator.cs
fuelHandlerClassName = cs["fuelHandlerName"]
fuelHandlerModulePath = cs["shuffleLogic"]
fuelHandlerClassName = cs[CONF_FUEL_HANDLER_NAME]
fuelHandlerModulePath = cs[CONF_SHUFFLE_LOGIC]

if not fuelHandlerClassName:
# give the default FuelHandler. This does not have an implemented outage, but
Expand Down
19 changes: 12 additions & 7 deletions armi/physics/fuelCycle/fuelHandlerInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

"""A place for the FuelHandler's Interface"""

from armi import runLog
from armi import interfaces
from armi.utils import plotting
from armi import runLog
from armi.physics.fuelCycle import fuelHandlerFactory
from armi.physics.fuelCycle.settings import CONF_PLOT_SHUFFLE_ARROWS
from armi.physics.fuelCycle.settings import CONF_RUN_LATTICE_BEFORE_SHUFFLING
from armi.physics.fuelCycle.settings import CONF_SHUFFLE_LOGIC
from armi.utils import plotting


class FuelHandlerInterface(interfaces.Interface):
Expand Down Expand Up @@ -48,7 +51,7 @@ def specifyInputs(cs):
cs.getSetting(settingName): [
cs[settingName],
]
for settingName in ["shuffleLogic", "explicitRepeatShuffles"]
for settingName in [CONF_SHUFFLE_LOGIC, "explicitRepeatShuffles"]
if cs[settingName]
}
return files
Expand All @@ -62,10 +65,12 @@ def interactBOC(self, cycle=None):
# if lattice physics is requested, compute it here instead of after fuel management.
# This enables XS to exist for branch searching, etc.
mc2 = self.o.getInterface(function="latticePhysics")
if mc2 and self.cs["runLatticePhysicsBeforeShuffling"]:
if mc2 and self.cs[CONF_RUN_LATTICE_BEFORE_SHUFFLING]:
runLog.extra(
'Running {0} lattice physics before fuel management due to the "runLatticePhysicsBeforeShuffling"'
" setting being activated.".format(mc2)
'Running {0} lattice physics before fuel management due to the "{1}"'
" setting being activated.".format(
mc2, CONF_RUN_LATTICE_BEFORE_SHUFFLING
)
)
mc2.interactBOC(cycle=cycle)

Expand Down Expand Up @@ -104,7 +109,7 @@ def manageFuel(self, cycle):
self.r.core.locateAllAssemblies()
shuffleFactors, _ = fh.getFactorList(cycle)
fh.outage(shuffleFactors) # move the assemblies around
if self.cs["plotShuffleArrows"]:
if self.cs[CONF_PLOT_SHUFFLE_ARROWS]:
arrows = fh.makeShuffleArrows()
plotting.plotFaceMap(
self.r.core,
Expand Down
15 changes: 10 additions & 5 deletions armi/physics/fuelCycle/fuelHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from armi.physics.fuelCycle import assemblyRotationAlgorithms as rotAlgos
from armi.physics.fuelCycle.fuelHandlerFactory import fuelHandlerFactory
from armi.physics.fuelCycle.fuelHandlerInterface import FuelHandlerInterface
from armi.physics.fuelCycle.settings import CONF_ASSEMBLY_ROTATION_ALG
from armi.reactor.flags import Flags
from armi.utils.customExceptions import InputError

Expand Down Expand Up @@ -117,17 +118,21 @@ def outage(self, factor=1.0):
self.chooseSwaps(factor)

# do rotations if pin-level details are available (requires fluxRecon plugin)
if self.cs["fluxRecon"] and self.cs["assemblyRotationAlgorithm"]:
if self.cs["fluxRecon"] and self.cs[CONF_ASSEMBLY_ROTATION_ALG]:
# Rotate assemblies ONLY IF at least some assemblies have pin detail
# The user can choose the algorithm method name directly in the settings
if hasattr(rotAlgos, self.cs["assemblyRotationAlgorithm"]):
rotationMethod = getattr(rotAlgos, self.cs["assemblyRotationAlgorithm"])
if hasattr(rotAlgos, self.cs[CONF_ASSEMBLY_ROTATION_ALG]):
rotationMethod = getattr(rotAlgos, self.cs[CONF_ASSEMBLY_ROTATION_ALG])
rotationMethod()
else:
raise RuntimeError(
"FuelHandler {0} does not have a rotation algorithm called {1}.\n"
'Change your "assemblyRotationAlgorithm" setting'
"".format(rotAlgos, self.cs["assemblyRotationAlgorithm"])
"Change your {2} setting"
"".format(
rotAlgos,
self.cs[CONF_ASSEMBLY_ROTATION_ALG],
CONF_ASSEMBLY_ROTATION_ALG,
)
)

# inform the reactor of how many moves occurred so it can put the number in the database.
Expand Down
30 changes: 15 additions & 15 deletions armi/physics/fuelCycle/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def getFuelCycleSettingValidators(inspector):

queries.append(
settingsValidation.Query(
lambda: bool(inspector.cs["shuffleLogic"])
^ bool(inspector.cs["fuelHandlerName"]),
lambda: bool(inspector.cs[CONF_SHUFFLE_LOGIC])
^ bool(inspector.cs[CONF_FUEL_HANDLER_NAME]),
"A value was provided for `fuelHandlerName` or `shuffleLogic`, but not "
"the other. Either both `fuelHandlerName` and `shuffleLogic` should be "
"defined, or neither of them.",
Expand Down Expand Up @@ -177,15 +177,15 @@ def getFuelCycleSettingValidators(inspector):
]

def _locateRegexOccurences():
with open(inspector._csRelativePath(inspector.cs["shuffleLogic"])) as src:
with open(inspector._csRelativePath(inspector.cs[CONF_SHUFFLE_LOGIC])) as src:
src = src.read()
matches = []
for pattern, _sub in regex_solutions:
matches += re.findall(pattern, src)
return matches

def _applyRegexSolutions():
srcFile = inspector._csRelativePath(inspector.cs["shuffleLogic"])
srcFile = inspector._csRelativePath(inspector.cs[CONF_SHUFFLE_LOGIC])
destFile = os.path.splitext(srcFile)[0] + "migrated.py"
with open(srcFile) as src, open(destFile, "w") as dest:
srcContent = src.read() # get the buffer content
Expand All @@ -198,42 +198,42 @@ def _applyRegexSolutions():
dest.write("from armi import runLog\n")
dest.write(regexContent)

inspector.cs = inspector.cs.modified(newSettings={"shuffleLogic": destFile})
inspector.cs = inspector.cs.modified(newSettings={CONF_SHUFFLE_LOGIC: destFile})

queries.append(
settingsValidation.Query(
lambda: " " in inspector.cs["shuffleLogic"],
lambda: " " in inspector.cs[CONF_SHUFFLE_LOGIC],
"Spaces are not allowed in shuffleLogic file location. You have specified {0}. "
"Shuffling will not occur.".format(inspector.cs["shuffleLogic"]),
"Shuffling will not occur.".format(inspector.cs[CONF_SHUFFLE_LOGIC]),
"",
inspector.NO_ACTION,
)
)

def _clearShufflingInput():
inspector._assignCS("shuffleLogic", "")
inspector._assignCS("fuelHandlerName", "")
inspector._assignCS(CONF_SHUFFLE_LOGIC, "")
inspector._assignCS(CONF_FUEL_HANDLER_NAME, "")

queries.append(
settingsValidation.Query(
lambda: inspector.cs["shuffleLogic"]
and not inspector._csRelativePathExists(inspector.cs["shuffleLogic"]),
lambda: inspector.cs[CONF_SHUFFLE_LOGIC]
and not inspector._csRelativePathExists(inspector.cs[CONF_SHUFFLE_LOGIC]),
"The specified shuffle logic file '{0}' cannot be found. "
"Shuffling will not occur.".format(inspector.cs["shuffleLogic"]),
"Shuffling will not occur.".format(inspector.cs[CONF_SHUFFLE_LOGIC]),
"Clear specified file value?",
_clearShufflingInput,
)
)

queries.append(
settingsValidation.Query(
lambda: inspector.cs["shuffleLogic"]
and inspector._csRelativePathExists(inspector.cs["shuffleLogic"])
lambda: inspector.cs[CONF_SHUFFLE_LOGIC]
and inspector._csRelativePathExists(inspector.cs[CONF_SHUFFLE_LOGIC])
and _locateRegexOccurences(),
"The shuffle logic file {} uses deprecated code."
" It will not work unless you permit some automated changes to occur."
" The logic file will be backed up to the current directory under a timestamped name"
"".format(inspector.cs["shuffleLogic"]),
"".format(inspector.cs[CONF_SHUFFLE_LOGIC]),
"Proceed?",
_applyRegexSolutions,
)
Expand Down
Loading