From ea74277df9d8ad0ba8083b132ee0106d69674534 Mon Sep 17 00:00:00 2001 From: jstilley Date: Wed, 30 Oct 2024 13:24:19 -0700 Subject: [PATCH] Adding setting to control MCNP / ENDF library --- armi/physics/neutronics/settings.py | 11 ++++ armi/reactor/blueprints/isotopicOptions.py | 19 +++--- .../blueprints/tests/test_customIsotopics.py | 60 ++++++++++++++++++- 3 files changed, 78 insertions(+), 12 deletions(-) diff --git a/armi/physics/neutronics/settings.py b/armi/physics/neutronics/settings.py index f9e23cabc..6d257bf3d 100644 --- a/armi/physics/neutronics/settings.py +++ b/armi/physics/neutronics/settings.py @@ -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" @@ -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", diff --git a/armi/reactor/blueprints/isotopicOptions.py b/armi/reactor/blueprints/isotopicOptions.py index dfb6af5d9..a3db5c506 100644 --- a/armi/reactor/blueprints/isotopicOptions.py +++ b/armi/reactor/blueprints/isotopicOptions.py @@ -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, ) @@ -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 = { @@ -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"]] @@ -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) diff --git a/armi/reactor/blueprints/tests/test_customIsotopics.py b/armi/reactor/blueprints/tests/test_customIsotopics.py index 4c341b45b..5a1271d73 100644 --- a/armi/reactor/blueprints/tests/test_customIsotopics.py +++ b/armi/reactor/blueprints/tests/test_customIsotopics.py @@ -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): @@ -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: @@ -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 @@ -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) + )