Skip to content

Commit

Permalink
Adding setting to control MCNP / ENDF library
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Oct 30, 2024
1 parent c885a05 commit ea74277
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 12 deletions.
11 changes: 11 additions & 0 deletions armi/physics/neutronics/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
CONF_INNERS_ = "inners"
CONF_LOADING_FILE = "loadingFile"
CONF_NEUTRONICS_KERNEL = "neutronicsKernel"
CONF_MCNP_LIB_BASE = "mcnpLibraryBaseName"
CONF_NEUTRONICS_TYPE = "neutronicsType"
CONF_NUMBER_MESH_PER_EDGE = "numberMeshPerEdge"
CONF_OUTERS_ = "outers"
Expand Down Expand Up @@ -172,6 +173,16 @@ def defineSettings():
options=[],
enforcedOptions=True,
),
setting.Setting(
CONF_MCNP_LIB_BASE,
default="ENDF/B-VII.1",
description=(
"Library name for MCNP cross sections. "
"ENDF/B-VII.1 is the default library. "
),
label="Default base library name",
options=["ENDF/B-VII.0", "ENDF/B-VII.1", "ENDF/B-VIII.0"],
),
setting.Setting(
CONF_NEUTRONICS_TYPE,
default="real",
Expand Down
19 changes: 8 additions & 11 deletions armi/reactor/blueprints/isotopicOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
CONF_FISSION_PRODUCT_LIBRARY_NAME,
)
from armi.physics.neutronics.settings import (
CONF_MCNP_LIB_BASE,
CONF_NEUTRONICS_KERNEL,
CONF_XS_KERNEL,
)
Expand Down Expand Up @@ -456,7 +457,6 @@ def getDefaultNuclideFlags():
We will include B10 and B11 without depletion, sodium, and structural elements.
We will include LFPs with depletion.
"""
nuclideFlags = {}
actinides = {
Expand Down Expand Up @@ -511,7 +511,6 @@ def eleExpandInfoBasedOnCodeENDF(cs):
For example: {oxygen: [oxygen16]} indicates that all
oxygen should be expanded to O16, ignoring natural
O17 and O18. (variables are Natural/NuclideBases)
"""
elementalsToKeep = set()
oxygenElementals = [nuclideBases.byName["O"]]
Expand All @@ -536,22 +535,20 @@ def eleExpandInfoBasedOnCodeENDF(cs):

if "MCNP" in cs[CONF_NEUTRONICS_KERNEL]:
expansionStrings.update(mcnpExpansions)
if int(cs["mcnpLibrary"]) == 50:
elementalsToKeep.update(nuclideBases.instances) # skip expansion
# ENDF/B VII.0
elif 70 <= int(cs["mcnpLibrary"]) <= 79:
if cs[CONF_MCNP_LIB_BASE] == "ENDF/B-VII.0":
elementalsToKeep.update(endf70Elementals)
# ENDF/B VII.1
elif 80 <= int(cs["mcnpLibrary"]) <= 89:
elif cs[CONF_MCNP_LIB_BASE] == "ENDF/B-VII.1":
elementalsToKeep.update(endf71Elementals)
# ENDF/B VIII.0
elif cs[CONF_MCNP_LIB_BASE] == "ENDF/B-VIII.0":
elementalsToKeep.update(endf80Elementals)
else:
raise InputError(
"Failed to determine nuclides for modeling. "
"The `mcnpLibrary` setting value ({}) is not supported.".format(
cs["mcnpLibrary"]
)
"Failed to determine nuclides for modeling. The `mcnpLibraryBaseName` "
f"setting value ({cs[CONF_MCNP_LIB_BASE]}) is not supported."
)

elif cs[CONF_XS_KERNEL] in ["", "SERPENT", "MC2v3", "MC2v3-PARTISN"]:
elementalsToKeep.update(endf70Elementals)
expansionStrings.update(mc2Expansions)
Expand Down
60 changes: 59 additions & 1 deletion armi/reactor/blueprints/tests/test_customIsotopics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@

import yamlize

from armi import runLog
from armi import settings
from armi.physics.neutronics.settings import CONF_MCNP_LIB_BASE
from armi.physics.neutronics.settings import CONF_NEUTRONICS_KERNEL
from armi.physics.neutronics.settings import CONF_XS_KERNEL
from armi.reactor import blueprints
from armi.reactor.blueprints import isotopicOptions
from armi.reactor.flags import Flags
from armi import runLog
from armi.tests import mockRunLogs
from armi.utils.customExceptions import InputError
from armi.utils.directoryChangers import TemporaryDirectoryChanger


class TestCustomIsotopics(unittest.TestCase):
Expand Down Expand Up @@ -529,6 +533,8 @@ class TestNuclideFlagsExpansion(unittest.TestCase):
SI: {burn: true, xs: true}
MO: {burn: true, xs: true}
W: {burn: true, xs: true}
ZN: {burn: true, xs: true}
O: {burn: true, xs: true}
blocks:
uzr fuel: &block_0
fuel:
Expand All @@ -546,6 +552,14 @@ class TestNuclideFlagsExpansion(unittest.TestCase):
id: 0.0
mult: 1.0
od: 10.0
dummy:
shape: Circle
material: ZnO
Tinput: 25.0
Thot: 600.0
id: 0.0
mult: 1.0
od: 10.0
assemblies:
fuel a:
specifier: IC
Expand All @@ -568,3 +582,47 @@ def test_expandedNatural(self):
self.assertNotIn("FE56", nd) # natural isotopic not requested
self.assertNotIn("FE51", nd) # un-natural
self.assertNotIn("FE", nd)

def test_eleExpandInfoBasedOnCodeENDF(self):
with TemporaryDirectoryChanger():
# Reference elements to expand by library
ref_E70_elem = ["C", "V", "ZN"]
ref_E71_elem = ["C"]
ref_E80_elem = []

# Load settings and set neutronics kernel to MCNP
cs = settings.Settings()
cs = cs.modified(newSettings={CONF_NEUTRONICS_KERNEL: "MCNP"})

# Set ENDF/B-VII.0 as MCNP cross section library base
cs = cs.modified(newSettings={CONF_MCNP_LIB_BASE: "ENDF/B-VII.0"})
eleToKeep, expansions = isotopicOptions.eleExpandInfoBasedOnCodeENDF(cs)
E70_elem = [x.label for x in eleToKeep]

# Set ENDF/B-VII.1 as MCNP cross section library base
cs = cs.modified(newSettings={CONF_MCNP_LIB_BASE: "ENDF/B-VII.1"})
eleToKeep, expansions = isotopicOptions.eleExpandInfoBasedOnCodeENDF(cs)
E71_elem = [x.label for x in eleToKeep]

# Set ENDF/B-VIII.0 as MCNP cross section library base
cs = cs.modified(newSettings={CONF_MCNP_LIB_BASE: "ENDF/B-VIII.0"})
eleToKeep, expansions = isotopicOptions.eleExpandInfoBasedOnCodeENDF(cs)
E80_elem = [x.label for x in eleToKeep]

# Assert equality of returned elements to reference elements
self.assertEqual(sorted(E70_elem), sorted(ref_E70_elem))
self.assertEqual(sorted(E71_elem), sorted(ref_E71_elem))
self.assertEqual(sorted(E80_elem), sorted(ref_E80_elem))

# Disallowed inputs
not_allowed = ["ENDF/B-VIIII.0", "ENDF/B-VI.0", "JEFF-3.3"]
# Assert raise InputError in case of invalid library setting
for x in not_allowed:
with self.assertRaises(InputError) as context:
cs = cs.modified(newSettings={CONF_MCNP_LIB_BASE: x})
_ = isotopicOptions.eleExpandInfoBasedOnCodeENDF(cs)

self.assertTrue(
"Failed to determine nuclides for modeling"
in str(context.exception)
)

0 comments on commit ea74277

Please sign in to comment.