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

Adding a check on the grid/component consistency in the blueprints #2045

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
25 changes: 25 additions & 0 deletions armi/reactor/blueprints/blockBlueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def construct(

self._checkByComponentMaterialInput(materialInput)

allLatticeIds = set()
for componentDesign in self:
filteredMaterialInput, byComponentMatModKeys = self._filterMaterialInput(
materialInput, componentDesign
Expand Down Expand Up @@ -184,6 +185,30 @@ def construct(
# learn mult from grid definition
c.setDimension("mult", len(c.spatialLocator))

idsInGrid = list(gridDesign.gridContents.values())
if componentDesign.latticeIDs:
for latticeID in componentDesign.latticeIDs:
allLatticeIds.add(str(latticeID))
# the user has given this component latticeIDs. check that
# each of the ids appears in the grid, otherwise
# their blueprints are probably wrong
if len([i for i in idsInGrid if i == str(latticeID)]) == 0:
raise ValueError(
f"latticeID {latticeID} in block blueprint '{self.name}' is expected "
"to be present in the associated block grid. "
"Check that the component's latticeIDs align with the block's grid."
)
Comment on lines +188 to +200
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought.

This method is suddenly quite long.

Could we move this to a private helper method that just does the error handling? What do you think?


# for every id in grid, confirm that at least one component had it
if gridDesign:
idsInGrid = list(gridDesign.gridContents.values())
for idInGrid in idsInGrid:
if str(idInGrid) not in allLatticeIds:
raise ValueError(
f"ID {idInGrid} in grid {gridDesign.name} is not in any components of block {self.name}. "
"All IDs in the grid must appear in at least one component."
)
Comment on lines +202 to +210
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought.

This method is suddenly quite long.

Could we move this to a private helper method that just does the error handling? What do you think?


# check that the block level mat mods use valid options in the same way
# as we did for the by-component mods above
validMatModOptions = self._getBlockwiseMaterialModifierOptions(
Expand Down
63 changes: 61 additions & 2 deletions armi/reactor/blueprints/tests/test_blockBlueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,41 @@
- - - 1 1 1 1
- - 1 1 2 1 1
- 1 1 1 1 1 1
1 3 1 2 1 3 1
1 2 1 2 1 2 1
1 1 1 1 1 1
1 1 2 1 1
1 1 1 1

"""

FULL_BP_ERRANT_ID = (
FULL_BP.split("lattice map:")[0]
+ """lattice map: |
- - - 1 1 1 1
- - 1 1 1 1 1
- 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1
1 1 1 1

"""
)

FULL_BP_NO_COMP = (
FULL_BP.split("lattice map:")[0]
+ """lattice map: |
- - - 1 1 1 1
- - 1 1 1 1 1
- 1 1 1 1 1 1
1 3 1 1 1 3 1
1 1 1 1 1 1
1 1 1 1 1
1 1 1 1

"""
)

FULL_BP_GRID = (
FULL_BP.split("lattice map:")[0]
+ """grid contents:
Expand Down Expand Up @@ -276,7 +304,7 @@ def test_getLocatorsAtLatticePositions(self):
gridDesign = bDesign._getGridDesign(self.blueprints)
grid = gridDesign.construct()
locators = gridDesign.getLocators(grid, ["2"])
self.assertEqual(len(locators), 3)
self.assertEqual(len(locators), 5)
self.assertIs(grid[locators[0].getCompleteIndices()], locators[0])

def test_blockLattice(self):
Expand All @@ -297,6 +325,37 @@ def test_blockLattice(self):
seen = True
self.assertTrue(seen)

def test_componentsNotInLattice(self):
"""
Ensure that we catch cases when a component is expected to be in the grid,
but is not. In this case, latticeID "2" is not in the lattice.
"""
with self.assertRaises(ValueError) as ee:
with io.StringIO(FULL_BP_ERRANT_ID) as stream:
self.blueprints = blueprints.Blueprints.load(stream)
self.blueprints._prepConstruction(self.cs)

self.assertIn(
"Check that the component's latticeIDs align with the block's grid.",
ee.args[0],
)

def test_latticeNotInComponents(self):
"""
Ensure that we catch cases when a latticeID listed in the grid is not present
in any of the components on the block. In this case, latticeID "2" is not
in the lattice.
"""
with self.assertRaises(ValueError) as ee:
with io.StringIO(FULL_BP_NO_COMP) as stream:
self.blueprints = blueprints.Blueprints.load(stream)
self.blueprints._prepConstruction(self.cs)

self.assertIn(
"All IDs in the grid must appear in at least one component.",
ee.args[0],
)

def test_nonLatticeComponentHasRightMult(self):
"""Make sure non-grid components in blocks with grids get the right multiplicity."""
aDesign = self.blueprints.assemDesigns.bySpecifier["IC"]
Expand Down
2 changes: 1 addition & 1 deletion armi/reactor/blueprints/tests/test_gridBlueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def test_simpleReadLatticeMap(self):
before, after = outText.split("lattice map:")
self.assertGreater(len(before), 100)
self.assertGreater(len(after), 20)
self.assertIn("1 3 1 2 1 3 1", after, msg="lattice map not showing up")
self.assertIn("1 2 1 2 1 2 1", after, msg="lattice map not showing up")
self.assertNotIn(
"- -3", after, msg="grid contents are showing up when they shouldn't"
)
Expand Down
4 changes: 0 additions & 4 deletions armi/tests/c5g7/c5g7-blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ blocks:
widthInner: 21.42
widthOuter: 21.42
mult: 1.0
latticeIDs: [FC]
# latticeIDs is needed to ensure that the center of the bounding
# Component shares the same center/origin as the rest of the
# components in the block. See #332."
# end-block-uo2
mox: &block_mox
grid name: MOX grid
Expand Down