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

Inherit XS Settings when creating a new XS ID #1653

Merged
merged 16 commits into from
Jun 7, 2024
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
30 changes: 23 additions & 7 deletions armi/physics/neutronics/crossSectionGroupManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@

import numpy

from armi import context
from armi import interfaces
from armi import runLog
from armi import context, interfaces, runLog
from armi.physics.neutronics import LatticePhysicsFrequency
from armi.physics.neutronics.const import CONF_CROSS_SECTION
from armi.reactor import flags
from armi.reactor.components import basicShapes
from armi.reactor.flags import Flags
from armi.utils.units import TRACE_NUMBER_DENSITY
from armi.physics.neutronics import LatticePhysicsFrequency

ORDER = interfaces.STACK_ORDER.BEFORE + interfaces.STACK_ORDER.CROSS_SECTIONS

Expand Down Expand Up @@ -874,11 +873,11 @@ def interactBOL(self):
reactor state.
"""
# now that all cs settings are loaded, apply defaults to compound XS settings
from armi.physics.neutronics.settings import CONF_XS_BLOCK_REPRESENTATION
from armi.physics.neutronics.settings import (
CONF_DISABLE_BLOCK_TYPE_EXCLUSION_IN_XS_GENERATION,
CONF_LATTICE_PHYSICS_FREQUENCY,
CONF_XS_BLOCK_REPRESENTATION,
)
from armi.physics.neutronics.settings import CONF_LATTICE_PHYSICS_FREQUENCY

self.cs[CONF_CROSS_SECTION].setDefaults(
self.cs[CONF_XS_BLOCK_REPRESENTATION],
Expand Down Expand Up @@ -1233,8 +1232,19 @@ def createRepresentativeBlocksUsingExistingBlocks(
for newXSID in modifiedReprBlocks:
oldXSID = origXSIDsFromNew[newXSID]
oldBlockCollection = blockCollectionByXsGroup[oldXSID]

# create a new block collection that inherits all of the properties
# and settings from oldBlockCollection.
if len(oldBlockCollection._validRepresentativeBlockTypes) > 0:
validBlockTypes = []
for flag in oldBlockCollection._validRepresentativeBlockTypes:
validBlockTypes.append(flags._toString(Flags, flag))
else:
validBlockTypes = None
newBlockCollection = oldBlockCollection.__class__(
oldBlockCollection.allNuclidesInProblem
oldBlockCollection.allNuclidesInProblem,
validBlockTypes=validBlockTypes,
averageByComponent=oldBlockCollection.averageByComponent,
john-science marked this conversation as resolved.
Show resolved Hide resolved
)
newBlockCollectionsByXsGroup[newXSID] = newBlockCollection
return newBlockCollectionsByXsGroup, modifiedReprBlocks, origXSIDsFromNew
Expand Down Expand Up @@ -1293,6 +1303,12 @@ def _getModifiedReprBlocks(self, blockList, originalRepresentativeBlocks):
if b.getMicroSuffix() == origXSID:
b.p.xsType = newXSType

# copy XS settings to new XS ID
self.cs[CONF_CROSS_SECTION][newXSID] = copy.deepcopy(
self.cs[CONF_CROSS_SECTION][origXSID]
)
self.cs[CONF_CROSS_SECTION][newXSID].xsID = newXSID

return modifiedReprBlocks, origXSIDsFromNew

def getNextAvailableXsTypes(self, howMany=1, excludedXSTypes=None):
Expand Down
45 changes: 34 additions & 11 deletions armi/physics/neutronics/tests/test_crossSectionManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

:py:mod:`armi.physics.neutronics.crossSectionGroupManager`
"""
from io import BytesIO
import copy
import os
import unittest
from io import BytesIO
from unittest.mock import MagicMock

from six.moves import cPickle
Expand All @@ -29,28 +29,25 @@
from armi.physics.neutronics import crossSectionGroupManager
from armi.physics.neutronics.const import CONF_CROSS_SECTION
from armi.physics.neutronics.crossSectionGroupManager import (
AverageBlockCollection,
BlockCollection,
CrossSectionGroupManager,
FluxWeightedAverageBlockCollection,
)
from armi.physics.neutronics.crossSectionGroupManager import (
MedianBlockCollection,
AverageBlockCollection,
)
from armi.physics.neutronics.crossSectionGroupManager import CrossSectionGroupManager
from armi.physics.neutronics.crossSectionSettings import XSModelingOptions
from armi.physics.neutronics.fissionProductModel.tests import test_lumpedFissionProduct
from armi.physics.neutronics.settings import (
CONF_XS_BLOCK_REPRESENTATION,
CONF_LATTICE_PHYSICS_FREQUENCY,
CONF_XS_BLOCK_REPRESENTATION,
)
from armi.reactor.blocks import HexBlock
from armi.reactor.flags import Flags
from armi.reactor.tests import test_reactors, test_blocks
from armi.tests import TEST_ROOT
from armi.tests import mockRunLogs
from armi.reactor.tests import test_blocks, test_reactors
from armi.tests import TEST_ROOT, mockRunLogs
from armi.utils import units
from armi.utils.directoryChangers import TemporaryDirectoryChanger


THIS_DIR = os.path.dirname(os.path.abspath(__file__))


Expand Down Expand Up @@ -829,7 +826,25 @@ def test_createRepresentativeBlocksUsingExistingBlocks(self):
This tests that the XS ID of the new representative block is correct and that the
compositions are identical between the original and the new representative blocks.
"""
_o, r = test_reactors.loadTestReactor(TEST_ROOT)
o, r = test_reactors.loadTestReactor(TEST_ROOT)
# set a few random non-default settings on AA to be copied to the new BA group
o.cs[CONF_CROSS_SECTION].update(
{
"AA": XSModelingOptions(
"AA",
geometry="0D",
averageByComponent=True,
xsMaxAtomNumber=60,
criticalBuckling=False,
xsPriority=2,
)
}
)
o.cs[CONF_CROSS_SECTION].setDefaults(
crossSectionGroupManager.AVERAGE_BLOCK_COLLECTION, ["fuel"]
)
aaSettings = o.cs[CONF_CROSS_SECTION]["AA"]
self.csm.cs = copy.deepcopy(o.cs)
self.csm.createRepresentativeBlocks()
unperturbedReprBlocks = copy.deepcopy(self.csm.representativeBlocks)
self.assertNotIn("BA", unperturbedReprBlocks)
Expand All @@ -852,6 +867,14 @@ def test_createRepresentativeBlocksUsingExistingBlocks(self):
)
self.assertEqual(origXSIDsFromNew["BA"], "AA")

# check that settings were copied correctly
baSettings = self.csm.cs[CONF_CROSS_SECTION]["BA"]
self.assertEqual(baSettings.xsID, "BA")
for setting, baSettingValue in baSettings.__dict__.items():
if setting == "xsID":
continue
self.assertEqual(baSettingValue, aaSettings.__dict__[setting])

def test_interactBOL(self):
"""Test `BOL` lattice physics update frequency.

Expand Down
2 changes: 2 additions & 0 deletions doc/release/0.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Bug Fixes
---------
#. Fixed four bugs with "corners up" hex grids. (`PR#1649 <https://github.com/terrapower/armi/pull/1649>`_)
#. Fixed ``safeCopy`` to work on both Windows and Linux with strict permissions (`PR#1691 <https://github.com/terrapower/armi/pull/1691>`_)
#. When creating a new XS group, inherit settings from initial group. (`PR#1653 <https://github.com/terrapower/armi/pull/1653>`_)

#. TBD

Quality Work
Expand Down
Loading